Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
3
Question by SineDeviance · Mar 06, 2015 at 01:46 AM · shadershadowstransparentdiffusetransparent diffuse

Transparent w/ Full Shadowcasting in Unity 5

Hey guys! I'm trying to get this shader that worked in 4.x to work in 5, but I'm not having much luck.

What it does is, it allows transparent objects to cast shadows from directional lights and etc. I use it for roofs of houses and such as my game is a top-down game with day/night cycles; when the player walks into a building there is a trigger that disables the mesh renderer on the actual roof and enables the renderer on a clone with this shader applied.

It worked fine in Unity 4.x, but in 5.x the alpha slider no longer works; the object does seem to cast shadows properly but it will not go transparent with alpha. I'm not great with shaders, I borrowed this one from the Unity forums a long time ago. It seems that Unity's shader structure has changed significantly with 5.x; anyone know how I can resolve it?

Thanks!

 Shader "Transparent/Diffuse with Shadow" {
     Properties {
         _Color ("Main Color", Color) = (1,1,1,1)
         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
     }
      
     SubShader {
         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
         LOD 200
         Blend SrcAlpha OneMinusSrcAlpha
         CGPROGRAM
         #pragma surface surf Lambert addshadow
      
         sampler2D _MainTex;
         fixed4 _Color;
      
         struct Input {
             float2 uv_MainTex;
         };
      
         void surf (Input IN, inout SurfaceOutput o) {
             fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
             o.Albedo = c.rgb;
             o.Alpha = c.a;
         }
         ENDCG
     }
      
     Fallback "Transparent/VertexLit"
     }
Comment
Add comment · Show 1
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 Sparkline · Jul 10, 2015 at 08:19 AM 0
Share

Did you find the solution?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dover8 · Aug 27, 2015 at 09:31 AM

Came across the same issue, though my shader was slightly different to begin with. I'm also doing the opposite of you (casting shadows ONTO transparent objects), but I think this solution will work for you.

After your last line of the surface shader, try clipping values below a threshold, ie:

 o.Alpha = c.a;
 clip (o.Alpha - 0.01);
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 HeyJoeLang · Oct 06, 2015 at 08:01 PM 0
Share

Hey Dover8,

I am looking for a transparent material that receives shadows. Have you been able to successfully do it? If so, would you share the shader code?

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

22 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

Related Questions

Diffuse 2-sided shader only accepts light on one side? 2 Answers

Lighting artifacts through transparent material 0 Answers

Transparent Diffuse issues 1 Answer

How to force transparent shader for smooth lod transition to receive shadows? 0 Answers

Transparent shader has no shadow? 2 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