• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Per Pixel Test

## Recommended Posts

Hi I would like to know if it is possible to do a fast test if a pixel was rendered or not. (i''d like to use that for rendering my lensflares faster. at the moment i test if the line from the point to the camera intersects my bounding volumes or some triangles. but hey: this is so sloooow i guess it is possible to render just some white pixels and test for this if the lensflare is visible or not. how could i do this?

##### Share on other sites
If you have GF3/4 you can use NV_occlusion_query, it returns the number of pixels rendered, exactly what you need.

-Lev

##### Share on other sites
Use gluProject to find the lensflare''s screen coordinates. Then use glReadPixels to get the depth buffer value at that point. Compare it with the z-value you got from gluProject. If it''s less than the one from the depth buffer, the lens flare is visible.

##### Share on other sites
but remember : Reading back from frame buffer is *slow*. It causes bubble in rendering pipeline and if not placed in right place it might crash your framerate.

You should never let your fears become the boundaries of your dreams.

##### Share on other sites
NO-NO don''t use VRAM reads. They are SLOW. And if I say SLOW I mean SLOOOOOOOOOOOW. Use NV_occlusion_query or do a raycast with the CPU.

##### Share on other sites

So all those fancy 3D Engines out there use the NV extension is this also available for other 'newer' 3D Cards?
hmm... but whats up with older engines like unreal engine? would they trace a ray for every lensflare in frustrum? this seems to be a bottleneck for me... hmm. okay, i think it goes like this:

for every lensflare in frustrum  intersection := false  trace ray    if ray intersects bounding volume      test for every triangle      if there was an intersection        intersection := true  if intersection    draw lensflare

but hu. if there are objects with hundreds of polygons (imagine an enemy in front of a light source) and 20 lensflares... ugh. would this really work?

[edited by - 2do on August 18, 2002 7:50:55 AM]

##### Share on other sites
You can use a simple VRAM readback. It''s not slow, if you only read a single pixel. Around 90% of all engines out there do it like that.

It''s true that it creates a bubble in the command stream, but a very small one for a single pixel. Try to do it at the end of the frame. And if you''re not hopelessly geometry bound, then you won''t even notice a speed difference at all.

Just don''t start reading back hundreds or thousands of pixels per frame.

/ Yann