What do you want this Quad for?
Is it something like an overlay for a HUD?
If so then yes there is a very elegant solution:
Make an ortho matrix the width and height of your screen for your projection matrix, and load the modelview matrix with the identity.
Then draw a quad of screen dimensions at Z = 0.0, or simply using 2f coords.
If you are texturing the Quad then make an ortho matrix for your texture which uses the width and height of the texture, and use TexCoords that run from 0.0 - 1.0 etc.
Ah yes of course.
I don’t want to use ortho projection and I’m aware of that technique. I am coding up a volume renderer on gpu and using the world origins of the pixels as the origins of rays for raycasting process. Normally I render a bounding box and use the pixels on the surface to generate rays but this doesn’t work when camera is inside the bounding box and what good is a volume renderer if you can’t see inside?
How do you get the ‘extent’ values? And can you remind me what inverse projections I need to get into world space from eye?
Of course it’ll be deforming. You MUST keep your extX=1.0 and extY=1.0
Look at it like this: you’re transforming from clipspace to worldspace. Clipspace is [-1;1] ranges. The viewport aspect-ratio and FOV are taken care of by the projection-matrix already.
Nice that you noticed my z=0 example is incorrect, and should be z=-1 :).
Ah, and it should be “projview" instead of "viewproj”
And using [1,1] for x,y. My structures are column major so don’t know why this worked and not the other way around. The flickering though…I have no idea how to fix it. An epsilon is no good.
Ilian’s method is almost right
To get the nearplane quad in worldspace, compute the inverse of Projection*View and transform these 4 NDC corners of the nearplane by that. Finally divide the resulting vectors by w.
Sorry for resurrecting this post but I just had the same problem, and wanted to say that the solution proposed last by skynet worked as a charm. DmitryM’s solution worked well for me as well, but I had some precision problems with the plane not quite filling the entire viewport for some reason.
Anyway, for skynets solution I set up vertices with z=-1, w=1, and x and y at -1 and 1, as instructed. In glm, I used glm::mat4 m = glm::inverse(p*v). mvp then becomes the identity matrix, so in the vertex shader I did gl_Position = pos_in.
In the fragment shader I needed the world coordinate. The world coordinate becomes vec4 worldPos = M*pos; worldPos /= worldPos.w. All working now, thank you all for your help!