DX9 version of Multi-Detailmapping Terrains

Posted By: Steempipe

DX9 version of Multi-Detailmapping Terrains - 11/11/04 21:47

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;

}

}
Posted By: task1

Re: DX9 version of Multi-Detailmapping Terrains - 11/17/04 18:01

nice shader!thanks Eric!!!

project
Posted By: Peter Churness

Re: DX9 version of Multi-Detailmapping Terrains - 11/19/04 01:10

Hey Eric,

This looks like great work! Could you possibly post examples of the actual color map, detail maps and blend map that a person might use with this shader? That would be helpful for me and perhaps for some others...

Thanks!!

Peter
Posted By: don

Re: DX9 version of Multi-Detailmapping Terrains - 11/23/04 15:29

thanks for your help Steempipe!!!it is working very nice!

one question: is there a way to give every texture another .tga?
Posted By: Steempipe

Re: DX9 version of Multi-Detailmapping Terrains - 11/24/04 11:03

Peter Churness: I'll see about getting a small demo that has an example of the images and a brief document on what is what. May take awhile, since my time is limited right now. If all else fails, I'll cough up and post the images you are curious about.

don: As far as the extra "TGA's"; Are you asking about adding an alpha channel blendmap into the other texture?? If so, yes. But you will probably have side-effects if you put the alphas in the entSkin textures, tho.
Posted By: LogantheHogan

Re: DX9 version of Multi-Detailmapping Terrains - 11/24/04 15:34

A small test level I threw together, combining a dirt and a grass detail map:


So, for those of you who were too lazy to try it on your own, that's what this effect looks like.
Posted By: indiGLOW

Re: DX9 version of Multi-Detailmapping Terrains - 11/25/04 23:10

nice...
Posted By: Nadester

Re: DX9 version of Multi-Detailmapping Terrains - 11/26/04 13:16

Quote:

So, for those of you who were too lazy to try it on your own, that's what this effect looks like.



Want to post a demo Logan so all of us lazy folks don't have to get up off our rears and hack one together?
Posted By: task1

Re: DX9 version of Multi-Detailmapping Terrains - 11/30/04 17:46

hi guys.

tried also to implementate more then one tga in this script.but it doesnīt work.donīt know why.is it possible that I could use for each texture a different tga?

thanx for help
Posted By: Steempipe

Re: DX9 version of Multi-Detailmapping Terrains - 11/30/04 18:01

Hmmmm.... looks like it may be time to make some changes and post a demo.
Posted By: task1

Re: DX9 version of Multi-Detailmapping Terrains - 11/30/04 21:38

hehe would be nice
Posted By: William

Re: DX9 version of Multi-Detailmapping Terrains - 01/09/05 09:17

Sorry to bring this thread up again Steempipe, but I need to ask you a couple things about this shader. Anyways, I was wondering how I'd be able to have 4 detail maps instead of 2(badly needed!)? It would be great if I could have an alpha map in the colormap which defines where to put the additional 2 detail maps. If not that then perhaps the G and B of the alphamap can define where to put the additional 2 detail maps. If you dont have time to modify the script then please share some guidence on how I would go about it.
Besides that, I was wondering if a pixel shader version of this would be much faster than current FFP version(the current one of this is speedy enough but 4 detail maps may slow it down...)? As well, does an FFP shader even require any fallbacks at all? Shouldn't a Geforce 2 card work well with FFP? If it does require fallbacks what would they be? Thank You, your time is highly appreciated.
Posted By: Steempipe

Re: DX9 version of Multi-Detailmapping Terrains - 01/10/05 01:43

A quick note to answer part of your question:

I would still consider putting a bare minimum fallback in the effect file. You never really know what card will be running it. For example; it may not support (3) texes per pass, alphaops, or the order of args.
I put (2) fallbacks, (1) being the colormap and 1 detailmap, (2) being just the colormap.
Even if using d3d_shaderversion, I would still add a fallback technique in case something slides through.

As far as the amount of textures, passes, what-not. I am making a point to script in the ability for an "option menu" where the number of textures blended, the detail amount of the textures, query what pixelshader is available, etc, can be user selected.
I believe it should be up to the end-user to decide how much they want to tax their system and to give options to ensure that they will in fact be able to run the proggie.

I'll try to get back to you about adding more textures.. it will probably be via Private Message, tho.

Eric
Posted By: DARKLORD

Re: DX9 version of Multi-Detailmapping Terrains - 01/30/05 08:43

Yes Steempipe great work!
It would be great if you could post this shader with 4 working textures and the other things William said.

Thx DARKLORD
Posted By: RaSTaFaRi_87

Re: DX9 version of Multi-Detailmapping Terrains - 11/21/05 02:20

what about the the new shader with 4 textures(detailmaps)?

Mfg

RaSTaFaRi
© 2024 lite-C Forums