Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ThisGuyThatsHere · Jun 15, 2017 at 08:42 PM · shaderalphatransparentvertex shadercutoff

Shader bug or code fault?

Hey, so I've got this weird problem, here is how my shader looks: alt text

but for some reason, based on camera rotation (and position!, for example it doesn't happen on Y=0 in a short radius around center) it becomes this: alt text

I just don't understand the problem here, code:

 Shader "Environment/Leaves"
 {
     Properties
     {
         _Tex ("Texture", 2D) = "white" {}
         _LightingTex ("Lighting Texture |R|", 2D) = "white" {}
         _LightingMult ("Lighting Multiplier", Float) = 1.0
         _Color ("Tint", Color) = (1,1,1,1)
         _Cutoff ("Alpha Cutoff", Range(0,1)) = 0.1
     }
     SubShader
     {
         Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
         LOD 100
 
         Pass
         {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             // make fog work
             #pragma multi_compile_fog
             
             #include "UnityCG.cginc"
             #include "UnityLightingCommon.cginc"
 
             #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight
             #include "AutoLight.cginc"
 
             struct appdata
             {
                 float4 vertex : POSITION;
                 float3 normal : NORMAL;
                 float2 texcoord : TEXCOORD0;
             };
 
             struct v2f
             {
                 float2 uv : TEXCOORD0;
                 SHADOW_COORDS(1)
                 fixed3 diffDef : COLOR0;
                 fixed3 diffRev : COLOR1;
                 float4 pos : SV_POSITION;
             };
             
             sampler2D _Tex;
             sampler2D _LightingTex;
             float4 _Tex_ST;
             
             v2f vert (appdata v)
             {
                 float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
 
                 v2f o;
                 o.pos = UnityObjectToClipPos(v.vertex);
                 o.uv = v.texcoord;
                 half3 worldNormal = UnityObjectToWorldNormal(v.normal);
                 half nlDef = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
                 half nlRev = max(0, dot(worldNormal * -1.0, _WorldSpaceLightPos0.xyz));
                 o.diffDef = nlDef * _LightColor0;
                 o.diffRev = nlRev * _LightColor0;
 
                 TRANSFER_SHADOW(o)
                 return o;
             }
 
             fixed4 _Color;
             float _Cutoff;
             float _LightingMult;
 
             float sum3 (fixed3 v) {
                 return v.x + v.y + v.z;
             }
 
             fixed4 frag (v2f i) : SV_Target
             {
                 fixed4 col = tex2D(_Tex, i.uv);
                 fixed4 lightOcc = tex2D(_LightingTex, i.uv) * _LightingMult;
                 clip(col.a - _Cutoff);
                 fixed shadow = SHADOW_ATTENUATION(i);
                 fixed3 light;
                 if(sum3(i.diffDef) > sum3(i.diffRev)) {
                     light = i.diffDef * shadow;
                 } else {
                     light = i.diffRev * shadow;
                 }
                 col.rgb *= light;
                 col += lightOcc;
                 col *= _Color;
                 return col;
             }
             ENDCG
         }

         // Simple shadow pass
         Pass
         {
             Tags {"LightMode"="ShadowCaster"}
 
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #pragma multi_compile_shadowcaster
             #include "UnityCG.cginc"
 
             struct v2f { 
                 float2 uv : TEXCOORD0;
                 V2F_SHADOW_CASTER;
             };
             
             sampler2D _Tex;
 
             v2f vert(appdata_base v)
             {
                 float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
 
                 v2f o;
                 o.uv = v.texcoord;
                 TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
                 return o;
             }
 
             float _Cutoff;
 
             float4 frag(v2f i) : SV_Target
             {
                 fixed4 col = tex2D(_Tex, i.uv);
                 clip(col.a - _Cutoff);
                 SHADOW_CASTER_FRAGMENT(i)
             }
             ENDCG
         }
     }
 }


as2.png (446.1 kB)
as1.png (411.0 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ThisGuyThatsHere · Jun 16, 2017 at 08:45 AM

Nevermind, the problem was kind of stupid, but if anyone has similar problem, dont forget:

 Tags {"LightMode"="ForwardBase"}


Comment
Add comment · Share
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

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

97 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Transparent shader: final alpha value wrong 2 Answers

Is it possible to tell unity not to render overlapping transparent objects after certain number of times? 1 Answer

[Unity5]how to change alpha by using shader. 1 Answer

transparent mode does not work at alpha=255 1 Answer

About shader! 0 Answers


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