- Home /
Shader not working properly in Deferred render mode
Hello everyone. I've been attempting to learn how to write my own shaders and so far so good; until I tested my shader in deferred render mode, that is. The shader works perfectly in forward mode, but in deferred mode the second pass doesn't seem to want to render at all (see images) or else its just using the fallback (Bumped Diffuse). Left image is forward rendering, Right image is deferred rendering.
Also, as you can see, the shader receives realtime shadows in deferred mode, but it does not cast them. I assume that I have to implement shadows in my shader, but I couldn't find anything useful on that subject...
Any insight would be much appreciated.
Here is my shader code:
Shader "Custom/FX Alpha Blend" {
Properties{
_MainColor ("Main Color", Color) = (1, 1, 1, 1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
_Shininess ("Shininess", Range (0.01, 1)) = 0.5
_MainTex ("Main Tex", 2D) = "white" {}
_BumpMap ("Normalmap", 2D) = "bump" {}
_FXColor ("FX Color", Color) = (1, 1, 1, 1)
_FXTex ("FX Tex", 2D) = "white" {}
_BlendTex ("Additive Blend Tex", 2D) = "white" {}
_BlendTex2 ("Additive Blend Tex 2", 2D) = "white" {}
}
SubShader {
//1st pass - bump, spec lighting on main tex
CGPROGRAM
#pragma surface surf BlinnPhong
fixed4 _MainColor;
sampler2D _MainTex;
sampler2D _BumpMap;
half _Shininess;
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = tex.rgb * _MainColor.rgb;
o.Gloss = tex.a;
o.Alpha = 1;
o.Specular = _Shininess;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG
//2nd Pass - FX and blend textures
Pass{
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
//Vertex
struct v2f {
float4 pos : POSITION;
float2 uv_fx : TEXCOORD0;
float2 uv_bt : TEXCOORD1;
float2 uv_bt2 : TEXCOORD2;
};
float4 _FXTex_ST;
float4 _BlendTex_ST;
float4 _BlendTex2_ST;
v2f vert(appdata_base v){
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv_fx = TRANSFORM_TEX(v.texcoord, _FXTex);
o.uv_bt = TRANSFORM_TEX(v.texcoord, _BlendTex);
o.uv_bt2 = TRANSFORM_TEX(v.texcoord, _BlendTex2);
return o;
}
//Frag
float4 _FXColor;
sampler2D _FXTex;
sampler2D _BlendTex;
sampler2D _BlendTex2;
half4 frag(v2f IN) : COLOR{
//Compute fx texture
half4 c_fx = tex2D (_FXTex, IN.uv_fx.xy) * _FXColor;
c_fx.rgb *= c_fx.a;
//Compute blend texture
half4 c_bt = tex2D (_BlendTex, IN.uv_bt.xy);
//Compute blend texture
half4 c_bt2 = tex2D (_BlendTex2, IN.uv_bt2.xy);
//Compute final color
c_fx.r *= max(c_bt.r, c_bt2.r);
c_fx.g *= max(c_bt.g, c_bt2.g);
c_fx.b *= max(c_bt.b, c_bt2.b);
return c_fx;
}
ENDCG
}
}
Fallback "Bumped Diffuse"
}
For the full scope of this endeavor, here is my material setup in the inspector.
Your answer
Follow this Question
Related Questions
combine deferred and forward rendering 0 Answers
Unity Shader Render Queue Causing Various Problems. 0 Answers
Simple shader Parse error: syntax error problem 0 Answers
clipping shader for OpenGL quad 0 Answers