PDA

View Full Version : Cube Map Question

Lurking
07-30-2002, 11:42 AM
I am having a problem understanding how you pass a vector into a cubemap. Right now i am looking over the CubeMap slide from nvidia's site and I am trying to understand the Normalization CubeMap. How do you pass information into a Cubemap?

- Lurking

fresh
07-30-2002, 12:04 PM
A cube map is just 6 texture maps each of which represent one side of the cube's faces.

Imagine you're in the center of a unit cube. Given a unit vector, you could "cast a ray" to one side of a face and look up the value of that texel. That's all a cubemap is. It allows you to look up (x,y,z) in one of 6 textures. A normalization cube map takes any (x,y,z) and returns the normalized version of that. When trying to interpolate a normal across a triangle it usually becomes un-normalized. Using a cubemap allows you to renormalize this vector with a simple texture map lookup.

Lurking
07-30-2002, 12:26 PM
Im sorry about how novice this may sound but how do you use the texture to look up the position of my light source?

- Lurking

SirKnight
07-30-2002, 01:17 PM
Im sorry about how novice this may sound but how do you use the texture to look up the position of my light source?

You can't. Why would you need to use a texture for that? Your light position is stored into a float array in your C code, so you always have access to it.

When you create the normal cubemap just bind it to a texture unit and when you pass your vector as tex coords using glTexCoord or whatever opengl makes it work just fine.

-SirKnight

fresh
07-30-2002, 02:03 PM
SirKnight -
Actually you can use a cubemap to look up lighting information. It's pretty straight forward to encode diffuse lights into a cubemap. You can then get as many lights as you want for just one cubemap lookup.

Lurking -
You need to render your lights into 6 textures and then use your normal as the parameter into glTexCoord. You can then disable GL_LIGHTING. You'd also need to update the cubemaps if your lights move.

SirKnight
07-30-2002, 05:37 PM
Yes I know you can store diffuse and specular info in a texture, thats very easy to do, and with a nice fragment program this data can be accessed easily, but he asked for finding the _position_ of the light in a texture. You don't encode light source _positions_ in textures, they just aren't usefull for that.

-SirKnight

Lurking
07-30-2002, 05:45 PM
Well I plan on using nvparse (which i am very new too) to work w/ my per pixel lighting. So that is why i dont understand how to look up where the position of my light source is.

- Lurking

jwatte
07-30-2002, 06:42 PM
Lurking,

You need to specify where your light is as an INPUT to the cube map look-up. Ways of doing this include:
- pre-calculating light position and send it in with TexCoord3f()
- using TexGen() in NORMAL_MAP (for diffuse) and REFLECTION_MAP (for specular) mode and rotating texture coordinates using the texture coordinate matrix
- doing it all in a vertex shader

Lurking
07-30-2002, 07:38 PM
Is there away around using the vertex shader?

- Lurking

SirKnight
07-30-2002, 07:55 PM
Ok now I see what you want. I didn't understand what you meant before. What you need to do is calculate the surface to light vector then pass that as tex coords into a texture unit with a normalization cubemap bound to it. Make sure and transform the light into the correct space first. So the surface to light vector is just: surfToLight = Light - Vertex; Then just pass that into a tex unit like i said above, then its ready to go in the combiners. There are many demos of this around. Check out the Lit Quad demo in the nvidia OpenGL SDK.

-SirKnight

[This message has been edited by SirKnight (edited 07-30-2002).]

Lurking
07-30-2002, 08:11 PM
thanks so much. im not sure if thats everything for me but im going to play w/ that for a bit. Thanks so much for everybody responding so quickly!

- Lurking

Devulon
08-01-2002, 03:38 AM
Cube Maps can be used to look up any function in 3 dimensions (x,y,z) thats all maps do anyway. It just always happens that the data is treated as colors. I am looking forward to more and more ridiculous formats for textures. So I can do even more ridiculous lookups that make no sense. I am serious though there are a lot of interesting things you can do with simple lookups.

Devulon

davepermen
08-01-2002, 05:27 AM
actually for generic 3d functions u use a 3d texture.

a cubemap is a DIRECTION LOOKUP. you pass in a vector as texcoord, and you get the color/data-texel on the cubemap in this direction.

now if you want a normalizationcubemap, then you store for every texel on the cubemap the normalized vector of the texcoorddirection pointing to this texel.