terrain multitexturing shader

Posted By: ventilator

terrain multitexturing shader - 09/20/03 21:07

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

Re: terrain multitexturing shader - 09/21/03 02:17

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

Re: terrain multitexturing shader - 09/21/03 03:51

thanks! i will look into how a two-pass fixed function fallback can be done...
Posted By: indiGLOW

Re: terrain multitexturing shader - 10/21/03 05:10

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

Re: terrain multitexturing shader - 12/04/03 18:58

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 .

Posted By: ventilator

Re: terrain multitexturing shader - 12/04/03 19:28

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

Re: terrain multitexturing shader - 12/04/03 19:51

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

Re: terrain multitexturing shader - 12/04/03 20:02

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

Re: terrain multitexturing shader - 12/04/03 20:11

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

Re: terrain multitexturing shader - 12/04/03 20:16

maybe you have this problem? -> http://www.conitecserver.com/ubbthreads/showflat.php?Cat=&Board=SHADER&Number=320744&Forum=All_Forums&Words=&Match=Entire%20Phrase&Searchpage=1&Limit=25&Old=1day&Main=320364&Search=true#Post320744
Posted By: Darkstorm

Re: terrain multitexturing shader - 12/04/03 20:22

Hmm. I tried adjusting the variable and it didn't make any difference. I can run other shaders, just not the one that I really want to use (being this one).
Posted By: Darkstorm

Re: terrain multitexturing shader - 12/04/03 20:40

Sorry to post again but I missed the 15 minute edit window. I disabled anisotropy on my card and still get the same error so it doesn't seem to be the problem. Oh well.
Posted By: ventilator

Re: terrain multitexturing shader - 12/04/03 20:43

do you use any other effects in your test level? maybe there is some interference?

...
maybe i will make an example level with this effect later...
Posted By: Darkstorm

Re: terrain multitexturing shader - 12/04/03 20:46

Yeah that would probably be a good idea. That way you won't have to deal with my annoying questions . Thanks again for your help.
Posted By: Zio

Re: terrain multitexturing shader - 12/04/03 20:49

I had the same problem with the waving grass shader, and I too have a GeForce 3. It appears that the GF3 only has 1.1 shader support, so if you change the "ps.1.3" to "ps.1.1", it will run. With the waving grass shader, this worked perfect. However I haven't tested this shader yet, so I'm only guessing that it would also work for this too.
Posted By: ventilator

Re: terrain multitexturing shader - 12/04/03 20:56

oh, thanks ace! i thought a gf3 is basically the same as a gf4?

i think in order to convert this shader to ps 1.1 you will have to change:

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

into:

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

(i think ps 1.1 doesn't support three t registers as source. ...again, i haven't tested this...)
Posted By: Darkstorm

Re: terrain multitexturing shader - 12/04/03 20:58

I have to comment out the entire pixel shader block to get it run. Changing to 1.1 doesn't seem to help.
Posted By: Zio

Re: terrain multitexturing shader - 12/04/03 21:29

I just tested it, and got it working perfectly after the following changes:

A) Changed ps.1.3 to ps.1.1
B) Changed all "texSkin"'s to "entSkin"'s.
C) Changed:
lrp r0.rgb,t2.a,t0,t1 // blend t0 with t1 using the alpha channel of t2
into:
mov r1,t1
lrp r0.rgb,t2.a,t0,r1 // blend t0 with t1 using the alpha channel of t2
D) Changed my terrains skills 41~44 to float(10) rather than just 10. heh, forgot that the first time >.<


I must say, this shader is awesome! Makes terrain look MUCH nicer.
Posted By: Darkstorm

Re: terrain multitexturing shader - 12/04/03 21:37

Cool! Thanks a ton Ace (and Vent). This is nice. Thought I was going to have a "productive" working on some web stuff but this kind of kills that idea. Quick question, did you leave "+mov r0.a,c0" in when you changed the code?
Posted By: ventilator

Re: terrain multitexturing shader - 12/04/03 21:43

yes, you should leave the "+mov r0.a,c0". it copies 1 into the alpha channel of the resulting pixels and thus makes the terrain non-transparent.

...
but it isn't really needed because the alpha which results from the lrp would add up to 1 anyway. i just thought the shader is easier to understand this way and i think because of the + it runs parallel to the lrp command and doesn't slow down the execution of the shader.
Posted By: ello

Re: terrain multitexturing shader - 12/04/03 21:49

In Antwort auf:

i think because of the + it runs parallel to




now that sounds interesting. does this work for all commands?
Posted By: Darkstorm

Re: terrain multitexturing shader - 12/04/03 21:53

Man, I can't thank you (and Conitec) enough for this. With multitexturing and vertex stitching I'm finally getting close to where I want to be with terrains. Very cool ventilator.
Posted By: ventilator

