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 TrashPanda · Dec 27, 2017 at 02:45 PM · unity 5rotationshadershadersspriterenderer

Shader doesn't work when object is inverted by axis

I have simple shader that imitates "Filled" Image Type for SpriteRenderer. It allows to cut off part of sprite depending of it's fill amount. But shader doesn't work if Object is inverted by any axis (no matter is it inverted by rotation, scale or "Flip" checkbox on SpriteRenderer). When Object is inverted Sprite isn't drawn at all.

Shader:

     Shader "Custom/ProgressShaderUpToDown" {
         Properties{
             _MainTex("Base (RGB)", 2D) = "white" {}
             _Progress("Progress (Float)", Float) = 0
             _Color("Tint", Color) = (1.0, 0.6, 0.6, 1.0)
         }
     
         SubShader{
             Tags{ "Queue" = "Transparent" }
             Pass{
             Blend SrcAlpha OneMinusSrcAlpha
             CGPROGRAM
             #pragma vertex vert_img
             #pragma fragment frag
     
             #include "UnityCG.cginc"
     
         uniform sampler2D _MainTex;
         uniform float _Progress;
         uniform fixed4 _Color;
     
             float4 frag(v2f_img i) : COLOR
             {
                 float4 result = tex2D(_MainTex, i.uv);
     
                 if (i.uv.y > _Progress)
                 {
                     result.a = 0;
                 }
     
                 return result*_Color;
             }
                 ENDCG
             }
         }
     }

How can I fix this?

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

Answer by $$anonymous$$ · Dec 27, 2017 at 05:49 PM

Sprites that are flipped by scale or rotation will naturally not be drawn by a shader that does not have culling set to off (see SL-CullAndDepth) because the triangle winding order then ends up inverted in clip space. I don't think that should be the case with the flip switch but I can't check that right now. Maybe just check whether disabling culling (and therefore making your shader double-sided) works for you.

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 TrashPanda · Dec 27, 2017 at 06:41 PM 1
Share

Thanks dude!

If anyone care here is shader that works for both sides:

 Shader "Custom/ProgressShaderUpToDown" {
     Properties{
         _$$anonymous$$ainTex("Base (RGB)", 2D) = "white" {}
     _Progress("Progress (Float)", Float) = 0
         _Color("Tint", Color) = (1.0, 0.6, 0.6, 1.0)
     }
 
         SubShader{
         Tags{ "Queue" = "Transparent" }
         Pass{
         Blend SrcAlpha One$$anonymous$$inusSrcAlpha
         Cull Off
         CGPROGRA$$anonymous$$
 #pragma vertex vert_img
 #pragma fragment frag
 
 #include "UnityCG.cginc"
 
         uniform sampler2D _$$anonymous$$ainTex;
     uniform float _Progress;
     uniform fixed4 _Color;
 
     float4 frag(v2f_img i) : COLOR
     {
         float4 result = tex2D(_$$anonymous$$ainTex, i.uv);
 
         if (i.uv.y > _Progress)
         {
             result.a = 0;
         }
 
         return result*_Color;
     }
         ENDCG
     }
     }
 }

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

207 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Any idea how to get object rotation or transformMatrix in the vertex shader? 0 Answers

Distort shader not showing sprites 2 Answers

U5 shader coming out solid black on newer iOS devices (iPad 2 Air / iPhone 6) 1 Answer

Allow 2D sprite to receive light from any direction and show on both sides 0 Answers

I Installed URP But I Can't Create 2D Shaders 1 Answer


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