Advertisement

How to hide a lens flare behind mountains ?

Started by February 11, 2002 03:32 AM
41 comments, last by Bestel 23 years ago
Hi I'm trying to improve features of the openGL Game programming book's engine (A time to kill). I've made a system to display lens flare :
Lens flares

First, I display my background, then the terrain and after my lens flare. My problem is that I would like to hide flares when a mountain comes front.
The flare hasn't been hidden by the mountain
Have you an idea on how I could do that ? Edited by - bestel on February 11, 2002 4:32:59 AM
the easy, but not very efficient way is simply to use glReadPixels at the centre point of the flare, and test the depth value...

the better way is to do a line of sight test on the appropriate triangles of the terrain.

nice flare btw.
Advertisement
Thank you

I haven''t thought at the first solution

But do you really think that glReadPixels will be less efficient than test with a line ?

Because on the second solution we have to check a lot of polygons... (But I''m quite new in openGL programming, so I don''t know really how fast are each procedure)

If you think that to do a line of sight test on the appropriate triangles of the terrain is better, do you know where I could find a little algorithm to do that. Or, is there anybody who could explain me the principle ?
depending on the terrain detail, you may well only have to test about 50-100 triangles.. This is very fast with a well written algo' (use normals on the triangles edges NOT the aweful internal angles method..)
an it's always best to have a triangle class where normals, edge normals (sometimes called antiplanes) etc are all pre-computed.

ReadPixels is very slow on older hardware. and basically any non-nvidia/ati chip.. so it isn't the best idea. and you have to get the various matricies to project the actual location of the flare... and also, once the flare is offscreen, you can't test it without rendering the scene to a tiny buffer. Obviously rather slow.

Edited by - RipTorn on February 11, 2002 5:48:59 AM
Sorry, this is not a reply to your problem, but I wanted to ask what programming experience you (Bestel) had before you read the ''OpenGL Game Programming'' book, e.g. experienced c++ / beginner c++ / beginner pascal etc.

Also, I don''t know anything about OpenGL, but could the order of which you render the scene make a difference to how the lens flare is seen? i.e. if you render the background, the lens flare _then_ the terrain? Only a thought!
---------------------------------------------------------Until you've failed, you don't know what success is.
Yes, ok, I see glReadPixels() should be slow

But I have not a precise idea about how to do it with a line of sight test.

All my normals are stored in memory. (but I''ve no idea about why I should use it for this algo'')... (And there is a method to compute internal angles?... I learn things every day )

I can know the vector between the player position and the flare.
Then, I think that I have to check if a face is meeting this vector.

I don''t know how to do that. I understand that I have to test only triangles which are in the lens direction... but I don''t know how to do that too...
Advertisement
Mr_Confused :

Before to read this book, I had a good experience in C/C++.
If you ask this question to know if you can read the book without know C++ (all exemples are in c/c++) ... I think that yes. I think that you will be able to understand mechanism of openGL (I knew quite nothing about openGL before to read it )

But, maybe that on few exemple (around the end) it will be more complicated to understand without to know the language.

___

unfortunately, if I draw terrain before my lens flare... I will not see little red circle like on screenshot


Edited by - bestel on February 11, 2002 5:49:55 PM
Ok, my 2 cents, if you are using a quadtree is easy enoguh i think , just clip the ray from the ''sun'' to the viewer as you traverse the quadtree for rendering, do a fast intersection test using plucker coordinates for any triangle in the quad tree node storing the triangle list, if the test is true ,set the lensflare rendering flag to false .
if you are not using a quad tree , or any visibility structure
you can test the ray against each triangle as you render it
which obviously may take time to compute.


I have looked for on the internet to learn more about plucker coordinates. This method allows us to to know if there is an intersection between two portion of directed line (is it true?)

But, I don't know how to apply this with my problem, because I would like to make a test between a line and a face...

Does anybody has a little algorithm which could save me ?

Edited by - bestel on February 11, 2002 8:32:41 AM
I''d recommend to stick to the glReadPixels solution.
It''s fast enough for one pixel only, and it works in all cases.

If you have to test the intersection, first of all it will be either slow, or very complicated to implement, and it will work only with terrain data : if you insert other objects in your scene they won''t be able to hide the sun, unless you compute intersection with them too... a real pain in the ### : a lot of coding work, and a lot of processing time to waste (even with an optimized intersection algo).

This topic is closed to new replies.

Advertisement