Detailmapping with Cubemapreflections

From GameStudio Wiki

Jump to: navigation, search

Copy this functional code into your shader file (or create a new shader.c/.h file for it): (This is Lite-C but can be easily converted to C-Script)

void mtl_detailShiny_init();
void mtl_detailShiny_func();

char* MTL_DETAILSHINY_CUBEMAP = "detailShiny+6.tga";

MATERIAL* mtl_detailShiny =
{
	event = mtl_detailShiny_init;
	flags = enable_view;
	effect = "detailShiny.fx";
}

void mtl_detailShiny_init()
{
	//load cubemap
	mtl.skin1 = bmap_create(MTL_DETAILSHINY_CUBEMAP);
	bmap_to_cubemap(mtl.skin1);
	mtl.event = mtl_detailShiny_func;
}

void mtl_detailShiny_func()
{
	mat_set(mtl.matrix, matViewInv);
	mtl.matrix41 = 0;
	mtl.matrix42 = 0;
	mtl.matrix43 = 0;
}

Create a new textfile which is called "detailShiny.fx" and paste this code into it:

extern texture entSkin1;
extern texture entSkin2;
extern texture mtlSkin1;

extern float4x4 matMtl;

technique detailShiny
{
	pass p0
	{
		Lighting = true;
		
		//render model with skin1
		Texture[0] = <entSkin1>;
		ColorArg1[0] = Texture;
		texcoordindex[0] = 0;
		
		//tile skin2 over it
		Texture[1] = <entSkin2>;
		colorarg1[1] = Texture;
		colorarg2[1] = current;
		colorop[1] = modulate;
		texcoordindex[1] = 0;
		texturetransformflags[1] = count2;
		texturetransform[1] = { 15.0,0.0,0.0,0.0, // tiles u
										0.0,15.0,0.0,0.0, // tiles v
										0.0,0.0,0.0,0.0,
										0.0,0.0,0.0,0.0};
		
		//apply transparent cubemap
		texture[2]=<mtlSkin1>;
		colorArg1[2]=Texture;
		
		colorOp[2]=blendFactorAlpha;
		textureFactor=0x25FFFFFF; //~15% cubemap alpha
//		textureFactor=0x75FFFFFF; //~75%
//		textureFactor=0x80FFFFFF; //~50%
//		textureFactor=0x40FFFFFF; //~25%

		addressU[2]=Clamp;
		addressV[2]=Clamp;
		texCoordIndex[2]=cameraSpaceReflectionVector;
		textureTransformFlags[2]=Count3;
		textureTransform[2]=<matMtl>;
	}
};

Put into your modelfile (which should be rendered with the shader) the texture into skin1 and the detail texture into skin2. To use another cubemap, replace the char definition.

Because of the usage of both detail map and cubemap, the model could get slightly darker - you can troubleshoot it by raising the emmissive values of the material (I suggest to do this modelwise in the DirectX material definition).

Have fun with this!
Cheers, Christian

Personal tools