• 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 freddyhuu · Sep 11, 2013 at 09:51 AM · shadershadow

I create a cutout shader do not cut shadow!!!

Hello, guys. I created a cutout shader use for my game character, but the shadow do not cutout. look this: alt text

未标题-1副本.jpg (483.6 kB)
Comment
Add comment · Show 5
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 freddyhuu · Sep 11, 2013 at 09:55 AM 0
Share
     Properties{
          _AT ("Alphatest_Cutoff", Range(0, 1)) = 0.5}
 
     SubShader{
          Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
          
     Cull off
     ZWrite On
     ZTest LEqwal
     Color$$anonymous$$ask RGBA
     
     CGPROGRA$$anonymous$$
     #pragma surface surf BlinnPhongEditor vertex:vert Alphatest:_AT
     #pragma exclude_renderers gles
     #pragma target 3.0
     
     Fallback"Transparent/Cutout/Diffuse"
 
avatar image whydoidoit · Sep 11, 2013 at 09:56 AM 0
Share

Probably need to see the code...

avatar image freddyhuu · Sep 11, 2013 at 10:07 AM 0
Share

The left object in photo is used transparent/cutout/bump specular.It is right.

avatar image whydoidoit · Sep 12, 2013 at 02:54 AM 0
Share

There is no cutout happening in that cutout shader by the look of things, where is the surf function? The _AT function?

avatar image freddyhuu · Sep 12, 2013 at 03:13 AM 0
Share

Thank you for your answer~~~ whtdoidoit I have Properties { _AT ("AlphaTest_Cutoff", Range(0, 1)) = 0.5 } If i change _AT to _Cutout, they are the same result.

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Matou · Oct 24, 2014 at 02:18 PM

A bit late but maybe this can help:

As said above, you must add a fallback shader like

 Fallback "Transparent/Cutout/Diffuse"

BUT you also have to rename your "_AT" parameter in "_Cutoff" (case-sensitive!) because the fallback shader uses a "_Cutoff" parameter to compute shadows. For the same reason, you may have to add a "_Color" parameter too. I think the shadow computation part uses the alpha component of the "_Color" parameter to weight the fragment alpha output.

If you don't define those parameters or you use the wrong names, the shadow computation won't work correctly.

It took me very long to understand that. And I never saw this written anywhere in Unity doc... I had to make lots of experiment to finally get it...

Peace :)

Comment
Add comment · Show 1 · 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
avatar image bricevdm · Dec 18, 2016 at 04:12 PM 0
Share

you could also copy the shadow pass from another shader if you don't feel like exposing _Color or _Cutoff. "Legacy Shaders/Transparent/Cutout/VertexLit" for example, where you can see the actual computation and why those parameters are needed:

 float4 frag( v2f i ) : SV_Target
 {
     fixed4 texcol = tex2D( _$$anonymous$$ainTex, i.uv );
     clip( texcol.a * _Color.a  - _Cutoff );
             
     SHADOW_CASTER_FRAG$$anonymous$$ENT(i)
 }
avatar image
0

Answer by cod · Sep 11, 2013 at 10:30 AM

try to put at the end of the shader

 Fallback "Transparent/Cutout/Diffuse"

If I am right this should let your shader cast the right shadow, as it takes the shadow casting codes from it

I hope this helps and let me know if it works :)

Comment
Add comment · Show 1 · 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
avatar image freddyhuu · Sep 12, 2013 at 02:18 AM 0
Share

Thank you $$anonymous$$r.cod. I only a little Chinglish. Hah ha. 1st: I have used this"Fallback"Transparent/Cutout/Diffuse"", it is no use for this shader. 2nd: I also used Tags{"Light$$anonymous$$ode"="ShadowCaster"}, the shadow will be ok, but the material appears black, it is looks like no light.

avatar image
0

Answer by freddyhuu · Sep 12, 2013 at 06:58 AM

When i use projector shadow , it is all right. But it is no best way.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Only standard shader objects cast shadows in build. 0 Answers

Help with making a water shader receive light 1 Answer

how to add shadows to billboard shader help.... 2 Answers

Surface Reflection Shader with Shadows 0 Answers

Shadow catcher - possible? 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