Skip to main content
gamedev.net
🔒 Locked

Environment Mapping....

Started by daedalusd Jul 9, 2000 at 3:44 PM 1 replies 350+ views
Original Post
daedalusd
daedalusd
Hey all, Well i can honestly say i''ve spent all day trying to get this working, so no-one can say that i haven''t tried before resorting to asking the more experienced of you out there =) Im trying to get Spherical environment mapping to work in my app. I''ve picked apart the DX7 sample which does this, using the teapot X model. So heres where I am so far, i''ve calculated normals for each face, and also each vertex and they are stored away safely =) But unfortunately in my engine i have flat faces (i.e a cube) each poly with it''s own set of 3 vertices, so each vertex normal will in effect be the same as the face normal (so the vertex normals are of no use to me in this case). This presents a major problem, since the spherical environment mapping seems to just use 1 texel per face (at least thats what it looks like, but basically it''s screwed =) As far as i can see it''s all implemented perfectly assuming that i''m using the teapot model =) hehe, but not for my real world data. Has anyone got any advice or can point me to a Direct3d IM tutorial on this (i''ve looked all over the net for a decent sample, but all i find is forumlas and theory which i''m afraid to say I can''t translate into code =( Thanks in advance for any help you can give Adam
nes8bit
nes8bit
I''m not exactally sure what your problem is, but I think I know what it is. Does only 1 texel show up per face on the cube? If that''s the problem, then you need to create seperate normals for the cube. I think jLeslie told me this.

For i = 0 to TriangleCount
TriangleNormal(i) = TrianglePoint(i) - CenterPos
VectorNormalize TriangleNormal(i)
Next

Now set the coordinates using the seperate triangle normal.

------------------------
Captured Reality
daedalusd
daedalusd
Thanks for the reply, i actually got it all working the way I wanted to just before you replied =)

Basically i subtract the vertex position from the camera position, then multiply the vector by the View Matrix, Normalize it, then add the X/Y Vertex normal to the X/Y of the resulting vector. Finally set the envmap u to the resulting (X/2)+0.5 and the v to (Y/2)+0.5

If i don''t do the /2+0.5 it''s exactly the same result as letting DX calculate the texture coordinates using D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR, except i found that by using part of the spherical environment map forumla, i get the result i wanted.

Still thanks for your help =)

Adam "Nutz" Hoult
VB Gaming Central

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.