aboutsummaryrefslogtreecommitdiff
path: root/KaplaDemo/externalIP/resources/shaders/dof_fs.cpp
diff options
context:
space:
mode:
authorgit perforce import user <a@b>2016-10-25 12:29:14 -0600
committerSheikh Dawood Abdul Ajees <Sheikh Dawood Abdul Ajees>2016-10-25 18:56:37 -0500
commit3dfe2108cfab31ba3ee5527e217d0d8e99a51162 (patch)
treefa6485c169e50d7415a651bf838f5bcd0fd3bfbd /KaplaDemo/externalIP/resources/shaders/dof_fs.cpp
downloadphysx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.tar.xz
physx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.zip
Initial commit:
PhysX 3.4.0 Update @ 21294896 APEX 1.4.0 Update @ 21275617 [CL 21300167]
Diffstat (limited to 'KaplaDemo/externalIP/resources/shaders/dof_fs.cpp')
-rw-r--r--KaplaDemo/externalIP/resources/shaders/dof_fs.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/KaplaDemo/externalIP/resources/shaders/dof_fs.cpp b/KaplaDemo/externalIP/resources/shaders/dof_fs.cpp
new file mode 100644
index 00000000..98ca0566
--- /dev/null
+++ b/KaplaDemo/externalIP/resources/shaders/dof_fs.cpp
@@ -0,0 +1,38 @@
+ uniform sampler2D colorTex;
+ uniform sampler2D depthTex;
+ uniform float sx;
+ uniform float sy;
+
+ void main (void)
+ {
+ const float depthEnd = 0.993;
+ const float depthSize = 0.015;
+
+ vec3 colorP = texture2D(colorTex, gl_TexCoord[0]).rgb;
+ float depth = texture2D(depthTex, gl_TexCoord[0].st).r;
+
+ if ((depth - depthEnd) < depthSize)
+ {
+ const int depthKernelSize = 5;
+ vec3 colorSum = vec3(0.0);
+ float cnt = 0.0;
+ for (int x = -depthKernelSize; x <= depthKernelSize; x++)
+ for (int y = -depthKernelSize; y <= depthKernelSize; y++)
+ {
+ float s = gl_TexCoord[0].s + x * sy;
+ float t = gl_TexCoord[0].t + y * sy;
+ float scalex = ((depthKernelSize+1) - abs(float(x))) / depthKernelSize;
+ float scaley = ((depthKernelSize+1) - abs(float(y))) / depthKernelSize;
+ float scale = scalex * scaley;
+ vec3 color = texture2D(colorTex, vec2(s,t)).rgb;
+ colorSum += scale * color;
+ cnt += scale;
+ }
+
+ colorSum /= cnt;
+ float depthScale = pow(max(0.0f,min(1.0, ( abs(depth-depthEnd)) / depthSize)),1.5);
+ colorP = depthScale * colorSum + (1.0 - depthScale) * colorP;
+ }
+
+ gl_FragColor = vec4(colorP, 1.0);
+ } \ No newline at end of file