Re: terrain multitexturing shader - 12/04/03 21:58

Quote:

now that sounds interesting. does this work for all commands?




the color data and alpha data pipeline are parallel in the graphics hardware. i think you can only pair instructions if one outputs to .rgb and the other to .a!
Posted By: 3D_Train_Driver

Re: terrain multitexturing shader - 12/08/03 05:27

Sorry ventilator !
Your shader works fine but the detail_size seems to be switched off then.
Because I want to use rather huge terrains I cannot use one texture of 256x256 size all over the terrain. This looks very blurred then.
How can I fix this problem?
Do you have any idea?

Posted By: Darkstorm

Re: terrain multitexturing shader - 12/08/03 11:33

If you look at one of Vent's earlier posts, he explained (to me the simp) how to go about adding detail maps.
Posted By: 3D_Train_Driver

Re: terrain multitexturing shader - 12/08/03 16:10

I already read these instructions.
May be I did something wrong.
But I don`t want to add a detail map. I want to have all the textures tiled all
over the terrain map.
Posted By: 3D_Train_Driver

Re: terrain multitexturing shader - 12/08/03 17:12

OK. I think it works now but it is not supported by my hardware. This message appears when I change vs 1.3 to 1.1 and ps 1.3 to 1.1
I try some other things. If I have success I`ll post it.
Posted By: Darkstorm

Re: terrain multitexturing shader - 12/08/03 20:26

Sorry. I misunderstood your post. You said detail_size so I thought you wanted detail maps. The first two skins do in fact tile. Have you played with the UV settings?

As far as the errors, I had trouble with it as well but the changes mentioned in this thread got everything working for me.
Posted By: 3D_Train_Driver

Re: terrain multitexturing shader - 12/08/03 20:47

Hi !

It works now. I did not create an appropriate alpha channel in the TGA texture.

Great!
Posted By: Antitrone

Re: terrain multitexturing shader - 12/23/03 07:22

there was something about "with some changes it can be blendet with the terrains slope" or something like that.
i mean if thats possible and if anyone can add a part in with was written i with high the textures are displayed- than it should be no problem do write a prog for multitexture terrains. like the particle progs of triple x.
plz tell me that it's not too dificult. i cant do thi anyway because of i absolutly cant script but it would be gread if there a volonteers (hope that's correct )
Posted By: SFMAT4

Re: terrain multitexturing shader - 01/22/04 04:38

Hallo,

ich habe den Shader mit den Detailmap Änderungen versehen. Allerdings wird angezeigt, dass das meine Hardware nicht unterstützt.
Habe ich etwas falsch gemacht oder kann ich diesen Effekt nicht auf einer Geforce 4 Ti 4200 nutzen?

Vielen Dank für die Hilfe!

MfG
SF

Code:
  

material mat_terrain_multitexture
{
effect=
"
texture entSkin1;
texture entSkin2;
texture entSkin3;
texture entSkin4;

matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;

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

technique multitexture
{
pass p
{
texture[0]=<entSkin1>;
texture[1]=<entSkin2>;
texture[2]=<entSkin3>;
Texture[3]=<entSkin4>;

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[65]=(1.0f,1.0f,0.0f,0.0f); // specifies the tiling of the detail map
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

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
mul oT3.xy,v7.xy,c65.xy // output scaled uvs for the detailmap

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.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
mul r0.rgb,r0,t3_bias // add(signed) rgb of t3 (detailmap)
mul r0.rgb,r0,v0 // modulate with diffuse vertex lighting
};
}
}
";
}



Posted By: ventilator

Re: terrain multitexturing shader - 01/22/04 07:00

mul r0.rgb,r0,t3_bias

versuch mal bei mul das _bias wegzulassen:

mul r0.rgb,r0,t3

und verwende einen leeren fallback:

technique fallback { pass p0 { } }

auf meiner geforce4 ti4200 funktionieren die meisten shader nicht wenn keine leere fallbacks hinzufüge! sehr seltsam...
Posted By: SFMAT4

Re: terrain multitexturing shader - 01/26/04 03:10

Hallo,

so langsam wirds mir peinlich

Ich habe deine Änderungen eingefügt. Allerdings kommt entweder eine Fehlermeldung wenn ich den leeren fallback um den Shader lege, oder es wird kein Multytexturing angezeigt wenn ich die Zeile nur über den Shader schreibe.
Warscheinlich habe ich nur irgendwas falsch verstanden. Aber ich befasse mich erst seit kurzen mit Shader effekten. Ich bitte meine "dumme" Frage daher zu entschuldigen
Danke für eure GEdult.

MfG
SF

Code:
 
technique fallback { pass p0 { } }
technique multitexture
{
pass p
{
.
.
.



Code:
 
technique fallback { pass p0 {
technique multitexture
{
pass p
{
.
.
.
} }


Posted By: Rhuarc

Re: terrain multitexturing shader - 01/26/04 05:15

Any screenshots for the Pixelshader support impaired?
Posted By: Steempipe

Re: terrain multitexturing shader - 01/26/04 09:29

I am working on learning the shaders. But have a couple of small shots here:
http://steempipe.technicalfoundry.com/terrainshots.html

This is using Vent's stock multitexture shader.

Just some one-offs for comparison. The shader is using (1) Grass Tex, (1) Dirt Tex, and (1) alphamap for blending.

Small pics, and not *very* exciting, yet.
Posted By: ventilator

Re: terrain multitexturing shader - 01/26/04 10:29

die fallback technique muss hinter der multitexture technique stehen!
Posted By: Darkstorm

Re: terrain multitexturing shader - 01/27/04 01:09

Hey-

Not to cross post but I thought I might get the shader gurus attention more easily in here . I am having a few glitches with the shading of the terrain when using this shader. Any ideas/help would be appreciated. You can check out some shots snd more info here:

http://www.conitecserver.com/ubbthreads/showflat.php?Cat=&Number=339498&page=0&view=collapsed&sb=5&o=&fpart=1

Thanks.
Posted By: Rhuarc

Re: terrain multitexturing shader - 01/27/04 01:14

Shots look cool, can't wait to buy my new video card
Posted By: slacker

Re: terrain multitexturing shader - 01/27/04 13:01

Trying to sort this out - I got that you have two tiled textures, and the shader blends between them based on an alpha channel that is not tiled. cool btw..

(what exactly is a detail map, is it overlayed on your tiled mipmap?}

Is it possible to have a map as a lightmap to do shadows (not tiled)??

thx.
Posted By: Darkstorm

Re: terrain multitexturing shader - 01/27/04 13:41

Does this shader set light direction or affect the way that the terrain is shaded? I have been having some strange results (see previous post for link).
Posted By: Darkstorm

Re: terrain multitexturing shader - 01/27/04 14:40

Another question, could this be modified to use a third texture?
Posted By: ventilator

Re: terrain multitexturing shader - 01/27/04 14:51

yes, a third texture would be possible! the limit is how many texture stages the hardware supports in one pass and most current cards support 4. for more textures you would have to do multipass rendering which is slow because it's like rendering the terrain several times...

the terrain gets lit from the sun direction!

to reduce your problems with the gouraud shading artifacts, try to adjust the sun vector and maybe instead of <veclight> try to use arbitrary ambient values like vertexShaderConstant[19]=(0.5f,0.5f,0.5f,0.0f);. <veclight> is the brightness of the shadowmap below the entity and actually it doesn't make much sense to use that for terrains.

but i don't know where the seams from the stitching come from. i never stitch terrains. i think once quadtrees are implemented, terrain stitching won't be necessary anymore for improving performance...
Posted By: Darkstorm

Re: terrain multitexturing shader - 01/27/04 15:16

Maybe I'm missing something here but, if the terrain gets lit from the sun direction why does changing it seem to have no effect on the terrain? Now I know absolutely nothing about shaders but it seems that something has set a light direction independant from that of what I set in WED or script. Am I just losing what marbles that I have left?
Posted By: ventilator

Re: terrain multitexturing shader - 01/27/04 15:24

i don't know which version of the shader you are using (this thread got a bit messy!). but adjusting the sun_angle works for me.

you could try something like:

sun_angle.tilt=30;
while(1)
{
sun_angle.pan+=5*time;
wait(1);
}

to find out if it has an effect...
Posted By: Darkstorm

Re: terrain multitexturing shader - 01/27/04 15:59

Okay its official... I'm an idiot . I think Conitec might want to seriously considering putting my title back to newbie. Anyway, without embarrassing myself too much, I rectified the sun problem and now all is well. Thanks for being so patient Ventilator.

Now to figure out how to add a third texture to the mix (oh boy).
Posted By: ventilator

Re: terrain multitexturing shader - 01/27/04 16:25

Quote:


(what exactly is a detail map, is it overlayed on your tiled mipmap?}





detail maps get used to add details like cracks which are visible when the camera is close (this avoids that the textures just look blurry when the camera is close). detail maps have a very fine resolution (high tiling) and get overlayed over the other textures. but it's difficult to create a good looking detail map...

Quote:


Is it possible to have a map as a lightmap to do shadows (not tiled)??





yes!
Posted By: slacker

Re: terrain multitexturing shader - 01/29/04 07:04

Got this working and it is cool - I had some issues building the model correctly - here is how I got it going. Import the bmp into med to creat a HMP terrain- import a tileable texture (say 256x256), add skin, import second tileable texture, add skin, import larger TGA (512x,or...)with an alpha channel, do not adapt skin points. Watch your skin numbers, adding a skin does not take you to that skin.

should you add mimaps for the tileable skins??

here is a screen shot



added some trees and a skycube. What would make this alot better is shadows on the ground. It seems like using a luminance map or multiplying blend mode image with the non-alpha part of the tga image with alpha is a natural place to start any help would be greatly appreciated!

Thx for the awesome shader!


Posted By: Darkstorm

Re: terrain multitexturing shader - 01/30/04 00:14

Quote:

yes, a third texture would be possible! the limit is how many texture stages the hardware supports in one pass and most current cards support 4. for more textures you would have to do multipass rendering which is slow because it's like rendering the terrain several times...




Its me bothering Ventilator again . So, care to enlighten me about adding a third texture? I don't even know eher to start. I wanted to test it out to see how it worked.
Posted By: ventilator

Re: terrain multitexturing shader - 01/30/04 00:22

it depends on what the third texture should be. adding a detailmap on one of the tiled textures or on the whole terrain is easy and i think it's described in this thread although it will be hard to filter out this information!

if you want to have a third tiled texture which behaves like the other two tiled textures, a way to control where it should appear is necessary. i think one of the color channels of the "macro map" could be used for that but i would have to check wolfgang engels shader fundamentals again to see how that works.
Posted By: Darkstorm

Re: terrain multitexturing shader - 01/30/04 00:25

Hey. I was wanting to add a third tiled texture to the mix. About the topic clutter, I guess I should have stared a new thread for all of ramblings... sorry about that .

Quote:

but i would have to check wolfgang engels shader fundamentals again to see how that works.




Is that a push? Are you trying to get me to learn? How dare you!


Posted By: ventilator

Re: terrain multitexturing shader - 01/30/04 00:40

i don't mind the clutter i just could imagine that for an absolute shader beginner it's somewhat tricky to put together all the information of this puzzle!

i looked it up. the blue channel of the macro map could be used to control where the third texture should appear.

i will describe how to add it. what graphics card do you use? geforce3?
Posted By: Darkstorm

Re: terrain multitexturing shader - 01/30/04 00:52

Yep. GeForce3 Ti200. I really appreciate you doing this.
Posted By: ventilator

Re: terrain multitexturing shader - 01/30/04 01:36

the changes for the vertex shader:
Code:

texture entSkin1; // tiled texture 1
texture entSkin2; // tiled texture 2
texture entSkin3; // tiled texture 3
texture entSkin4; // !NEW! -> this is the macro map now! make sure you also assign it that way in med!

...

texture[0]=<entSkin1>;
texture[1]=<entSkin2>;
texture[2]=<entSkin3>;
texture[3]=<entSkin4>; // !NEW!

...

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

...

mul oT0.xy,v7.xy,c64.xy // output scaled uvs - tiled texture 1
mul oT1.xy,v7.xy,c64.zw // output scaled uvs - tiled texture 2
mul oT2.xy,v7.xy,c65.xy // !NEW! output scaled uvs - tiled texture 3
mov oT3.xy,v7.xy // !NEW! output uvs - macro map



the pixelshader:
Code:

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

lrp r0.rgb,t3.b,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



the blue channel of the macro map defines where the third texture appears. i don't have the time to test it at the moment so probably you will have to experiment a little! i hope it works!
Posted By: Darkstorm

Re: terrain multitexturing shader - 01/30/04 01:43

Thanks. When you say the blue channel, do you mean that I use the blue channel of the RGB for the third texture? Meaning that the third textures "placement" will be independent from the alpha channel?
Posted By: ventilator

Re: terrain multitexturing shader - 01/30/04 01:46

yes! but because the red and green channel aren't used you simply could draw shades of black and white into all color channels...
Posted By: Darkstorm

Re: terrain multitexturing shader - 01/30/04 01:50

Yar! I'll give it a shot and post my results. I owe you a grog or something .
Posted By: Darkstorm

Re: terrain multitexturing shader - 01/30/04 02:20

I get the effect unsupported by hardware error. I'll keep playing but I think I'll just make it worse.

Code:
lrp r0.rgb,t3.b,r0,t2 // blend the result with t2 depending on t3 blue

+mov r0.a,c0



That bit is the culprit. Everything runs fine untill I add that.
Posted By: ventilator

Re: terrain multitexturing shader - 01/30/04 02:44

yes, the problem gets caused by invalid swizzling!

try to replace

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

with:

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

Quote:

The .b replicate functionality is available in ps.1.1 - ps.1.3 since the release of DirectX 8.1, but this swizzle is only valid together with an alpha write mask in the destination register of an instruction [...]




http://www.shaderx.com/direct3d.net/tutorials/shader/shader3.html -> swizzling/using selectors
Posted By: Darkstorm

Re: terrain multitexturing shader - 01/30/04 03:17

Beautiful!!!! That change works perfectly. So, go ahead and fax me that paperwork for my first born son and show me where to sign!
Posted By: Darkstorm

Re: terrain multitexturing shader - 01/30/04 04:15

Here's a question. I will only need three textures on a few on the HMPs. Since this seems to slow the FPS quite a bit, is it possible to have an if statement that checks to see how many skins the HMP has and, depending on that number, assigns the approproate shader to the terrain? Seems like it should be but I thought that I would ask the master coder before I tried hacking out some code .
Posted By: ventilator

Re: terrain multitexturing shader - 01/30/04 04:24

i think you could use ent_skins in the terrain action to find out the number of skins and then assign the proper material.

...
i am not sure but i think you should also add this to the shader:
MagFilter[2]=linear;
MinFilter[2]=linear;
MipFilter[2]=linear;
MagFilter[3]=linear; // !NEW!
MinFilter[3]=linear; // !NEW!
MipFilter[3]=linear; // !NEW!
point filtering seems to be the default for every stage above one. but probably this isn't very noticeable on the macro map...

...
Quote:

should you add mimaps for the tileable skins??


yes!
Posted By: Darkstorm

Re: terrain multitexturing shader - 01/30/04 04:58

Everything seems to working as it should. Here is a quick test shot of it in action. This is actually a riverbed but I moved the water for the shot.



The sand is the third tileable texture. Looks pretty nice.
Posted By: ventilator

Re: terrain multitexturing shader - 01/30/04 05:20

it looks very nice! ...a good geforce3/4 compatible water shader would be a nice addition but i am still looking for one...
Posted By: Darkstorm

Re: terrain multitexturing shader - 01/30/04 13:28

Be sure and start a post whenever you find a good water shader. I am in desparate need. I have started reading the shader explanation from the link that you posted but I fear it will be some time before in can start pumping these out on my own . Kind of stinks not having a coder working on this project. Maybe I'll have to get one.
Posted By: M3PHiSTOPH3L3S

Re: terrain multitexturing shader - 01/30/04 14:21

Hello this is my first real shader I have implemented. It works great, but I think I'm doing something wrong with the alphachannel or just the image format. All my textures I use with it have discolored lines through them--besides that they look fine. I've tried using PSP and Photoshop--24 bit and 32 bit TGAs. Both formats have that distortion on the end. All 3 of my entSkins are 256x256. I have not modified the code at all. Has anyone ever ran into this?

M3PHiSTO
Posted By: M3PHiSTOPH3L3S

Re: terrain multitexturing shader - 01/30/04 15:22

Ahh needs to be 16 bit...cant tell i dont work with models usually can ya?

Great work! looks nice.

M3PHiSTO
Posted By: Darkstorm

Re: terrain multitexturing shader - 01/30/04 15:31

I usually use BMP for the tileable skins and a 32bit TGA for the "blend" skin.
Posted By: ventilator

Re: terrain multitexturing shader - 01/30/04 15:42

i use 24bit tgas for the tileable textures and a 32bit tga for the blend texture and it works fine! ...psp has a known tga bug so maybe this causes your problem?
Posted By: SFMAT4

Re: terrain multitexturing shader - 02/07/04 20:22

Hi,

I have changed the Multytexturing Shader effekt. Tha 4th Skin is a TGA skin for static shadow effect.
But the shadow is to "hard". The terrain is very large and The 4th skin issn´t tiled. My Question: Is there a chance to smoot these effect?
Terrain
thx for help

MfG
SF
Posted By: ventilator

Re: terrain multitexturing shader - 02/07/04 20:25

add this:

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

all stages above 1 seem to use point sampling by default...
Posted By: SFMAT4

Re: terrain multitexturing shader - 02/07/04 22:09

thank you it works!
Posted By: NefariousD

Re: terrain multitexturing shader - 02/08/04 00:15

Would someone be so kind as to post an example of the blending TGA? I cant seem to figure out how to use it to blend the two textures.
Posted By: NefariousD

Re: terrain multitexturing shader - 02/08/04 02:31

Nevermind! Got it working! Thanks to everyone for this terrific shader! Definately makes terrain look 150% better. Will post some customary screenies soon
Posted By: ventilator

Re: terrain multitexturing shader - 02/20/04 19:01

...a quickly hacked together terrain multitexturing editor i did a while ago...

-> terrain_editor.zip ~ 3mb

(shift+) cursor keys - fly around
rmb - rotate camera
(alt+) lmb - draw into the blue channel of the terrain macro map
s - save macro map
1 - display alpha channel
2 - display blue channel
3 - display multitextured terrain

because of a bug in pixel_to_vec i don't have the necessary control over the alpha channel so the tool is buggy and quite useless!
Posted By: poloman

Re: terrain multitexturing shader - 02/25/04 19:08

Wow ! The editor is too great !

Thanks , Vent , you are the man.


Posted By: makai

Re: terrain multitexturing shader - 03/25/04 10:26

can anybody export a working multi texture terrain with geforce 3/4 compatible shader and all textures, with source ?
it would help me to understand how it works.. i cant get this thing working :-( all my tries failed..

ill give 5 stars for this!
Posted By: Steempipe

Re: terrain multitexturing shader - 03/27/04 06:56

Did you look at, or use, the terrain shader that is on the wiki pages? It is the same as what is talked about in this thread.

I have a link to some textures I used for the shader as well as a basic TGA that can be used for testing to see if things blend for you. In this thread:
web page
The files are still on the server.

You have ps.1.1 or higher support from your card??

What are the problems that you are facing?? Is it error codes?? No blending??

I have no basic terrain project built right now. Should you find that your card supports these things and you remain totally frustrated, make a post and I'll see what i can do.

Eric

Posted By: makai

Re: terrain multitexturing shader - 03/29/04 02:42

thanks for your reply, i tried it like you explained it in the linked thread, but it still doesn't work. i have to paint in the red,blue,green,alpha channels of my last tga skin, to set the blending thing, right ?
do you have a terrain file with your skins and alpha ? this would really help, you'll get 5 stars!
Posted By: Migueljb01

Re: terrain multitexturing shader - 04/03/04 07:49

Could someone please post the complete code snippet to use with 3 textures and 1 alpha map. Sorry to ask this but I can't figure it out from all the post above. Thanks for your help.

-spider21
Posted By: msKEN

Re: terrain multitexturing shader - 04/04/04 02:07

I'm with spider21, I'm lost. Drew, Drew where are you Drew? We need you.... lol
Posted By: Steempipe

Re: terrain multitexturing shader - 04/04/04 03:11

Okay... here is a link to download a small test level I made.
termultitex.cd.zip (approx. 2.26 MB)
You'll find the shader_terrain.wdl file that is for ps1.1 and copied from ventilators shader.

The HMP has 3 skins, these are the organic textures.
-Grass
-sand
-cracked earth
The top of the hills will be all grass. Shading into dirt as elevation decreases and then a couple of patches of cracked ground here and there.

The mtlSkin is the blending map with info in the A channel and B channel.
The A channel is blending the grass and sand.
The B channel is blending the cracked ground.

Include the <shader_terrain.wdl> file in your main WDL file.
Assignt the behavior (the action name in the <shader_terrain.wdl>) Shader_Terrain to your model/Hmp and go nuts.

Good luck.
Eric

Posted By: Steempipe

Re: terrain multitexturing shader - 04/04/04 10:25

Quote:

thanks for your reply, i tried it like you explained it in the linked thread, but it still doesn't work. i have to paint in the red,blue,green,alpha channels of my last tga skin, to set the blending thing, right ?
do you have a terrain file with your skins and alpha ? this would really help, you'll get 5 stars!




Yes. You have to paint in the RGB (you'll be using the b channel) and the A channels. Take a look at the test level I posted here and examine the TGA thing.

Eric

Posted By: makai

Re: terrain multitexturing shader - 04/04/04 17:11

as i promised, i gave you 5 stars!
i downloaded the example, but i can just see only one texture. i have an geforce 4 GO with 64 mb.
Posted By: Steempipe

Re: terrain multitexturing shader - 04/04/04 19:57

I took a look at nvidia site and from what I can see, the GO will not do shaders.

web page

I may have missed something in the specs, but you may be out of luck.

Eric
Posted By: Lennart_hillen

Re: terrain multitexturing shader - 04/05/04 03:20

Could someone please post a lot of screens of multitexture lanscapes? I don't have a good video card, So the demo isn't working
Im just so curious how it looks...;)
Posted By: makai

Re: terrain multitexturing shader - 04/05/04 04:36

i thought about that already but then i noticed that farcry for example uses multitexturing too, so it must be possible!
Posted By: Migueljb01

Re: terrain multitexturing shader - 04/05/04 07:02

Just a thought but can I use a 1024x1024 terrain made in Photoshop. Use a 1024x1024 tga alpha map. Then for the 3 textures just use 256x256. For the script that uses 3 textures. I would just like to know the limitations or whats best for this shader script or best for the level. Thanks for reply's.

-miguel
Posted By: Migueljb01

Re: terrain multitexturing shader - 04/06/04 14:59

I used a 512x512 terrain. For the textures I used 256x256 for the dirt and grass and the brick was 128x128. Can anyone tell me why ingame they look tiled and not natural looking. What parts in the script deal with the tiling? Thanks for anyone's help.




-miguel
Posted By: Steempipe

Re: terrain multitexturing shader - 04/06/04 17:50

tile scale in the demo you downloaded is controlled by these:
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)

The <vecSkill41> part is set in your Action.

Since I cannot see your screenshot, I am just gonna shoot some ideas:
-Add mipmaps to all your entSkins or if you use mtlSkins add mipmaps in the starter function.

-Change this in the WDL file:

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

to >>>>>>>>>>>>>>>>>

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

Good luck!





Posted By: Turotulco

Re: terrain multitexturing shader - 04/30/04 13:41

Quote:

Okay... here is a link to download a small test level I made.
termultitex.cd.zip (approx. 2.26 MB)
You'll find the shader_terrain.wdl file that is for ps1.1 and copied from ventilators shader.





Hi Eric,

I'm trying to get this to function. Your Demo exe works beautifully. But when I try to add the shader_terrain.wdl to my own project I get a bunch of syntax errors on the script. (I'm going to try and insert an image here)



Any idea what might be going on? The script looks perfect to me, and the syntax checker in SED reports no errors.

Im running A6 Commercial.
Posted By: Steempipe

Re: terrain multitexturing shader - 04/30/04 17:22


Not sure why your compiler is complaining of <texSkins> if you have copied the effect file that is currently working in the demo, but make sure that any reference to <texSkin> is changed to <entSkin>.

Otherwise, send your effect file over this way, either by PM or post the code.

Eric
Posted By: Turotulco

Re: terrain multitexturing shader - 04/30/04 18:09

Hi Eric,

Thanks for the reply. The reason it refers to texSkin instead of Entskin is because the screenshot was taken after I had grabbed Ventilators original code and insured that I was having the same problem with the original code. However, I get the exact same error using your shader_terrain.wdl. IOW, It's not your code that's broken, it's my environment somehow. I was just hoping that someone could tell me why the compiler was choking on the effect string. At least, that's what it looks like to me. ;-)

I am running the Commercial version 6.11.4 and should have no trouble with this. I have the action attached to the hmp and the compiler appears to be choking on a syntax error. But the code I am using is the code from your demo (or in this case Ventilators), copied into my working directory unmodified.

Any suggestions anyone?
Posted By: Turotulco

Re: terrain multitexturing shader - 05/01/04 03:16

Ah. Nevermind. The problem seems to be my version of A6, 6.11 is not gonna do it. I need 6.20. Unfortunately, my upgrade to A6 did not include a new client# and password, and I am dealing with slow turnaround on messages to the sales department. ;-)

Oh look! Another weekend. <VBG>

After I can manage my upgrade I am really looking forward to playing with this. Very neat stuff.
Posted By: qwerty823

Re: terrain multitexturing shader - 05/01/04 03:48

Check and see if your password.txt file changed. When I upgraded from comm to pro, I thought I didnt get a new one was well, but low and behold, my passowrd.txt file was updated with the new one.
Posted By: Turotulco

Re: terrain multitexturing shader - 05/01/04 13:25

Qwerty! You're the Man!

Thanks many times over. Downloading as we speak.
Posted By: Turotulco

Re: terrain multitexturing shader - 05/01/04 18:52

OK. I'm up to 6.22 on the engine and now everyting compiles and runs. The script seems to be working because the tga map <four.tga> is getting applied to my terrain and the textures tiling can be affected by the skills in the action.

I'm basically having two problems at this point, mainly due to my ignorance. The first is LOD. When I examine the demo steempipe provides in MED I see three skins. Yet when I extract them, each skin turns into 4 bmps. One 256x256 gray, and three others at 128, 64 and 32, each a smaller LOD. 12 bmps for 3 skins. Can someone point me towards an explanation of creating this in MED? I'm suspecting that will answer my second question which is...

Alpha Channel. I'm using PSP7 and it doesn't seem to give me a lot of control over alpha channels. IOW, I can't seem to discover any way of manipulating the a channel or the b channel.

Thanks for all the help in getting this far, this is looking like one heck of a lot of fun.
Posted By: Steempipe

Re: terrain multitexturing shader - 05/01/04 19:27

When I made the HMP in MED and imported the skins I added MipMaps to each of the (3) skins. That is why when you extract/export the skins you are getting a total of 12 spit out.

I am not familiar with how PSP manipulates the layers. Hopefully you can find a tutorial someplace.
Posted By: Turotulco

Re: terrain multitexturing shader - 05/01/04 20:51

Thanks! Yes, now my own terrain is set up pretty much like your example, skinwise, and it's a much smoother display now. I've used mipmaps and secondary skins to add texture to the terrains before. I didn't realize that simply adding mipmaps would create the LOD textures for a skin in MED. That's very nice.

The PSP is still giving me a little trouble, though I found I can splt the RGB channels into three parts and paint on each one, then merge them back together. But I only seem to be affecting the blue channel. I'm monkeying around with setting the palette transparency now and I think that should give me the alpha channel.

This is very cool.
Posted By: PHeMoX

Re: terrain multitexturing shader - 05/01/04 23:05

Hi

I've downloaded this little zip file, but when you come to the edge of the terrain, the crack-like texture seems to stop real suddenly, instead of blending over nice, anyone knows why??
Posted By: Turotulco

Re: terrain multitexturing shader - 05/01/04 23:37

I saw that too in the Demo. If you edit the four.tga you'll see it is the blend map for the cracked earth. In the places you noticed a sharp transition on the terrain, you'll see that the edges are very sharp on the blend map. I just did a Gausian blur in PSP, saved it, and the harsh edges went away.
Posted By: Steempipe

Re: terrain multitexturing shader - 05/02/04 03:53

yah.... I just looked at the shader and realized that it needed to be different. I must have been expirimenting then, or somehow got the wrong build available.

So..... make the changes to the code like this:
Getting rid of the stupid "point" values.

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


Blending should happen better then. And anything you do with brushes or blurs or whatever in your photoeditor will be icing on the cake.

Sorry...
E
Posted By: Turotulco

Re: terrain multitexturing shader - 05/02/04 05:16

You have absolutely nothing to be sorry for. ;.) The work that you and Ventilator have done has given the rest of us a beachead into the land of shaders.

Hmmmm...

Now must go find the difference between "Linear" and "Point".

Have you got any good pointers for where to start reading to pick up a little more info on this stuff?
Posted By: Steempipe

Re: terrain multitexturing shader - 05/02/04 13:13

The links that are at the Wiki in the Shader section are great places and I look at the DXSDK docs alot.
It mainly is just a matter of looking over the docs, the code samples, and then playing with things to see what happens. I've browsed a few books here and there and found that they seem to echo what is already at MSDN or the Shaderx sites. Hmmm... I seem to visit Flipcode, Gamedev, & Gamasutra sites alot.
And naturally, the great effects that the others here have posted are bits of gold.
Posted By: lolek

Re: terrain multitexturing shader - 05/02/04 19:31

Why effects program with try and error? Who scripting an Effect editor for fallback techniques?
Steempipe, your multitexturing code is very well. Unfortunately, I don't understand everything of this.
I already have some tutorials over terrain, modeling, particle and a different one written. Unfortunately, therefore I don't also have any time to study everything about effects. I'm glad there is you,ventilator and other shader experts.
Posted By: PHeMoX

Re: terrain multitexturing shader - 05/03/04 20:32

The blending problem seems to be solvable in both ways, gaussian blur in photoshop (although it reduces some detail), and getting rid of the point values..

Does anyone has a shader which produces a layer of 3d-ish grass? Just curious...

(DAMM I still have to wait for 3dgs A6 com to arrive at my mailbox, yet I am patience itself, because of these great shaders on the forums hehehe)
Posted By: task1

Re: terrain multitexturing shader - 01/06/05 01:25

hallo ventilator,

in diesem eintrag hast du von "invalid swizzling" gesprochen.

der neue code war:

mov r1.a, t1.b
lrp r0.rgb, r1.a, t2 ,t3
+mov r0.a, c0

das funktioniert bei mir gut, aber sobald ich t1.b durch t1.r oder t1.g ersetze, bekomme ich die gleiche oder eine ähnliche fehlermeldung wieder.

das genaue problem habe ich nicht verstanden.könntest du evtl nochmal erklären was das problem genau ist?
Posted By: thermalheat

Re: terrain multitexturing shader - 05/10/05 14:53

Hi,

I know that this is an old thread but I would like to learn more on shaders so could anyone kindly please provide files (level, skins and wdl associated/specific to the level) for my learning purposes?

Would look towards for reply on this.

Thank you for your time.

=ThermalHeat=
Posted By: PHeMoX

Re: terrain multitexturing shader - 05/10/05 18:57

Don't want to sound rude or anything, but try searching more with the search option on this forum.. Especially look for Drew medina and ventilator, or matt auf der heide and ello's posts, or any other shaderking i forgot to mention, out there, you will find tons of information about shaders (and quite some code examples too)!! Also note that some of the codes are old DirectX 8 shaders, which will have to be slightly altered to work with DirectX 9 ---> Consult the Wikipage and also maybe google for information on shaders, that'll get you started!!


Cheers
© 2024 lite-C Forums