View Full Version : Pseudo-perspective shader

okinp

10-07-2011, 04:07 PM

Hi,

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,

Nik.

Alfonse Reinheart

10-07-2011, 04:14 PM

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?

okinp

10-07-2011, 05:39 PM

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...

-Nik.

Alfonse Reinheart

10-07-2011, 07:21 PM

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.

okinp

10-09-2011, 03:47 PM

Thanks Alfonse,

I'll try what you described and see if I can make it work....

-Nik.

sqrt[-1]

10-09-2011, 07:46 PM

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

eg.

http://en.wikipedia.org/wiki/Graphical_projection

http://en.wikipedia.org/wiki/Isometric_projection

http://en.wikipedia.org/wiki/Oblique_projection

ugluk

10-12-2011, 03:54 AM

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.

Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.