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
1
Question by 1danielcoelho · Aug 28, 2016 at 01:25 PM · shadershadowstransparencycutout

No shadows when looking through a cutout shader

I'm trying to have a custom cutout shader cast shadows (blue arrow), and allow shadows to be seen through the cutout (red arrow). As you can see, none of that is happening right now.

alt text

(Its a cube with the cutout shader intersecting a default cube below, viewed from the top with an orthographic camera)

I need a custom shader because the border cutout detail is stored in a separate detail texture. My shader code is below:

 Shader "Custom/TerrainShader" {
     Properties {
         _Color ("Color", Color) = (1,1,1,1)
         _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
         _DetailTex ("Detail (RGB)", 2D) = "white" {}
     }
     SubShader {
         Tags { "Queue"="AlphaTest" "RenderType"="TransparentCutout" }
         LOD 200
         
         CGPROGRAM        
         #pragma surface surf Standard fullforwardshadows alphatest:_Cutoff
                 
         #pragma target 3.0
 
         sampler2D _MainTex;
         sampler2D _DetailTex;        
         fixed4 _Color;
 
         struct Input {
             float2 uv_MainTex;
             float2 uv2_DetailTex;
         };
 
         void surf (Input IN, inout SurfaceOutputStandard o) {            
             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color * tex2D(_DetailTex, IN.uv2_DetailTex);
             o.Albedo = c.rgb;
             o.Alpha = c.a;
         }
         ENDCG
     }
     FallBack "Transparent/Cutout/Diffuse"
 }

It is based on the old Transparent/Cutout/Diffuse shaders, but also samples the detail texture I described.

If I change the Queue to Overlay, it draws on top of the shadow casting and I can see shadows through the cutout (red arrow), but obviously it doesn't cast its own shadows then. I think I have to alter the shadow pass to make it discard the alpha pixels in the detail texture, but that wouldn't solve the problem pointed at by the red arrow, I think.

Any ideas?

noshadow.png (21.5 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

2 Replies

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

Answer by 1danielcoelho · Aug 29, 2016 at 09:20 AM

User bgolus on UnityForums nailed the solution with his post.

Basically I needed to add addshadow to my pragma line, since that makes Unity generate a custom shadow caster pass for my surface shader, which takes my custom _DetailTex into account. If I don't do that, it will use the shadow caster pass of my Fallback shader (Transparent/Cutout/Diffuse) instead, which doesn't know about my _DetailTex.

It now looks exactly as you would expect:

alt text


after.png (12.6 kB)
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
avatar image
3

Answer by Namey5 · Aug 28, 2016 at 09:15 PM

Add the "addshadow" keyword to the surface declaration.

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 1danielcoelho · Aug 28, 2016 at 09:22 PM 0
Share

That did it!

User bgolus on UnityForums gave a great explanation of why too

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Is there a way to have a transparent vertex shader recieve and cast Shadows? 0 Answers

Shader Depth Mask - Shadows with cutouts 2 Answers

Adding cutout transparency to a skin shader 0 Answers

(SOLVED) How to bake lightmaps with transparent cutout shader ? 2 Answers

An Outline like the Editor does in game, with transparency 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