aboutsummaryrefslogtreecommitdiff
path: root/KaplaDemo/externalIP/resources/ssao.fs
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/ssao.fs
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/ssao.fs')
-rw-r--r--KaplaDemo/externalIP/resources/ssao.fs45
1 files changed, 45 insertions, 0 deletions
diff --git a/KaplaDemo/externalIP/resources/ssao.fs b/KaplaDemo/externalIP/resources/ssao.fs
new file mode 100644
index 00000000..52d04f7d
--- /dev/null
+++ b/KaplaDemo/externalIP/resources/ssao.fs
@@ -0,0 +1,45 @@
+#define SAMPLEDIV 4
+#define NUMSAMPLES SAMPLEDIV*SAMPLEDIV
+#define iNUMSAMPLES 1.0f / (SAMPLEDIV * SAMPLEDIV)
+#define BIAS 1.0f
+
+uniform vec3 samples[NUMSAMPLES];
+uniform sampler2D depthTex;
+uniform sampler2D normalTex;
+uniform sampler2D unitVecTex;
+uniform mat4x4 biasProjMat;
+uniform mat4x4 biasProjMatInv;
+
+void main (void)
+{
+ float ssao = 0.0;
+ float depth = texture2D(depthTex, gl_TexCoord[0].st).r;
+ if(depth < 1.0)
+ {
+ vec3 dir = normalize(texture2D(unitVecTex, gl_TexCoord[1].st).rgb * 2.0f - 1.0f);
+ vec3 n = normalize(texture2D(normalTex, gl_TexCoord[0].st).rgb * 2.0f - 1.0f);
+ vec4 myPosEye = biasProjMatInv * vec4(gl_TexCoord[0].st, depth, 1.0f);
+ myPosEye.xyz /= myPosEye.w;
+ vec3 t0 = normalize(dir - n * dot(dir, n));
+ vec3 t1 = cross(n, t0);
+ mat3x3 rmat = mat3x3(t0, t1, n);
+ for(int i = 0; i < NUMSAMPLES; i++)
+ {
+ vec3 samplePosEye = rmat * samples[i] + myPosEye.xyz;
+ vec4 samplePosScreen = biasProjMat * vec4(samplePosEye, 1.0f);
+ samplePosScreen.xyz /= samplePosScreen.w;
+ float sampleDepth = texture2D(depthTex, samplePosScreen.st).r;
+ if(sampleDepth < samplePosScreen.z)
+ {
+ vec4 surfacePosWorld = biasProjMatInv * vec4(samplePosScreen.st, sampleDepth, 1.0f);
+ surfacePosWorld.xyz /= surfacePosWorld.w;
+ vec3 p2p = surfacePosWorld.xyz - myPosEye.xyz;
+ ssao += 1.0f / (BIAS+dot(p2p, p2p));
+ }
+ }
+ ssao = 1.0f - ssao * iNUMSAMPLES;
+ } else {
+ ssao = 1.0f;
+ }
+ gl_FragColor = vec4(ssao,ssao,ssao,1.0f);
+}