Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (TipmyPip, AndrewAMD, Quad, aliswee, degenerate_762), 970 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 4
Page 1 of 11 1 2 3 10 11
terrain multitexturing shader #17295
09/20/03 21:07
09/20/03 21:07
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
here is my terrain multitexturing shader!

the terrain needs 3 textures:
  • 1. tiled - tiling can be specified with entity skill41(u) and skill42(v)
  • 2. tiled - tiling can be specified with entity skill43(u) and skill44(v)
  • 3. not tiled - this texture's alpha channel specifies how the first two textures get blended. (the pixelshader additionally adds (signed) this texture's color channels but you could comment out this line if you don't need this.)

with some changes it would also be possible to blend the textures depending on the terrain's slope instead of the alpha channel.

Code:
material mat_terrain_multitexture

{
effect=
"
texture texSkin1;
texture texSkin2;
texture texSkin3;

matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;

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

technique multitexture
{
pass p0
{
Texture[0]=<texSkin1>;
Texture[1]=<texSkin2>;
Texture[2]=<texSkin3>;

MagFilter[2]=linear;
MinFilter[2]=linear;
MipFilter[2]=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[95]=(0.0f,0.0f,0.0f,0.0f);

VertexShader=
decl
{
stream 0;
float v0[3]; //position
float v3[3]; //normal
float v7[2]; //uv
}
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.x,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
mov oT2.xy,v7.xy // output uvs - stage 2
};

PixelShader=
asm
{
ps.1.3
def c0,0,0,0,1
tex t0 // sample t0
tex t1 // sample t1
tex t2 // sample t2
lrp r0.rgb,t2.a,t0,t1 // blend t0 with t1 using the alpha channel of t2
+mov r0.a,c0
//add r0.rgb,r0,t2_bias // add(signed) rgb of t2
mul r0.rgb,r0,v0 // modulate with diffuse vertex lighting
};
}
}
";
}

starter mat_terrain_multitexture_init
{
vec_set(mat_terrain_multitexture.ambient_blue,mat_terrain.ambient_blue);
vec_set(mat_terrain_multitexture.diffuse_blue,mat_terrain.diffuse_blue);
vec_set(mat_terrain_multitexture.specular_blue,mat_terrain.specular_blue);
mat_terrain_multitexture.power=mat_terrain.power;
}



i am a beginner with writing shaders so please tell me if you find any mistakes or if you know how to improve it!

i also would like to know if exactly the same thing would be possible with the fixed d3d path? i don't think so because the fixed path is somewhat inflexible...

Re: terrain multitexturing shader [Re: ventilator] #17296
09/21/03 02:17
09/21/03 02:17
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
This is a very useful shader example.

You can do it also in the fixed function pipeline, but then you would need two passes for the terrain. Your shader code is faster, however a two-pass fixed function technique could be used as a fallback.

Re: terrain multitexturing shader [Re: jcl] #17297
09/21/03 03:51
09/21/03 03:51
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
thanks! i will look into how a two-pass fixed function fallback can be done...

Re: terrain multitexturing shader [Re: ventilator] #17298
10/21/03 05:10
10/21/03 05:10
Joined: Oct 2003
Posts: 1,550
United Kingdom
indiGLOW Offline
Serious User
indiGLOW  Offline
Serious User

Joined: Oct 2003
Posts: 1,550
United Kingdom
Ok so I have no idea what any of that meant, please could someone ....point me in the right direction or spare a few moments to take me through it I would really appreciate it.....


The Art of Conversation is dead : Discuss
Re: terrain multitexturing shader [Re: ventilator] #17299
12/04/03 18:58
12/04/03 18:58
Joined: Jun 2001
Posts: 2,006
USA
Darkstorm Offline
Senior Expert
Darkstorm  Offline
Senior Expert

Joined: Jun 2001
Posts: 2,006
USA
Sorry for being a newb but, would someone be so kind as to give me an assist on this code here. This is my first venture into actually trying to use materials and shaders and I'm not having much luck.

How exactly are the three skins supposed to be set up? Right now I have a terrain 512x512 heightmap with the skins set up like this:

1) 256x256 tiling texture
2) 256x256 tiling texture
3) 512x512 32bit TGA with alpha channel

I think that's right but who knows. I put the material in its own WDL and included it. I placed the action after main in my level script. When I run the level all I get is effect unsupported by hardware and then the terrain with the first skin.

I have a GeForce3 Ti 200 using 52.16 Detonator. This should be able to handle this right?

Anyway, thanks for listening to my newb struggles .


Re: terrain multitexturing shader [Re: Darkstorm] #17300
12/04/03 19:28
12/04/03 19:28
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
it should work... have you changed all the texskins to entskin? did you set the tiling parameters in the terrain action?

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=mat_terrain_multitexture;
}

btw. it's very easy to add an additional detailmap or such things to this shader...

Re: terrain multitexturing shader [Re: ventilator] #17301
12/04/03 19:51
12/04/03 19:51
Joined: Jun 2001
Posts: 2,006
USA
Darkstorm Offline
Senior Expert
Darkstorm  Offline
Senior Expert

Joined: Jun 2001
Posts: 2,006
USA
Thanks for the reply. Now, bare with me, what do the parameters in the action represent? What do they do exactly? Is it for UV? Also, how "easy" would it be for someone like me to add a detail map to this? I'd really like to learn the workings of this stuff but I don't really know where to begin.

Re: terrain multitexturing shader [Re: Darkstorm] #17302
12/04/03 20:02
12/04/03 20:02
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
my.skill41=float(10); // u multiplication factor of texture 1 -> will tile the texture 10 times along u
my.skill42=float(20); // v multiplication factor of texture 1
my.skill43=float(5); // u multiplication factor of texture 2
my.skill44=float(10); // v multiplication factor of texture 2

.
.
.

for a detail map you could add the following:

...
texture entSkin4; // the 4th texture of the model will be the detail map
...
Texture[3]=<entSkin4>;
...
VertexShaderConstant[65]=(96.0f,192.0f,0.0f,0.0f); // specifies the tiling of the detail map
...
mul oT3.xy,v7.xy,c65.xy // output scaled uvs for the detailmap


and the pixel shader will look like that:

ps.1.3
def c0,1,1,1,1
tex t0 // sample colormap1
tex t1 // sample colormap2
tex t2 // sample macromap
tex t3 // sample detailmap
lrp r0.rgb,t2.a,t0,r1 // blend t0 with t1 using the alpha channel of t2
+mov r0.a,c0
//add r0.rgb,r0,t2_bias // add(signed) rgb of t2
add r0.rgb,r0,t3_bias // add(signed) rgb of t3 (detailmap)
mul r0.rgb,r0,v0 // modulate with diffuse vertex lighting


(but i haven't tested this )

...alternatively you it would also be possible to apply the detailmap to one of the colormaps only...

Re: terrain multitexturing shader [Re: ventilator] #17303
12/04/03 20:11
12/04/03 20:11
Joined: Jun 2001
Posts: 2,006
USA
Darkstorm Offline
Senior Expert
Darkstorm  Offline
Senior Expert

Joined: Jun 2001
Posts: 2,006
USA
Hmm. I'm still getting the W1551 error. Is there a specific size/naming convention for the skins that needs to be used? How about the terrain itself? Do I need to skin it in a specific way? Thanks again for your patience .

Re: terrain multitexturing shader [Re: Darkstorm] #17304
12/04/03 20:16
12/04/03 20:16
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441

Page 1 of 11 1 2 3 10 11

Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1