DX9 Multitexturing

Posted By: Macom

DX9 Multitexturing - 10/17/04 08:08

Hi,

can someone of the shader-gurus change this multitexturing code to a dx9 compatible version ? I think the original is from stempie or ventilator ...

Code:

material mtl_multitexture
{
effect=
"
texture entSkin1;
texture entSkin2;
texture entSkin3;
texture entSkin4;
matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;
vector vecSunDir;
vector vecFog;
technique multitexture
{
pass p0
{
Texture[0]=<entSkin1>; // colormap1
Texture[1]=<entSkin3>; // colormap2
Texture[2]=<entSkin2>; // colormap3
Texture[3]=<entSkin4>; // macromap
magFilter[2]=linear;
minFilter[2]=linear;
mipFilter[2]=linear;
magFilter[3]=linear;
minFilter[3]=linear;
mipFilter[3]=linear;
zWriteEnable=true;
vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;
vertexShaderConstant[16]=<vecSunDir>;
vertexShaderConstant[20]=<vecFog>;
vertexShaderConstant[64]=(10.0f,10.0f,16.0f,16.0f);
vertexShaderConstant[65]=(8.0f,8.0f,0.0f,0.0f); // u_scale3,v_scale3
vertexShaderConstant[95]=(0.5f,1.0f,2.0f,0.0f);
vertexShader=
asm
{
vs_1_1
dcl_position v0
dcl_normal v3
dcl_texcoord0 v7

m4x4 oPos,v0,c0 // transform position to clip space

m3x3 r0,v3,c4 // transform normal to world space
dp3 r0.w,r0,r0 // renormalize it
rsq r0.w,r0.w
mul r0,r0,r0.w

dp3 oD0,r0,-c16 // normal.light -> lighting constant

mov r1.w,c20.w // r1.w=1
dp4 r0,v0,c10 // distance to camera position
add r0,r0,-c20.x // distance-fog_start
mad r0.x,-r0.x,c20.z,r1.w // 1-(distance-fog_start)*(1/(fog_end-fog_start))
max oFog.x,r0.x,c95.w // clamp with custom max value

mul oT0.xy,v7.xy,c64.xy // output scaled uvs - colormap1
mul oT1.xy,v7.xy,c64.zw // output scaled uvs - colormap2
mul oT2.xy,v7.xy,c65.xy // output scaled uvs - colormap3
mov oT3.xy,v7.xy // output uvs - macromap
};

pixelShader=
asm
{
ps.1.1
def c0,1,1,1,1
tex t0 // sample colormap1
tex t1 // sample colormap2
tex t2 // sample colormap3
tex t3 // sample macromap

mov r1,t1
lrp r0.rgb,t3.a,t0,r1 // blend t0 with t1 depending on t3 alpha
+mov r0.a,c0

mov r1.a,t3.b
lrp r0.rgb,r1.a,r0,t2 // blend the result with t2 depending on t3 blue
+mov r0.a,c0

mul r0.rgb,r0,v0 // modulate with diffuse vertex lighting
};
}
}
technique fallback { pass p0 { } }
";
}


Posted By: Macom

Re: DX9 Multitexturing - 10/18/04 07:02

Nobody ? It is the shader from the wiki :
TerrainMultitexturing
Posted By: ventilator

Re: DX9 Multitexturing - 10/18/04 07:16

Texture[0]=<entSkin1>;
Texture[1]=<entSkin2>;
Texture[2]=<entSkin3>;
Texture[3]=<entSkin4>;
MagFilter[2]=linear;
MinFilter[2]=linear;
MipFilter[2]=linear;
MagFilter[3]=linear;
MinFilter[3]=linear;
MipFilter[3]=linear;
ZWriteEnable=true;
VertexShaderConstant[0]=<matWorldViewProj>;
VertexShaderConstant[4]=<matWorld>;
VertexShaderConstant[8]=<matWorldView>;
VertexShaderConstant[16]=<vecSunDir>;
VertexShaderConstant[20]=<vecFog>;

some of this stuff is case sensitive now and you have to remove the .x of oFog.x. these are the errors i noticed at first sight but there might be some others. what do the error messages say?
Posted By: Macom

Re: DX9 Multitexturing - 10/18/04 07:53

Thx venitlator. The error is :


Posted By: ventilator

Re: DX9 Multitexturing - 10/18/04 07:57

the () of the shader constants have to be changed to {}.
Posted By: Macom

Re: DX9 Multitexturing - 10/18/04 08:14

Thx a lot! It works fine now ... Small thing, but big error.
Posted By: task1

Re: DX9 Multitexturing - 10/21/04 03:14

I tried to use the shader but got an error message.has anybody an idea what this means???


Posted By: RobH

Re: DX9 Multitexturing - 10/21/04 05:31

