1 registered members (AndrewAMD),
801
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
DX9 version of Multi-Detailmapping Terrains
#36036
11/11/04 21:47
11/11/04 21:47
|
Joined: Dec 2003
Posts: 1,097 Maryland, USA
Steempipe
OP
Serious User
|
OP
Serious User
Joined: Dec 2003
Posts: 1,097
Maryland, USA
|
Can be easily adapted to just modulating the textures (instead of Addsigned for a "detailmapping" effect) for multi-texturing. In that case, the colormap sampler could be a tileable texture and the transformation set to a scale factor.
This is from my FX file... so it will be necessary to load the FX file, create the Material, Action and so forth.
/*------------------------------------------------------------------- A few Ideas on Detailmapping A large Colormap
Requirements: 3DGS A6.31+ Commercial and Directx 9.00c -Large Colormap skin in entSkin1 -Suitable Detailmap Texture in entSkin2 and entSkin3 -Blendmap for Technique #1 in mtlSkin1 Alpha. -Sun positions and color to be set in 'Map Properties' -Ambient light color set in Map Properites -Fog Color and ranges set Eric Hendrickson-Lambert (Steempipe) ~ Credit if used, is appreciated
10-26-04: -Implemented 10-27-04: -Added variables for setting up lighting and tiling Note: This is a WIP and in an expirimental phase right now. Things most likely will change, for the better I hope.
If you have <var Detail_Size> set in you main function, you will see that our scaling gets re-multiplied. Pick the way you want to do it. If you choose using the vars in this FX file, then set Detail_Size=0; in main func.
---------------------------------------------------------------------*/ /*************************************** Tweakable Variables ***************************************/
//////////////////////////////////////////////////// // Assign the tile size of the detailmap. // float Detailmap_Size1 = 16.0; float Detailmap_Size2 = 14.0;
//////////////////////////////////////////////////// // Grab the ambient light color from the engine. // float4 vecLight;
///////////////////////////////////////////////////////////////////////////////////// // Let's allow for adjusting the intensity of the ambient light color on the entity. // float ambientLightFactor = 0.8;
/*************************************** Default Variables ***************************************/
//////////////////////////////////////////////////////////////////// // Here we just create and plug some values into a matrix for // use in scaling during the stages. //
float4x4 matDetailMapSize = {1.0, 0.0, 0.0 ,0.0, // U scale of Detailmap 0.0, 1.0, 0.0, 0.0, // V scale of Detailmap 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
float4x4 matColorMapSize = {1.0, 0.0, 0.0 ,0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
/*************************************** Setup Textures ***************************************/
Texture entSkin1; // The large Colormap Skin in RGB Texture entSkin2; // Detailmap in RGB Texture entSkin3; // Detailmap in RGB Texture mtlSkin1; // Blendmap for Technique#1 - Pass 1 in Alpha
sampler s_Colormap = sampler_state { Texture = (entSkin1); MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; AddressU = WRAP; AddressV = Wrap; AddressW = Wrap; MaxMipLevel=0; MipMapLodBias=0.0; };
sampler s_Detailmap = sampler_state { Texture = (entSkin3); MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; AddressW = Wrap; MaxMipLevel=0; MipMapLodBias=0.0; };
sampler s_Detailmap1 = sampler_state { Texture = (entSkin2); MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; AddressW = Wrap; MaxMipLevel=0; MipMapLodBias=0.1; };
sampler s_DetailBlendmap = sampler_state { Texture = (mtlSkin1); MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; AddressW = Wrap; MaxMipLevel=0; MipMapLodBias=0.1; };
///////////////////////////////////////////// // T E C H N I Q U E ' S /////////////////////////////////////////////
///////////////////////////////////////////// // Just slap down the colormap and // then (2) Detailmaps based on // a blendmap. ///////////////////////////////////////////// technique detailmap_technique_one { pass p0 { Sampler[0] = (s_Colormap); Sampler[1] = (s_Detailmap1); // Make sure defaults are set // AlphaBlendEnable = False; DitherEnable = True; zWriteEnable = True; zEnable = True; CullMode = None; Lighting = True; // Allow for diffuse lighting from engine //////////////////////////////////////////////////////////////////////// // If the Ambient Light Color is set in Map Properites, // Here we have the opportunity to apply it to the terrain. // We will use ambientLightFactor to adjust its intensity. // Ambient = mul(vecLight, ambientLightFactor);
////////////////////////////////////////////////// // Apply the Colormap // TextureTransformFlags[0] = Count2; TexCoordIndex[0] = 0; TextureTransform[0]= (matColorMapSize); ColorOp[0] = Modulate; // Modulate diffuse lighting with colormap texture ColorArg1[0] = Texture; ColorArg2[0] = Diffuse; AlphaOp[0] = Disable; ////////////////////////////////////////////////// // Apply the Detailmap // TextureTransformFlags[1] = Count2; TexCoordIndex[1] = 1; TextureTransform[1]= (matDetailMapSize * Detailmap_Size1); ColorOp[1] = Addsigned; ColorArg1[1] = Texture; ColorArg2[1] = Current; AlphaOp[1] = Disable; ColorOp[2] = Disable; AlphaOp[2] = Disable;
}
pass p1 { Sampler[0] = (s_DetailBlendmap); // Blendmap is Alpha Sampler[1] = (s_Colormap); // The Colormap Sampler[2] = (s_Detailmap); // The Detailmap Lighting = True; Clipping=True; DitherEnable=True; ////////////////////////////////////////////////// // Setup the Blendmap // AlphaBlendEnable = True; SrcBlend = srcAlpha; DestBlend = InvSrcAlpha;
DitherEnable = True; zWriteEnable = True; zEnable = True; CullMode = None; Lighting=True; // Get lighting from engine /////////////////////////////////////////////////////////////// // Adjust the lighting, furthur, if desired. // // //Ambient = mul(vecLight, (ambientLightFactor * 1.1)); ColorArg1[0] = Current; ColorOp[0] = SelectArg1; AlphaArg1[0] = Texture; AlphaOp[0] = SelectArg1;
////////////////////////////////////////////////// // Re-apply the Colormap for blending reasons // undetermined at this point. // TextureTransformFlags[1] = Count2; TextureTransform[1]= (matColorMapSize); texcoordindex[1]=0;
ColorArg1[1] = Texture; ColorArg2[1]= Current; ColorOp[1] =Modulate; alphaarg1[1] = current; alphaop[1]=Disable;
////////////////////////////////////////////////// // Apply the 2nd Detailmap // TextureTransformFlags[2] = Count2; TextureTransform[2]= (matDetailMapSize * Detailmap_Size2);
texcoordindex[2]=1; ColorOp[2] = Addsigned; ColorArg1[2] = Texture; ColorArg2[2] = Current; AlphaOp[2]=Disable;
ColorOp[3]=Disable; AlphaOp[3]=Disable;
} }
|
|
|
|