• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

How to add alpha cutout shader to this curveworld shader 1 Answer

Sprite is covered in shadow. 0 Answers

Transparency between mesh a cube and a sprite 0 Answers

Dirt / Dust Shader, Light Interaction 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges