Accessing TEXDIM0 in GL3

Jim Bastow's icon

I'm having issues accessing the TEXDIM0 state in my vertex shader when using the GL3 package. The shader doesn't return an error but it seems like there isn't any value in the state.

Weirdly if I pass the variable directly to the fragment shader it works fine.

Is there some sort of transformation I need to do on the co-ordinates in the vertex shader? The sh.passthrudim.vp.glsl shader has this code, yet I can't find adequate information on how to update this for GL3.

texdim0 = vec2 (abs(gl_TextureMatrix[0][0][0]),abs(gl_TextureMatrix[0][1][1]));

Patch/shader attached.

Max Patch
Copy patch and select New From Clipboard in Max.

texdim.jxs
jxs 1.60 KB

Rob Ramirez's icon

hmm, definitely something amiss here. thanks for the report. I would just send the dims manually for now.

Rob Ramirez's icon

sorry for the late follow up on this. The error is in the shader. you have the texdim variable defined as a vertex attribute rather than a shader uniform:

in vec2 texdim; should be uniform vec2 texdim;

LSka's icon

I'm having issues too with dynamically setting dims in a glcore shader.
I was following Federico Foderaro's tutorial on mesh instancing and how to map a texture across instances of a plane.



I made some slight modifications:

Max Patch
Copy patch and select New From Clipboard in Max.

all is fine as long as I set the dimensions manually: e.g
jit_out.texCoord0 = vec2(textureMatrix0 * vec4(texCoord / vec2(16,9) + instance_texCoordOffset, 0., 1.));

however, if I try to get dimensions from the input matrix in order to dynamically change the number of planes, I get the blocky image below.

this is what I get if I use
jit_out.texCoord0 = vec2(textureMatrix0 * vec4(texCoord / texdim0 +instance_texCoordOffset, 0., 1.));
at line 45 of the attached shader

instanceShaderTexCoords.jxs
jxs 2.12 KB


What am I doing wrong?

TFL's icon

If I replace texdim0 by vec2(1920,1080) I get the same result, so I think in this context texdim0 refers to dimensions of tex1 (chickens.mp4), not the "plane control" matrix. I'm not familiar with jit.gl.buffer and vertex attributes, but as a workaround you could easily pass the matrix dimension as an attribute of the shader instead on gettting dimensions of the vertex attribute matrix.

TFL's icon

Like this (but i'm not sure this is the result you want to get actually).

Max Patch
Copy patch and select New From Clipboard in Max.

instanceShaderTexCoords.jxs
jxs 2.21 KB

LSka's icon

thanks @TFL, that's exactly what I was looking for.