environmental mapping

Hi guys, i am trying to write my own algorithm for environmental mapping. My approach is use a 6 faces cube map as the environment, map the vertex of the polygon to the cube map, and then interpolate the texture position across the polygon during rasterization. My questions is how to deal with the situation where the vertices from a polygon were mapped in different faces of the cube map? Should I split the polygon to make sure all the vertices mapped in a single face or use some clever algorithm to cope with interpolation between 2 vertices that are mapped to different faces of the cube map?

Thanks in advance!
Pan

Isn’t the whole point of the cube map texture type to just allow you to render a cube and have the texture automatically mapped to it?

the main point of cube mapping is to create fake reflection of a shinny object with arbitrary shape. Traditionally realistic reflection is achieved by ray tracing, however this ray tracing is too slow for real time application.

With cube mapping, you map a surface from an object to a per-rendered cube map texture which was generated by rendering the scene 6 times from the view point of the object. This create an effect that the object is reflecting its surrounding environment.

what the agent ment is that opengl provides you with an cube map texture type, which you provide with the six faces and which handles all the interpolation for you.

You don’t upload six textures and then decide in the shader which one to use by yourselve.

Just google a bit around and you will find how to use it.

Yeah, i know there are 3d APIs out there that will do it for you. But I would like to “reinvent” the wheel by writing my own cube mapping algorithm. Just to kill time during Christmas break :slight_smile:

Seeing all the projects of phu004, it looks like he is writing a software renderer or something similar. He tries to implement Cube maps in his engine, which is supposed to be some kind of software-opengl.

I am thinking about building my environment map using Spherical coordinate system. Interpolation between 2 points on a sphere is a lot easier than on a 6 faces cube map (since we no longer need to worry about the case where 2 reflection rays hit on different faces). Environment map in Spherical coordinate can be easily generated by firing 360 * 360 rays at the center of the cube map.

I gave up the idea of building the environment map with spherical coordinate system. It turns out that interpolating 2 points on a sphere is a lot harder than i thought.

Have you tried using quaternions?

You don’t need to do anything special. To sample a diffuse texture on the sphere, the normal points to the sample.