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 InkaTorque · Nov 20, 2020 at 09:26 PM · spriteshadowsalphacutoutcutoff

Is there a way to cast (maybe recieve) sprite shadows without discarding alpha pixels with cutout shader?

Hi , everybody !

I´m working on a 2.5D game that has movement on all axes and uses hand drawn sprites ( not pixel art , this is very important).

I managed to make our sprites cast an recieve shadows by making our shader render in the Geometry queue and using an alpha cutoff parameter so that the shadows show the correct sillouete of the sprite. This worked and generated a really cool level of polish in our project but it has one big disadvantage : The alpha pixels that are below the cutout threshold are not rendered at all. Since our art is hand drawn and has alpha gradients , this is not aceptable because we lose quality , sprites look jagged and pixelated on the edges due to the pixels getting discarded. Here is an image explainng the problem

alt text

I would really like to know if there is any way to cast shadows without discarding those alpha pixels. In my complete ingnorance of shaders I was thinking of a shader with multiple passes or using a second sprite renderer in each object to with the cutout shader but not rendering anything at all so that it only casts shadows but that seems really overkill. The ability to cast shadows is really cool and I don't want to lose it.

The project uses forward renderer and uses de default/basic render from Unity ( not using URP or HDRP)

Also : Is there any way my sprites could also recieve shadows without having to use the geometry queue? Recieving shadows would be the extra quality touch the game would need to look really good.

Here is the shader I´m currently using

 Shader "Custom/CharactersV4Players"{
     Properties
     {
         [PerRendererData] _MainTex("Texture", 2D) = "white" {}      
         _EffectColor1("Effect Color", Color) = (1,1,1,1)
         _Crossfade("Fade", float) = 0
         _FlashColor("Flash Color", Color) = (1,1,1,1)
         _FlashAmount("Flash Amount",Range(0.0,1.0)) = 0
         _Cutoff("Alpha Cutoff", Range(0,1)) = 0.9
      
     }
  
     SubShader
     {
         Tags
         {
             "Queue" = "Transparent"
             "IgnoreProjector" = "True"
             "RenderType" = "TransparentCutOut"
             "PreviewType" = "Plane"
             "CanUseSpriteAtlas" = "True"
         }
  
      
         Cull Off
         Lighting Off
         ZWrite Off
         Blend SrcAlpha OneMinusSrcAlpha
  
  
         CGPROGRAM
             #pragma surface surf Lambert alpha:blend fullforwardshadows addshadow alphatest:_Cutoff  
  
             #pragma target 3.0
      
             struct Input {
                 fixed2 uv_MainTex;
                 fixed4 color : COLOR;
             };
  
             sampler2D _MainTex;
             fixed4 _EffectColor1;
             fixed _Crossfade;
             fixed4 _FlashColor;
             float _FlashAmount;
  
             void surf(Input IN, inout SurfaceOutput o)
             {
                 fixed4 col = tex2D(_MainTex, IN.uv_MainTex);
                 fixed4 returnColor = lerp(col, col * _EffectColor1, _Crossfade) * _EffectColor1.a + col * (1.0 - _EffectColor1.a);
  
                 o.Albedo = returnColor.rgb * IN.color.rgb;
                 o.Alpha = col.a * IN.color.a;
  
                 o.Albedo = lerp(o.Albedo,_FlashColor.rgb,_FlashAmount);
              
             }
         ENDCG
     }
     Fallback "Legacy Shaders/Transparent/Cutout/VertexLit"
 }

 


alphadiscard-2.jpg (208.7 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

181 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 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 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 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 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 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 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 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

Adjusting alpha cutoff during run time doesn't work 1 Answer

which shader to use for dualsided alpha cutout with light cookie enabled? 1 Answer

Adding shadows to transparent shader? 0 Answers

Distance in the shadows of the sprites and quads. 0 Answers

Mesh transparency halfway cutoff script 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