Reflections and Normals not working in Deferred Rendering

Hi there.

I have a custom shader that has a normal map plus a reflection map to reflect back a cube map (reflection probe). The shader works perfectly well in Forward rendering mode, but only draws the diffuse texture in Deferred mode (which I need to switch to).

I’ve found that there’s very little documentation on writing surface shaders with deferred rendering so can someone please point me in the direction to making this work. The crux of the shader is below.

thanks

void surf(Input IN, inout SurfaceOutput o)
        {
            fixed4 d = tex2D(_MainTex, IN.uv_MainTex); //Get the diffuse texture
            o.Albedo = d.rgb; //Set the diffuse texture pixel to the output pixel

            o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));

            fixed4 c = tex2D(_RefectionTex, IN.uv_MainTex); //Get the Reflection texture

            half3 emission = tex2D(_EmissionMap, IN.uv_MainTex) * _EmissionColor;

            //This will grab whatever cube map is available from the first Reflection Probe it finds.
            if (c.a > 0.1f)
                o.Emission = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, WorldReflectionVector(IN, o.Normal)).rgb * c.a *_RefIntensity;

            o.Emission += emission.rgb;

            clip(d.a - _Alpha); //Add the alpha cutoff from the diffuse texture.
        }
        ENDCG

In deferred, the gbuffer passes (which is when the surface Shader gets run) doesn’t get any reflection probes by default. This is because in the deferred rendering path the reflections are calculated as deferred passes like lights. If you want to render something using the deferred rendering path that has reflections, you have to set the appropriate PBR material parameters to have it show those reflections. Using a Standard Specular shader might be the easiest option for you, or have your shader exclude itself from the deferred path and always render as forward.

Thanks, yes I looked at the standard specular shader which is why I wrote my own. The standard specular reflections are not strong enough and I wanted a shader that gave me a lot more control over the reflections.

Excluding the shader from the deferred path causes problems for other shaders and you get weird effects.

What are the PBR parameters to use?

thanks

Setting the specular color to white and the smoothness to 1.0 with the Standard Specular shader is the best you can do. If that’s not bright enough for you, you cannot use the deferred rendering path for that shader.

Note that the standard shading model that Unity uses is energy conserving. The short version of what that means is a fully white specular will completely mute the diffuse.

You’re probably better off adding exclude_path:deferred to your #pragma surface line to force it to render during the forward path.