Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by 7th_zorro. 04/27/24 04:42
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Quad, Akow, 7th_zorro), 756 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 5 1 2 3 4 5
Searching HLSL Terrain Multitexturing... #322901
05/10/10 13:55
05/10/10 13:55
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
I´ve looked at the Wiki.. but the link seems to be broken.:

Soo...

1.) Does someone have the shader on his HDD???
2.) Has someone an example on how to add more textures to it?

^^


Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: Searching HLSL Terrain Multitexturing... [Re: Espér] #322916
05/10/10 14:33
05/10/10 14:33
Joined: Apr 2010
Posts: 172
W
wdlmaster Offline
Member
wdlmaster  Offline
Member
W

Joined: Apr 2010
Posts: 172
Try this one:

Code:
float4x4 matWorld;
float4x4 matWorldViewProj;

float4 vecSunDir;
float4 vecAmbient;
float4 vecSunColor;
float2 tiles = {50,50};

texture entSkin1;

texture dmap1_bmap;
texture dmap2_bmap;
texture dmap3_bmap;
texture dmap4_bmap;
texture dmap5_bmap;

sampler2D blend = sampler_state {	Texture = <entSkin1>;mipfilter=2;minfilter=2;magfilter=2;};

sampler2D skin1 = sampler_state {	Texture = <dmap1_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin2 = sampler_state {	Texture = <dmap2_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin3 = sampler_state {	Texture = <dmap3_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin4 = sampler_state {	Texture = <dmap4_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin5 = sampler_state {	Texture = <dmap5_bmap>;mipfilter=2;minfilter=2;magfilter=2;};

void VS (	in float4 iPos : POSITION,
		in float3 iNorm : NORMAL,
		in float4 iTex : TEXCOORD0,
		out float4 oPos : POSITION,
		out float3 oNorm : TEXCOORD1,
		out float4 oTex : TEXCOORD0)
	{
	oPos = mul (iPos,matWorldViewProj);
	oNorm = mul(iNorm,matWorld);
	oTex = iTex;
	}

float4 PS(	in float2 tex : TEXCOORD0,
		in float3 iNorm : TEXCOORD1) : COLOR {

	float4 map = tex2D(blend,tex);

	float4 color = tex2D(skin1,tiles * tex);
	color = lerp(color,tex2D(skin2,tiles * tex),map.r);
	color = lerp(color,tex2D(skin3,tiles * tex),map.g);
	color = lerp(color,tex2D(skin4,tiles * tex),map.b);
	color = lerp(color,tex2D(skin5,tiles * tex),map.a);

	color *= vecSunColor * saturate(dot(-vecSunDir, normalize(iNorm))) + vecAmbient;	
	return color;}

technique t{ pass p{	AlphaBlendEnable = 0;
			zWriteEnable = 1;
			VertexShader = compile vs_2_0 VS();		
			PixelShader = compile ps_2_0 PS();			
		}}



You have to define 5 BMAPs named dmap1...dmap5. The first skin of the terrain / model ist the blendmap.

dmap1 is the basecolor, dmap2,3,4 are RGB and dmap5 is Alpha.
This shader only supports the sun. But adding more lights is no problem (if you need them). You can add as many textures as the shader model supports (in a single pass). This is done by "splitting" the RGBA channels. You can use for example 4 textures per channel (would be 17 textures in one pass!) But there are restrictions (of course). You can't blend straight between all textures! If you use such a 17-texture-shader, i recommend to use the 4 textures per channel only as texture variations and not as completely different textures.

I hope you understand what i mean...

The same can be done by using more blendmaps.

Re: Searching HLSL Terrain Multitexturing... [Re: wdlmaster] #322918
05/10/10 14:41
05/10/10 14:41
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
i´m not really understanding that blendmap thing... Y_Y


Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: Searching HLSL Terrain Multitexturing... [Re: Espér] #322920
05/10/10 15:00
05/10/10 15:00
Joined: Apr 2010
Posts: 172
W
wdlmaster Offline
Member
wdlmaster  Offline
Member
W

Joined: Apr 2010
Posts: 172
The blendmap defines, where the 5 textures are "placed". This texture is not tiled.

Black means, that the base texture is rendered (dmap1)
red = dmap2
green = dmap3
blue = dmap4
and alpha channel = dmap5

Re: Searching HLSL Terrain Multitexturing... [Re: wdlmaster] #322921
05/10/10 15:10
05/10/10 15:10
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
hmm.. isn´t there a shader wich uses the vertex/Polygon height in the map for texturing?


Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: Searching HLSL Terrain Multitexturing... [Re: Espér] #322927
05/10/10 15:49
05/10/10 15:49
Joined: Apr 2010
Posts: 172
W
wdlmaster Offline
Member
wdlmaster  Offline
Member
W

Joined: Apr 2010
Posts: 172
yes, but the blendmap method is waaaayyyy more flexible.

Code:
float4x4 matWorld;
float4x4 matWorldViewProj;

float4 vecSunDir;
float4 vecAmbient;
float4 vecSunColor;
float2 tiles = {50,50};

texture dmap1_bmap;
texture dmap2_bmap;
texture dmap3_bmap;
texture dmap4_bmap;
texture dmap5_bmap;

sampler2D skin1 = sampler_state {	Texture = <dmap1_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin2 = sampler_state {	Texture = <dmap2_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin3 = sampler_state {	Texture = <dmap3_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin4 = sampler_state {	Texture = <dmap4_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin5 = sampler_state {	Texture = <dmap5_bmap>;mipfilter=2;minfilter=2;magfilter=2;};

void VS (	in float4 iPos : POSITION,
		in float3 iNorm : NORMAL,
		in float4 iTex : TEXCOORD0,
		out float4 oPos : POSITION,
		out float3 oNorm : TEXCOORD1,
		out float4 oTex : TEXCOORD0,
		out float y : TEXCOORD2)
	{
	oPos = mul (iPos,matWorldViewProj);
	oNorm = mul(iNorm,matWorld);
	oTex = iTex;
	y = mul(iPos,matWorld).y;
	}

float4 PS(	in float2 tex : TEXCOORD0,
		in float3 normal : TEXCOORD1,
		in float y : TEXCOORD2) : COLOR {

	float4 color = tex2D(skin1,tiles * tex);

	color = lerp(color,tex2D(skin2,tiles * tex),saturate((1500-y) / 100));
	color = lerp(color,tex2D(skin3,tiles * tex),saturate((1000-y) / 100));
	color = lerp(color,tex2D(skin4,tiles * tex),saturate((500-y) / 100));
	color = lerp(color,tex2D(skin5,tiles * tex),saturate(1-pow(normal.y,1)));	

	color *= vecSunColor * saturate(dot(-vecSunDir, normalize(normal))) + vecAmbient;	
	return color;}

technique t{ pass p{	AlphaBlendEnable = 0;
			zWriteEnable = 1;
			VertexShader = compile vs_2_0 VS();		
			PixelShader = compile ps_2_0 PS();			
		}}



you can (must) play around with the values in the pixelshader to fit your needs (example):

color = lerp(color,tex2D(skin2,tiles * tex),saturate((1500-y) / 100));

the 1500 is the height in quants and the 100 is the smoothness. The last texture is blended according to the surface normal. I'm not sure if this is what you looking for, but it's worth a try. You could also combine both techniques. (blendmap + height-dependend)

Re: Searching HLSL Terrain Multitexturing... [Re: wdlmaster] #322928
05/10/10 16:04
05/10/10 16:04
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
ok.. du you have an example for the blendmap (or an example model with the skins)? ( have no idea what such a thing should look like...)

Last edited by Espér; 05/10/10 16:11.

Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: Searching HLSL Terrain Multitexturing... [Re: Espér] #322932
05/10/10 16:20
05/10/10 16:20
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Thats an easy one. Imagine a plateau with a mountain in the center of it. Leave the blendmap black except for the center area, there you paint it red. Now define the base texture as a grass area and set the first map to a rocky one. The center area now gets the rock texture, the surrounding gets the grass texture.


Always learn from history, to be sure you make the same mistakes again...
Re: Searching HLSL Terrain Multitexturing... [Re: Uhrwerk] #322935
05/10/10 16:24
05/10/10 16:24
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
ok...
My skins are now in the following order:

Skin1: Blendmap
Skin2: Stone-tex
Skin3: Dirt tex
Skin4: Grass Tex
Skin5: Sand tex


Ingame the complete terrain is just shown.. black...


Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: Searching HLSL Terrain Multitexturing... [Re: Espér] #322938
05/10/10 16:36
05/10/10 16:36
Joined: Apr 2010
Posts: 172
W
wdlmaster Offline
Member
wdlmaster  Offline
Member
W

Joined: Apr 2010
Posts: 172
no wonder... the names of your definded BMAPs in the script and in the shader must be identical.

Page 1 of 5 1 2 3 4 5

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