I can´t get this multitex-shader to work. My code:



bmap HighGrass = <herbe7.bmp>;
bmap Blender14 = <blender14.tga>;



material mat_terrain_multitexture
{

Skin1 = HighGrass;
Skin2 = Blender14;


effect=
"
texture entSkin1;
texture entSkin2;
texture entSkin3;
texture entSkin4;
texture mtlSkin1;
texture mtlSkin2;


matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;

vector vecSunDir;
vector vecDiffuse;
vector vecAmbient;
vector vecLight;
vector vecFog;
vector vecSkill41;

technique multitextureps14
{
pass p0
{
texture[0]=<entSkin1>;
texture[1]=<entSkin2>;
texture[2]=<entSkin3>;
texture[3]=<entSkin4>;
texture[4]=<mtlSkin1>;
texture[5]=<mtlSkin2>;

MaxMipLevel[0]= 0;
MaxMipLevel[1]= 0;
MaxMipLevel[2]= 0;
MaxMipLevel[3]= 0;
MaxMipLevel[4]= 0;
MaxMipLevel[5]= 0;

magFilter[0]=linear;
minFilter[0]=linear;
mipFilter[0]=linear;

magFilter[1]=linear;
minFilter[1]=linear;
mipFilter[1]=linear;

magFilter[2]=linear;
minFilter[2]=linear;
mipFilter[2]=linear;

MagFilter[3]=linear;
MinFilter[3]=linear;
MipFilter[3]=linear;

MagFilter[4]=linear;
MinFilter[4]=linear;
MipFilter[4]=linear;

MagFilter[5]=linear;
MinFilter[5]=linear;
MipFilter[5]=linear;


zWriteEnable=true;

vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;

vertexShaderConstant[16]=<vecSunDir>;
vertexShaderConstant[17]=<vecDiffuse>;
vertexShaderConstant[18]=<vecAmbient>;
vertexShaderConstant[19]=<vecLight>;
vertexShaderConstant[20]=<vecFog>;


vertexShaderConstant[64]=<vecSkill41>;
vertexShaderConstant[65]={20.0f,15.0f,0.0f,0.0f0};
vertexShaderConstant[66]={25.0f,20.0f,0.0f,0.0f};
vertexShaderConstant[67]={25.0f,20.0f,0.0f,0.0f};

vertexShaderConstant[95]={0.0f,0.0f,0.0f,0.0f};

vertexShader=



dec_position v0
dec_normal v1
dec_texcoord v3
dec_texcoord v4


asm
{
vs.1.1
m4x4 oPos,v0,c0 // transform position to clip space



m3x3 r0,v3,c4 // transform normal to world space


dp3 r0.w,r0,r0 // renormalize it
rsq r0.w,r0.w
mul r0,r0,r0.w






dp3 r0,r0,-c16 // normal.light -> lighting constant
mul r0.xyz,r0,c17 // modulate against material diffuse color
add oD0.xyz,r0,c19 // add environment light

mov r1.w,c20.w // r1.w=1
dp4 r0,v0,c10 // distance to camera position
add r0,r0,-c20.x // distance-fog_start
mad r0.x,-r0.x,c20.z,r1.w // 1-{distance-fog_start}*{1/{fog_end-fog_start}}
max oFog,r0.x,c95.w // clamp with custom max value

mul oT0.xy,v7.xy,c64.xy // output scaled uvs - stage 0
mul oT1.xy,v7.xy,c64.zw // output scaled uvs - stage 1
mul oT2.xy,v7.xy,c65.xy
mul oT3.xy,v7.xy,c67.xy
mul oT4.xy,v7.xy,c66.xy
mov oT5.xy,v7.xy


};

pixelShader=
asm
{
ps.1.4
//def c0,1,1,1,1

texld r0,t0
texld r1,t1
texld r2,t2
texld r3,t3
texld r4,t4
texld r5,t5

lrp r0.rgb,r5.a,r0,r1 // blend t1 with t0 using the alpha channel of t5

lrp r0.rgb,r5.b,r2,r0 // blend the result with t2 depending on t5 blue

lrp r0.rgb,r5.g,r3,r0 // blend the result with t3 depending on t5 green

lrp r0.rgb,r5.r,r4,r0 // blend the result with t4 depending on t5 red

mul r0.rgb,r0,v0 // modulate with diffuse vertex lighting


};
}

}



technique multitextureps11
{
pass p0
{
texture[0]=<entSkin3>;
texture[1]=<entSkin1>;
texture[2]=<entSkin4>;
texture[3]=<mtlSkin2>;


MaxMipLevel[0]= 0;
MaxMipLevel[1]= 0;
MaxMipLevel[2]= 0;
MaxMipLevel[3]= 0;
MaxMipLevel[4]= 0;

magFilter[0]=linear;
minFilter[0]=linear;
mipFilter[0]=linear;

magFilter[1]=linear;
minFilter[1]=linear;
mipFilter[1]=linear;

magFilter[2]=linear;
minFilter[2]=linear;
mipFilter[2]=linear;

magFilter[3]=linear;
minFilter[3]=linear;
mipFilter[3]=linear;

magFilter[4]=linear;
minFilter[4]=linear;
mipFilter[4]=linear;

zWriteEnable=true;

vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;

vertexShaderConstant[16]=<vecSunDir>;
vertexShaderConstant[17]=<vecDiffuse>;
vertexShaderConstant[18]=<vecAmbient>;
vertexShaderConstant[19]=<vecLight>;
vertexShaderConstant[20]=<vecFog>;

vertexShaderConstant[64]=<vecSkill41>; //(u_scale1, v_scale1, u_scale2, v_scale2)
vertexShaderConstant[65]={20.0f,15.0f,0.0f,0.0f}; // !NEW! -> {u_scale3, v_scale3, 0, 0}

vertexShaderConstant[95]={0.0f,0.0f,0.0f,0.0f};

vertexShader=

{


dec_position v0
dec_normal v1
dec_texcoord v3
dec_texcoord v4


}
asm
{
vs.1.0
m4x4 oPos,v0,c0 // transform position to clip space

mul oT0.xy,v7.xy,c64.xy // output scaled uvs - stage 0
mul oT1.xy,v7.xy,c64.zw
mul oT2.xy,v7.xy,c65.xy // output scaled uvs - stage 1
mov oT3.xy,v7.xy // output uvs - stage 2

m3x3 r0,v3,c4 // transform normal to world space
dp3 r0.w,r0,r0 // renormalize it
rsq r0.w,r0.w
mul r0,r0,r0.w

dp3 r0,r0,-c16 // normal.light -> lighting constant
mul r0.xyz,r0,c17 // modulate against material diffuse color
add oD0.xyz,r0,c19 // add environment light

mov r1.w,c20.w // r1.w=1
dp4 r0,v0,c10 // distance to camera position
add r0,r0,-c20.x // distance-fog_start
mad r0.x,-r0.x,c20.z,r1.w // 1-(distance-fog_start)*(1/(fog_end-fog_start))
max oFog.x,r0.x,c95.w // clamp with custom max value
};

pixelShader=
asm
{
ps.1.1
def c0,1,1,1,1
tex t0 // sample t0
tex t1
tex t2 // sample t1
tex t3 // sample t2

mov r1,t0
lrp r0.rgb,t3.a,t1,r1 // blend t0 with t1 depending on t3 alpha
+mov r0.a,c0

mov r1.a,t3.b
lrp r0.rgb,r1.a,t2,r0 // blend the result with t2 depending on t3 blue
+mov r0.a,c0

mul r0.rgb,r0,v0 // modulate with diffuse vertex lighting

};
}




}







";

}


