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