// use a matrix for cubic environment mapping
function mtl_env_init()
{
bmap_to_cubemap(mtl.skin1);
// generate a user matrix that transforms camera space back to world space
while(1)
{
mat_set(mtl.matrix,mat_viewinv);
// reset the translation part of the matrix
mtl.matrix41 = 0; // 0 is the same as floatv(0)
mtl.matrix42 = 0;
mtl.matrix43 = 0;
wait(1);
}
}
MATERIAL* mtl_envcube // environment cube
{
skin1 = bmp_envcube;
event = mtl_env_init;
effect =
"
texture mtlSkin1;
matrix matMtl;
technique envcube
{
pass p0
{
Texture[0]=<mtlSkin1>;
AddressU[0] = Clamp; // don't wrap around edges
AddressV[0] = Clamp;
TexCoordIndex[0] = CameraSpaceReflectionVector;
TextureTransformFlags[0] = Count3;
TextureTransform[0] = <matMtl>; // transform camera space back to world space
ColorOp[0] = SelectArg1; // ignore the ambient light
ColorArg1[0] = Texture;
}
}
";
}
► latest version online