[SOLVED] PGraphics or PImage as Uniform not working when using GLSL in Java OpenGL

UPDATE - PROBLEM SOLVED

Looks like that in order to pass a texture to the vertex shader, you need to pass it also to the fragment shader, something I never considered.

New Vertex Shader:

uniform mat4 transform;

attribute vec4 vertex;

uniform sampler2D txtr;

void main() {
    vec2 c = vec2(0.5, 0.5);  // uv coordinate on the texture, ideally an attribute
    float st = texture2D(txtr, c).r;  // get the color of that pixel
    gl_Position = transform * vertex;  // apply the transformation
    gl_PointSize = st * 10.0;    // point size according to the red channel of the specific pixel
}

New fragment shader

varying vec4 vertColor;

uniform sampler2D txtr;

void main() {
    vec2 c = vec2(0.5, 0.5);  // uv coordinate on the texture, ideally an attribute
    vec3 s = texture2D(txtr, c).rgb;  // get the color of that pixel
    gl_FragColor = vec4(s.r, s.g, s.b, 1.0);   // apply the color to the particle
}
3 Likes