1 Shader "Hidden/ColorCorrectionCurves" {
2     Properties {
3         _MainTex (
"Base (RGB)", 2D) = "" {}
4
5         _RgbTex (
"_RgbTex (RGB)", 2D) = "" {}
6         
7         _ZCurve (
"_ZCurve (RGB)", 2D) = "" {}
8         
9         _RgbDepthTex (
"_RgbDepthTex (RGB)", 2D) = "" {}
10     }
11     
12     
// note: also have a look at ColorCorrectionCurvesSimple
13     
// for a much simpler color correction without use of
14     
// depth texture lookups
15     
16     
// Shader code pasted into all further CGPROGRAM blocks
17     CGINCLUDE
18
19     #include
"UnityCG.cginc"
20     
21     
struct v2f {
22         float4 pos : SV_POSITION;
23         float2 uv : TEXCOORD0;
24         float2 uv2 : TEXCOORD1;
25     };
26      
27     sampler2D _MainTex;
28     sampler2D_float _CameraDepthTexture;
29     
30     float4 _CameraDepthTexture_ST;
31     uniform float4 _MainTex_TexelSize;
32     
33     sampler2D _RgbTex;
34     sampler2D _ZCurve;
35     sampler2D _RgbDepthTex;
36
37     
fixed _Saturation;
38     
39     v2f vert( appdata_img v )
40     {
41         v2f o;
42         o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
43         o.uv = v.texcoord.xy;
44         o.uv2 = TRANSFORM_TEX(v.texcoord, _CameraDepthTexture);
45         
46         #
if UNITY_UV_STARTS_AT_TOP
47         
if (_MainTex_TexelSize.y < 0)
48             o.uv2.y =
1-o.uv2.y;
49         #endif
50         
51         
return o;
52     }
53     
54     half4 frag(v2f i) : SV_Target
55     {
56         half4 color = tex2D(_MainTex, i.uv);
57
58         half3 ycoords = half3(
0.5,1.5,2.5) * 0.25;
59         
60         half3 red = tex2D(_RgbTex, half2(color.r, ycoords.x)).rgb * half3(
1,0,0);
61         half3 green = tex2D(_RgbTex, half2(color.g, ycoords.y)).rgb * half3(
0,1,0);
62         half3 blue = tex2D(_RgbTex, half2(color.b, ycoords.z)).rgb * half3(
0,0,1);
63         
64         half theDepth = SAMPLE_DEPTH_TEXTURE( _CameraDepthTexture, i.uv2) ;
65         half zval = tex2D(_ZCurve, half2( Linear01Depth (theDepth),
0.5));
66         
67         half3 depthRed = tex2D(_RgbDepthTex, half2(color.r, ycoords.x)).rgb * half3(
1,0,0);
68         half3 depthGreen = tex2D(_RgbDepthTex, half2(color.g, ycoords.y)).rgb * half3(
0,1,0);
69         half3 depthBlue = tex2D(_RgbDepthTex, half2(color.b, ycoords.z)).rgb * half3(
0,0,1);
70         
71         color = half4( lerp(red+green+blue, depthRed+depthBlue+depthGreen, zval), color.a);
72
73         half lum = Luminance(color.rgb);
74         color.rgb = lerp(half3(lum,lum,lum), color.rgb, _Saturation);
75         
return color;
76     }
77
78     ENDCG
79     
80 Subshader {
81  Pass {
82       ZTest Always Cull Off ZWrite Off
83
84       CGPROGRAM
85       #pragma vertex vert
86       #pragma fragment frag
87       ENDCG
88   }
89 }
90
91 Fallback off
92     
93 }
// shader


Gõ tìm kiếm nhanh...