Hello everyone, I'm quite new to Unity Shaders and want to find out how a simple deferred shader works in unity. I found some tutorials online but it's not that what i know from my studies with openGL and GLSL. Well I know that deferred shading works with multiple passes. First fill your g-buffer and use your results in a second pass. With my openGL setup it was quite easy that i filled the buffer and then send these textures to the second pass into my fragment shader. So in Unity it seams to be quite easy to make multiple passes in one shader file. This is a little pseudo Code I already have until now. Code (CSharp): Shader "Deferred Shader" { Properties { ...some properties for inspector. } SubShader { // My First Pass to fill G-Buffer Pass { Tags{ "LightMode" = "Deferred" } // Data that my fragmentshader has to safe struct fragmentdata { half4 albedo : SV_Target0; half4 specular : SV_Target1; half4 normal : SV_Target2; half4 position : SV_Target3; }; vertexdata vert(appdata_base) { vertexdata vs; .. do simple calcus return vs } fragmentdata frag(vertexdata vs) { //Fill my textures for SVTarget 0 -3 with data from inspector and VS shader. } } This seams to work... If i switch to deferred lighting in unity and check the single channels i can see the correct result. So now I want to use these textures in my second "lightpass" The following code i placed below the deferred base: Code (CSharp): // My second Pass to make lighting Pass { Tags{ "LightMode" = "ForwardBase" } //ini gbuffer read var. // these vars are global and should have the result from the SV_Target 0...3 right??? sampler2D _CameraGBufferTexture0; sampler2D _CameraGBufferTexture1; sampler2D _CameraGBufferTexture2; sampler2D _CameraGBufferTexture3; struct v2f { . . . }; v2f vert(appdata_base) { v2f fr .. do simple calcus return fr } fixed4 frag(v2f fr) { //Get GBuffers with: float4 albedo = tex2D(_CameraGBufferTexture0, fr.uv); . . . // Calculate Light with Phong return final color //calculated by gbuffer textures. } } This second pass has... well no effect at all. So what is my main problem? What do I have to do to setup the light pass in unity after filling the gbuffer? I hope you can get an idea of my problem :-D. Thank you =).
The forward base pass is only used for forward rendering. If your shader has a deferred pass it'll skip the forward passes when being rendered using the deferred pipeline. All deferred lighting passes are done with an internal deferred shading shader which you can override in the graphics settings. But all deferred objects will use that shader for lighting once it's overridden.
Hello, ah okay I didn't see that internal shader. Okay this makes sense. Thank you very much! Now I understand a tutorial that i found yesterday... Thanks for your hint <3.