From 61d202edc42edb6faa7354d0fc6868a9743f0247 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 29 Jul 2012 19:42:53 +0000 Subject: [PATCH] fish eye shader works when non-pot textures are not supported --- java/examples/OpenGL/Shaders/FishEye/data/FishEye.glsl | 10 ++++++++-- .../OpenGL/Shaders/GlossyFishEye/data/FishEye.glsl | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/java/examples/OpenGL/Shaders/FishEye/data/FishEye.glsl b/java/examples/OpenGL/Shaders/FishEye/data/FishEye.glsl index 398fdbd9d..65d005e0a 100644 --- a/java/examples/OpenGL/Shaders/FishEye/data/FishEye.glsl +++ b/java/examples/OpenGL/Shaders/FishEye/data/FishEye.glsl @@ -11,6 +11,8 @@ precision mediump int; #endif uniform sampler2D textureSampler; +uniform mat4 texcoordMatrix; + varying vec4 vertColor; varying vec4 vertTexcoord; @@ -26,7 +28,11 @@ void main(void) { // case the area displayed is not the entire half-sphere. float maxFactor = sin(apertureHalf); - vec2 pos = 2.0 * vertTexcoord.st - 1.0; + // The st factor takes into account the situation when non-pot + // textures are not supported, so that the maximum texture + // coordinate to cover the entire image might not be 1. + vec2 stFactor = vec2(1.0 / abs(texcoordMatrix[0][0]), 1.0 / abs(texcoordMatrix[1][1])); + vec2 pos = (2.0 * vertTexcoord.st * stFactor - 1.0); float l = length(pos); if (l > 1.0) { @@ -46,6 +52,6 @@ void main(void) { float u = r * cos(phi) + 0.5; float v = r * sin(phi) + 0.5; - gl_FragColor = texture2D(textureSampler, vec2(u, v)) * vertColor; + gl_FragColor = texture2D(textureSampler, vec2(u, v) / stFactor) * vertColor; } } \ No newline at end of file diff --git a/java/examples/OpenGL/Shaders/GlossyFishEye/data/FishEye.glsl b/java/examples/OpenGL/Shaders/GlossyFishEye/data/FishEye.glsl index 398fdbd9d..65d005e0a 100644 --- a/java/examples/OpenGL/Shaders/GlossyFishEye/data/FishEye.glsl +++ b/java/examples/OpenGL/Shaders/GlossyFishEye/data/FishEye.glsl @@ -11,6 +11,8 @@ precision mediump int; #endif uniform sampler2D textureSampler; +uniform mat4 texcoordMatrix; + varying vec4 vertColor; varying vec4 vertTexcoord; @@ -26,7 +28,11 @@ void main(void) { // case the area displayed is not the entire half-sphere. float maxFactor = sin(apertureHalf); - vec2 pos = 2.0 * vertTexcoord.st - 1.0; + // The st factor takes into account the situation when non-pot + // textures are not supported, so that the maximum texture + // coordinate to cover the entire image might not be 1. + vec2 stFactor = vec2(1.0 / abs(texcoordMatrix[0][0]), 1.0 / abs(texcoordMatrix[1][1])); + vec2 pos = (2.0 * vertTexcoord.st * stFactor - 1.0); float l = length(pos); if (l > 1.0) { @@ -46,6 +52,6 @@ void main(void) { float u = r * cos(phi) + 0.5; float v = r * sin(phi) + 0.5; - gl_FragColor = texture2D(textureSampler, vec2(u, v)) * vertColor; + gl_FragColor = texture2D(textureSampler, vec2(u, v) / stFactor) * vertColor; } } \ No newline at end of file