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
0
Question by hunvee3 · Nov 04, 2016 at 10:24 PM · shadersbackgroundmovietexturemovieunlit

Unlit Shader with Shadows from point lights.

Hi guys, I'm really a noob at shader coding, I found this shader that does almost what I need but has a problem, I need an object to be unlit, has a texture, and receives shadows form directional lights and point lights, specially the last one. The idea is that I will have a quad or plane (facing up) in which I'll be loading an image or movie texture, and the objects on top of it should cast shadows on this quad or plane. I need ir to receive shadows caused by a point light because thats what my client needs.

Here is the shader that receive shadows only from a directional light, I would need someone to add the point light support.

Shader "UnlitShadows/UnlitShadowReceive" { Properties{ _MainTex("Base (RGB)", 2D) = "white" {} } SubShader{ Pass{ SetTexture[_MainTex] } Pass { Blend DstColor Zero Tags{ "LightMode" = "ForwardBase" } CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" #pragma multi_compile_fwdbase #include "AutoLight.cginc" struct v2f { float4 pos : SV_POSITION; LIGHTING_COORDS(0,1) }; v2f vert(appdata_base v) { v2f o; o.pos = mul(UNITY_MATRIX_MVP, v.vertex); TRANSFER_VERTEX_TO_FRAGMENT(o); return o; } fixed4 frag(v2f i) : COLOR{ float attenuation = LIGHT_ATTENUATION(i); return attenuation; } ENDCG } } Fallback "VertexLit" }

Thanks in advance!!!

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
2
Best Answer

Answer by Namey5 · Nov 04, 2016 at 10:59 PM

 Shader "UnlitShadows/UnlitShadowReceive" { 
     Properties { 
         _MainTex("Base (RGB)", 2D) = "white" {} 
     } 
 
     SubShader {     
         Pass { 
             Tags { "LightMode" = "ForwardBase" } 
             CGPROGRAM 
             #pragma vertex vert 
             #pragma fragment frag 
             #include "UnityCG.cginc" 
             #pragma multi_compile_fwdbase 
             #include "AutoLight.cginc" 

             sampler2D _MainTex;
             float4 _MainTex_ST;

             struct v2f { 
                 float4 pos : SV_POSITION; 
                 LIGHTING_COORDS(0,1) 
                 float2 uv : TEXCOORD2;
             }; 
 
             v2f vert(appdata_base v) { 
                 v2f o; 
                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 
                 o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
                 TRANSFER_VERTEX_TO_FRAGMENT(o); 
                 return o; 
             } 
 
             fixed4 frag(v2f i) : COLOR
             { 
                 float attenuation = LIGHT_ATTENUATION(i); 
                 return tex2D (_MainTex, i.uv) * attenuation; 
             } 
             ENDCG 
         } 
 
         Pass { 
             Blend One One
             Tags { "LightMode" = "ForwardAdd" } 
             CGPROGRAM 
             #pragma vertex vert 
             #pragma fragment frag 
             #include "UnityCG.cginc" 
             #pragma multi_compile_fwdadd_fullshadows 
             #include "AutoLight.cginc" 

             sampler2D _MainTex;
             float4 _MainTex_ST;
 
             struct v2f { 
                 float4 pos : SV_POSITION; 
                 LIGHTING_COORDS(0,1) 
                 float2 uv : TEXCOORD2;
             }; 
 
             v2f vert(appdata_base v) { 
                 v2f o; 
                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 
                 o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
                 TRANSFER_VERTEX_TO_FRAGMENT(o); 
                 return o; 
             } 
 
             fixed4 frag(v2f i) : COLOR
             { 
                 float attenuation = LIGHT_ATTENUATION(i); 
                 return tex2D (_MainTex, i.uv) * attenuation; 
             } 
             ENDCG 
         } 
     } 
     Fallback "VertexLit" 
 }


Comment
Add comment · Show 12 · 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 hunvee3 · Nov 05, 2016 at 01:42 AM 0
Share

alt text

Hi @Namey5 !, Thank you for your answer, as you can see in the image, it still doesn't work 100% but it's so close. I beg you to help me XD... The soccer ball is casting shadows from the point light, and into the plane (which has the shader attached) but its shadow is only visible over the directional light shadow. I would like the shadow from the pont light to be rendered as in any surface. I think you get the Idea.

It's so close! XD, thank you very much.

avatar image Namey5 hunvee3 · Nov 05, 2016 at 04:46 AM 0
Share

The image you provided doesn't publicly exist according to my system, however it would be because you aren't rendering the shadows on top of the object, you are blending them with the texture. I've updated my answer to do it how you would generally do shadows.

avatar image hunvee3 Namey5 · Nov 05, 2016 at 10:45 AM 0
Share

Hi!, Thanks a lot, It was my bad, I didn't have a texture assigned to the quad so when you said that I'm blending de shadows I understood. You saved me.

I have one more request though, if it's possible. This works great and its enough for my client to be appy, but, I was wondering if it's possible to make it fully unlit but receive shadows. http://www.mediafire.com/view/2cb85c75qhhkdnr/unity%20answer.png Heres a link to another image. The view on the left shows you the scene whithout the point light and the other one shows it with the point light, and there's a little bit of light on the background quad. It so little that it is not a problem but if u cana dn have the time it would be great. Again Thank you so much for this!!

Heres a link

Show more comments
avatar image dansopanso · Jun 18, 2018 at 10:39 PM 0
Share

Wow! That's fantastic. Thanks so much for sharing this!

There is just one thing I noticed... When I apply the shader to my unlit texture the shadows on the object are completely black. While the shadows casted on a Standart $$anonymous$$aterial are slightly transparent. Is there any way to match the darkness of the shadows? So that the shadows on the unlit material are also slighly transparent? That would be awesome. Thanks in advance..

avatar image dansopanso dansopanso · Jun 18, 2018 at 10:44 PM 0
Share

I just had to turn down the strength of my directional light :p Thanks again for sharing!!!

avatar image Davood_Kharmanzar · Mar 17, 2019 at 07:15 PM 0
Share

@Namey5 hello, i know this is really old thread!!

but ... is it possible to using that on HDRP??

i wants an HDRP Unlit shader with cast-receive shadow ... does exists an shader for that??

avatar image Namey5 Davood_Kharmanzar · Jun 17, 2019 at 03:21 AM 0
Share

The new render pipelines (including HDRP) use their own shader language, so while it is possible, I haven't really looked into writing shaders for said pipelines yet. $$anonymous$$aybe in the future, but for now I can't help you.

avatar image Daniel_Darko · May 30, 2020 at 02:43 AM 0
Share

Sorry to bump this again but the shadows that are being received are completely black and im not sure how to adjust them. Is there something I should add to the shader? Thank you!

avatar image Namey5 Daniel_Darko · May 30, 2020 at 08:50 AM 0
Share

This shader is purely unlit with shadows. If you want to add ambient lighting, then you can do so in the base pass (lines 19-37);

 struct v2f 
 { 
     float4 pos : SV_POSITION; 
     LIGHTING_COORDS(0,1) 
     float2 uv : TEXCOORD2;
     float3 worldNorm : TEXCOORD3;
 }; 
  
 v2f vert (appdata_full v) 
 { 
     v2f o; 
     o.pos = mul(UNITY_$$anonymous$$ATRIX_$$anonymous$$VP, v.vertex); 
     o.uv = TRANSFOR$$anonymous$$_TEX (v.texcoord, _$$anonymous$$ainTex);
     o.worldNorm = UnityObjectToWorldNormal (v.normal);
     TRANSFER_VERTEX_TO_FRAG$$anonymous$$ENT(o); 
     return o; 
 } 
  
 fixed4 frag (v2f i) : COLOR
 { 
     float attenuation = LIGHT_ATTENUATION(i); 
 
     //You can replace 'ambient' with a solid colour, or whatever you want.
     //In this case, I'll use the environment SH to fit with normal ambient lighting
     i.worldNorm = normalize (i.worldNorm);
     half3 ambient = ShadeSH9 (float4 (i.worldNorm, 1));
 
     half4 c = tex2D (_$$anonymous$$ainTex, i.uv);
     c.rgb = c.rgb * (attenuation + ambient);
     return c;
 } 

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Movie Texture playback choppy on Xbox One 0 Answers

MovieTexture stops playing after first frame 0 Answers

Unlit Terrain Foliage, is it possible? 1 Answer

Making a shader for an inside out sphere unlit? 3 Answers

Shader graph place small image/texture at specific location on object,Shader graph place texture at specific place on object 0 Answers


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