post_process.glshad

来源:互联网 发布:mac 编译安装php 编辑:程序博客网 时间:2024/06/10 16:56
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////#include "shaders/nmg_common_maths.glinc"////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////NmgCommon{}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////NmgShaders{  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  NmgInterpolators (InterpolatorsMain)  {    varying mediump vec2 PSUV0;  }    NmgInterpolators (InterpolatorsUV4)  {    varying mediump vec2 PSUV0;    varying mediump vec2 PSUV1;    varying mediump vec2 PSUV2;    varying mediump vec2 PSUV3;  }    NmgInterpolators (InterpolatorsUV14)  {    varying mediump vec4 PSUV0_1;    varying mediump vec4 PSUV2_3;    varying mediump vec4 PSUV4_5;    varying mediump vec4 PSUV6_7;    varying mediump vec4 PSUV8_9;    varying mediump vec4 PSUV10_11;    varying mediump vec4 PSUV12_13;  }    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  NmgVertexShader (VS_Main)  {    attribute vec3 VSPosition;    attribute vec2 VSTexCoord0;    void main()    {      gl_Position.xy = VSPosition.xy;      gl_Position.z = 0.0;      gl_Position.w = 1.0;      PSUV0.xy = VSTexCoord0.xy;    }  }    NmgVertexShader (VS_MainUV4)  {    attribute vec3 VSPosition;    attribute vec2 VSTexCoord0;    uniform mediump vec4 g_avSampleOffsets [4];        void main()    {      gl_Position.xy = VSPosition.xy;      gl_Position.z = 0.0;      gl_Position.w = 1.0;      PSUV0.xy = VSTexCoord0.xy + g_avSampleOffsets [0].xy;      PSUV1.xy = VSTexCoord0.xy + g_avSampleOffsets [1].xy;      PSUV2.xy = VSTexCoord0.xy + g_avSampleOffsets [2].xy;      PSUV3.xy = VSTexCoord0.xy + g_avSampleOffsets [3].xy;    }  }    NmgVertexShader (VS_MainUV14)  {    attribute vec3 VSPosition;    attribute vec2 VSTexCoord0;    uniform mediump vec4 g_avSampleOffsets [14];        void main()    {      gl_Position.xy = VSPosition.xy;      gl_Position.z = 0.0;      gl_Position.w = 1.0;      PSUV0_1.xy = VSTexCoord0.xy + g_avSampleOffsets [0].xy;      PSUV0_1.zw = VSTexCoord0.xy + g_avSampleOffsets [1].xy;      PSUV2_3.xy = VSTexCoord0.xy + g_avSampleOffsets [2].xy;      PSUV2_3.zw = VSTexCoord0.xy + g_avSampleOffsets [3].xy;      PSUV4_5.xy = VSTexCoord0.xy + g_avSampleOffsets [4].xy;      PSUV4_5.zw = VSTexCoord0.xy + g_avSampleOffsets [5].xy;      PSUV6_7.xy = VSTexCoord0.xy + g_avSampleOffsets [6].xy;      PSUV6_7.zw = VSTexCoord0.xy + g_avSampleOffsets [7].xy;      PSUV8_9.xy = VSTexCoord0.xy + g_avSampleOffsets [8].xy;      PSUV8_9.zw = VSTexCoord0.xy + g_avSampleOffsets [9].xy;      PSUV10_11.xy = VSTexCoord0.xy + g_avSampleOffsets [10].xy;      PSUV10_11.zw = VSTexCoord0.xy + g_avSampleOffsets [11].xy;      PSUV12_13.xy = VSTexCoord0.xy + g_avSampleOffsets [12].xy;      PSUV12_13.zw = VSTexCoord0.xy + g_avSampleOffsets [13].xy;    }  }    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  NmgPixelShader (PS_ApplyColourLUT2D)  {    uniform sampler2D texSource1;    uniform sampler2D texSource2;    uniform mediump vec4 g_userData;    void main()    {      lowp vec4        vSource = texture2D (texSource1, PSUV0.xy);      mediump float        size = g_userData.x,        sizeRecip = g_userData.y,        sizeMinusOne = (size - 1.0);      mediump vec3        uvw = vSource.rbg;      // Adjust UV coords to centroid sampling      uvw *= vec3 (sizeMinusOne * sizeRecip);      uvw += vec3 (0.5 * sizeRecip);      // v-coord is blue channel (easy), u-coord is red channel scaled down to slice-size      uvw.x *= sizeRecip;      // Calculate the 2 slices to sample from, and the fractional value to interpolate between them later      mediump float        slice = (uvw.z * size) - 0.5;    // Subtract half so we either sample from previous slice (if < 0.5) or next slice (if > 0.5)      mediump float        slice1 = floor (slice),        slice2 = slice1 + 1.0;      slice1 = clamp (slice1, 0.0, sizeMinusOne);      slice2 = clamp (slice2, 0.0, sizeMinusOne);      mediump float        d = 1.0 - (slice2 - slice);      // safer than using (slice - slice1) on unclamped values      slice1 *= sizeRecip;      slice2 *= sizeRecip;      mediump vec2        uv1 = uvw.xy,        uv2 = uvw.xy;      uv1.x += slice1;      uv2.x += slice2;      lowp vec4        samp1 = texture2D (texSource2, uv1),        samp2 = texture2D (texSource2, uv2);      lowp vec4        result = mix (samp1, samp2, d);      gl_FragColor = result;    }  }    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  NmgPixelShader (PS_BlendDecal)  {    uniform sampler2D texSource1;    uniform sampler2D texSource2;        uniform mediump vec4 g_colour1;    uniform mediump vec4 g_colour2;    void main()    {      lowp vec4 inputA = texture2D (texSource1, PSUV0.xy).rgba * g_colour1;      lowp vec4 inputB = texture2D (texSource2, PSUV0.xy).rgba * g_colour2;      lowp vec4 result;    result.rgb = (inputB.rgb * inputB.a) + (inputA.rgb * (1.0 - inputB.a));    result.a = max (inputB.a, inputA.a);        gl_FragColor = result;    }  }    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  NmgPixelShader (PS_Copy)  {    uniform sampler2D texSource1;    uniform mediump vec4 g_colour1;    void main()    {      lowp vec4 textureColour = texture2D (texSource1, PSUV0.xy).rgba;      gl_FragColor = textureColour * g_colour1;    }  }    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  NmgPixelShader (PS_CustomFilter9)  {    uniform sampler2D texSource1;    uniform mediump vec4   g_avSampleOffsets [16];    uniform mediump vec4   g_avSampleWeights [16];    void main()    {      lowp vec4 vColour = vec4(0.0);      for (int i=0; i < 9; i++)      {        vColour += g_avSampleWeights[i].x * texture2D (texSource1, PSUV0.xy + g_avSampleOffsets[i].xy);      }      gl_FragColor = vColour;    }  }  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////    NmgPixelShader (PS_Downsample2x2)  {    uniform sampler2D texSource1;        void main ()    {      mediump vec4 colour;            colour = texture2D (texSource1, PSUV0.xy);      colour += texture2D (texSource1, PSUV1.xy);      colour += texture2D (texSource1, PSUV2.xy);      colour += texture2D (texSource1, PSUV3.xy);            const mediump float R_NUM_SAMPLES = (1.0 / 4.0);      gl_FragColor = colour * R_NUM_SAMPLES;    }  }    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////    NmgPixelShader (PS_Downsample4x4)  {    uniform sampler2D texSource1;    uniform mediump vec4 g_avSampleOffsets [16];        void main ()    {      const int NUM_SAMPLES = 16;      const mediump float R_NUM_SAMPLES = (1.0 / 16.0);      mediump vec4 colour = vec4 (0.0);            for (int i = 0; i < NUM_SAMPLES; i++)      {        colour += texture2D (texSource1, (PSUV0 + g_avSampleOffsets [i].xy));      }            gl_FragColor = colour * R_NUM_SAMPLES;    }  }    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////    NmgPixelShader (PS_DownsampleCube2x2)  {    uniform samplerCube texCubeMap;        uniform mediump mat4 g_matWVP;        uniform mediump vec4   g_avSampleOffsets [16];    uniform mediump vec4   g_avSampleWeights [16];        uniform mediump float g_fSamplerBias;        void main ()    {      const int NUM_SAMPLES = 4;      mediump vec4 vColour = vec4 (0.0, 0.0, 0.0, 0.0);            for (int i = 0; i < NUM_SAMPLES; i++)      {        mediump vec2 uv = PSUV0 + g_avSampleOffsets [i].xy;        uv = (uv * 2.0) - 1.0;        mediump vec3 v = vec3 (uv.x, -uv.y, 1.0);        v = normalize (v);                mediump vec4 medV = vec4 (v.xyz, 0.0);        v = (g_matWVP * medV).xyz;                vColour += textureCube (texCubeMap, v, g_fSamplerBias);      }            gl_FragColor = (vColour * 0.25);    }  }    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  NmgPixelShader (PS_GaussianBlur5x5)  {    uniform sampler2D texSource1;    uniform lowp vec4 g_avSampleWeights [16];        void main ()    {      const int NUM_SAMPLES = 13;      mediump vec4 colour = vec4 (0.0);            colour += texture2D (texSource1, PSUV0_1.xy) * g_avSampleWeights [0];      colour += texture2D (texSource1, PSUV0_1.zw) * g_avSampleWeights [1];      colour += texture2D (texSource1, PSUV2_3.xy) * g_avSampleWeights [2];      colour += texture2D (texSource1, PSUV2_3.zw) * g_avSampleWeights [3];      colour += texture2D (texSource1, PSUV4_5.xy) * g_avSampleWeights [4];      colour += texture2D (texSource1, PSUV4_5.zw) * g_avSampleWeights [5];      colour += texture2D (texSource1, PSUV6_7.xy) * g_avSampleWeights [6];      colour += texture2D (texSource1, PSUV6_7.zw) * g_avSampleWeights [7];      colour += texture2D (texSource1, PSUV8_9.xy) * g_avSampleWeights [8];      colour += texture2D (texSource1, PSUV8_9.zw) * g_avSampleWeights [9];      colour += texture2D (texSource1, PSUV10_11.xy) * g_avSampleWeights [10];      colour += texture2D (texSource1, PSUV10_11.zw) * g_avSampleWeights [11];      colour += texture2D (texSource1, PSUV12_13.xy) * g_avSampleWeights [12];            gl_FragColor = colour;    }  }    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  NmgPixelShader (PS_GaussianBlurSeparable5x5)  {    uniform sampler2D texSource1;    uniform lowp vec4 g_avSampleWeights [16];    void main ()    {      const int NUM_SAMPLES = 5;            mediump vec4 colour = vec4 (0.0);            colour += texture2D (texSource1, PSUV0_1.xy) * g_avSampleWeights [0];      colour += texture2D (texSource1, PSUV0_1.zw) * g_avSampleWeights [1];      colour += texture2D (texSource1, PSUV2_3.xy) * g_avSampleWeights [2];      colour += texture2D (texSource1, PSUV2_3.zw) * g_avSampleWeights [3];            gl_FragColor = colour;    }  }    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  NmgPixelShader (PS_GaussianBlurSeparable9x9)  {    uniform sampler2D texSource1;    uniform lowp vec4 g_avSampleWeights [16];    void main ()    {      const int NUM_SAMPLES = 9;          mediump vec4 colour = vec4 (0.0);            colour += texture2D (texSource1, PSUV0_1.xy) * g_avSampleWeights [0];      colour += texture2D (texSource1, PSUV0_1.zw) * g_avSampleWeights [1];      colour += texture2D (texSource1, PSUV2_3.xy) * g_avSampleWeights [2];      colour += texture2D (texSource1, PSUV2_3.zw) * g_avSampleWeights [3];      colour += texture2D (texSource1, PSUV4_5.xy) * g_avSampleWeights [4];      colour += texture2D (texSource1, PSUV4_5.zw) * g_avSampleWeights [5];      colour += texture2D (texSource1, PSUV6_7.xy) * g_avSampleWeights [6];      colour += texture2D (texSource1, PSUV6_7.zw) * g_avSampleWeights [7];      colour += texture2D (texSource1, PSUV8_9.xy) * g_avSampleWeights [8];            gl_FragColor = colour;    }  }    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  NmgPixelShader (PS_GaussianBlurOpaque5x5)  {    uniform sampler2D texSource1;        void cw (inout mediump float totalWeight, inout mediump vec4 vColour, mediump vec4 sample)    {      vColour.rgb += (sample.rgb * sample.a);      totalWeight += sample.a;    }        void main ()    {      const int NUM_SAMPLES = 13;      mediump float totalWeight = 0.0;      mediump vec4 vColour = vec4 (0.0, 0.0, 0.0, 0.0);      mediump vec4 vCentre = texture2D (texSource1, PSUV0_1.xy);      if (vCentre.a > 0.0)      {        mediump vec4 vSample = texture2D (texSource1, PSUV0_1.xy);        cw (totalWeight, vColour, vSample);        vSample = texture2D (texSource1, PSUV0_1.zw);        cw (totalWeight, vColour, vSample);        vSample = texture2D (texSource1, PSUV2_3.xy);        cw (totalWeight, vColour, vSample);        vSample = texture2D (texSource1, PSUV2_3.zw);        cw (totalWeight, vColour, vSample);        vSample = texture2D (texSource1, PSUV4_5.xy);        cw (totalWeight, vColour, vSample);        vSample = texture2D (texSource1, PSUV4_5.zw);        cw (totalWeight, vColour, vSample);        vSample = texture2D (texSource1, PSUV6_7.xy);        cw (totalWeight, vColour, vSample);        vSample = texture2D (texSource1, PSUV6_7.zw);        cw (totalWeight, vColour, vSample);        vSample = texture2D (texSource1, PSUV8_9.xy);        cw (totalWeight, vColour, vSample);        vSample = texture2D (texSource1, PSUV8_9.zw);        cw (totalWeight, vColour, vSample);        vSample = texture2D (texSource1, PSUV10_11.xy);        cw (totalWeight, vColour, vSample);        vSample = texture2D (texSource1, PSUV10_11.zw);        cw (totalWeight, vColour, vSample);        vSample = texture2D (texSource1, PSUV12_13.xy);        cw (totalWeight, vColour, vSample);        vColour.rgb /= totalWeight;        vColour.a = 1.0;      }      else      {        vColour = vCentre;      }      gl_FragColor = vColour;    }  }    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  NmgPixelShader (PS_GaussianBlurCube5x5)  {    uniform samplerCube texCubeMap;    uniform mediump mat4 g_matWVP;    uniform lowp vec4 g_avSampleWeights [16];    uniform mediump vec4 g_avSampleOffsets [16];    void main ()    {      const int NUM_SAMPLES = 13;      mediump vec4 colour = vec4 (0.0);            // Loop unrolled to fix compilation on Samsung Galaxy S4 I9500 (PowerVR SGX544MP3)      // WARNING: 0:25: Calls to any function that may require a gradient calculation inside a conditional block may return undefined results      mediump vec2 uv;      mediump vec3 v;      mediump vec4 v4;            uv = PSUV0.xy + g_avSampleOffsets [0].xy;      uv = (uv * 2.0) - 1.0;      v = vec3 (uv.x, -uv.y, 1.0);      v = normalize (v);      v4 = g_matWVP * vec4 (v, 0.0);      v = v4.xyz;      colour += textureCube (texCubeMap, v) * g_avSampleWeights [0];            uv = PSUV0.xy + g_avSampleOffsets [1].xy;      uv = (uv * 2.0) - 1.0;      v = vec3 (uv.x, -uv.y, 1.0);      v = normalize (v);      v4 = g_matWVP * vec4 (v, 0.0);      v = v4.xyz;      colour += textureCube (texCubeMap, v) * g_avSampleWeights [1];            uv = PSUV0.xy + g_avSampleOffsets [2].xy;      uv = (uv * 2.0) - 1.0;      v = vec3 (uv.x, -uv.y, 1.0);      v = normalize (v);      v4 = g_matWVP * vec4 (v, 0.0);      v = v4.xyz;      colour += textureCube (texCubeMap, v) * g_avSampleWeights [2];            uv = PSUV0.xy + g_avSampleOffsets [3].xy;      uv = (uv * 2.0) - 1.0;      v = vec3 (uv.x, -uv.y, 1.0);      v = normalize (v);      v4 = g_matWVP * vec4 (v, 0.0);      v = v4.xyz;      colour += textureCube (texCubeMap, v) * g_avSampleWeights [3];            uv = PSUV0.xy + g_avSampleOffsets [4].xy;      uv = (uv * 2.0) - 1.0;      v = vec3 (uv.x, -uv.y, 1.0);      v = normalize (v);      v4 = g_matWVP * vec4 (v, 0.0);      v = v4.xyz;      colour += textureCube (texCubeMap, v) * g_avSampleWeights [4];            uv = PSUV0.xy + g_avSampleOffsets [5].xy;      uv = (uv * 2.0) - 1.0;      v = vec3 (uv.x, -uv.y, 1.0);      v = normalize (v);      v4 = g_matWVP * vec4 (v, 0.0);      v = v4.xyz;      colour += textureCube (texCubeMap, v) * g_avSampleWeights [5];            uv = PSUV0.xy + g_avSampleOffsets [6].xy;      uv = (uv * 2.0) - 1.0;      v = vec3 (uv.x, -uv.y, 1.0);      v = normalize (v);      v4 = g_matWVP * vec4 (v, 0.0);      v = v4.xyz;      colour += textureCube (texCubeMap, v) * g_avSampleWeights [6];            uv = PSUV0.xy + g_avSampleOffsets [7].xy;      uv = (uv * 2.0) - 1.0;      v = vec3 (uv.x, -uv.y, 1.0);      v = normalize (v);      v4 = g_matWVP * vec4 (v, 0.0);      v = v4.xyz;      colour += textureCube (texCubeMap, v) * g_avSampleWeights [7];            uv = PSUV0.xy + g_avSampleOffsets [8].xy;      uv = (uv * 2.0) - 1.0;      v = vec3 (uv.x, -uv.y, 1.0);      v = normalize (v);      v4 = g_matWVP * vec4 (v, 0.0);      v = v4.xyz;      colour += textureCube (texCubeMap, v) * g_avSampleWeights [8];            uv = PSUV0.xy + g_avSampleOffsets [9].xy;      uv = (uv * 2.0) - 1.0;      v = vec3 (uv.x, -uv.y, 1.0);      v = normalize (v);      v4 = g_matWVP * vec4 (v, 0.0);      v = v4.xyz;      colour += textureCube (texCubeMap, v) * g_avSampleWeights [9];            uv = PSUV0.xy + g_avSampleOffsets [10].xy;      uv = (uv * 2.0) - 1.0;      v = vec3 (uv.x, -uv.y, 1.0);      v = normalize (v);      v4 = g_matWVP * vec4 (v, 0.0);      v = v4.xyz;      colour += textureCube (texCubeMap, v) * g_avSampleWeights [10];            uv = PSUV0.xy + g_avSampleOffsets [11].xy;      uv = (uv * 2.0) - 1.0;      v = vec3 (uv.x, -uv.y, 1.0);      v = normalize (v);      v4 = g_matWVP * vec4 (v, 0.0);      v = v4.xyz;      colour += textureCube (texCubeMap, v) * g_avSampleWeights [11];            uv = PSUV0.xy + g_avSampleOffsets [12].xy;      uv = (uv * 2.0) - 1.0;      v = vec3 (uv.x, -uv.y, 1.0);      v = normalize (v);      v4 = g_matWVP * vec4 (v, 0.0);      v = v4.xyz;      colour += textureCube (texCubeMap, v) * g_avSampleWeights [12];      gl_FragColor = colour;    }  }    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  NmgPixelShader (PS_DOF)  {         uniform sampler2D texSource1; // Source Colour    uniform sampler2D texSource2; // Downsampled + Blurred    uniform sampler2D texSource3; // Source Depth         uniform mediump vec4 g_vDOFConstants;    uniform mediump vec4 g_vDepthConstants;    uniform mediump vec4 g_vDOFPixelSize;        mediump float calculateDepthBlur (highp float fDepth, mediump vec2 texUV)    {            mediump float fFocalPlaneDistance = g_vDOFConstants.x;      mediump float fNearBlurPlaneDistance = g_vDOFConstants.y;      mediump float fFarBlurPlaneDistance = g_vDOFConstants.z;      mediump float fFarBlurLimit = g_vDOFConstants.w;                 mediump float fDepthBlur;            if (fDepth < fFocalPlaneDistance)      {        fDepthBlur = (fDepth - fFocalPlaneDistance) / (fFocalPlaneDistance - fNearBlurPlaneDistance);        fDepthBlur *= (fDepthBlur * fDepthBlur);        fDepthBlur = max (fDepthBlur, -fFarBlurLimit);      }      else      {        fDepthBlur = (fDepth - fFocalPlaneDistance) / (fFarBlurPlaneDistance - fFocalPlaneDistance);        fDepthBlur = min (fDepthBlur, fFarBlurLimit);      }            fDepthBlur = abs (fDepthBlur);            return fDepthBlur;    }        mediump vec4 simpleDOF (mediump vec4 vSample, sampler2D texLowRes, mediump vec2 texUV)    {      const mediump vec2 c_vMaxCoC = vec2 (5.0, 10.0);      const mediump float c_fRadiusScale = 0.5;      const int NUM_POISSON_TAPS = 4;            mediump float fTapBlur = vSample.a;      // Save depth      mediump vec3 vTapHigh = vSample.rgb;            mediump float fCenterDepth = vSample.a;      // Convert depth into blur radius in pixels      mediump float fDiscRadius = abs (fCenterDepth * c_vMaxCoC.y - c_vMaxCoC.x);              // Compute disc radius on low-res image      mediump float fDiscRadiusLow = fDiscRadius * c_fRadiusScale;      //      // Treat center point as one of our taps      //      mediump vec2 vCoordLow = texUV;      mediump vec3 vTapLow = texture2D (texLowRes, vCoordLow).rgb;      // Mix lo-res and hi-res taps based on bluriness      mediump vec3 vTap = lerp (vTapHigh, vTapLow, fTapBlur);                  return vec4 (vTap.xyz, 1.0);      // Accumulate output color across all taps      /*mediump vec4 vOutColor;            vOutColor.rgb = vTap.rgb;      vOutColor.a   = 1.0;            //      // Unoptimised basic version      //          mediump vec2 g_Poisson [NUM_POISSON_TAPS] ;      g_Poisson [0] = vec2 (-0.5, 0.0);      g_Poisson [1] = vec2 (0.5, 0.0);      g_Poisson [2] = vec2 (0.0, -0.5);      g_Poisson [3] = vec2 (0.0, 0.5);              for (int i = 0; i < NUM_POISSON_TAPS; i++)      {        // Fetch lo-res tap        mediump vec2 vCoordLowInner = texUV + (g_vDOFPixelSize.zw * g_Poisson[i] * fDiscRadiusLow);        mediump vec3 vTapLowInner = texture2D (texLowRes, vCoordLowInner).rgb;                    // Mix lo-res and hi-res taps based on bluriness        mediump vec3 vTapInner = lerp (vTapHigh, vTapLowInner, fTapBlur);                    // Accumumate        vOutColor.rgb += vTapInner.rgb * fTapBlur;        vOutColor.a   += fTapBlur;      }            // Normalize result      vSample = (vOutColor / vOutColor.a);            return vSample;*/    }          void main ()    {      mediump vec4 sample = texture2D (texSource1, PSUV0);            /*      mediump float alpha = sample.a;      mediump float adaptedLum = texture2D (texSource5, vec2 (0.5, 0.5)).g;      mediump float midGrey = texture2D (texSource6, vec2 (0.5, 0.5)).r;      *///#define Z_IN_ALPHA 1#if !defined (Z_IN_ALPHA)      highp float zDepth = texture2D (texSource3, PSUV0).r;            // Go from range of 0.5 -> 1.0 to the range 0.0 to 1.0      zDepth = (zDepth - 0.5) * 2.0;      highp float fDepth = g_vDepthConstants.y / (zDepth + g_vDepthConstants.x);#else      highp float zDepth = sample.a;      highp float fDepth = (1.0 - sqrt (zDepth)) * 20.0;#endif      sample.a = calculateDepthBlur (fDepth, PSUV0);      sample   = simpleDOF (sample, texSource2, PSUV0);           //mediump vec4 sample = texture2D (texSource2, PSUV0);      gl_FragColor = sample;    }  }  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  NmgPixelShader (PS_DOFPreCalc)  {         uniform sampler2D texSource1; // Source Colour    uniform sampler2D texSource2; // Downsampled + Blurred    mediump vec4 simpleDOFBlend (sampler2D texHighRes, sampler2D texLowRes, mediump vec2 texUV)    {      mediump vec4 vSample = texture2D (texHighRes, texUV);      mediump float fTapBlur = vSample.a;      mediump vec3 vTapHigh = vSample.rgb;      mediump vec2 vCoordLow = texUV;      mediump vec3 vTapLow = texture2D (texLowRes, vCoordLow).rgb;      // Mix lo-res and hi-res taps based on blurriness      mediump vec3 vTap = lerp (vTapHigh, vTapLow, fTapBlur);      return vec4 (vTap.xyz, 1.0);    }    void main ()    {      mediump vec4 sample = simpleDOFBlend (texSource1, texSource2, PSUV0);      gl_FragColor = sample;    }  }  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  NmgPixelShader (PS_ApplyTint)  {    const mediump vec3 LUMINANCE_VECTOR = vec3 (0.2125, 0.7154, 0.0721);      uniform sampler2D texSource1; // source    uniform sampler2D texSource2; // gradient map    uniform mediump float g_filterGradientMapBlend;        mediump vec3 ApplyGradientMap (mediump vec3 inputColour, mediump float lum, mediump float blend, sampler2D sampGradientMap)    {      mediump vec4 grad = texture2D (sampGradientMap, vec2 (lum, 0.0));       mediump vec3 result = lerp (inputColour.rgb, grad.rgb, blend * grad.a);      return result;    }    void main ()    {      mediump vec4 sample = texture2D (texSource1, PSUV0);            mediump float luminance = dot (sample.rgb, LUMINANCE_VECTOR);            sample.rgb = ApplyGradientMap (sample.rgb, luminance, g_filterGradientMapBlend, texSource2);            gl_FragColor = sample;    }  }  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  NmgPixelShader (PS_PreMultiplyAlpha)  {    uniform sampler2D texSource1;    void main()    {      lowp vec4 textureColour = texture2D (texSource1, PSUV0.xy).rgba;      textureColour.xyz *= textureColour.w;            gl_FragColor = textureColour;    }  }    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////NmgTechnique (PostApplyColourLUT2D,         VS_Main, InterpolatorsMain, PS_ApplyColourLUT2D)NmgTechnique (PostBlendDecal,               VS_Main, InterpolatorsMain, PS_BlendDecal)NmgTechnique (PostCopy,                     VS_Main, InterpolatorsMain, PS_Copy)NmgTechnique (PostCustomFilter9,            VS_Main, InterpolatorsMain, PS_CustomFilter9)NmgTechnique (PostDownsample2x2,            VS_MainUV4, InterpolatorsUV4, PS_Downsample2x2)NmgTechnique (PostDownsample4x4,            VS_Main, InterpolatorsMain, PS_Downsample4x4)NmgTechnique (PostDownsampleCube2x2,        VS_Main, InterpolatorsMain, PS_DownsampleCube2x2)NmgTechnique (PostGaussianBlur5x5,          VS_MainUV14, InterpolatorsUV14, PS_GaussianBlur5x5)NmgTechnique (PostGaussianBlurSeparable5x5, VS_MainUV14, InterpolatorsUV14, PS_GaussianBlurSeparable5x5);NmgTechnique (PostGaussianBlurSeparable9x9, VS_MainUV14, InterpolatorsUV14, PS_GaussianBlurSeparable9x9);NmgTechnique (PostGaussianBlurOpaque5x5,    VS_MainUV14, InterpolatorsUV14, PS_GaussianBlurOpaque5x5);NmgTechnique (PostGaussianBlurCube5x5,      VS_Main, InterpolatorsMain, PS_GaussianBlurCube5x5);NmgTechnique (PostDepthOfField,             VS_Main, InterpolatorsMain, PS_DOF);NmgTechnique (PostDepthOfFieldPreCalc,      VS_Main, InterpolatorsMain, PS_DOFPreCalc);NmgTechnique (PostApplyTint,                VS_Main, InterpolatorsMain, PS_ApplyTint);NmgTechnique (PreMultiplyAlpha,             VS_Main, InterpolatorsMain, PS_PreMultiplyAlpha);////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

0 0