sh.passthrudim.vp.glsl equivalent for GL3?
Hi, what would be the GL3 equivalent for the old GL2 passthrough vertex shader GLSL sh.passthrudim.vp.glsl?
Cheers!
in vec3 jit_position;
in vec2 jit_texcoord;
out jit_PerVertex {
vec2 texorient1;
vec2 texorient0;
vec2 texdim1;
vec2 texdim0;
vec2 texcoord1;
vec2 texcoord0;
} jit_out;
uniform mat4 modelViewProjectionMatrix;
uniform mat4 textureMatrix0;
uniform mat4 textureMatrix1;
void main() {
gl_Position = modelViewProjectionMatrix*vec4(jit_position, 1.);
jit_out.texcoord0 = vec2(textureMatrix0 * vec4(jit_texcoord, 0., 1.));
jit_out.texcoord1 = vec2(textureMatrix1 * vec4(jit_texcoord, 0., 1.));
jit_out.texdim0 = vec2(abs(textureMatrix0[0][0]), abs(textureMatrix0[1][1]));
jit_out.texdim1 = vec2(abs(textureMatrix1[0][0]), abs(textureMatrix1[1][1]));
jit_out.texorient0 = vec2(textureMatrix0[0][0] / jit_out.texdim0.x, textureMatrix0[1][1] / jit_out.texdim0.y);
jit_out.texorient1 = vec2(textureMatrix1[0][0] / jit_out.texdim1.x, textureMatrix1[1][1] / jit_out.texdim1.y);
}
Hi Diemo, this is the GL3 equivalent.
Check out jit.fx.td.repos.jxs to see it used in context
Hi Matteo, thanks a lot for the hint! I made it work although I had picked up just enough GLSL to write this shader...
Now I wonder if the passthrough projection calculations are really needed. I saw in jit.fx.tr.zoomfade.jxs:
<program name="vp" type="vertex" >
<![CDATA[
#version 330 core
in vec2 uv;
out jit_PerVertex {
vec2 uv;
} jit_out;
void main(void) {
gl_Position = vec4(uv*2 - 1, 0, 1);
jit_out.uv = uv*2 - 1;
}
]]>
</program>
Cool, happy it worked out!
Yes, you can skip matrix multiplications in jit.gl.slab's vertex shaders.
gl_Position = modelViewProjectionMatrix*vec4(jit_position, 1.);
This line takes "jit_position", which is normalized and unipolar [0; 1] in jit.gl.slab, and makes the X and Y coordinates bipolar [-1; 1].
So, you can do the same with:
gl_Position = vec4(jit_position.xy*2 - 1, 0, 1);
But consider that it's a veeeery minor optimization, and the computation is repeated just 4 times (one for each vertex of the screen-sized quad). So, it's just a matter of style, as it doesn't impact performance in the slightest; you can pick the one you prefer based on readability and clarity.
In theory, you wouldn't need the input vertex positions either and just derive everything from the built-in variable gl_VertexID :
jit_out.uv = vec2(gl_VertexID % 2, floor(gl_VertexID*0.5));
gl_Position = vec4( jit_out.uv*2 - 1, 0.0, 1.0);