Reputation: 294
Problem, perhaps, simple: I can't figure out how to get the skybox and apply it to my shader.
I think I'm close but how do I take the skybox from the scene??
mygameobjec.GetComponent<Renderer>().material.SetTexture("_SkyReflection",Skybox.material.Texture??);
Thanks
Upvotes: 0
Views: 704
Reputation: 1268
Try RenderSettings.skybox.mainTexture.
https://docs.unity3d.com/ScriptReference/RenderSettings-skybox.html
A tip though: it is also possible to access the current reflection environment inside the shader from a shader global called unity_SpecCube0. Here is a function i often use in my shaders:
// 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);
}
Upvotes: 1