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 dillon_kneeland · Jun 06, 2016 at 07:14 AM · shaderlightingsurfaceshader

Two Color Lighting Shader Not Working

I'm writing a shader that is supposed to check if there is any light. If there is then it gets drawn as highlight color otherwise it gets drawn as shadow color. The two colors aren't supposed to interact with each other but for a reason I can't seem to find in my code they are.

Here's the code:

 Shader "Custom/Shader 1" {
     Properties {
         _ShadowColor("Shadow Color", Color) = (0.0, 0.0, 0.0, 0.0)
         _HighlightColor("Highlight Color", Color) = (1.0, 1.0, 1.0, 0.0)
     }
     SubShader {
         Tags {
             "Queue" = "Geometry"
             "RenderType" = "Opaque"
         }
         CGPROGRAM
             #pragma surface surf DuelColor
 
             #include "UnityCG.cginc"
 
             half4 _ShadowColor;
             half4 _HighlightColor;
 
             half4 LightingDuelColor(SurfaceOutput s, half3 lightDir, half atten) {
                 half4 c;
                 half NdotL = dot(s.Normal, lightDir);
                 if (Luminance(s.Albedo * _LightColor0.rgb * (NdotL * atten)) > 0) {
                     c.rgb = _HighlightColor.rgb;
                 }
                 else {
                     c.rgb = _ShadowColor.rgb;
                 }
                 c.a = 0.0;
                 return c;
             }
 
             struct Input {
                 float4 Color : COLOR;
             };
 
             void surf(Input IN, inout SurfaceOutput o) {
                 o.Albedo = fixed3(1.0, 1.0, 1.0);
             }
         ENDCG
     }
 }

Here's what's happening:
alt text
As you can see it should be showing up as green and red but instead it's showing up as red and yellow which is a mix of green and red. If someone knows what's happening please tell me. Thank you in advance

@FortisVenaliter

capture.png (48.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

2 Replies

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

Answer by FortisVenaliter · Jun 08, 2016 at 06:37 PM

Okay, so I tried it myself, and was perplexed because it came out perfectly: alt text

Then, I tried adding a new directional light, and I got this: alt text

So, the issue is definitely related to the light setup. From what I can tell, it's running the shader as a separate pass for each light, and adding them together (you're using the deferred rendering path, right?). This is because you are using a surface shader, so there's still other code going on under the hood.

Try basing your shader off the non-surface examples here. That way Unity won't add lighting to what you write, but you lose the GI lighting stuff as well.


test1.jpg (20.0 kB)
test2.jpg (21.1 kB)
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 dillon_kneeland · Jun 09, 2016 at 01:12 AM 0
Share

Thank you, I had a feeling it had to do with the fact that I was using a surface shader ins$$anonymous$$d of a vertex fragment shader. Thank you very much ^_^

avatar image
0

Answer by Thibault-Potier · Nov 07, 2018 at 06:24 PM

Hi Did you managed to achieve what you wanted ? I'm trying to do something similar but i'm a total beginner with shader

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Surface shader: Wrong lighting when moving vertices 1 Answer

Standard Surface Shader with fade too dark 0 Answers

Help with adding a normalmap to a shader 1 Answer

Why does specular highlight ignore vertex position? 1 Answer

Raymarching - bad shadows/light quality on fractals 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