Surface shader Lighting model in Deferred and Forward

Hi,
I’ve built a lighting model for forward rendering. I used :

half4 LightingMy (MySurfaceOutput s, half3 lightDir, half3 viewDir, half atten)

For me I can duplicate the model for deferred lighting but how ?
If I have :

half4 LightingMy_PrePass (MySurfaceOutput s, half4 light)

How can I access to viewDir, atten or lightDir ? In the PrePass how can I compute NdotL or NdotV ?
Should I used different path ? One for shadows and other for diffuse etc…

Thanks.

The deferred renderer doesn’t quite work in the same way as the forward renderer.

Deferred rendering essentially creates a bunch of textures that represents the scene - essentially a screengrab of the scene’s normals, diffuse colour, depth, etc - and then those textures can be lit as if they were a flat quad that fills the screen. The textures hold all of the required information for doing that. It’s a bit more complex than that, but that’s the gist of it.

So the deferred rendering pipeline only has one lighting function and that lighting function is applied to everything at once. I don’t have the filename to hand, but inside the built-in shader resources you can find the shader that the deferred renderer uses for it’s lighting. I think if you copy that file into your assets folder, you can edit the shader in there and it’ll use that one instead of the built-in one.

It’s what makes multiple lights so cheap in the deferred pipeline, because rather than several drawcalls for everything in your scene (one for each light affecting each model) it’s simply one draw call for each light regardless of what the light’s shining on, and it’s a bit cheaper to calculate because all the scene rendering’s already been done and it’s stored in those textures (which get called GBuffers in this case).

1 Like

I was asking why deferred if forward can handle multiple light but you outstrip my words :slight_smile:
Thanks for you answer.

Edit: Unfortunately I don’t see what file do you mean. In CGIncludes ?
Edit: I think I got it : Internal-PrePassLighting.shader

1 Like