Search Unity

Possible to get Skybox Cubemap ref from within shader?

Discussion in 'Shaders' started by Warrior1424, Feb 27, 2018.

  1. Warrior1424

    Warrior1424

    Joined:
    Sep 30, 2010
    Posts:
    984
    Is it possible to get the current skybox material's cubemap from within a shader?
    Kind of like how you can use "unity_FogDensity" to get the global fog density setting.

    So instead of having a public cubemap variable that I drag a cubemap into for my material, it would just pull the skybox's cubemap one into the shader.


    EDIT: This might make it easier. Even if I can access " RenderSettings.customReflection" via a shader I can do what I want. I've been digging through cginc files to find any references to properties but haven't had any luck yet.
     
    Last edited: Feb 28, 2018
  2. Warrior1424

    Warrior1424

    Joined:
    Sep 30, 2010
    Posts:
    984
    Ok so not the cleanest solution, but currently I have a script that sets my global shader property to the custom reflection probe in the render settings:

    Code (CSharp):
    1. Shader.SetGlobalTexture("_Sky", RenderSettings.customReflection);
    This code is on an empty gameobject, set to run on awake and to run in the editor.
     
  3. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    From the unity vertex and fragment examples:
    Code (CSharp):
    1. // sample the default reflection cubemap, using the reflection vector
    2. half4 skyData = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, i.worldRefl);
    3. // decode cubemap data into actual color
    4. half3 skyColor = DecodeHDR (skyData, unity_SpecCube0_HDR);
     
    i9mobile and mtessmann like this.