Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Capitals · Aug 31, 2017 at 12:12 PM · shaderimage effectsblendingblitting

Why does my Image effect shader output gets darker over time?

For some reason, when I use my main texture inside my shader it, over time, gets darker. Before: alt text After Seconds of Playing: alt text

This is the shader code.

 Shader "Hidden/Vintage"
 {
     Properties
     {
         _MainTex ("Texture", 2D) = "white" {}
         _Perlin ("Perlin", 2D) = "white" {}
         _Degrade ("Degrade", 2D) = "white" {}
         _Under ("Undertexture", Color) = (0,0,0,0)
         _Darker ("Darkertexture", Color) = (0,0,0,0)
 
         _Size ("Size", Range(0,2)) = 1 
         _Vig ("Vig", Range(0,1)) = 1 
         _VigIntensity ("Vignette Intensity", Float) = 15
         _DegradeSize ("Degrade", Float) = 1 
 
         _NoRed ("No Red", Range(0,1)) = 1 
 
     }
     SubShader
     {
         // No culling or depth
         Cull Off ZWrite Off ZTest Always
         Tags {"Queue" = "Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
         Blend Off
         //Blend DstColor SrcColor
         //AlphaToMask On
 
         Pass
         {
             CGPROGRAM
 
             #pragma vertex vert
             #pragma fragment frag
             
             #include "UnityCG.cginc"
 
             float4  _MainTex_ST;
 
             struct appdata
             {
                 float4 vertex : POSITION;
                 float2 uv : TEXCOORD0;
             };
 
             struct v2f
             {
                 float2 uv : TEXCOORD0;
                 float4 vertex : SV_POSITION;
                 float4 screenPos : TEXCOORD1;
             };
 
             v2f vert (appdata v)
             {
                 v2f o;
                 o.vertex = UnityObjectToClipPos(v.vertex);
                 o.uv = v.uv;
                 o.screenPos = ComputeScreenPos(o.vertex);
                 return o;
             }
             
             sampler2D _MainTex, _Perlin, _Degrade;
 
             float _Size, _DegradeSize, _Vig, _NoRed, _VigIntensity;
             fixed4 _Under, _Darker;
 
             fixed4 frag (v2f i) : SV_Target
             {
                 //float2 newUV = TRANSFORM_TEX(i.uv, _Perlin);
                 fixed4 per = tex2D(_Perlin, i.uv);
                 fixed4 deg = tex2D(_Degrade, i.uv * _DegradeSize + _Time[0]);
                 fixed4 col = tex2D(_MainTex, i.uv);
                 fixed4 tCol = tex2D(_MainTex, i.uv);
 
                 //return per;
 
                 float2 sp = (i.screenPos.xy/i.screenPos.w);
    
                 sp *=  1.0 - sp.yx;   //vec2(1.0)- uv.yx; -> 1.-u.yx; Thanks FabriceNeyret !
     
                 float vig = sp.x*sp.y * _VigIntensity; // multiply with sth for intensity
     
                 vig = pow(vig, _Vig); // change pow for modifying the extend of the  vignette
 
                 vig = vig;
 
 
                 fixed3 BColor = fixed3(1,1,1);
 
                 //if(tCol.r > 0.01 && tCol.g < 0.2 && tCol.b < 0.2 && _NoRed > 0)
                 //    col.rgb =  _Under.rgb * (col.r);
 
 
                 col = lerp(_Under, col, col.a);
                 return lerp(col, fixed4(0,0,0,.5), vig);
 
                 fixed4 OUT = col;
 
                 OUT = lerp(OUT, _Darker, (vig * (1-per.b) * _Size) / _DegradeSize);
 
                 //fixed4 BColor = fixed4(0,0,0,1);
 
                 //OUT.a = lerp(OUT.a, BColor, vig/2);
 
                 //OUT.rgb = OUT.rgb * (OUT.a) + _Darker.rgb * (1-OUT.a);
                 
                 //OUT.rgb = OUT.a;
 
                 //OUT.a = 1;
 
                 if(tCol.r > 0.01 && tCol.g < 0.2 && tCol.b < 0.2 && _NoRed > 0)
                     tCol.rgb = 0;
 
                 OUT.rgb += tCol.rgb * 0.4;
 
                 return OUT;
             }
             ENDCG
         }
     }
 }

I am using Graphics.Blit to get the camera's render texture, I have a feeling that it is a blending issue, however I have no idea what is needed to fix this. I would like to have it look like the first picture and for it not to get darker when I play the game. Thanks.

wierd1.png (247.5 kB)
wierd2.png (236.3 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

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.

Follow this Question

Answers Answers and Comments

153 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

Related Questions

How to Fade into black and white in a particular scene? 1 Answer

Does Polybrush Texture Blend Shader (HDRP) just have albedo maps, no normal maps? 0 Answers

how to hide intersections between meshes 0 Answers

Accessing RGBA channels of a Texture through a shader. 0 Answers

Lerping normal maps in shadergraph 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