starter mat_terrain_multitexture_init

{


bmap_to_mipmap(mat_terrain_multitexture.skin1);
bmap_to_mipmap(mat_terrain_multitexture.skin2);


}



action Shader_Terrain
{
my.skill41=float(20); //set the U tiling size of Tex 0
my.skill42=float(25); //set the V tiling size of Tex 0
my.skill43=float(20); //Set the U tiling size of Tex 1
my.skill44=float(25); //Set the V tiling size of Tex 1

my.flare = off;
my.transparent = off;
my.albedo = 0;
my.material = mat_terrain_multitexture;
}


I´ve got this error:

Malfunction W1550

Error in Effect:
mat_terrain_multitexture(78):error X3000:syntax error:unexpected integer constant

The debug syntax check found no error, can anybody help??
Posted By: Macom

Re: DX9 Multitexturing - 10/21/04 07:30

some errors :

use

vertexShader=

asm
{
vs_1_1
dec_position v0
dec_normal v1
dec_texcoord v3
dec_texcoord v4

instead of

vertexShader=

dec_position v0
dec_normal v1
dec_texcoord v3
dec_texcoord v4


asm
{
vs.1.1

there may be more errors.
Posted By: Steempipe

Re: DX9 Multitexturing - 10/21/04 08:03

For both the ps11 and ps14 code you posted...

Change the stream declarations from this:


Quote:

vertexShader=

dec_position v0
dec_normal v1
dec_texcoord v3
dec_texcoord v4


asm
{
vs.1.1

m4x4 oPos,v0,c0 // transform position to clip space

..........





To this: (Note the location of where the declarations go now.)

Quote:

vertexShader=

asm
{
vs.1.1

dcl_position v0
dcl_normal v3
dcl_texcoord0 v7

m4x4 oPos,v0,c0
..........






And in your ps11 code, change <oFog.x>, to <oFog>. Just like you have in the ps14 code.

And as pointed out, change the <vs.1.0> in the ps11 code to <vs.1.1>.
Posted By: Steempipe

Re: DX9 Multitexturing - 10/21/04 08:13

Quote:

I´ve got this error:

Malfunction W1550

Error in Effect:
mat_terrain_multitexture(78):error X3000:syntax error:unexpected integer constant

The debug syntax check found no error, can anybody help??






After you do all the above corrections.... then for this one;
Try correction in this line: (get rid of the last zero)
vertexShaderConstant[65]={20.0f,15.0f,0.0f, 0.0f0 };

if you still get the error, try changing this line:
vertexShaderConstant[64]=<vecSkill41>;

to something like:
vertexShaderConstant[64]={20.0f,15.0f,0.0f,0.0f};

If it goes away, then you know where to focus attention.
Posted By: lekboon

Re: DX9 Multitexturing - 10/21/04 13:01

hi,i modify the multitexture shader from wiki and follow the advise from Steempipe. The shader finishly work in DX9 version.
here is the code:



material mtl_multitexture
{
effect=
"
texture entSkin1;
texture entSkin2;
texture entSkin3;
texture entSkin4;
matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;
vector vecSunDir;
vector vecFog;
technique multitexture
{
pass p0
{
Texture[0]=<entSkin1>; // colormap1
Texture[1]=<entSkin3>; // colormap2
Texture[2]=<entSkin2>; // colormap3
Texture[3]=<entSkin4>; // macromap
magFilter[2]=linear;
minFilter[2]=linear;
mipFilter[2]=linear;
magFilter[3]=linear;
minFilter[3]=linear;
mipFilter[3]=linear;
zWriteEnable=true;
vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;
vertexShaderConstant[16]=<vecSunDir>;
vertexShaderConstant[20]=<vecFog>;
vertexShaderConstant[64]={10.0f,10.0f,16.0f,16.0f};
vertexShaderConstant[65]={8.0f,8.0f,0.0f,0.0f}; // u_scale3,v_scale3
vertexShaderConstant[95]={0.5f,1.0f,2.0f,0.0f};
vertexShader=
asm
{
vs_1_1
dcl_position v0
dcl_normal v3
dcl_texcoord0 v7

m4x4 oPos,v0,c0 // transform position to clip space

m3x3 r0,v3,c4 // transform normal to world space
dp3 r0.w,r0,r0 // renormalize it
rsq r0.w,r0.w
mul r0,r0,r0.w

dp3 oD0,r0,-c16 // normal.light -> lighting constant

mov r1.w,c20.w // r1.w=1
dp4 r0,v0,c10 // distance to camera position
add r0,r0,-c20.x // distance-fog_start
mad r0.x,-r0.x,c20.z,r1.w // 1-(distance-fog_start)*(1/(fog_end-fog_start))
max oFog,r0.x,c95.w // clamp with custom max value

mul oT0.xy,v7.xy,c64.xy // output scaled uvs - colormap1
mul oT1.xy,v7.xy,c64.zw // output scaled uvs - colormap2
mul oT2.xy,v7.xy,c65.xy // output scaled uvs - colormap3
mov oT3.xy,v7.xy // output uvs - macromap
};

pixelShader=
asm
{
ps.1.1
def c0,1,1,1,1
tex t0 // sample colormap1
tex t1 // sample colormap2
tex t2 // sample colormap3
tex t3 // sample macromap

mov r1,t1
lrp r0.rgb,t3.a,t0,r1 // blend t0 with t1 depending on t3 alpha
+mov r0.a,c0

mov r1.a,t3.b
lrp r0.rgb,r1.a,r0,t2 // blend the result with t2 depending on t3 blue
+mov r0.a,c0

mul r0.rgb,r0,v0 // modulate with diffuse vertex lighting
};


}
}
technique fallback { pass p0 { } }
";
}

action terrain
{
my.skill41=float(10);
my.skill42=float(20);
my.skill43=float(5);
my.skill44=float(10);

my.flare=off;
my.transparent=off;
my.material=mtl_multitexture;
}
Posted By: Ahriman

Re: DX9 Multitexturing - 10/21/04 17:47

lekboon: Tested this code it works great thanks to all contributors, a couple questions or request rather please. Dynamic lighting is not working on the terrain, also would it be possible to add 1 or 2 more textures to the blending?
Posted By: RobH

Re: DX9 Multitexturing - 10/22/04 16:56

I have no only one texture, no multitexturing. I have an macromap and three textures. What made I wrong or have i forget??
Posted By: task1

Re: DX9 Multitexturing - 11/01/04 21:13

yeah lekboon you rocks!

thanks alot to everybody!

project page
© 2023 lite-C Forums