Created
May 28, 2016 15:53
-
-
Save sagarpatel/eca7d52c3c3e4a9f0f44811ac88c5d44 to your computer and use it in GitHub Desktop.
fixed hirontal articfacts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Hidden/NewImageEffectShader" | |
{ | |
Properties | |
{ | |
_MainTex ("Texture", 2D) = "white" {} | |
_EffectScaler ("Effect Scaler", float) = 0 | |
_EffectLerp ("Effect Lerp", float) = 0 | |
} | |
SubShader | |
{ | |
// No culling or depth | |
Cull Off ZWrite Off ZTest Always | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float2 uv : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
float4 scrPos:TEXCOORD1; | |
}; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); | |
o.uv = v.uv; | |
o.scrPos = ComputeScreenPos(o.vertex); | |
return o; | |
} | |
sampler2D _MainTex; | |
uniform half4 _MainTex_TexelSize; | |
sampler2D _CameraDepthTexture; | |
float _EffectScaler; | |
float _EffectLerp; | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
// pixel to uv ratios | |
float pr_x = 1 / _MainTex_TexelSize.x; | |
float pr_y = 1 / _MainTex_TexelSize.y; | |
fixed4 col = tex2D(_MainTex, i.uv); | |
fixed4 ogCol = col; | |
float ogColPowerScaler = ogCol.x;//length(ogCol); | |
float depth = pow(1 - Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv)), 10); | |
float offset_x = depth * min(pow(frac(i.uv.y / 7) * _EffectScaler * ogColPowerScaler, 2), 0.1); | |
float2 offsetCoord_1 = float2(i.uv.x + offset_x, i.uv.y); | |
float2 offsetCoord_2 = float2(i.uv.x - offset_x, i.uv.y); | |
fixed4 samp_1 = tex2D(_MainTex, offsetCoord_1); | |
fixed4 samp_2 = tex2D(_MainTex, offsetCoord_2); | |
fixed4 effectCol_1 = (depth *ogCol + samp_1 + samp_2) /3; | |
//col = pow( 1- Linear01Depth(tex2D(_CameraDepthTexture, i.uv)), 100 ); | |
//float depth = 1- pow( Linear01Depth(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos)).r), 1) ; | |
col = lerp(ogCol, effectCol_1, _EffectLerp ); | |
//col = fixed4(depth,depth,depth,1); | |
//col = abs(col - brightness); | |
// just invert the colors | |
//col = 1 - col; | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment