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 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 this 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) = "white" {}
     }
     
     Subshader
     {
         Tags { "RenderType"="Opaque" }
         
         Pass
         {
             Tags { "LightMode" = "Always" }
             
             CGPROGRAM
                 #pragma vertex vert
                 #pragma fragment frag
                 #pragma fragmentoption ARB_precision_hint_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 this 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 this 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 within 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 this 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 this...

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

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

Shader displaying with weird colors 1 Answer

Can someone add (or help me add) a wind effect to my current shader? 0 Answers

Help Please,Help Pease 0 Answers

Water Shader foam does only work in SceneEditor 0 Answers

shader graph messes up the texture (2D) 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