Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MZGS · Apr 08, 2013 at 02:06 PM · shadershadowsshaderlabdeferred

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.

alt text alt text

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"
 }
forward rendering.png (244.3 kB)
deferred rendering.png (212.3 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MZGS · Apr 08, 2013 at 02:08 PM 0
Share

For the full scope of this endeavor, here is my material setup in the inspector. alt text

material.png (90.1 kB)

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Transparent w/ Full Shadowcasting in Unity 5 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges