For educational purposes I'm trying to simulate what a scene would look like with a perspective matrix deformation (before everything is brought to NDC) but I'm unsure how to do this.
I'd like to do this only with matrices transformations if that is possible. A cube would then deform depending on where the perspective camera is set up.
I've set up two cameras, the perspective camera and the observer camera.
This, in theory, could be achieved by applying the perspective camera perspetive-view matrix on the observer camera's cube, right? I've tried this with no luck. Wouldn't this supposed make all vertices to fit the perspective camera homogenous coordinates?
The effect I'm trying to achieve is this one (source):
Thank you!
Edit:
// model translate
model = perspective_camera->projection * perspective_camera->view * model;
shaders["scene"].setBool("second_camera", true);
// draw model
and the shader:
if(second_camera) {
vec4 model_div_w = model * model_coefficients;
model_div_w = model_div_w/model_div_w.w;
gl_Position = projection * view * model_div_w;
}
This is what I got from this code:
Panning the perspective camera slightly to the left gets me this, shouldn't the blocks pan to the other side? They are actually accompanying the camera. (Moving the camera further has the same effect but more even pronounced)
Thanks!