- Home /
Surface shader custom lighting model in deferred lighting
I have a custom lighting model that is working as expected in forward rendering. Following the documentation at https://docs.unity3d.com/Manual/SL-SurfaceShaderLighting.html I attempted to support deferred by adding a (...)_PrePass function. It did not appear to be working, so I scaled back to a basic example.
I am sure that I the project/camera is set to deferred because e.g. the frame debugger shows other objects using the standard shader drawing as you would expect in the RenderDeferred.x steps.
For example, following http://kylehalladay.com/blog/tutorial/2014/04/05/Writing-Shaders-For-Deferred-Lighting-Unity.html . That shader does not work either - it does not render anything.
Has anything changed in how this works? Here is the body of the example shader:
Shader "Custom/DeferredDiffuse"
{
Properties
{
_MainTex("Base (RGB)", 2D) = "white" {}
}
SubShader
{
Tags{ "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf MyDiffuse
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf(Input IN, inout SurfaceOutput o) {
half4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
float4 LightingMyDiffuse_PrePass(SurfaceOutput i, float4 light)
{
return float4(i.Albedo * light.rgb, 1.0);
}
ENDCG
}
}
Are you using Deferred or Pre Pass (Legacy Deferred)? Because these definitions would be for the latter. The shader should still be compatible in all 3 rendering paths.
@Namey5 Thanks for the comment. I was using deferred, when I switch to legacy deferred the object draws as expected.
Yeah, technically speaking the only shader compatible with full Deferred shading is the Standard shader. If you want to utilize elements of the G-Buffer but still use custom shaders, pre-pass (Deferred lighting) is the way to go.
Your answer
Follow this Question
Related Questions
Modify Gbuffer Layout / Add RenderTarget 2 Answers
Particle shaders not visible when using multiple cameras 0 Answers
Deferred Light Rendering: Prevent additional lighting passes on pixels in overlapping point lights 0 Answers
[Deferred Decals] Add simple specular channel to deffered decals 0 Answers
Is it possible to avoid writing to certain g-buffers? 1 Answer