Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 TylerGlaiel · Apr 21, 2013 at 08:24 PM · shadersshadowscg

Accessing shadow texture in shader

Hey, I need to know what unity names its shadow texture in CG shaders, and how can I access it when doing vert/frag shaders instead of surface shaders?

the macros (LIGHTING_COORDS, LIGHT_ATTENUATION, TRANSFER_VERTEX_TO_FRAGMENT) do not seem to work, I get solid white as my shadow texture (have tried with multiple different compiler pragmas)

Anyone ever do this? Or am I up shit creek and have to go generate my own shadow texture with a 2nd camera?

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 whydoidoit · Apr 21, 2013 at 08:55 PM

Add SHADOW_COORDS(x) to your vertex to fragment structure where X is a free TEXCOORD

Use TRANSFER_SHADOW(output) in your vertex shader

Multiply the colour by SHADOW_ATTENUATION(input) in your fragment shader

Comment
Add comment · Show 6 · 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 TylerGlaiel · Apr 21, 2013 at 09:47 PM 0
Share

same deal, shadow texture is always white.

avatar image whydoidoit · Apr 21, 2013 at 09:54 PM 0
Share

Post your shader code - that works in all of my shaders.

avatar image TylerGlaiel · Apr 21, 2013 at 09:59 PM 0
Share

i figured it out, it requires "Light$$anonymous$$ode" = "ForwardBase"

#pragma multi_compile_fwdbase

AND requires forward rendering (not ideal)

so i'm just gonna generate my own shadow map ins$$anonymous$$d

avatar image whydoidoit · Apr 21, 2013 at 10:00 PM 0
Share

$$anonymous$$uch better performance than deferred though...

avatar image whydoidoit · Apr 21, 2013 at 10:01 PM 0
Share

But I guess you must have a lot of lights :)

Show more comments
avatar image
0

Answer by karmakun · Jan 13, 2014 at 07:19 PM

here the example, actually you are very close

about shader: ignore de uv:TEXCOORD, no need for shadow pass

Shader "Custom/shadows" { Properties {

 }
 SubShader 
 {
 Tags {"Queue" = "Geometry" "RenderType" = "Opaque"}
 pass{

     Tags { "LightMode" = "ForwardBase" }
     
     CGPROGRAM
     #pragma vertex vert
     #pragma fragment frag
     #pragma multi_compile_fwdbase
     #pragma fragmentoption ARB_fog_exp2
     #pragma fragmentoption ARB_precision_hint_fastest
     #include "UnityCG.cginc"
     #include "AutoLight.cginc"
     struct a2v
     {
         float4 vertex : POSITION;
         float3 normal : NORMAL;
         float2 texcoord: TEXCOORD0;
     };
     
     struct v2f
     {
         float4 pos : SV_POSITION;
         float2 uv : TEXCOORD0;    
         float3 normal : TEXCOORD1;
         LIGHTING_COORDS(2,3)
         
     };
     
     
     v2f vert (a2v v)
     {
         v2f o;
         o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
         o.uv = v.texcoord;
         o.normal = v.normal;
         TRANSFER_VERTEX_TO_FRAGMENT(o);
         return o;
     }
     
     float4 frag (v2f i) : COLOR
     {
         float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
         float atten = LIGHT_ATTENUATION(i) ;
         float3 lambert = float(max(0.0,dot(i.normal,lightDirection)));;
         return float4(lambert *atten,1);
     }
     
     ENDCG
     }
 } 
 FallBack "Diffuse"

}

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

13 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

Related Questions

How to add shadows to surface shader? 1 Answer

Sampling Shadowmap in Post Processing Shader 0 Answers

Spherical Hamonics - ShadeSH9 and Surface Shader issue 0 Answers

Using Vertex Color increases Draw Call 0 Answers

How to get camera location in object space? 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