CubicEnvironmentMappingOnLevelGeometry

From GameStudio Wiki

Jump to: navigation, search

code for the cubemap.fx file:

		texture entSkin1;
                texture mtlSkin1;
                matrix matMtl;
                technique envmap
                {
                        pass p0
                        {
                                texture[0]=<entSkin1>;
                                texture[1]=<mtlSkin1>;

				Lighting=True;
                                zWriteEnable=true;
                                alphaBlendEnable=false;
				localviewer=true;
                                colorArg1[0]=Texture;
                                colorOp[0]=Modulate;
                                colorArg2[0]=Diffuse;
				colorArg2[1]=Current;
                                colorArg1[1]=Texture;
                                colorOp[1]=Modulate;//blendCurrentAlpha;
                                addressU[1]=Clamp;
                                addressV[1]=Clamp;
                                texCoordIndex[1]=cameraSpaceReflectionVector;
                                textureTransformFlags[1]=Count3;
                                textureTransform[1]=<matMtl>;
                        }
                }


add the following to your Main script:


bmap envmap = <desertsm+6.tga>; //your environment map definition

// next: your material, the name has to be exactly the one of the wad texture you use, i chose "brushed_metal02"
material brushed_metal02
{
	skin1=envmap; //your environment map
}

starter load_shaders() // your starter that loads the shader at engine startup
{
d3d_automaterial=1;
effect_load (brushed_metal02, "envmap.fx");
wait(1);
bmap_to_cubemap(bmap_to_mipmap(brushed_metal02.skin1)); // mips for making it run faster
mat_set(brushed_metal02.matrix,matViewInv); // the important part for level geometry
        brushed_metal02.matrix41=0;
        brushed_metal02.matrix42=0;
        brushed_metal02.matrix43=0;
}
Personal tools