• 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
1
Question by maxxa05 · Aug 25, 2012 at 06:36 PM · shadercolorimage effects

Vignette shader hard edges

When I tried the vignette effect, it gave me the hard edges you can see in the picture below. I gave a shot at doing my own shader for it, and even if I'm able to make them more sublte, it isn't quite as smooth as I'd like. I know it's due to the gap between the 256 levels of grayscale, but i'd like to know if there's any workaround for this.

The screenshot below is the camera facing a gray plane. I included my shader code below.

alt text

     Shader "test/VignettingShader" {
     
     Properties {
         _MainTex ("Base", 2D) = "white" {}
     }
     
     CGINCLUDE
     
     #include "UnityCG.cginc"
     
 
     ENDCG 
     
 Subshader {
  Pass {
       ZTest Always Cull Off ZWrite Off
       Fog { Mode off }      
 
       CGPROGRAM
       #pragma fragmentoption ARB_precision_hint_fastest 
       #pragma vertex vert
       #pragma fragment frag
       
           struct v2f {
         float4 pos : POSITION;
         float2 uv : TEXCOORD0;
     };
     
     sampler2D _MainTex;
 
         
     v2f vert( appdata_img v ) {
         v2f o;
         o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
         o.uv = v.texcoord.xy;
         return o;
     } 
     
     half4 frag(v2f i) : COLOR {
 
         
         
           float2 texCoord=i.uv;
 
   // Take texture color
   half4 color = tex2D (_MainTex, i.uv);
   
   //vignette effect
   texCoord -= 0.5;
     float vignette = 1.0 - pow(dot(texCoord, texCoord),1);
 
     vignette = pow(vignette,5);//determine vignette amount
 
 color*=vignette;
 
 
   return color;
         
         
     }
       
       ENDCG
   }
 }
 
 Fallback off    
 } 
vignette.png (38.0 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

1 Reply

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

Answer by ScroodgeM · Aug 25, 2012 at 07:19 PM

these hard edges are not shader or calculations limit. this is a screen limit. 99% of world screens works with 32bit color, 8 bit per color channel. so you can't increase this 1/256 color level step.

but... you can do something 8)

replace

return color;

with

return color + float4(0, 0.0013, 0.0026, 0);

this will smooth color step

(50,50,50) -> (51,51,51)

to something like

(50,50,50) -> (51,50,50) -> (51,51,50) -> (51,51,51)

some type of fake, but looks triple smoothly 8)

alt text


1.png (53.3 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 maxxa05 · Aug 25, 2012 at 07:31 PM 0
Share

Thanks, it gives a small tint but barely noticeable, clever solution anyway.

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Material doesn't have a color property '_Color' 4 Answers

How to blend between LUT textures in Unity's color correction script? 0 Answers

Need help with using world position in shader 1 Answer

Shader that does per Vert alpha with co 0 Answers

How to get pixel coordinates in an image effect shader 2 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