Skip to main content
GameDev.net gamedev.net
🔒 Locked

delete

Started by 20050525 Aug 6, 2005 at 12:25 AM 5 replies 1k views
Original Post
20050525
20050525
delete [Edited by - LEdxP37 on April 29, 2007 1:49:01 PM]
nihilisticod
nihilisticod
i am confused about the problem? Your picture shows that it does display when it should be behind your gun? Do you mean that the picture is showing the flare because nothing is occluding the center of the sun, but you do not want the flare effect drawn over the gun?

Or is the problem that you want the tested point to realize that it is behind your gun and not display the glow? If this is the case, i would venture to guess that you are changing the matrix and displaying the gun in a new view so it is screwing up all your depth testing for that pixel. You would have to display the gun in your environment. instead of resetting the view to draw the gun, try transforming the gun to your players position so that it is "located" in the world right in front of you. This will give it the appropriate tiny z-values that will cause your tests to be correct.
Ilici
Ilici
Basically you need some kind of occlusion test. Easiest would be to trace a ray from the camera to the sun and intersect it with the geometery, that's what games usually do. Using occlusion queries needs another rendering pass which may be more expensive than ray tracing.

To build the ray, find the screen coordinate of the center of the sun using gluProject then, IIRC, you transform by the inverses of the modelview and the projection matrices.

point.x = - (2.0f * (float)SunX / width - 1.0f ) / mp[0];
point.y = (2.0f * (float)SunY / height - 1.0f) / mp[5];
point.z = 1.0f;

ray->d.x = (mm[0] * point.x + mm[1] * point.y + mm[ 2] * point.z);
ray->d.y = (mm[4] * point.x + mm[5] * point.y + mm[ 6] * point.z);
ray->d.z = (mm[8] * point.x + mm[9] * point.y + mm[10] * point.z);
ray->d = Normalize(ray->d);

ray->p = Camera;

Where mp is the projection matrix and mm is the modelview. width and height are the dimensions of the screen.
mikeman
mikeman
Quote:

..my sun glare is 0-.1...


Well, that's your problem. That puts the "glare" in front of every other object. Why did you put it in that range? I suspect because you didn't want the glare quad to be "blocked" by other objects due to depth testing, but the solution to that is simply glDisable(GL_DEPTH_TEST).

Anyway, for the sun glare, you don't even have to do a depth comparison. Theoretically, it's in infinite distance, so we already know that it's behind any other object. Assuming you have cleared the zbuffer with 1.0, all you need to do is render the scene, then perform a glReadPixels() at the position of the glare and see if the depth value is less than 1.0. If it is, then there is an object there, and we know for sure that it's hiding the sun, so fade out the glare.
X5-Programmer
X5-Programmer
Hi, Well, first of all I havent done this before but if you want to fade the
sun or something can't you just do something like this?

int position[2];position[1] = abs((int)SunPosition[1] - SCREEN_X/2);position[2] = abs((int)SunPosition[2] - SCREEN_Y/2);GLfloat sun_distance = sqrt(position[1] * position[1] + position[2] * position[2]);GLfloat alpha = 1.0 - sun_distance / 500.0;glColor4f(1.0f, 1.0f, 1.0f, alpha );drawStuffs.


I have not try it but I hope it works, hehe

well gl.
-[ thx ]-

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.