View Full Version : Billboard that covers always one pixel
01-06-2010, 01:31 PM
Happy New Year everyone.
New year, new problem i can't get my brains on. I have the following need: From any camera position find a scale for the billboard transformation matrix so that the rendered billboard will cover only one pixel in the color buffer. Right now i use a fixed small scale (0.01f) and it sometimes gets draw and sometimes not causing flickering since i test this way the visibility (visible = occlusion_query_passed_samples != 0). Any help and ideas are totally welcome since i have no more ideas from where to start.
p.s. Points aren't working at all (passed samples always 0).
01-06-2010, 05:59 PM
Do you need to do this with a transformation matrix? You just want to take some point, and spread the quad to cover a pixel. Sounds like a simple vertex shader tweak (delta) on the clip-space XY position.
01-07-2010, 05:59 AM
No really with a matrix, whatever works with occlusion query. Transform into clip-space and go from there, i would have thought NDC-space would be better here, no?
01-07-2010, 07:01 AM
Transform into clip-space and go from there, i would have thought NDC-space would be better here, no?
Yeah, NDC is what you want, but ideally you'd like this to be a vertex shader thing, and the perspective divide to take you to NDC doesn't happen until after the vertex shader.
However, you can easily back your NDC adjustment up to clip space by pre-multiplying your NDC XY offsets by gl_Position.w -- as it'll be divided out later in the perspective divide. Then you can do this at the end of the vertex shader in clip space. For instance:
gl_Position.xy += vec2(ndc_deltax,ndc_deltay) * gl_Position.w;
No really with a matrix, whatever works with occlusion query.
There's no reason that the above should be incompatible with occlusion query if done at the end of the vertex shader. If you've got some vert_offsetx = -1/+1, vert_offsety = -1/+1 for each of your quad verts, then your deltax and deltay are just:
ndc_delta = vert_offset * scale
where scale just scales NDC (-1..1) units to pixel resolution units.
If you have to have this gl_Position.xy adjustment in matrix form, I think this can be smashed onto the end of the gl_Projection fairly nicely:
1 0 0 deltax
0 1 0 deltay
0 0 1 0
0 0 0 1
01-09-2010, 09:46 AM
That puts some new thoughts on the design. I will mess with it a bit and might post the source if when done. Thanks for the hints Dark Photon.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.