Terrain - FFP - Blend 5 Textures

Posted By: Steempipe

Terrain - FFP - Blend 5 Textures - 05/08/05 22:51

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;

}

}



Posted By: paulshort

Re: Terrain - FFP - Blend 5 Textures - 05/08/05 23:03

Steampipe your amazing...
Posted By: Matt_Aufderheide

Re: Terrain - FFP - Blend 5 Textures - 05/08/05 23:37

are you sure there's no way to use a rgb blend map? Can you access the rgb channels at all in fixed function? because my terrain editor generates a color blend map.
Posted By: Steempipe

Re: Terrain - FFP - Blend 5 Textures - 05/08/05 23:49

I have some ideas I'll try to work out this week. With any luck I will be able to post good news. I'd like to finish the ps.1.1 5 tex hack, also.

paulshort: Thanks!
Posted By: Rhuarc

Re: Terrain - FFP - Blend 5 Textures - 05/09/05 00:11

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
Posted By: Steempipe

Re: Terrain - FFP - Blend 5 Textures - 05/09/05 00:30

Not quite so cut and dry... but you're on the right path.
Posted By: Rhuarc

Re: Terrain - FFP - Blend 5 Textures - 05/09/05 01:33

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
Posted By: Loopix

Re: Terrain - FFP - Blend 5 Textures - 05/09/05 06:12

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... )
Posted By: FeiHongJr

Re: Terrain - FFP - Blend 5 Textures - 05/09/05 07:55

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.
Posted By: Pappenheimer

Re: Terrain - FFP - Blend 5 Textures - 05/09/05 16:21

Fantastic Contribution!
I totally agree with Loopix!
Posted By: Rigoletto

Re: Terrain - FFP - Blend 5 Textures - 05/09/05 17:18

@steempipe: Good work, now i have more knowledge to assimilate. Would speed increase if it shinked to 3 passes? I think it could be possible?

@rhuarc: Thanks for how to coloring with FF. Now i can finish my second tutorial.
Posted By: xoNoid

Re: Terrain - FFP - Blend 5 Textures - 05/24/05 17:17

I know this is an old topic but has anyone made a working example of this shader? If so I would appreciate them posting it.
Posted By: jumpman

Re: Terrain - FFP - Blend 5 Textures - 06/04/05 17:14

How do you set up the alpha channel as a blending map? Has anyone got this code working?
Posted By: xoNoid

Re: Terrain - FFP - Blend 5 Textures - 06/04/05 17:32

I got it to work PM me if you want an example.
Posted By: Pappenheimer

Re: Terrain - FFP - Blend 5 Textures - 06/05/05 11:16

Quote:

I got it to work PM me if you want an example.




Maybe, you wanna add a demo to the resources at Acknex Unlimited!
Posted By: XNASorcerer

Re: Terrain - FFP - Blend 5 Textures - 10/10/05 16:03

Steempipe,

Sorry to bring this back, but did you manage to achieve the rgb blend map?
Posted By: Steempipe

Re: Terrain - FFP - Blend 5 Textures - 10/10/05 20:30

I'll look to see where I left off at with the thing, and if I got it close.
Posted By: XNASorcerer

Re: Terrain - FFP - Blend 5 Textures - 10/13/05 02:43

Thanks
Posted By: XNASorcerer

Re: Terrain - FFP - Blend 5 Textures - 11/02/05 16:41

Quote:

I'll look to see where I left off at with the thing, and if I got it close.




Any news about that?
Posted By: Grafton

Re: Terrain - FFP - Blend 5 Textures - 11/03/05 00:48

An RGB method would be great since you would need only 1 blendmap and could include it as an entskin! It sounds like Rhuarc might have got this working?
Posted By: Sebe

Re: Terrain - FFP - Blend 5 Textures - 11/03/05 00:49

You can find a terrain shader with an rgb blendmap in the wiki, but it requires vs 1.1 and ps 1.3.
Posted By: Steempipe

Re: Terrain - FFP - Blend 5 Textures - 11/03/05 01:05

Quote:

Quote:

I'll look to see where I left off at with the thing, and if I got it close.




Any news about that?




Funny thing. I cannot find the project anywhere . If I have time, in the distant future I may re-create it. Man.... my head is already starting to hurt!
Posted By: XNASorcerer

Re: Terrain - FFP - Blend 5 Textures - 11/04/05 23:30

Yes, but it only uses 3 textures.
Posted By: Captain_Kiyaku

Re: Terrain - FFP - Blend 5 Textures - 11/29/05 13:59

one stupid questions (i always have problems with the blendmaps to blend it correct o:O)

bmap sand = <sand.tga>;
bmap grass = <grass.tga>;
bmap road = <road.tga>;
bmap stone = <stone.tga>;

are this the blendmaps?

also i have a question about the blendmaps

if i want the road lying over the sand for example and sometimes the sand over the road. do i just have to do it with the alpha? (white things will be shown and alpha = nothing?)

cause i often have problems what teture comes first and how i let them blend over each other ^^''
Posted By: XNASorcerer

Re: Terrain - FFP - Blend 5 Textures - 11/29/05 14:26

DS_Kihaku,
Why don't try this tutorial here. Perhaps it could help you.
Posted By: Captain_Kiyaku

Re: Terrain - FFP - Blend 5 Textures - 11/29/05 14:28

cause it uses RPG blendmaps and not sure if its always the same technique
Posted By: Stansmedia

Re: Terrain - FFP - Blend 5 Textures - 11/28/06 10:23

I cant igure out how to blend the textures together on the terrain. can somebody explain what to do?
Posted By: Pappenheimer

Re: Terrain - FFP - Blend 5 Textures - 11/28/06 18:42

Nagashi made a magnificant simple demo:

http://www.coniserver.net/ubbthreads/showflat.php/Cat/0/Number/708538/Main/708053#Post708538

The map with the simple colors like red, green, blue black, that is the blendmap.
© 2024 lite-C Forums