【发布时间】:2019-10-12 12:44:30
【问题描述】:
问题可能很简单: 我不知道如何获取天空盒并将其应用到我的着色器。
我想我已经很接近了,但是如何从场景中取出天空盒??
mygameobjec.GetComponent<Renderer>().material.SetTexture("_SkyReflection",Skybox.material.Texture??);
谢谢
【问题讨论】:
标签: c# unity3d shader textures skybox
问题可能很简单: 我不知道如何获取天空盒并将其应用到我的着色器。
我想我已经很接近了,但是如何从场景中取出天空盒??
mygameobjec.GetComponent<Renderer>().material.SetTexture("_SkyReflection",Skybox.material.Texture??);
谢谢
【问题讨论】:
标签: c# unity3d shader textures skybox
试试 RenderSettings.skybox.mainTexture。
https://docs.unity3d.com/ScriptReference/RenderSettings-skybox.html
提示:也可以从名为 unity_SpecCube0 的着色器全局访问着色器内的当前反射环境。这是我经常在我的着色器中使用的一个函数:
// Returns the reflection color given a normal and view direction.
inline half3 SurfaceReflection(half3 viewDir, half3 worldNormal, half roughness) {
half3 worldRefl = reflect(-viewDir, worldNormal);
half r = roughness * 1.7 - 0.7 * roughness;
float4 reflData = UNITY_SAMPLE_TEXCUBE_LOD(
unity_SpecCube0, worldRefl, r * 6
);
return DecodeHDR (reflData, unity_SpecCube0_HDR);
}
【讨论】: