View Full Version : Environmentalmapping: How to calculate the vectors in a vp?

Hi

just wanted to add env mapping to my project, when i noticed, that i use vpīs for everything. So no texcoord-generation :-(

Well, now iīd like to do it myself in the vp, but i couldnīt find the equation for it in the spec. Can someone tell me the formula?

Thanks in advance,

Jan.

V-man

12-02-2003, 09:45 AM

Which one?

sphere map, reflection map and normal map

They involve computing a reflection vector

r = u - 2* n' (n' DOT u) (1)

where u is unit vector in eye space from eye to vector.

n' is normal in eye space

m = 2 SQRT(r.x^2 + r.y^2 + (r.z+1)^2)

s = r.x/m + 0.5

t = r.y/m + 0.5

The above is sphere map from red book

reflection uses the same equation as (1)

and it uses the r.x, r.y, r.z to access a cubemap.

normal map? I think it uses the eye space normal vector as a reflection vector to

lookup up into a cubemap.

Hope that helps.

I want to use cubemaps, so it should be reflection-mapping.

"where u is unit vector in eye space from eye to vector."

You mean "from eye to vertex", donīt you?

Eyespace means, that i have to transform everything with my modelview-matrix, no?

Iīm a bit confused at the moment, have to check that stuff tomorrow.

Thanks,

Jan.

Originally posted by Jan2000:

Hi

just wanted to add env mapping to my project, when i noticed, that i use vpīs for everything. So no texcoord-generation :-(

Well, now iīd like to do it myself in the vp, but i couldnīt find the equation for it in the spec. Can someone tell me the formula?

Thanks in advance,

Jan.

Hello! I know how to do that for cubic environment maps. To calculate, for instance, coords for reflection (environment mapping is a technique that simulates highly reflective surfaces without using ray tracing, you know) you should use following formula:

RefVec = 2*(E dot N)*N - E

where E - is vector from our eye position (defined in constant registers) to vertex (incoming in vertex program (vp)), transformed by a World matrix (also stored in const regs); and N - our normal, transformed by World matrix;

Transform vertex position and normal by World matrix and use this formula. Finally, put answer into texture coords register.

Sorry if I understand your question unproperly.

And one question for You.

Whether OpenGL has higher language for writing vertex and fragment programs in a C-like style?

Great, thanks!

OpenGL itself does not have a C-like language for writing vertex- or fragment-programs. At least not yet. But one can use CG instead (www.cgshaders.org).

Jan.

Ati catalyst 3.9(+) has support for Glslang.. not all aspects of the language, but enough to do that, and many other things.. ( it doenst support loops, even if they are of know length, and it fallsback, correctly, into software when using the noise functions)

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.