updates to the shader examples in android

This commit is contained in:
codeanticode
2012-07-29 19:43:25 +00:00
parent 61d202edc4
commit 2acc1fac60
7 changed files with 21 additions and 34 deletions

View File

@@ -1,5 +1,3 @@
// Issues: flickers and scene doesn't move
PShader edges;
boolean applyFilter = true;

View File

@@ -1,6 +1,3 @@
// Issues: crashes with
// java.lang.RuntimeException: can only create 8 lights
// Fish-eye shader, useful for dome projection
PGraphics canvas;

View File

@@ -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;
}
}

View File

@@ -1,5 +1,3 @@
// Issues: same as FishEye
// Fish-eye shader on the main surface, glossy specular reflection shader
// on the offscreen canvas.

View File

@@ -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;
}
}

View File

@@ -1,6 +1,3 @@
// Issues: shader cannot be compiled:
// (48) : error C5013: profile does not support "for" statements and "for" could not be unrolled.
// Separable-blur shader (works by applying two successive passes
// in each direction of the image)
@@ -12,7 +9,6 @@ void setup() {
size(200, 200, P2D);
blur = loadShader(PShader.TEXTURED, "blur.glsl");
blur.set("blurSize", 9);
blur.set("sigma", 5.0f);
src = createGraphics(width, height, P2D);
@@ -48,18 +44,3 @@ void draw() {
image(pass2, 0, 0);
}
void keyPressed() {
if (key == '9') {
blur.set("blurSize", 9);
blur.set("sigma", 5.0);
} else if (key == '7') {
blur.set("blurSize", 7);
blur.set("sigma", 3.0);
} else if (key == '5') {
blur.set("blurSize", 5);
blur.set("sigma", 2.0);
} else if (key == '3') {
blur.set("blurSize", 5);
blur.set("sigma", 1.0);
}
}

View File

@@ -14,7 +14,6 @@ uniform vec2 texcoordOffset;
varying vec4 vertColor;
varying vec4 vertTexcoord;
uniform int blurSize;
uniform int horizontalPass; // 0 or 1 to indicate vertical or horizontal pass
uniform float sigma; // The sigma value for the gaussian function: higher value means more blur
// A good value for 9x9 is around 3 to 5
@@ -24,9 +23,11 @@ uniform float sigma; // The sigma value for the gaussian function: higher
const float pi = 3.14159265;
// Blur size divided by two (it is hard-coded because GLSL ES doesn't support
// variable loop length).
const float iter = 4.5;
void main() {
float numBlurPixelsPerSide = float(blurSize / 2);
vec2 blurMultiplyVec = 0 < horizontalPass ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
// Incremental Gaussian Coefficent Calculation (See GPU Gems 3 pp. 877 - 889)
@@ -44,7 +45,7 @@ void main() {
incrementalGaussian.xy *= incrementalGaussian.yz;
// Go through the remaining 8 vertical samples (4 on each side of the center)
for (float i = 1.0; i <= numBlurPixelsPerSide; i++) {
for (float i = 1.0; i <= iter; i++) {
avgValue += texture2D(textureSampler, vertTexcoord.st - i * texcoordOffset *
blurMultiplyVec) * incrementalGaussian.x;
avgValue += texture2D(textureSampler, vertTexcoord.st + i * texcoordOffset *