• 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 gangafinti · Jul 08, 2015 at 09:10 PM · cg

Shadow caster shader

Hi, I am working on a vert/frag shader, and I displace the vertexes. The problem is that the shadow that is being cast by the object stays the same. Does anyone know how to edit the shadows that an object casts, I can't find ANY documentation on it exept this piece, but I dont know how to get it to work for my shader, if anyone knows where I can find documentation on it or how to adjust this pieces youll have my thanks for ever :)!

 Pass
         { 
             Name "ShadowCaster"
             Tags { "LightMode" = "ShadowCaster" }
 
             Fog {Mode Off}
             ZWrite On ZTest Less Cull Off
             Offset 1, 1
 
             CGPROGRAM
 
             #pragma vertex vert
             #pragma fragment frag
             #pragma fragmentoption ARB_precision_hint_fastest
             #pragma multi_compile_shadowcaster
             #include "UnityCG.cginc"
             
             struct v2f
             {
                 V2F_SHADOW_CASTER; 
                 float2 uv : TEXCOORD1;
             };
 
 
             v2f vert(appdata_full v )
             {
                v2f o;
                 TRANSFER_SHADOW_CASTER(o)
                  
               return o;
             }
 
             float4 frag( v2f i ) : COLOR
             {
                 fixed4 texcol = tex2D( _MainTex, i.uv );
                 clip( texcol.a - _Cutoff );
                 SHADOW_CASTER_FRAGMENT(i)
             }
             ENDCG
         } 
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
0

Answer by Paradiser · Apr 13, 2018 at 11:25 AM

Mistake in vertex shader.

             v2f vert(appdata_full v )
             {
                 v2f o;
                 o.uv = v.texcoord;
                 TRANSFER_SHADOW_CASTER(o)
                 return o;
             }

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
2

Answer by Steven-1 · Mar 07, 2016 at 01:18 PM

A bit of a late response, but I am pretty sure you can just use the directive addshadow to tell Unity to make a matching shadow caster pass. (instead of writing a shadow caster pass yourself)

just add #pragma addshadow, I think

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 CommanderThrawn · Jan 27, 2017 at 12:01 AM 0
Share

Perfect, works for me!

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

24 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

Related Questions

How can I make my own shader include file (.cginc or .glslinc)? 2 Answers

Cg shaders in unity and point sprites 2 Answers

Blended texture Shader 1 Answer

_World2Object and _Object2World problem 0 Answers

cross product in cg shader - error "can't find __getVectorIndex" 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