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 /
  • Help Room /
avatar image
0
Question by vdogamr · Feb 23, 2018 at 08:17 AM · unity 5shadercolorshader programminglighting-model

Shader Colors are doubled

This might be related to https://answers.unity.com/questions/1351430/wrong-color-in-ui-shader-with-alpha-blending.html, but that has no answers.

I feel I have a very simple shader:

 Shader "Custom/MultiLayerShader" {
     Properties {
         _Layer0Color ("Color0", Color) = (1,1,1,1)
         _Layer0Texture ("Texture0 (RGB)", 2D) = "white" {}
         _Layer1Color ("Color1", Color) = (1,1,1,1)
         _Layer1Texture ("Texture1 (RGB)", 2D) = "white" {}
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
 
         CGPROGRAM
         #pragma surface surf SimpleLambert
         #pragma target 3.0
 
         sampler2D _Layer0Texture;
         sampler2D _Layer1Texture;
 
         struct Input {
             float2 uv_Layer0Texture;
             float2 uv2_Layer1Texture;
         };
 
         fixed4 _Layer0Color;
         fixed4 _Layer1Color;
 
         UNITY_INSTANCING_BUFFER_START(Props)
         UNITY_INSTANCING_BUFFER_END(Props)
 
         void surf (Input IN, inout SurfaceOutput o) {
             fixed4 c0 = tex2D (_Layer0Texture, IN.uv_Layer0Texture) * _Layer0Color * .5f;
             fixed4 c1 = tex2D (_Layer1Texture, IN.uv2_Layer1Texture) * _Layer1Color * .5f;
 
             fixed4 color;
             color.rgb = (c0.rgb * (1 - c1.a)) + (c1.rgb * c1.a);
             color.a = c0.a;
 
             o.Albedo = color.rgb;
             o.Alpha = color.a;
         }
 
         half4 LightingSimpleLambert (SurfaceOutput s, half3 lightDir, half atten) {
             half NdotL = dot(s.Normal, lightDir);
             half4 c;
             c.rgb = s.Albedo;// * _LightColor0.rgb * (NdotL * atten * 1);
             c.a = s.Alpha;
             return c;
         }
 
         ENDCG
     }
     FallBack "Diffuse"
 }



To get anywhere close to the right colors I have to cut my _Layer0Color and _Layer1Color in half. If I output these values directly without any other math, they are still 2x the color values. If I output them directly after cutting them in half I get the exact colors I expect.

After that... I don't even know what is wrong with the (1 - c1.a) calculation. If I set my Albedo to it by itself I get a sold white image, even though using c1.a by itself shows me a grayscale image I would expect. If I set: o.Albedo = .5f, I still get solid white. Oddly if I set it to .25, I get a gray of 140,140,140.

Can someone please help explain where all the extra math is coming from, how I can disable it, or how I can know the exact values I need to work around it?

Thanks.

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

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

A public list of color in shader. 0 Answers

Very basic shader problem 0 Answers

Unity equivalent to glDepthMask or alternative? 0 Answers

Toon Shader rendering backfaces black instead of transparent 0 Answers

Getting Color Generated from Shader to Script to Shader 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