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
0
Question by absameen · Apr 22, 2012 at 06:31 PM · shadershadowsdepthmask

DepthMask Shader - Receive Shadows

I have a simple DepthMask shader that masks any objects behind it. I would like the DepthMask shader to receive shadows as well. How is this possible?

Here is the shader:

 Shader "Depth Mask" {
     SubShader {
         Tags {"Queue" = "Geometry-10" }
         Lighting Off
         ZTest LEqual
         ZWrite On
         ColorMask 0
         Pass {}
     }
 }
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
1
Best Answer

Answer by absameen · Apr 22, 2012 at 07:05 PM

For anyone interested, I managed to find a solution to this by combining two shaders from the forums. Here is the working shader:

 Shader "FX/Matte Shadow Mask" {
 
 Properties {
  _Color ("Main Color", Color) = (1,1,1,1)
  _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
  _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
 
 }
 
 
 SubShader {
 
  Tags {"Queue" = "Geometry-10" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
  LOD 200
  Blend Zero SrcColor
  Lighting Off
  ZTest LEqual
  ZWrite On
  ColorMask 0
  Pass {}
 
 CGPROGRAM
 #pragma surface surf ShadowOnly alphatest:_Cutoff
 
 
 fixed4 _Color;
 
 struct Input {
 
  float2 uv_MainTex;
 
 };
 
 inline fixed4 LightingShadowOnly (SurfaceOutput s, fixed3 lightDir, fixed atten)
 
 {
  fixed4 c;
  c.rgb = s.Albedo*atten;
  c.a = s.Alpha;
  return c;
 }
 
 void surf (Input IN, inout SurfaceOutput o) {
  fixed4 c = _Color;
  o.Albedo = c.rgb;
  o.Alpha = 1;
 }
 ENDCG
 }
 Fallback "Transparent/Cutout/VertexLit"
 }
Comment
Add comment · Show 5 · 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 bktan81 · Mar 11, 2013 at 06:01 AM 0
Share

It works like a champ!!!! Thanks!

avatar image ArtiomK · Jun 27, 2013 at 05:54 AM 0
Share

That's exactly, what I was looking for a whole day! Thanks!!!

avatar image octaviomejiadiaz · Feb 04, 2014 at 11:37 PM 0
Share

what do i can do, if i want to change the color of the light received?, cause if i change anny color in the mask, change all the plane color. ?

avatar image nsurdu · Apr 30, 2014 at 04:39 PM 0
Share

Awesome! But can it be modified so that it doesn't obscure the objects behind ?

avatar image $$anonymous$$ · Jul 24, 2015 at 08:54 AM 0
Share

Hi.. this shader works great. But I don't want to the masking behaviour in it. I want to cast shadow on a transparent plane with shadows and with a skybox in the scene. But after putting the skybox the plane is not transparent anymore in the game mode, while it is transparent in the scene mode(screenshot attached). Which I suppose is because of the masking property. I have no knowledge about shader scripting and it is required on an urgent basis. Would really appreciate if someone could help me in this. Thanks

alt text

shadow-on-transparent-plane.png (242.3 kB)
avatar image
0

Answer by master_render · Aug 29, 2015 at 02:50 PM

Hello,

Thank you for the provided shader. It works fine on windows, but on Android there is bad jitters on the shadows because of the alpha test.

I've tried a similar setup like in the picture below. There is an invisible plane under the robot object which is rendered in the depth maps only with ColorMask 0. Then, under the invisible plane there is another plane with a texture. It has the ReceiveShadows bool set to true.

alt text

It works fine on Windows, you can check the picture. But on Android the invisible plane's depth is not written into the depth for some reason :(.

alt text

Does anyone have an idea why the invisible plane doesn't render on Android?


final.png (455.5 kB)
setup.png (381.9 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

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

8 People are following this question.

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

Related Questions

Unity 2D Shader Graph Sprite transparent when in shadow 0 Answers

Raymarching - bad shadows/light quality on fractals 0 Answers

How do I render a scene's depth buffer when I have custom vertex shaders? 0 Answers

Unlit shader with shadows. 0 Answers

Scene lights flickering 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