fish eye shader works when non-pot textures are not supported

This commit is contained in:
codeanticode
2012-07-29 19:42:53 +00:00
parent 90c070e759
commit 61d202edc4
2 changed files with 16 additions and 4 deletions
@@ -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;
}
}
@@ -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;
}
}