I’m trying my hardest to understand shaders. I know how they work theoretically, the coding seems to be difficult.
While trying to write a shader I stumbled onto this problem…
Processing:
PImage img;
PShader shader;
void setup() {
size(640, 480, P2D);
img = loadImage(dataPath("image.jpg"));
shader = new PShader(this, dataPath("vert.glsl"), dataPath("frag.glsl"));
}
void draw() {
background(127); // set background color to white
image(img, 0, 0, width, height);
filter(shader);
save(dataPath("output.png"));
}
Vertex shader ‘data\vertex.glsl’:
attribute vec4 position;
attribute vec2 texCoord;
out vec2 vTexCoord;
void main() {
vTexCoord = texCoord;
gl_Position = position;
}
Fragment shader ‘data\frag.glsl’:
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D tex;
in vec2 vTexCoord;
void main() {
vec4 col = texture2D(tex, vTexCoord);
gl_FragColor = vec4(col.r, 0.0, 0.0, col.a); // keep only the red channel
}
Input image ‘data\image.jpg’:
Output image ‘data\output.png’:
Even removing everything related to the image gives me a black corner.
Processing:
PShader shader;
void setup() {
size(640, 480, P2D);
shader = new PShader(this, dataPath("vert.glsl"), dataPath("frag.glsl"));
}
void draw() {
filter(shader);
save(dataPath("output.png"));
}
Output image:
Using a default renderer gives me an error:
PShader shader;
void setup() {
size(640, 480);
shader = new PShader(this, dataPath("vert.glsl"), dataPath("frag.glsl"));
}
void draw() {
filter(shader);
save(dataPath("output.png"));
}
JustATest.pde:5:0:5:0: ClassCastException: class processing.awt.PGraphicsJava2D cannot be cast to class processing.opengl.PGraphicsOpenGL (processing.awt.PGraphicsJava2D and processing.opengl.PGraphicsOpenGL are in unnamed module of loader 'app')
What even is the problem and how do I fix it?