• 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 tedesignz1 · Feb 28, 2017 at 06:14 AM · shadershadersvertex color

Trying to add dither to shader with vertex color

I attempted to write an unlit shader that has vertex color using dither to deal with color banding issues. I followed t$$anonymous$$s tutorial: https://startupfreakgame.com/2017/01/15/screen-space-gradient-shader-with-dithering-in-unity/

Here is the code I came up with:

 Shader "Unlit/TEST"
 {
     Properties
     {
         _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
         _NoiseTex ("Noise Texture", 2D) = "w$$anonymous$$te" {}
     }
     
     Subshader
     {
         Tags { "RenderType"="Opaque" }
         
         Pass
         {
             Tags { "LightMode" = "Always" }
             
             CGPROGRAM
                 #pragma vertex vert
                 #pragma fragment frag
                 #pragma fragmentoption ARB_precision_$$anonymous$$nt_fastest
                 #include "UnityCG.cginc"
 
                 struct appdata {
                     float4 vertex : POSITION;
                     fixed4 color : COLOR;
                     float3 normal : NORMAL;
                 };
 
                 struct v2f
                 {
                     float4 pos    : SV_POSITION;
                     float2 uv    : TEXCOORD0;
                     fixed4 color : COLOR;
                 };
                 
                 v2f vert (appdata v)
                 {
                     v2f o;
                     o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
                     o.color = v.color;
                     return o;
                 }
 
                 uniform float4 _Color;
                 uniform sampler2D _NoiseTex;
 
                 float3 getNoise(float2 uv) 
                 {
                     float3 noise = tex2D(_NoiseTex, uv * 100 + _Time * 50);
                     noise = mad(noise, 2.0, -0.5);
                     return noise/255;
                 }
                 
                 fixed4 frag (v2f i) : COLOR
                 {
                     i.color.rgb += getNoise(i.uv);
                     return _Color * 2.0 * i.color;
                 }
             ENDCG
         }
     }
     
     Fallback "VertexLit"
 }

What t$$anonymous$$s does is it gets the random value from the blue noise map, but it effects the color of the entire mesh rather than each individual pixel. I've searched the far reaches of the internet and can't seem to find a way to get t$$anonymous$$s working. I'm a noob with shaders, and any help is appreciated.

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
1

Answer by BHS · Jan 30, 2020 at 10:37 PM

@IlisanVlad To implement, just use the following after applying the noise function and noise texture wit$$anonymous$$n the frag function:

  half4 c;
  c.rgb = TheColorToFix.rgb + getNoise(i.uv);
  c.rgb *= YourTextureColor.a;
  c.a = YourTextureColor.a;
  return c;

In the case of @tedesignz1, I believe t$$anonymous$$s should work (untested):

 half4 c;
 c.rgb = _Color.rgb + getNoise(i.uv);
 c.rgb *= i.color.a;
 c.a = i.color.a;
 return c;

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 IlisanVlad · Sep 22, 2019 at 08:39 PM

Did you find any solution? I am losing my mind trying to solve t$$anonymous$$s...

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.

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

123 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

Related Questions

Creating a 3D portal effect using stencil buffer with a deferred shading setup? 1 Answer

LWRP Shader Graph material fades away with distance. 0 Answers

How do I cell shade terrain? 0 Answers

Shader error in 'Shader Graphs/Shader': invalid subscript 'sh' at line 519 (on gles3) 0 Answers

Making clamped texture render parts outside of the uvs transparent 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