summaryrefslogtreecommitdiff
path: root/src/shader/CalcGradient_glsl_ps.h
diff options
context:
space:
mode:
authorJason Maskell <Jason Maskell>2016-08-01 12:10:17 +0700
committerJason Maskell <Jason Maskell>2016-08-01 12:10:17 +0700
commit4f696cb8b1ee6fe6056017272ede68e38abb0564 (patch)
treed8cdb963e00bc8ef60d047c2e647eece6eeaa0bb /src/shader/CalcGradient_glsl_ps.h
parentDon't need FindDirectX anymore, so deleted it and modified the cmake files. (diff)
downloadwaveworks_archive-4f696cb8b1ee6fe6056017272ede68e38abb0564.tar.xz
waveworks_archive-4f696cb8b1ee6fe6056017272ede68e38abb0564.zip
Removed nvsf_ prefix from all shader variables.
Added manually generated glsl.h files for the OpenGL sample. Breaking DRY but no longer need sed and an external CL call to get glsl. Worth the tradeoff. OpenGL sample now compiles and runs but fails at runtime when loading a texture.
Diffstat (limited to 'src/shader/CalcGradient_glsl_ps.h')
-rw-r--r--src/shader/CalcGradient_glsl_ps.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/shader/CalcGradient_glsl_ps.h b/src/shader/CalcGradient_glsl_ps.h
new file mode 100644
index 0000000..2ef7ed8
--- /dev/null
+++ b/src/shader/CalcGradient_glsl_ps.h
@@ -0,0 +1,36 @@
+R"glsl(
+//------------------------------------------------------------------------------------
+// Global variables
+//------------------------------------------------------------------------------------
+
+uniform vec4 g_Scales;
+uniform vec4 g_OneTexel_Left;
+uniform vec4 g_OneTexel_Right;
+uniform vec4 g_OneTexel_Back;
+uniform vec4 g_OneTexel_Front;
+
+uniform sampler2D g_samplerDisplacementMap;
+
+varying float2 vInterpTexCoord;
+
+void main()
+{
+ // Sample neighbour texels
+ float3 displace_left = texture(g_samplerDisplacementMap, vInterpTexCoord.xy + g_OneTexel_Left.xy).rgb;
+ float3 displace_right = texture(g_samplerDisplacementMap, vInterpTexCoord.xy + g_OneTexel_Right.xy).rgb;
+ float3 displace_back = texture(g_samplerDisplacementMap, vInterpTexCoord.xy + g_OneTexel_Back.xy).rgb;
+ float3 displace_front = texture(g_samplerDisplacementMap, vInterpTexCoord.xy + g_OneTexel_Front.xy).rgb;
+
+ // -------- Do not store the actual normal value, instead, it preserves two differential values.
+ float2 gradient = float2(-(displace_right.z - displace_left.z) / max(0.01,1.0 + g_Scales.y*(displace_right.x - displace_left.x)), -(displace_front.z - displace_back.z) / max(0.01,1.0+g_Scales.y*(displace_front.y - displace_back.y)));
+ //float2 gradient = {-(displace_right.z - displace_left.z), -(displace_front.z - displace_back.z) };
+
+ // Calculate Jacobian corelation from the partial differential of displacement field
+ float2 Dx = (displace_right.xy - displace_left.xy) * g_Scales.x;
+ float2 Dy = (displace_front.xy - displace_back.xy) * g_Scales.x;
+ float J = (1.0f + Dx.x) * (1.0f + Dy.y) - Dx.y * Dy.x;
+
+ // Output
+ gl_FragColor = float4(gradient, J, 0);
+}
+)glsl";