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
2
Question by JtheSpaceC · Apr 01, 2017 at 11:01 AM · 2dspriteshaderscustom shader

Custom sprite Shader works in 5.5, not 5.6

Let me start by saying that I'm not good with shaders, but I successfully wrote a simple custom shader while using Unity 5.5. Its job is to take a sprite, colour it fully white, and allow me to change the colour in code to red or green (I use it for radar signatures of space ships).

Shader code here

It looks like this.alt text

Simple enough. But since upgrading to Unity 5.6, it comes out like this. It loses respect for the dimensions of the sprite (seems worse on convex shaped sprites) and also seems to colour it grey/transparent, not opaque white. alt text

The shader hasn't changed at all, I checked. So it's not like Unity rewrote something in my shader, but maybe elsewhere in the new graphics settings?

Thanks very much.

radar-sig-shader.png (55.6 kB)
radar-sig-shader-56.png (35.8 kB)
Comment
Add comment · Show 3
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 Orion · Apr 01, 2017 at 01:26 PM 0
Share

I had that happen to me too. After a bit of restarting everything worked fine.

avatar image JtheSpaceC Orion · Apr 01, 2017 at 01:41 PM 0
Share

Can you define "a bit of restarting" please? I've restarted the machine, Unity, and re-updated another copy of the 5.5 project to 5.6. No changes for me.

avatar image Orion JtheSpaceC · Apr 01, 2017 at 03:53 PM 0
Share

Sorry for not being more specific. In fact I just loaded a different level and started the game again and it had resolved itself. Sounds like you are encountering a different issue.

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by JtheSpaceC · Apr 03, 2017 at 12:36 PM

I think I've solved it..

I found that removing this line

 #pragma multi_compile _ ETC1_EXTERNAL_ALPHA

brings what you see in the second image back in line with the 1st. I'm not entirely sure what this is, and don't know what doing this will break (if anything). But since Android is referenced later in the shader with the External_Alpha and I'm not building for mobile, I'm happy enough to make the change, personally.

What I must reiterate however is that in 5.5 I had this line in the project and got my desired result, so something has changed under the hood in 5.6.0 and it may be something that Unity patches later and re-breaks on me while they solve it for others.

Hope this helps you though.

Comment
Add comment · Show 3 · 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 Dave-Carlile · Apr 03, 2017 at 12:40 PM 1
Share

I would suggest closing Unity, deleting your project's Library folder (after backing everything up), then trying again with that line included. Sometimes on an upgrade the cached items in Library don't all get rebuilt properly and deleting the folder will force Unity to rebuild it. It may not solve your issue, but it's usually worth a shot.

avatar image JtheSpaceC Dave-Carlile · Apr 03, 2017 at 12:48 PM 0
Share

Thanks for the suggestion. Always good to remember that one! I'd actually forgotten to do this this time, but just tried it there with no effect.

avatar image michaelwolf95 · May 01, 2017 at 07:12 PM 0
Share

Just commenting out this line fixed it for me! Thanks!

avatar image
2

Answer by alice_funo · Apr 16, 2017 at 08:45 AM

In 5.6, Unity seemed to have refactored some of the Sprite shader functionality to UnitySprites.cginc (download the shaders here to look: https://unity3d.com/get-unity/download/archive)

I've gotten better results without disabling that line (just in case I need to release on Android), but by overriding the default vert or pixel shaders. Those are all in UnitySprites.cginc for reference.

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

Answer by DungeonBrickStudios · Apr 28, 2017 at 09:50 AM

Using the hint that Alice_Funo gave (thanks Alice), I did the following to resolve the error without disabling that line (I am working on an android project as it is):

Under Pass, under CGPROGRAM, under the pragma and include statements, I added the CBUFFER bit, so it looks like the following:

 Pass
         {
         CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #pragma target 2.0
             #pragma multi_compile _ PIXELSNAP_ON
             #pragma multi_compile _ ETC1_EXTERNAL_ALPHA
             #pragma multi_compile_fog
             #include "UnityCG.cginc"
 
             CBUFFER_START(UnityPerDrawSprite)
             #ifndef UNITY_INSTANCING_ENABLED
             fixed4 _RendererColor;
             float4 _Flip;
             #endif
             float _EnableExternalAlpha;
             CBUFFER_END


My "fixed4 SampleSpriteTexture" function was replaced with the following:

 fixed4 SampleSpriteTexture (float2 uv)
             {
                 fixed4 color = tex2D (_MainTex, uv);
 
                 #if ETC1_EXTERNAL_ALPHA
                 fixed4 alpha = tex2D (_AlphaTex, uv);
                 color.a = lerp (color.a, alpha.r, _EnableExternalAlpha);
                 #endif
 
                 return color;
             }

That returned things to normal for me. Still need to test it on a mobile phone however.

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

124 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

Related Questions

Multiple lights disable additive intensity for Sprites-Diffuse? 0 Answers

Why Sprites-Default shader hasn't any fallback? 1 Answer

Double sided pass? 2 Answers

2D Sptite Shader Character in 3D World 0 Answers

Apply a shader to multiple 2D sprites 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