PDA

View Full Version : Environment mapping



tdavie
12-12-2000, 01:24 AM
Hi,
I have been writing a game which involves a ball moving around in a scene (which is renderd using OGL, not just a big texturemapped thing), up untill now I have been using a specific texture un the ball, but I would like to use environment mapping instead, to create a silvery ball. I have found out how to do this, providing the texture is provided, but I cannot work out how to generate a texture for the ball from the surrounding scene.

Any help would be much appreciated. Thanks.

Bob
12-12-2000, 01:39 AM
If you want 'true' reflections of the surrounding scene, you are are in some trouble. This isn't easy. But it can be done. You can take a 'screen shot' of the scene as it looks like as seen from the ball. I.e., place the viewpoint at the center of the sphere, direct the viewpoint towards the user, make a very wide field of view, and render the scene as normal (but NOT the sphere, since you are inside the sphere, it might occlude the whole scene), grab the backbuffer and make a texture out of it, and then use this texture as the enviroment texture.

It's might sound complicated, I know, but 'true' reflections like this isn't an easy task.

As soon as something changes (object or camera moves), you need to rebuild the texture.

If you use the cube environemnt mapping, you need to make all six textures, and update them only when the scene moves, not the camera. Or to make it slightly faster, only update the textures that is potentially visible from the current angle of view.

Mmm, hope I was clear enough on this one, else shout...

p.s. Forgot to mention it in my first version of my post, but I assumed that you are using sphere mapping in my first solution. And secondly, with the six cube textures, you should use a 90 degree field of view when rendering the textures.

[This message has been edited by Bob (edited 12-12-2000).]

Dodger
12-12-2000, 02:54 AM
What FOV angles are good for sphere mapping?

Bob
12-13-2000, 01:54 AM
Dunno really, but I think 'as large as possible'. Try with some large fov, like 170 or so. Haven't tried this idea yet, so don't even know if it works.

If someone tries, or already tried, please report your results http://www.opengl.org/discussion_boards/ubb/tongue.gif

ae97004
10-01-2002, 11:39 AM
Hey,
I got the basic idea but how do we take the back buffer and convert it to a texture, i mean the open GL commands, i have been playing aroud with this and iam all strung about, maybe you could help by posting a piece of code,
thankyou!!

Deiussum
10-01-2002, 11:49 AM
Use glReadPixels to grab the pixel data in the backbuffer for use in a texture. Might need to do some resizing after you read some pixels or else make sure you read an area so that the final results end up being dimensions that are a power of two. (e.g. 256x256, 512x256, 1024x512, etc.)

ae97004
10-01-2002, 12:07 PM
Hmm.. okay now i know the logic of what to do, would you guide me as to where i can find te syntax of these commands, i mean i thought of using glTexImage2D to grab image and the glGetTexImage to grab and put it as a texture, suppose iam using two buffers, glReadPixels is going to read the pixels and put them as a texture and then i use getTex for converting this to texture map and use it... iam not sure if what iam saying is making sense, but what i really need is some sample code for the usage of these functions...

thanks for the help, itrealy helped.
Regards


Use glReadPixels to grab the pixel data in the backbuffer for use in a texture. Might need to do some resizing after you read some pixels or else make sure you read an area so that the final results end up being dimensions that are a power of two. (e.g. 256x256, 512x256, 1024x512, etc.)[/QUOTE]