• 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 kamac · Mar 21, 2014 at 06:02 PM · diffuse

Invisible textured object cast shadows

I've seen this question: http://answers.unity3d.com/questions/269292/having-an-invisible-object-that-casts-shadows.html?sort=oldest and now I am wondering how to make an invisible textured object cast shadows.

So, I'd like to have transparent/cutout/diffuse that would only cast the shadow, and wouldn't render the object itself. Possible?

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

Answer by kamac · Mar 23, 2014 at 09:08 AM

For those wondering, and for future myself, it is possible, and here's the shader:

 Shader "Transparent/InvisibleShadowCasterTextured" 
 { 
 
     Properties 
     { 
          // Ususal stuffs
         _Color ("Main Color", Color) = (1,1,1,1)
         _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {}
         
         // Shadow Stuff
         _Cutoff ("Shadow Alpha cutoff", Range(0.25,0.9)) = 1.0
     } 
 
 
     SubShader 
     { 
         Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
     
         LOD 200
     
     
     
 // Pass to render object as a shadow caster
 Pass {
 Name "Caster"
 Tags { "LightMode" = "ShadowCaster" }
 Offset 1, 1
         
 Fog {Mode Off}
 ZWrite On ZTest LEqual Cull Off
 
 CGPROGRAM
 #pragma vertex vert
 #pragma fragment frag
 #pragma multi_compile_shadowcaster
 #include "UnityCG.cginc"
 
 struct v2f { 
     V2F_SHADOW_CASTER;
     float2  uv : TEXCOORD1;
 };
 
 uniform float4 _MainTex_ST;
 
 v2f vert( appdata_base v )
 {
     v2f o;
     TRANSFER_SHADOW_CASTER(o)
     o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
     return o;
 }
 
 uniform sampler2D _MainTex;
 uniform fixed _Cutoff;
 uniform fixed4 _Color;
 
 float4 frag( v2f i ) : COLOR
 {
     fixed4 texcol = tex2D( _MainTex, i.uv );
     clip( texcol.a*_Color.a - _Cutoff );
     
     SHADOW_CASTER_FRAGMENT(i)
 }
 ENDCG
 }
     
 // Pass to render object as a shadow collector
 Pass {
 Name "ShadowCollector"
 Tags { "LightMode" = "ShadowCollector" }
         
 Fog {Mode Off}
 ZWrite On ZTest LEqual
 
 CGPROGRAM
 #pragma vertex vert
 #pragma fragment frag
 #pragma multi_compile_shadowcollector
 
 #define SHADOW_COLLECTOR_PASS
 #include "UnityCG.cginc"
 
 struct v2f {
     V2F_SHADOW_COLLECTOR;
     float2  uv : TEXCOORD5;
 };
 
 uniform float4 _MainTex_ST;
 
 v2f vert (appdata_base v)
 {
     v2f o;
     TRANSFER_SHADOW_COLLECTOR(o)
     o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
     return o;
 }
 
 uniform sampler2D _MainTex;
 uniform fixed _Cutoff;
 uniform fixed4 _Color;
 
 fixed4 frag (v2f i) : COLOR
 {
     fixed4 texcol = tex2D( _MainTex, i.uv );
     clip( texcol.a*_Color.a - _Cutoff );
     
     SHADOW_COLLECTOR_FRAGMENT(i)
 }
 ENDCG
 }
     
     
         CGPROGRAM
         #pragma surface surf Lambert alphatest:_Cutoff
 
         sampler2D _MainTex;
         fixed4 _Color;
 
         struct Input {
             float2 uv_MainTex;
         };
 
         void surf (Input IN, inout SurfaceOutput o) {
             discard;
         }
         ENDCG
     }
     
     Fallback "Transparent/VertexLit"
 }
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

20 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

Related Questions

Some textures not affected by light? (With screenshots) 5 Answers

Cheap options for making diffuse-lit objects "interesting" 1 Answer

Change Main Color to Predefined colors randomly 1 Answer

Material doesn't have a texture property '_RendererColor' 1 Answer

Specular & alpha mapping 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