• 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 bluevideogame · Mar 06, 2019 at 11:30 PM · shaderlightingshadersshader programmingshaderlab

Unity Advanced Shader Help

I am creating a videogame in Unity. Every sprite is rendered with a Sprite Renderer with a Material that has the CornucopiaShader.shader. The problem I have is I want to limit the max brightness (or color) of the sprite to just be a normal image of the sprite regardless of the power of how many point lights are hitting it, the intensity of the lights, and also the ambient light in the unity scene. When the intensity of the lights hitting the sprite is below that max brightness level I want it to act like a normal lit sprite and be black if no lights are hitting it, and be half lit up if an intensity of 0.5 is hitting it etc, and everything in between like normal. Problem 1: In summary if three lights at say 5 intensity hit the sprite, I want the sprite to just look normal brightness of 1 and not flushed out white with light.

Since the player can rotate like paper mario and switch sides the current shader code acts that way, and also currently light that hits from the backface should also light up both sides like it currently does in the shader. Problem 2: But another problem I am having, like is seen in the four images I have included is when I flip the player, the intensity changes.

I have been trying to figure out these two problems for 3 days straight and cannot figure it out.

Picture 1

Picture 2

Picture 3

Picture 4

 Shader "Custom/CornucopiaShader" {

 Properties{
     _MainCol("Main Tint", Color) = (1,1,1,1)
     _MainTex("Main Texture", 2D) = "white" {}
     _Cutoff("Alpha cutoff", Range(0,0.5)) = 0.5
 }

 SubShader{
     Tags {"Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane"}
     Cull Off
     ZWrite Off
     LOD 200
     ColorMask RGB

     Blend SrcAlpha OneMinusSrcAlpha

     CGPROGRAM
     #pragma surface surf SimpleLambert alphatest:_Cutoff addshadow fullforwardshadows alpha:blend
     #pragma target 3.0

     #include "RetroAA.cginc"

     sampler2D _MainTex;
     float4 _MainTex_TexelSize;
     fixed4 _MainCol;

     half4 LightingSimpleLambert(SurfaceOutput s, half3 lightDir, half atten)
     {
         half4 c;

         c.rgb = s.Albedo * _MainCol.rgb * (atten)* _LightColor0.rgb;
         c.a = s.Alpha;

         return c;
     }

     struct Input {
         float2 uv_MainTex;
     };

     void surf(Input IN, inout SurfaceOutput o) {

         fixed4 c = RetroAA(_MainTex, IN.uv_MainTex, _MainTex_TexelSize);
         o.Albedo = lerp(c.rgb, c.rgb, c.a);
         o.Alpha = c.a;

     }
     ENDCG
 }

 Fallback "Transparent/Cutout/VertexLit"

}

 #include "UnityCG.cginc"

 #pragma target 3.0

 fixed4 RetroAA(sampler2D tex, float2 uv, float4 texelSize){
     float2 texelCoord = uv*texelSize.zw;
     float2 hfw = 0.5*fwidth(texelCoord);
     float2 fl = floor(texelCoord - 0.5) + 0.5;
     float2 uvaa = (fl + smoothstep(0.5 - hfw, 0.5 + hfw, texelCoord -     fl))*texelSize.xy;

 return tex2D(tex, uvaa);
 }


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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

191 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

Related Questions

How to adapt this shader into a transparent one (alpha blend) 0 Answers

Shader inverts uv map only once, how to fix it? 0 Answers

For a glass shader: How to "Fallback" completely 100% transparent that works in all device or that it do not render at all? 0 Answers

How do I get local object position param in particle system for shader? 0 Answers

Found undocumented ZTest mode, unity_GUIZTestMode for Shader. What kind of ZTest mode this is? 3 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