Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, Grant, Neb), 908 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 3
Page 1 of 3 1 2 3
Terrain multitexturing shader for PS 1.4 #22865
02/04/04 12:35
02/04/04 12:35
Joined: Dec 2003
Posts: 1,097
Maryland, USA
Steempipe Offline OP
Serious User
Steempipe  Offline OP
Serious User

Joined: Dec 2003
Posts: 1,097
Maryland, USA
I have been picking apart vents Terrain Multitexturing Shader (you are the best!) and have tried adapting it for use with PS 1.4 so that I could use more textures.

-Uses 4 entSkins with one being the alphamap.
-Each channel of the alphamap (arbg) is used for blending.
-uses 2 mtlSkins. Those 2 skins are assigned mipmapping in the Starter block.

Just thought I would post some code in case anyone else is working on this for PS 1.4.
Note that there really is no fallback and pixel shader 1.4 is needed.







Heres what I got so far:

// The following is derived *heavily* from Ventilators Terrain Multitexturing Shader.
// Many thanks go to Ventilator for forging the way.

// Steempipe's Terrain Shader rev 2.3.03.1 is my attempt to utilize more textures.
// To use this shader you must have PS1.4 support and VS1.1
////////////////////////////////////////////////////////////////////////////////////


// Load some textures in addition to the entSkins
bmap grass=<grass.bmp>;
bmap grassfine=<grassfine.bmp>;

material mat_terrain_multitexture
{

Skin1 = grass;
Skin2 = grassfine;


effect=
"
texture entSkin1;
texture entSkin2;
texture entSkin3;
texture entSkin4; //Alpha TGA
texture mtlSkin1;
texture mtlSkin2;

matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;

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

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

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

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

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

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

MaxMipLevel[5]= 0;
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>; //(u_scale1, v_scale1, u_scale2, v_scale2)
vertexShaderConstant[65]=(20.0f,15.0f,0.0f,0.0f);
vertexShaderConstant[66]=(15.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=
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
mul oT2.xy,v7.xy,c65.xy
mov oT3.xy,v7.xy
mul oT4.xy,v7.xy,c66.xy
mul oT5.xy,v7.xy,c67.xy

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.4
def c0,1,1,1,1
texld r0,t0 // sample t0
texld r1,t1 // sample t1
texld r2,t2 // sample t2
texld r3,t3 // sample t3
texld r4,t4 // sample t4
texld r5,t5 // sample t5


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


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


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


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


mul r0.rgb,r0,v0

};
}


}

technique fallback { pass p0 { } }

";
}


starter mat_terrain_multitexture_init

{

// Need to create MipMaps for the mtlSkins
bmap_to_mipmap(mat_terrain_multitexture.skin1);
bmap_to_mipmap(mat_terrain_multitexture.skin2);

}




