detail map on model + environment mapping

Posted By: HeelX

detail map on model + environment mapping - 11/17/07 12:26

This is a simple shader I needed for my current scene. It is a detail mapping shader, which tiles an entity skin2 over entity skin1. In addition, a cubemap will be projected over it, to make it shiny/icy/whatever.

This is how it looks like in my scene. The white environment is using this shader (it has a shadowmap plus the snow as detailmap plus a cubemap to make it "icy"). The floes use the environmental mapping part without the tiling and the water is Slin's NVidia oceanshader. The water depth are stacked slight transparent planes to simulate water depth. The snow is a particle effect.



Copy this functional code into your shader file (or create a new shader.c/.h file for it):

Code:
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:

Code:
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
Posted By: Machinery_Frank

Re: detail map on model + environment mapping - 11/17/07 12:37

This is a very well done composition of materials and effects. Thanks for sharing it!
Posted By: Pappenheimer

Re: detail map on model + environment mapping - 11/17/07 13:03

This scene is wonderful!

I'm very curious what you are working on!
I guess, Chrismas will show it! :-)
Posted By: Slin

Re: detail map on model + environment mapping - 11/17/07 14:45

Nice Scene
and thanks for the nice effect.
Would you mind adding it to the wiki, would it be okay if I add it or donīt you want it to be there?
Posted By: HeelX

Re: detail map on model + environment mapping - 11/17/07 14:56

Do it
Posted By: Slin

Re: detail map on model + environment mapping - 11/17/07 15:31

Done
Posted By: Ghost

Re: detail map on model + environment mapping - 11/17/07 15:48

Very nice HeelX and very kind of you to contribute it. Thanks.
- just need to add Santa;)
Posted By: Joozey

Re: detail map on model + environment mapping - 11/17/07 16:40

Thats how leveldesign should be done
Posted By: HeelX

Re: detail map on model + environment mapping - 11/17/07 17:02

I will post further screenshots of the scene in the other thread when I'm ready. I was quite busy these days with modeling and programming and I don't want to present crappy programmers artwork but pretty programmers artwork ^^

Cheers and thanks for the kind replies ^^
Posted By: bupaje

Re: detail map on model + environment mapping - 11/17/07 18:07

I love the way that looks, very cool in every sense of the word.
Posted By: frazzle

Re: detail map on model + environment mapping - 11/17/07 18:47

Great contribution Christian, that's just one great code
The effect you tried to achieve really results in this nice package

Cheers

Frazzle
Posted By: William

Re: detail map on model + environment mapping - 11/17/07 20:45

Thanks for the code HeelX. Screenshot looks great.
© 2024 lite-C Forums