Jump to content
  • Advertisement
Sign in to follow this  
ledxp37

delete

This topic is 4847 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
How do you make something in a scene always face the camera. this would be used for something like grass textures that are rotated with the camera movement. i am having problems with my lensflare...whenever i look to the outsides, the circles get narrow because its deeper on the z. how do i make it always face camera?
pic:

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!