Nice cubic mapping function

Blitz3D Forums/Blitz3D Programming/Nice cubic mapping function

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I am not sure if this is precisely cubic mapping, but it looks darn good on flat surfaces. The whole key here is that your vertex normals need to be right. One face of an object should have all the normals in the same direction, or else you get ugly stretching like when you use sphere mapping on a flat surface.



I really recommend viewing this demo first:

http://www.leadwerks.com/storage/shiny.zip

Function cubicmapvertex(surf,v,cam,verts=1)

x#=EntityX(cam)
y#=EntityY(cam)
z#=EntityZ(cam)
pitch#=EntityPitch(cam)
yaw#=EntityYaw(cam)
roll#=EntityRoll(cam)

RotateEntity cam,0,0,0
AlignToVector cam,VertexNX(surf,v),VertexNY(surf,v),VertexNZ(surf,v),3
RotateEntity cam,EntityPitch(cam),EntityYaw(cam),0
TFormPoint 0,0,0,0,cam
tx#=TFormedX()
ty#=TFormedY()	
TFormPoint VertexX(surf,v),VertexY(surf,v),VertexZ(surf,v),m,cam
tz#=TFormedZ()
If tz<100 tz=100
VertexTexCoords surf,v,((TFormedX()-tx/5.0)/tz)/2.0,((TFormedY()-ty/2.0)/tz)/5.0,0,1

PositionEntity cam,x,y,z
RotateEntity cam,pitch,yaw,roll

End Function