0
votes

I am having problems with placing point sprites in 3D space because of the matrices I am using. The problem is in my vertex shader (I have omitted the unnecessary parts):

#version 330

in vec3 position; // 3d position of the particle
uniform mat4 vp_matrix; // the projection and view matrices from the camera

void main()
{
    gl_Position = vp_matrix * vec4(position, 1);
}

Currently I am uploading the view and projection matrices to this matrix uniform. But this leads to the particles to rotate and move around in unexpected ways when the camera moves (i.e. differently from the other objects in my scene).

Does it make sense to apply the projection matrix to a point sprite? Or should I only be applying the view matrix? Should I be applying the entire view matrix, or just the translation and/or rotation?

1
"Does it make sense to apply the projection matrix to a point sprite? " Yes, why not? The 3D vertex coordinate of a point is not different to a coordinate of any other geometry. The projection matrix describes the mapping from 3D points of a scene, to 2D points of the viewport. You have to apply the projection matrix to the points sprites too.Rabbid76

1 Answers

0
votes

My apologies, turns out this "strange" movement was because of a wrong offset where I had wrote 3 floating point values instead of 2.

But in case anyone is wondering what matrix to apply to point sprites, @Rabbid76 is correct, you must apply the projection matrix to it, and you must also apply the view matrix. This means you DO apply both the view and projection matrices from the camera; this is because the camera's rotation and translation DOES need to affect points.