action terrain_multi_tex
{
my.skill41=float(20);
my.skill42=float(25);
my.skill43=float(10);
my.skill44=float(15);

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



Re: Terrain multitexturing shader for PS 1.4 [Re: Steempipe] #22866
02/05/04 11:57
02/05/04 11:57
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
very nice! but isn't it quite slow with 6 textures?

Re: Terrain multitexturing shader for PS 1.4 [Re: ventilator] #22867
02/05/04 19:22
02/05/04 19:22
Joined: Dec 2003
Posts: 1,097
Maryland, USA
Steempipe Offline OP
Serious User
Steempipe  Offline OP
Serious User

Joined: Dec 2003
Posts: 1,097
Maryland, USA
I had no noticable difference in my FPS while running the above terrain as compared to running a "basic" 1-skin, 1-detailmap of the same terrain from MED.
These were running at 800x600x32.

Visually, I had no problems that could be associated with a slow down from the rendering passes.

We will see what happens later, after I add models and things.




Re: Terrain multitexturing shader for PS 1.4 [Re: Steempipe] #22868
02/05/04 23:09
02/05/04 23:09
Joined: Oct 2003
Posts: 1,550
United Kingdom
indiGLOW Offline
Serious User
indiGLOW  Offline
Serious User

Joined: Oct 2003
Posts: 1,550
United Kingdom
How does the alpha map control all the seperate textures? Is it based on shade as well as the tga alpha map???




The Art of Conversation is dead : Discuss
Re: Terrain multitexturing shader for PS 1.4 [Re: indiGLOW] #22869
02/06/04 01:55
02/06/04 01:55
Joined: Sep 2003
Posts: 547
Bavaria, Germany
R
robertternes Offline
Developer
robertternes  Offline
Developer
R

Joined: Sep 2003
Posts: 547
Bavaria, Germany
Cool shader code... but can you give me this sand textur which is shown on these pictures? That textur between this gras and mud - texture on the first picture

Thank you.

Re: Terrain multitexturing shader for PS 1.4 [Re: robertternes] #22870
02/06/04 06:27
02/06/04 06:27
Joined: Dec 2003
Posts: 1,097
Maryland, USA
Steempipe Offline OP
Serious User
Steempipe  Offline OP
Serious User

Joined: Dec 2003
Posts: 1,097
Maryland, USA
I got the sand texture from here. You may find others you like, too.
http://perso.club-internet.fr/lemog/lemog_textures/sols_terresable.htm#
The filename of the texture I used is: 057terresable.jpg

Re: Terrain multitexturing shader for PS 1.4 [Re: indiGLOW] #22871
02/06/04 08:13
02/06/04 08:13
Joined: Dec 2003
Posts: 1,097
Maryland, USA
Steempipe Offline OP
Serious User
Steempipe  Offline OP
Serious User

Joined: Dec 2003
Posts: 1,097
Maryland, USA
@indiGLOW

I got the gist of the idea for using the other channels (RBG), besides the .a, in the TGA from ventilators terrain multitexturing shader where it is shown how to add a 3rd texture using the .b channel.

Each channel in the TGA, the A, R, G, & B, are holding a map for blending a particular texture. I drew on each individual channel to map where the particular textures will get placed. The shade from black to white will determine how much the textures get blended. This takes some fiddling around with to get the best results.
I decided to use black as the area that the particular texture will be less, or not, blended. I had to swap the last two param's in the LRP to accomodate this change and found that my results on blending were best that way. However, this may not be the case with each and every texture combination.

lrp r0.rgb,r3.b,r2,r0 // blend t2 with the result depending on t3 blue channel
t3.b is the blue channel.
r2 is my texture.
r0 is the result from the first lrp.

It was a tedious process and more or less a one-off working with the TGA. But to show an example,

Below Is my .a (r3.a). The black are cracks (t0), the white gravel (t1).


Below is my .b (r3.b). The white is sand (t2), black no blending. white to black some blending.


Below is my .g (r3.g). The white is my grass (t4).


Below is my .r (r3.r). The white is my fine grass (t5)


Besides adding mipmaps to the entSkin textures... I had to add the code in the starter to add mipmaps to the mtlSkins. This made a huge difference in the visuals.

So.... looking down on things the textures laid like this:


I am by no means a shader or alpha channel expert, but trying to learn.
Hope this helps anwser your question.

Eric

Re: Terrain multitexturing shader for PS 1.4 [Re: Steempipe] #22872
02/06/04 10:41
02/06/04 10:41
Joined: Aug 2001
Posts: 2,320
Alberta, Canada
William Offline
Expert
William  Offline
Expert

Joined: Aug 2001
Posts: 2,320
Alberta, Canada
Very intresting, keep it up!


Check out Silas. www.kartsilas.com

Hear my band Finding Fire - www.myspace.com/findingfire

Daily dev updates - http://kartsilas.blogspot.com/
Re: Terrain multitexturing shader for PS 1.4 [Re: William] #22873
02/06/04 22:00
02/06/04 22:00
Joined: Oct 2003
Posts: 1,550
United Kingdom
indiGLOW Offline
Serious User
indiGLOW  Offline
Serious User

Joined: Oct 2003
Posts: 1,550
United Kingdom
Great Stuff. I am now digesting your post and studying it closely. I have learnt much from your very informative post. Very helpful, 3 Stars for the thread and 3 Stars for you too.

I will post my results later tonight. Thanks again!
P.S any chance of posting your tga file to look at?


The Art of Conversation is dead : Discuss
Re: Terrain multitexturing shader for PS 1.4 [Re: indiGLOW] #22874
02/06/04 23:54
02/06/04 23:54
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 working with this some more, I have now got it all working fine. It looks great, but I do have one question. How can you change the scale factor of the two additional textures? Obviously I can change scale in the texture image itself, but it would help if you could change the scale factor of the extra images.

On a seperate note: As you are expanding on Vent's work, how about the grass shader? This is not maybe really a shader thing, but it would be fantastic if you could use a tga's channels to sow the grass. i.e using different channels to position the grass models in game, the engine can use this as a map to plant grass on different parts of the terrain.... I see that the latest fur shader is almost doing this, but a image based mapping system for entity placing would be a powerful tool.... Just an idea.

I will still post some screen shots of my terrain work later


The Art of Conversation is dead : Discuss
Page 1 of 3 1 2 3

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