mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
fish eye shader works when non-pot textures are not supported
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user