|
Terrain - FFP - Blend 5 Textures
#45405
05/08/05 22:51
05/08/05 22:51
|
Joined: Dec 2003
Posts: 1,097 Maryland, USA
Steempipe
OP
Serious User
|
OP
Serious User
Joined: Dec 2003
Posts: 1,097
Maryland, USA
|
Here is some code for blending (5) textures using the fixed-function pipe. Code:
/////////////////////////////////// // ffp5tex_action.wdl //
bind <ffp5tex.fx>;
//var terrain_chunk = 128;
// Additional FFP blendmaps //
bmap sand = <sand.tga>; bmap grass = <grass.tga>; bmap road = <road.tga>; bmap stone = <stone.tga>;
function makemips { bmap_to_mipmap(mtl.Skin1); bmap_to_mipmap(mtl.Skin2); bmap_to_mipmap(mtl.Skin3); bmap_to_mipmap(mtl.Skin4); }
material mat_ffp5terrain{
Skin1 = sand; Skin2 = grass; Skin3 = road; Skin4 = stone;
event = makemips;
}
Action Terrain { fps_max = 60; effect_load(mat_ffp5terrain, "ffp5tex.fx"); wait(1); my.material = mat_ffp5terrain; }
Code:
/////////////////////////////////// // ffp5tex.fx // /*********************************************************** FFP MultiTex Effect to blend 5 Textures.
5/8/05
Eric Hendrickson-Lambert (Steempipe)
Requires: GStudio 6.31 Comm+ DX 9.0c
Blendmaps for skins 2,3,4,5 are in their alpha channels
************************************************************/
//////////////////////////////////////////////////// // Assign the tile size of the Textures. //
float Skin_Size1 = 20; float Skin_Size2 = 20; float Skin_Size3 = 20; float Skin_Size4 = 20; float Skin_Size5 = 20;
float4 vecLight;
///////////////////////////////////////////////////////////////////////////////////// // Let's allow for adjusting the intensity of the ambient light color on the passes. // float ambientLightFactor = 1.0;
//////////////////////////////////////////////////////////////////// // Here we just create and plug some values into a matrix for // use in multiplying during the stages. //
float4x4 matTerrainTexSize = {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 };
float4x4 matAlphaMapSize = {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 };
Texture entSkin1; //1st tile tex RGB Texture mtlSkin1; //2nd tile tex RGB and blender in A Texture mtlSkin2; //3nd tile tex RGB and blender in A Texture mtlSkin3; //4nd tile tex RGB and blender in A Texture mtlSkin4; //5nd tile tex RGB and blender in A
sampler s_ShaleTex = sampler_state { Texture = (entSkin1); MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; AddressW = Wrap; MaxMipLevel=0; MipMapLodBias=0.0; };
sampler s_SandTex = sampler_state { Texture = (mtlSkin1); MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; AddressW = Wrap; MaxMipLevel=0; MipMapLodBias=0.0; };
sampler s_GrassTex = sampler_state { Texture = (mtlSkin2); MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; AddressW = Wrap; MaxMipLevel=0; MipMapLodBias=0.0; };
sampler s_RoadTex = sampler_state { Texture = (mtlSkin3); MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; AddressW = Wrap; MaxMipLevel=0; MipMapLodBias=0.0; };
sampler s_StoneTex = sampler_state { Texture = (mtlSkin4); MipFilter = Linear; MinFilter = Linear; MagFilter = Linear; AddressU = Wrap; AddressV = Wrap; AddressW = Wrap; MaxMipLevel=0; MipMapLodBias=0.0; };
technique technique_one
{ pass p0 { Sampler[0] = (s_ShaleTex); AlphaBlendEnable = False; AlphaTestEnable = False; DitherEnable = True; zWriteEnable = True; zEnable = True; CullMode = None; Lighting=True; Ambient = mul(vecLight, ambientLightFactor); TextureTransformFlags[0] = Count2; TexCoordIndex[0] = 1; TextureTransform[0]= mul(matTerrainTexSize,Skin_Size1); ColorOp[0] = Modulate; ColorArg1[0] = Texture; ColorArg2[0] = Diffuse; AlphaOp[0] = Disable; }
pass p1 { Sampler[0] = (s_SandTex); // Blendmap is Alpha Sampler[1] = (s_SandTex); // The Colormap Lighting = True; Clipping=True; DitherEnable=True; AlphaBlendEnable = True; AlphaTestEnable = False; SrcBlend = InvSrcAlpha; DestBlend = SrcAlpha;
DitherEnable = True; zWriteEnable = True; zEnable = True; CullMode = None; Lighting=True; Ambient = mul(vecLight, ambientLightFactor);
TextureTransformFlags[0] = Count2; TextureTransform[0]= (matAlphaMapSize); texcoordindex[0]=0; ColorArg1[0] = Texture; ColorOp[0] = SelectArg1; AlphaArg1[0] = Texture; AlphaOp[0] = SelectArg1;
TextureTransformFlags[1] = Count2; TextureTransform[1]= mul(matTerrainTexSize, Skin_Size2); texcoordindex[1]=1;
ColorArg1[1] = Texture; ColorArg2[1]= Diffuse; ColorOp[1] =Modulate; alphaarg1[1] = current; alphaop[1]=Disable;
}
pass p2 { Sampler[0] = (s_GrassTex); // Blendmap is Alpha Sampler[1] = (s_GrassTex); // The Colormap Lighting = True; Clipping=True; DitherEnable=True; AlphaBlendEnable = True; AlphaTestEnable = False; SrcBlend = InvSrcAlpha; DestBlend = SrcAlpha;
DitherEnable = True; zWriteEnable = True; zEnable = True; CullMode = None; Lighting=True; Ambient = mul(vecLight, ambientLightFactor);
TextureTransformFlags[0] = Count2; TextureTransform[0]= (matAlphaMapSize); texcoordindex[0]=0; ColorArg1[0] = Texture; ColorOp[0] = SelectArg1; AlphaArg1[0] = Texture; AlphaOp[0] = SelectArg1;
TextureTransformFlags[1] = Count2; TextureTransform[1]= mul(matTerrainTexSize, Skin_Size3); texcoordindex[1]=1;
ColorArg1[1] = Texture; ColorArg2[1]= Diffuse; ColorOp[1] =Modulate; alphaarg1[1] = current; alphaop[1]=Disable;
}
pass p3 { Sampler[0] = (s_RoadTex); // Blendmap is Alpha Sampler[1] = (s_RoadTex); // The Colormap Lighting = True; Clipping=True; DitherEnable=True; AlphaBlendEnable = True; AlphaTestEnable = False; SrcBlend = InvsrcAlpha; DestBlend = SrcAlpha;
DitherEnable = True; zWriteEnable = True; zEnable = True; CullMode = None; Lighting=True; Ambient = mul(vecLight, ambientLightFactor);
TextureTransformFlags[0] = Count2; TextureTransform[0]= (matAlphaMapSize); texcoordindex[0]=0; ColorArg1[0] = Texture; ColorOp[0] = SelectArg1; AlphaArg1[0] = Texture; AlphaOp[0] = SelectArg1;
TextureTransformFlags[1] = Count2; TextureTransform[1]= mul(matTerrainTexSize, Skin_Size4); texcoordindex[1]=1;
ColorArg1[1] = Texture; ColorArg2[1]= Diffuse; ColorOp[1] =Modulate; alphaarg1[1] = current; alphaop[1]=Disable;
}
pass p4 { Sampler[0] = (s_StoneTex); // Blendmap is Alpha Sampler[1] = (s_StoneTex); // The Colormap Lighting = True; Clipping=True; DitherEnable=True; AlphaBlendEnable = True; AlphaTestEnable = False; SrcBlend = InvsrcAlpha; DestBlend = SrcAlpha;
DitherEnable = True; zWriteEnable = True; zEnable = True; CullMode = None; Lighting=True;
Ambient = mul(vecLight, ambientLightFactor);
TextureTransformFlags[0] = Count2; TextureTransform[0]= (matAlphaMapSize); texcoordindex[0]=0; ColorArg1[0] = Texture; ColorOp[0] = SelectArg1; AlphaArg1[0] = Texture; AlphaOp[0] = SelectArg1;
TextureTransformFlags[1] = Count2; TextureTransform[1]= mul(matTerrainTexSize, Skin_Size5); texcoordindex[1]=1;
ColorArg1[1] = Texture; ColorArg2[1]= Diffuse; ColorOp[1] =Modulate; alphaarg1[1] = current; alphaop[1]=Disable;
} }
|
|
|
Re: Terrain - FFP - Blend 5 Textures
[Re: Steempipe]
#45409
05/09/05 00:11
05/09/05 00:11
|
Joined: Mar 2001
Posts: 3,298 Beverly, Massachusetts
Rhuarc
Expert
|
Expert
Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
|
You can use the RGB components by first masking the blendmap with a texture factor to remove all other colors, use dotproduct3 as the colorop to remove coloring and multiply it with the tiled texture stage. Quick example: TextureFactor = 0x00FF0000; //Mask for red ColorOp[0] = DotProduct3; ColorArg2[0] = Texture; ColorArg1[0] = TFactor; //////////////////////////////////////////// TextureTransformFlags[1] = Count2; TextureTransform[1]= mul(matTerrainTexSize, Skin_Size2); texcoordindex[1]=1; ColorOp[1] = Modulate; ColorArg1[1] = Texture; ColorArg2[1] = Current; -Rhuarc
|
|
|
Re: Terrain - FFP - Blend 5 Textures
[Re: Steempipe]
#45411
05/09/05 01:33
05/09/05 01:33
|
Joined: Mar 2001
Posts: 3,298 Beverly, Massachusetts
Rhuarc
Expert
|
Expert
Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
|
Well, at least it works . I've got a 4 texture + reflection mask running on this basis via FFP; performance isn't anything great- but it isn't too shabby either. -Rhuarc
|
|
|
Re: Terrain - FFP - Blend 5 Textures
[Re: Steempipe]
#45412
05/09/05 06:12
05/09/05 06:12
|
Joined: Mar 2005
Posts: 969 ch
Loopix
User
|
User
Joined: Mar 2005
Posts: 969
ch
|
You did it! Thank you very much for sharing it with all of us. Not everyone who has got such abilities does share his work for free...you do...and that is most generous! This way, good Ideas can become even better (example: GNU) and everyone can learn a lot. Thx! (sorry for giving feedback only now. Where I live, people just get out of bed while you are making night-shifts in front of your screens... )
|
|
|
Re: Terrain - FFP - Blend 5 Textures
[Re: Loopix]
#45413
05/09/05 07:55
05/09/05 07:55
|
Joined: Oct 2003
Posts: 2,628 IL,US
FeiHongJr
Expert
|
Expert
Joined: Oct 2003
Posts: 2,628
IL,US
|
Thanks for the contribution ill have to give it a try. Hope it works with my graphics card I really need to update that thing..... Anyone want to buy me a graphics card just kidding .... Or am i Thanks again.
|
|
|
|