Pseudo-perspective shader


I’ve been trying to figure out something for the last few days and I would like to make sure it’s possible to do…

I have a 6x2 multi-screen setup which is quite huge, and I would like to force the perspective distortion of objects to be exactly the same no matter what the position of them is on the screen.

So, even if an object is placed close to a corner I would like it to look exactly the same as if it was placed in the center (or some other position).

Orthographic projection is not an option…only perspective is, in order to get the result I am after.

I thought that all I would need to do is write a vertex shader where the projection matrix is manipulated for each object, according to its position…
(or should it be the modelview matrix??), but I am doing something wrong.

Can someone let me know if what I am trying to achieve is possible at all and maybe give me some direction???

Thanks a lot,


What you have asked for is not possible. Perspective projection, by definition will cause the appearance of objects to be different relative to where it is seen. That’s just how perspective works; that’s how vision works.

The “result I am after” doesn’t make sense. Can you diagram what it is that you’re trying to do?

Hi Alfonse,

thanks for your response…

Let me put this differently…

Imagine that each object has its own “camera” that follows it and keeps a constant relative position. I would like to render each object on screen at its correct position, and in the way that its “own camera” that follows it, would see it.

A way that I can think of that would probably achieve this result, would be to translate each object from its current position, to a constant (among objects) temp position, render it to an FBO (on a transparent or something texture or remove/make transparent with a shader the background pixels of the texture) and then display the texture on screen at the position that the object was.

In this way, all the objects will be drawn on screen, but their perspective distortion would be as if all objects had the same position.

The above described “solution” is an overkill and I would like instead to accomplish the same using shaders and manipulating the matrices.

I hope my question is a bit clearer now…


I hope my question is a bit clearer now…

I see what you’re getting at, but I have no idea why you would want to do this. It’s easy enough to implement, but I seriously doubt it’s going to do anything more than give the viewer a giant headache and be really fake-looking. It’s going to look like something out of MC Echer.

However, if you insist…

The first thing you need to realize is that all matrices are just transforms. They go from one space to another. No transform is special. Therefore, there is nothing inherently odd about taking 4D homogeneous vertices output from the perspective projection and applying a rotation transform to them.

So all you need to do is treat post-projective space as just model space. Think of each object after projection as being a model in its own model space, centered on the origin and with vertex position ranges on [1, -1] in all three axes. You can apply a Y rotation to this. Or a scale. Or a translation. Or any other transform that you would normally apply to a vertex.

So just position this [1, -1] region of space as you would any other model. So each object would be perspectively projected, then you do some transforms after the projection to put it in your scene. Your scene’s projection matrix needs to be orthographic, because you don’t want to double-project these things (that would defeat the “point” of this idea).

You don’t even need shaders to do this; you could do it in OpenGL 1.1 with the matrix stack. It’s all about what matrices you composite together and in which order.

Thanks Alfonse,

I’ll try what you described and see if I can make it work…


You sure you want perspective projection? You can load OpenGL matrices up with lots of other projection types:

This is a fun post. You can switch between projections easily enough. That is, you can draw some objects using an orthogonal projection and some using perspective, if that is what you want.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.