Search code examples
unity-game-engineshadercgshaderlab

What is IN.worldRefl in surface shader Input struct?


The question is pretty straight-forward. I have no idea what IN.worldRefl stands for, I've seen some tutorials using it with cubemaps but I still have no clue.

Unity's description for it is very poor:

float3 worldRefl - contains world reflection vector if surface shader does not write to o.Normal.


Solution

  • I've been researching for a few days now and I have a hunch about what IN.worldRefl means.

    First I saw this image (found here):

    enter image description here

    So I guess that IN.worldRefl is the reflection of the camera ray in the surface of a polygon of an object, as shown in the image.

    When one set, for example, the emission of the SurfaceOutput to be the texture of a cubemap in the position corresponding to IN.worldRefl, that is

    samplerCUBE _Cube;
    void surf (Input IN, inout SurfaceOutput o) {
        o.Emission = texCUBE (_Cube, IN.worldRefl).rgb;
    }
    

    it means that, setting the object inside a cube with the given cubemap, the reflected ray of the camera in the object polygon' surface will cross the cube in a point. The color of this point will be emitted by the object in the position where the camera ray touches the object.

    I can be totally wrong but this makes sense to me.