Transformations in Shaders
Posted by goosey on Apr 12, 2021; 2:55am
URL: https://forum.jogamp.org/Transformations-in-Shaders-tp4041109.html
I've been messing around with 3d rendering recently and was having trouble when trying to apply transformations in a vertex shader.
Usually, I'm able to do matrix transformations using standard OpenGL commands (glScalef, glRotatef, glTranslatef), but that doesn't work when using shaders.
How I tried to fix this was I applied all the transformations as I normally would and then I would get the current matrix from OpenGL and pass it to the shader as a uniform. In the vertex shader, I would then multiply the position by the transformation to get what I wanted.
However, this didn't work properly and it made some pretty wonky results.
here is my shader code:
#version 330
in vec3 position;
uniform mat4 transform;
out vec4 color;
void main()
{
gl_Position = transform * vec4(position, 1.0);
float depth = ((gl_Position.z + 1) / 2);
color = vec4(depth, depth, depth, 1);
}
I just can't seem to figure out what I'm doing wrong, so I decided to come over here to see if you guys had any ideas.