Jump to content

  • Log In with Google      Sign In   
  • Create Account

Advanced terrain erosion and texturing algorithms 2013


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Zero01   Members   -  Reputation: 109

Like
0Likes
Like

Posted 22 February 2013 - 03:29 PM

The terrain on the image below was created with unreal engine 3.

( http://www.unrealengine.com/files/features/Terrain_6.jpg )

 

How is it possible to generate such a well eroded terrain??

In the image stones (and rocks) alternates with soil heavily. What do you think? Are the stones on the path (in the middle) integrated in the heightmap? How is it easy possible to texture all the stones?


Unreal-Terrain_6.jpg



Sponsor:

#2 ali rahimi   Members   -  Reputation: 434

Like
1Likes
Like

Posted 23 February 2013 - 12:36 AM

This should help http://dice.se/wp-content/uploads/GDC12_Terrain_in_Battlefield3.pdf



#3 Zero01   Members   -  Reputation: 109

Like
0Likes
Like

Posted 23 February 2013 - 03:03 AM

Thank you ali, but I hoped to inspire a brief discussion about various techniques and concrete answers to my questions.



#4 ali rahimi   Members   -  Reputation: 434

Like
1Likes
Like

Posted 23 February 2013 - 09:48 AM

There is a section of that pdf which describe the texturing method. To build a texture mask or heightmap you may use a different app like world machine. But it seams you are asking for a masking. well it's just a mask with a proper blending. This is an extreme example of high detail masking and 3 planer texturing which i did few months ago. So it might be useful. However i changed it a lot due to it's heavy pixel shader usage.

//-------------------------------------------------------------------------------
//  www.ali-rahimi.net
//  Copyright ©, Ali Rahimi Shahmirzadi 2004-2013
//	Name:		Geoclip Terrain
//	Version:	1.0
//

float4x4 wvp : WorldViewProjection ; 
float4x4 wv : WorldView;
float4x4 viewIT : ViewInverseTranspose;
float4x4 worldIT : WorldInverseTranspose;
float4x4 world : World;

float4x4	Matrix_Mask 	: CHANNELMATRIX0;

float Scale :CHANNELVALUE0;
float Hight :CHANNELVALUE1;
float Tile_UV :CHANNELVALUE2;
float Blend_Contrast :CHANNELVALUE3;
float Tile_Z_Distance :CHANNELVALUE4;
float Blend_Texture_Power :CHANNELVALUE5;
float Blend_Texture_2_Power :CHANNELVALUE6;
float Tile_Big_UV :CHANNELVALUE7;
float Spec_Power        :CHANNELVALUE8;
float Spec_Glossiness   :CHANNELVALUE9;
float Material_ID       :CHANNELVALUE10;
float Variation_Map_Scale       :CHANNELVALUE11;
float Side_Desaturation  :CHANNELVALUE12;
float Side_Brightness :CHANNELVALUE13;
float Side_Hight :CHANNELVALUE14;
float Side_Z_Mask :CHANNELVALUE15;
//-------------------------------------------------------------------------------
// Textures
//-------------------------------------------------------------------------------
texture Displacement_Map : TEXTURE0;
sampler2D Displacement_MapSampler = sampler_state
{
	Texture = <Displacement_Map>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	AddressU = clamp;
	AddressV = clamp;
};

texture Normal_Map : TEXTURE1;
sampler2D Normal_Map_Sampler = sampler_state
{
	Texture = <Normal_Map>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU = wrap;
	AddressV = wrap;
};

texture Landscape_Mask : TEXTURE2;
sampler2D Landscape_Mask_Sampler = sampler_state
{
	Texture = <Landscape_Mask>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU = clamp;
	AddressV = clamp;
};

texture Albedo_1 : TEXTURE3;
sampler2D Albedo_1_Sampler = sampler_state
{
	Texture = <Albedo_1>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR ;
	AddressU = WRAP;
	AddressV = WRAP;
};

texture Albedo_2 : TEXTURE4;
sampler2D Albedo_2_Sampler = sampler_state
{
	Texture = <Albedo_2>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR ;
	AddressU = WRAP;
	AddressV = WRAP;
};

texture Albedo_3 : TEXTURE5;
sampler2D Albedo_3_Sampler = sampler_state
{
	Texture = <Albedo_3>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR ;
	AddressU = WRAP;
	AddressV = WRAP;
};

texture Albedo_4 : TEXTURE6;
sampler2D Albedo_4_Sampler = sampler_state
{
	Texture = <Albedo_4>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR ;
	AddressU = WRAP;
	AddressV = WRAP;
};

texture Normal_Map_1 : TEXTURE7;
sampler2D Normal_Map_1_Sampler = sampler_state
{
	Texture = <Normal_Map_1>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR ;
	AddressU = WRAP;
	AddressV = WRAP;
};

texture Normal_Map_2 : TEXTURE8;
sampler2D Normal_Map_2_Sampler = sampler_state
{
	Texture = <Normal_Map_2>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR ;
	AddressU = WRAP;
	AddressV = WRAP;
};

texture Normal_Map_3 : TEXTURE9;
sampler2D Normal_Map_3_Sampler = sampler_state
{
	Texture = <Normal_Map_3>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR ;
	AddressU = WRAP;
	AddressV = WRAP;
};

texture Normal_Map_4 : TEXTURE10;
sampler2D Normal_Map_4_Sampler = sampler_state
{
	Texture = <Normal_Map_4>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR ;
	AddressU = WRAP;
	AddressV = WRAP;
};

texture Variation_Map : TEXTURE11;
sampler2D Variation_Map_Sampler = sampler_state
{
	Texture = <Variation_Map>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR ;
	AddressU = WRAP;
	AddressV = WRAP;
};

texture Detail_Displacement : TEXTURE12;
sampler2D Detail_Displacement_Sampler = sampler_state
{
	Texture = <Detail_Displacement>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	AddressU = wrap;
	AddressV = wrap;
};

texture Detail_Normal_Map : TEXTURE1;
sampler2D Detail_Normal_Map_Sampler = sampler_state
{
	Texture = <Detail_Normal_Map>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU = clamp;
	AddressV = clamp;
};

texture Displacement_Mask : TEXTURE14;
sampler2D Displacement_Mask_Sampler = sampler_state
{
	Texture = <Displacement_Mask>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	AddressU = clamp;
	AddressV = clamp;
};

//Overlay Color Blend Formula 
float Overlay(float input1, float input2)
{ 
	float result = 0.0; 
	if (input2 < 0.5) result =  2 * input1 * input2; else result =  1 - 2 * (1 - input1) * (1 - input2); 
	return result; 
} 

//-------------------------------------------------------------------------------
// Structs
//-------------------------------------------------------------------------------
// input from application to vertex shader 
	struct a2v { 
	float4 position		: POSITION; 
	
}; 

// output from vertex shader to pixel shader 
struct v2f { 
    float4 position    	    : POSITION; 
	float  Depth            : TEXCOORD0;
	float4 wposition	    : TEXCOORD1; 
	float4 wposition_2	    : TEXCOORD2; 
//	float4 Vcolor    		: COLOR0; 
//	float2 texCoord		    : TEXCOORD2;


}; 

// output from pixel shader 
struct PixelShaderOut { 
        float4 rtarget0	: COLOR0; 
        float4 rtarget1	: COLOR1; 
        float4 rtarget2	: COLOR2; 
        float4 rtarget3	: COLOR3; 
}; 
//-------------------------------------------------------------------------------
// Vertex Shader
//-------------------------------------------------------------------------------
v2f av(a2v In) 
{ 
	v2f Out = (v2f)0; 


	float2 texCoord = (mul(In.position/Scale,world).xz)+float2(0.5,0.5);
	
	float4 Normal_Map = tex2Dlod(Normal_Map_Sampler, float4(texCoord.xy,0,0)).rgba;
	
    float Mask = tex2Dlod(Displacement_Mask_Sampler, float4(texCoord.xy,0,0)).x;
	
	float Detail_Displacement = tex2Dlod(Detail_Displacement_Sampler, float4(texCoord.xy,0,0)).x;
		  
	float Displacement_Map     = tex2Dlod(Displacement_MapSampler, float4(texCoord.xy,0,0)).x;
//		  Displacement_Map     = lerp(Detail_Displacement,Displacement_Map,Mask);
		  Displacement_Map     *= Hight;

	      In.position.y       +=Displacement_Map;
	
	Out.wposition_2            = mul(In.position, world);			  	

//-------------------------------------------------------------------------------
// Side Displacement
//-------------------------------------------------------------------------------

	float2 UV_X = mul(In.position,world).xy;
	float2 UV_Z = mul(In.position,world).zy;
	
//	float3 Normal          = lerp(float3(0,0,1),Normal_Map.rgb,Mask);
	float3 Normal          = Normal_Map.rgb;
	
	float  Displacement_X                 =  tex2Dlod(Normal_Map_Sampler, float4(Tile_Big_UV*UV_X.xy,0,0)).a;	

	float  Displacement_Z                 =  tex2Dlod(Normal_Map_Sampler,float4(Tile_Big_UV*UV_Z.xy,0,0)).a;
			   
    float3 Normal_Map_Mask     = Normal.xyz;
		   Normal_Map_Mask     = Normal_Map_Mask.xzy;
		   Normal_Map_Mask.z   = saturate(1-Normal_Map_Mask.z);
           Normal_Map_Mask     = saturate(5*pow(Normal_Map_Mask,5));

	float Normal_Map_Mask_G               = saturate(1-(2*(pow(Normal.b,7))));

    float3 Side_Normal_Direction_Mask     = Normal.xyz;

	float  Displacement_X_1               = Displacement_X;		   
           Displacement_X_1               = saturate(1-Displacement_X_1);
		   Displacement_X_1               = lerp(Displacement_X_1,0,Side_Normal_Direction_Mask.g);
           Displacement_X_1               = lerp(Displacement_X_1,0,Normal_Map_Mask.r);
           Displacement_X_1               *= Normal_Map_Mask_G;

           In.position.z                  += (Displacement_X_1*Side_Hight);

    float  Displacement_X_2               = Displacement_X;
           Displacement_X_2               = saturate(1-Displacement_X_2);
		   Displacement_X_2               = lerp(0,Displacement_X_2,Side_Normal_Direction_Mask.g);
           Displacement_X_2               = lerp(Displacement_X_2,0,Normal_Map_Mask.r);
           Displacement_X_2               *= Normal_Map_Mask_G; 

           In.position.z                  -= (Displacement_X_2*Side_Hight);

	float  Displacement_Z_1               = Displacement_Z;
           Displacement_Z_1               = saturate(1-Displacement_Z_1);
		   Displacement_Z_1               = lerp(Displacement_Z_1,0,Side_Normal_Direction_Mask.r);
           Displacement_Z_1               = lerp(Displacement_Z_1,0,Normal_Map_Mask.b);
           Displacement_Z_1               *= Normal_Map_Mask_G;

           In.position.x                  -= (Displacement_Z_1*Side_Hight);
		   
	float  Displacement_Z_2               = Displacement_Z;
           Displacement_Z_2               = saturate(1-Displacement_Z_2);
		   Displacement_Z_2               = lerp(0,Displacement_Z_2,Side_Normal_Direction_Mask.r);
           Displacement_Z_2               = lerp(Displacement_Z_2,0,Normal_Map_Mask.b);
           Displacement_Z_2               *= Normal_Map_Mask_G;

           In.position.x                  += (Displacement_Z_2*Side_Hight);

	float  Displacement_Y                 = saturate((Displacement_X_1+Displacement_X_2+Displacement_Z_1+Displacement_Z_2)/1);
           Displacement_Y                 *= Normal_Map.a;

           In.position.y                  += (Displacement_Y*(Side_Hight/200));
	   				   		   		   
//-------------------------------------------------------------------------------

	Out.position = mul(In.position, wvp);				//transform vert position to homogeneous clip space 

	float4	view_pos = mul(In.position, wv);
	Out.Depth = view_pos.z;	
		
	Out.wposition = mul(In.position, world);			

//	Out.Vcolor = float4(Displacement_Y,0,0,0);
	return Out; 
}
//-------------------------------------------------------------------------------
// SphereMapEncode2
//-------------------------------------------------------------------------------
float2 SphereMapEncode2( float3 normal )
{
    float2 enc = normalize(normal.xy) * sqrt(normal.z*0.5f + 0.5f);
    enc = enc*0.5 + 0.5f;
    return enc;
}

//-------------------------------------------------------------------------------
// Pixel Shader
//-------------------------------------------------------------------------------
PixelShaderOut af(v2f In) 
{ 
//-------------------------------------------------------------------------------
// Color 0
//-------------------------------------------------------------------------------
	float4 input1 = float4(In.Depth, 0, 0, 0); 

//-------------------------------------------------------------------------------
// Color 1
//-------------------------------------------------------------------------------

	float3 VertexPosition = In.wposition.xyz;

	float2 UV_X = float2(VertexPosition.x, VertexPosition.y);
	float2 UV_Y = float2(VertexPosition.x, 1-VertexPosition.z);
	float2 UV_Z = float2(VertexPosition.z, VertexPosition.y);


	float3 VertexPosition_2 = In.wposition_2.xyz;
	float2 UV_X_2 = float2(VertexPosition_2.x, VertexPosition_2.y);
	float2 UV_Y_2 = float2(VertexPosition_2.x, 1-VertexPosition_2.z);
	float2 UV_Z_2 = float2(VertexPosition_2.z, VertexPosition_2.y);
	
	float2 texCoord = float2(UV_Y_2.x,1-UV_Y_2.y)/Scale+float2(0.5,0.5);

    float Displacement_Mask = tex2D(Displacement_Mask_Sampler, texCoord.xy).x;
		   
	float4 Detail_Normal_Map   = tex2D(Detail_Normal_Map_Sampler, texCoord.xy).xyzw;
	
	float4 Normal              = tex2D(Detail_Normal_Map_Sampler, texCoord.xy).xyzw;

	float4 Mask                = tex2D(Landscape_Mask_Sampler, texCoord.xy);
//	       Mask  = lerp(float4(0,0,1,0),Mask,Displacement_Mask);
		   
//		   Normal              = lerp(Detail_Normal_Map,Normal,Displacement_Mask);


		   		   
//		In.Vcolor.rgb;//
	float4 Matrix_Mask_1  = mul(float4(VertexPosition.xyz, 1), (float4x4)Matrix_Mask);
   	bool   Matrix_Mask_2   = all(abs(Matrix_Mask_1.xyz/Matrix_Mask_1.w - 0.5f) < 0.5f);

//	clip(saturate(Matrix_Mask_2)-0.5);
	
    float3 Normal_Map_Mask     = Normal.xyz;
		   Normal_Map_Mask     = Normal_Map_Mask.xzy;
		   Normal_Map_Mask.z   = 1-Normal_Map_Mask.z;
		   Normal_Map_Mask     = Normal_Map_Mask * 2 - 1;
           Normal_Map_Mask     = saturate(pow(Normal_Map_Mask,Blend_Contrast));
		   Normal_Map_Mask     = normalize(Normal_Map_Mask);

    float3 World_Normal    = Normal.xyz;
	       World_Normal    = World_Normal.xzy;
		   World_Normal.z  = 1-World_Normal.z;
		   World_Normal    = World_Normal * 2 - 1;
		   
	float3 Nn = normalize(World_Normal.xyz); 
	float3 Bn = normalize(cross(float3(0,0,-1), World_Normal)); 
	float3 Tn = normalize(cross(Nn, Bn)); 

	float3x3 toWorld = transpose(float3x3(Bn, -Tn, Nn));
//-------------------------------------------------------------------------------			   
// Side Rock Normal
//-------------------------------------------------------------------------------
    float3 Side_Normal_Direction_Mask    = Normal.xyz;
		   Side_Normal_Direction_Mask    = 2*pow(Side_Normal_Direction_Mask,2);
		   Side_Normal_Direction_Mask    =  saturate(Side_Normal_Direction_Mask);

	float4 Side_Detail_Normal_X          = tex2D(Normal_Map_1_Sampler,(Tile_UV/4)*UV_X.xy);
           Side_Detail_Normal_X.g        = lerp(Side_Detail_Normal_X.g,1-Side_Detail_Normal_X.g,Side_Normal_Direction_Mask.g);
	float4 Side_Detail_Normal_Z          = tex2D(Normal_Map_1_Sampler,(Tile_UV/4)*UV_Z.xy);
           Side_Detail_Normal_Z          = Side_Detail_Normal_Z.grba;
           Side_Detail_Normal_Z.r        = lerp(1-Side_Detail_Normal_Z.r,Side_Detail_Normal_Z.r,Side_Normal_Direction_Mask.r);
 	float4 Side_Detail_Normal            = lerp(Side_Detail_Normal_X,Side_Detail_Normal_Z,Normal_Map_Mask.r);

	float4 Side_Normal_1_X               = tex2D(Normal_Map_1_Sampler, Tile_Big_UV*UV_X_2.xy);
           Side_Normal_1_X.g             = lerp(Side_Normal_1_X.g,1-Side_Normal_1_X.g,Side_Normal_Direction_Mask.g);
	float4 Side_Normal_1_Z               = tex2D(Normal_Map_1_Sampler,Tile_Big_UV*UV_Z_2.xy);
           Side_Normal_1_Z               = Side_Normal_1_Z.grba;
           Side_Normal_1_Z.r             = lerp(1-Side_Normal_1_Z.r,Side_Normal_1_Z.r,Side_Normal_Direction_Mask.r);
 	float4 Side_Normal_1                 = lerp(Side_Normal_1_X,Side_Normal_1_Z,Normal_Map_Mask.r);
//------------------------------------------------------------------------------- 	
// Side Rock Albedo
//-------------------------------------------------------------------------------
	float Side_Variation_1_X             = tex2D(Variation_Map_Sampler,Variation_Map_Scale*UV_X.xy).r;
	float Side_Variation_1_Z             = tex2D(Variation_Map_Sampler,Variation_Map_Scale*UV_Z.xy).r;
	float Side_Variation_1               = lerp(Side_Variation_1_X,Side_Variation_1_Z,Normal_Map_Mask.r);

	float Side_Variation_2_X             = tex2D(Variation_Map_Sampler,(Variation_Map_Scale/5)*UV_X.xy).r;
	float Side_Variation_2_Z             = tex2D(Variation_Map_Sampler,(Variation_Map_Scale/5)*UV_Z.xy).r;
	float Side_Variation_2               = lerp(Side_Variation_2_X,Side_Variation_2_Z,Normal_Map_Mask.r);
	
	float4 Side_Detail_Albedo_X          = tex2D(Albedo_1_Sampler,(Tile_UV/4)*UV_X.xy);
	float4 Side_Detail_Albedo_Z          = tex2D(Albedo_1_Sampler,(Tile_UV/4)*UV_Z.xy);
	float4 Side_Detail_Albedo            = lerp(Side_Detail_Albedo_X,Side_Detail_Albedo_Z,Normal_Map_Mask.r);

	float4 Side_Albedo_1_X               = tex2D(Albedo_1_Sampler,Tile_Big_UV*UV_X_2.xy);
	float4 Side_Albedo_1_Z               = tex2D(Albedo_1_Sampler,Tile_Big_UV*UV_Z_2.xy);
	float4 Side_Albedo_1                 = lerp(Side_Albedo_1_X,Side_Albedo_1_Z,Normal_Map_Mask.r);

	float4 Side_Albedo_2_X               = tex2D(Albedo_2_Sampler,Tile_UV*UV_X.xy);
	float4 Side_Albedo_2_Z               = tex2D(Albedo_2_Sampler,Tile_UV*UV_Z.xy);
	float4 Side_Albedo_2                 = lerp(Side_Albedo_2_X,Side_Albedo_2_Z,Normal_Map_Mask.r);

	float4 Side_Albedo_3_X               = tex2D(Albedo_3_Sampler,Tile_UV*UV_X.xy);
	float4 Side_Albedo_3_Z               = tex2D(Albedo_3_Sampler,Tile_UV*UV_Z.xy);
	float4 Side_Albedo_3                 = lerp(Side_Albedo_3_X,Side_Albedo_3_Z,Normal_Map_Mask.r);

	float4 Side_Albedo_4_X               = tex2D(Albedo_4_Sampler,Tile_UV*UV_X.xy);
	float4 Side_Albedo_4_Z               = tex2D(Albedo_4_Sampler,Tile_UV*UV_Z.xy);
	float4 Side_Albedo_4                 = lerp(Side_Albedo_4_X,Side_Albedo_4_Z,Normal_Map_Mask.r);
//-------------------------------------------------------------------------------	
// Combine big & small side albedo 
//-------------------------------------------------------------------------------
	float Side_Mask_R                    = pow((saturate (Mask.r+(Mask.r*Side_Albedo_4.a))),Blend_Texture_Power);
	float Side_Mask_G                    = pow((saturate (Mask.g+(Mask.g*Side_Albedo_2.a))),Blend_Texture_Power);
	
    float4 Side_Y_Small_Albedo	         = lerp((lerp(Side_Albedo_3,Side_Albedo_4,Side_Mask_R)),Side_Albedo_2,Side_Mask_G);

//  Side big small mask
	float Vertical_Normal_Mask           = mul(toWorld, Side_Normal_1.xyz*2-1).g;
		  Vertical_Normal_Mask           = 1-Vertical_Normal_Mask;
		  Vertical_Normal_Mask           = saturate (Vertical_Normal_Mask);
//    float Side_Dis_Mask                  = Vertical_Normal_Mask;
		  Vertical_Normal_Mask           = pow((saturate (Vertical_Normal_Mask+(Vertical_Normal_Mask*Side_Detail_Albedo.a))),5);

//  Side albedo final result
//    float4 Side_Albedo                   = float4((normalize(Side_Detail_Albedo.rgb)+Side_Albedo_1.rgb)*Side_Detail_Albedo.rgb,(Side_Detail_Albedo.a+Side_Albedo_1.a)/2);
//    float4 Side_Albedo                    = float4(Overlay(Side_Detail_Albedo.rgb.x, Side_Albedo_1.rgb.x), Overlay(Side_Detail_Albedo.rgb.y, Side_Albedo_1.rgb.y), Overlay(Side_Detail_Albedo.rgb.z, Side_Albedo_1.rgb.z),(Side_Detail_Albedo.a+Side_Albedo_1.a)/2);
    float4 Side_Albedo                   = float4(Side_Detail_Albedo.rgb,(Side_Detail_Albedo.a+Side_Albedo_1.a)/2);
           Side_Albedo.rgb *=Side_Brightness;
    float3 lumvec                        = float3(0.3,0.59,0.11).rgb;
    float  desat                         = dot(Side_Albedo.rgb,lumvec.rgb).x;
           Side_Albedo.rgb               = float3(lerp(Side_Albedo.rgb,desat.xxx,Side_Desaturation)).rgb;
	       Side_Albedo.rgb               = lerp(Side_Y_Small_Albedo.rgb,Side_Albedo.rgb,Vertical_Normal_Mask);

           Side_Albedo.a                 = lerp((Side_Albedo_1.a+Side_Y_Small_Albedo.a)/2,Side_Albedo.a,Vertical_Normal_Mask);
	       Side_Albedo.a                 =  1.5*pow(Side_Albedo.a,1.5);
//-------------------------------------------------------------------------------
// Top albedo
//-------------------------------------------------------------------------------
	float Top_Variation_1                = tex2D(Variation_Map_Sampler, Variation_Map_Scale*UV_Y.xy).r;
	float Top_Variation_2                = tex2D(Variation_Map_Sampler, (Variation_Map_Scale/5)*UV_Y.xy).r;
	float4 Albedo_2                      = tex2D(Albedo_2_Sampler, Tile_UV*UV_Y.xy);
	float4 Albedo_3                      = tex2D(Albedo_3_Sampler, Tile_UV*UV_Y.xy);
	float4 Albedo_4                      = tex2D(Albedo_4_Sampler, Tile_UV*UV_Y.xy);

	float Mask_R                         = pow((saturate (Mask.r+(Mask.r*Albedo_4.a))),Blend_Texture_Power);
	float Mask_G                         = pow((saturate (Mask.g+(Mask.g*Albedo_2.a))),Blend_Texture_Power);
	
    float4 Y_Small_Albedo	             = lerp((lerp(Albedo_3,Albedo_4,Mask_R)),Albedo_2,Mask_G);

//  Main side to top  mask
	float Normal_Map_Mask_G              = pow((saturate ((pow(Normal_Map_Mask.g,Blend_Texture_2_Power))+(Normal_Map_Mask.g*Side_Albedo.a))),Blend_Texture_Power);
		  
	float4 Albedo                        = lerp(Side_Albedo,Y_Small_Albedo,Normal_Map_Mask_G);

//-------------------------------------------------------------------------------
// Top normal
//-------------------------------------------------------------------------------
	float4 Normal_2                      = tex2D(Normal_Map_2_Sampler, Tile_UV*UV_Y.xy);	
	float4 Normal_3                      = tex2D(Normal_Map_3_Sampler, Tile_UV*UV_Y.xy);	
	float4 Normal_4                      = tex2D(Normal_Map_4_Sampler, Tile_UV*UV_Y.xy);

	float4 Y_Small_Normal	             = lerp((lerp(Normal_3,Normal_4,Mask_R)),Normal_2,Mask_G);
//-------------------------------------------------------------------------------			   
// Side Rock Normal
//-------------------------------------------------------------------------------
	float4 Side_Normal_2_X               = tex2D(Normal_Map_2_Sampler,Tile_UV*UV_X.xy);
           Side_Normal_2_X.g             = lerp(Side_Normal_2_X.g,1-Side_Normal_2_X.g,Side_Normal_Direction_Mask.g);
	float4 Side_Normal_2_Z               = tex2D(Normal_Map_2_Sampler,Tile_UV*UV_Z.xy);
           Side_Normal_2_Z               = Side_Normal_2_Z.grba;
           Side_Normal_2_Z.r             = lerp(1-Side_Normal_2_Z.r,Side_Normal_2_Z.r,Side_Normal_Direction_Mask.r);
 	float4 Side_Normal_2                 = lerp(Side_Normal_2_X,Side_Normal_2_Z,Normal_Map_Mask.r);

	float4 Side_Normal_3_X               = tex2D(Normal_Map_3_Sampler,Tile_UV*UV_X.xy);
           Side_Normal_3_X.g             = lerp(Side_Normal_3_X.g,1-Side_Normal_3_X.g,Side_Normal_Direction_Mask.g);
	float4 Side_Normal_3_Z               = tex2D(Normal_Map_3_Sampler,Tile_UV*UV_Z.xy);
           Side_Normal_3_Z               = Side_Normal_3_Z.grba;
           Side_Normal_3_Z.r             = lerp(1-Side_Normal_3_Z.r,Side_Normal_3_Z.r,Side_Normal_Direction_Mask.r);
 	float4 Side_Normal_3                 = lerp(Side_Normal_3_X,Side_Normal_3_Z,Normal_Map_Mask.r);

	float4 Side_Normal_4_X               = tex2D(Normal_Map_4_Sampler,Tile_UV*UV_X.xy);
           Side_Normal_4_X.g             = lerp(Side_Normal_4_X.g,1-Side_Normal_4_X.g,Side_Normal_Direction_Mask.g);
	float4 Side_Normal_4_Z               = tex2D(Normal_Map_4_Sampler,Tile_UV*UV_Z.xy);
           Side_Normal_4_Z               = Side_Normal_4_Z.grba;
           Side_Normal_4_Z.r             = lerp(1-Side_Normal_4_Z.r,Side_Normal_4_Z.r,Side_Normal_Direction_Mask.r);
 	float4 Side_Normal_4                 = lerp(Side_Normal_4_X,Side_Normal_4_Z,Normal_Map_Mask.r);

    float4 Side_Y_Small_Normal	         =  lerp((lerp(Side_Normal_3,Side_Normal_4,Side_Mask_R)),Side_Normal_2,Side_Mask_G);
	
//  Side normal final result		
    float4 Side_Normal_1_                = float4(Overlay(Side_Normal_1.rgb.x, Side_Detail_Normal.rgb.x), Overlay(Side_Normal_1.rgb.y, Side_Detail_Normal.rgb.y), Side_Normal_1.z,Side_Normal_1.a);
		   Side_Normal_1_.a              = (Side_Detail_Normal.a+Side_Normal_1.a)/2;
           Side_Normal_1_                = lerp(Side_Normal_1,Side_Normal_1_,Vertical_Normal_Mask);

	float4 Side_Normal	                 = float4(Overlay(Side_Normal_1_.rgb.x, Side_Y_Small_Normal.rgb.x), Overlay(Side_Normal_1_.rgb.y, Side_Y_Small_Normal.rgb.y), Side_Normal_1_.z,Side_Normal_1_.a);
           Side_Normal.a                 = (Side_Y_Small_Normal.a+Side_Normal_1_.a)/2;
           Side_Normal                   = lerp(Side_Normal,Side_Normal_1_,Vertical_Normal_Mask);
		   

	float4 Final_Normal                  = lerp(Side_Normal,Y_Small_Normal,Normal_Map_Mask_G);
	       Final_Normal.rgb              = Final_Normal.rgb * 2 - 1;
    	   Final_Normal.rgb              = mul(toWorld, Final_Normal.xyz).rgb; 

	float2 EncNormal                     = SphereMapEncode2(Final_Normal.xyz); 
	float4 input2                        = float4 (EncNormal, 0,0);

//-------------------------------------------------------------------------------
// Color 2
//-------------------------------------------------------------------------------
	 float Terrain_SSAO                  =  Normal.z; 
		   Terrain_SSAO                  = saturate(2*pow(Terrain_SSAO,5));
		   Terrain_SSAO                  = pow(saturate((Terrain_SSAO*Final_Normal.y)+Final_Normal.y),4);

     float Variation_1                   = lerp(Side_Variation_1,Top_Variation_1,Normal_Map_Mask_G);
           Variation_1                   = saturate(0.1+(2*pow(Variation_1,2)));
		   Variation_1                   = lerp(1,Variation_1,saturate(In.Depth/2000));

	 float Variation_2                   = lerp(Side_Variation_2,Top_Variation_2,Normal_Map_Mask_G);
           Variation_2                   = saturate(0.1+(2*pow(Variation_2,2)));

     float Variation                     = lerp(Variation_1,Variation_2,saturate(In.Depth/10000));

	float Spec_Power_Out                 = Albedo.a * Spec_Power;
          Albedo.rgb                     = Albedo.rgb*Variation;//*(saturate(0.5+Terrain_SSAO));

//          Albedo.rgb = In.Vcolor.rgb + Albedo.rgb ;
//		  Albedo.rgb = In.Vcolor.rgb ;
//		   Albedo.rgb = 1;
		float4 input3                    = float4(Albedo.rgb,Spec_Power_Out);
//-------------------------------------------------------------------------------
// Color 3
//-------------------------------------------------------------------------------

	float4 input4                        = float4(saturate(0.6+Terrain_SSAO),0, Spec_Glossiness, Material_ID);
//-------------------------------------------------------------------------------
// Output Pixel Shader
//-------------------------------------------------------------------------------	
	PixelShaderOut output; 
	output.rtarget0 = input1; 
	output.rtarget1 = input2; 
	output.rtarget2 = input3; 
	output.rtarget3 = input4; 
	return output; 
} 
//-------------------------------------------------------------------------------
// Technique
//-------------------------------------------------------------------------------
technique GBuffer  
{  
	pass pass0  
    {		 
		VertexShader = compile vs_3_0 av(); 
		ZEnable = TRUE;
		ZWriteEnable = TRUE;
//		fillmode = point;
//		fillmode = solid;
//		fillmode = wireframe;
		ZFunc = LESS;
		StencilEnable = TRUE;
		stencilfunc = ALWAYS;
		StencilPass = REPLACE;
		StencilFail = KEEP;
		StencilZFail = KEEP;
		StencilRef = 1;
		PixelShader = compile ps_3_0 af(); 
	}  

}    


#5 Zero01   Members   -  Reputation: 109

Like
0Likes
Like

Posted 23 February 2013 - 11:21 AM

Thank you very much, that looks promising.

You mean it's a mixture of masking and displacement mapping? Can you tell me a little bit more about that?

I was also astonished about the erosion effect on the path in the middle. The path looks so 'broken' and 'washed out'.

I already implemented thermal and hydraulic erosion, but I don't know how to get such results as in the image?



#6 ali rahimi   Members   -  Reputation: 434

Like
1Likes
Like

Posted 23 February 2013 - 02:27 PM

Erosion is more related to the overall shape and layer masks (which define erosion area). App like world machine will give you a full erosion mask and more. I think you miss understood masking with Erosion effect. Here you can see the result of my terrain. For a terrain we always have a low and high frequency texturing which must blend smoothly. That example code is  a good starting point to see how blending should be setup.  

http://quest3d.com/forum/index.php?topic=70937.120



#7 Hodgman   Moderators   -  Reputation: 30353

Like
2Likes
Like

Posted 23 February 2013 - 07:21 PM

How is it possible to generate such a well eroded terrain??

Many games generate their terrain using artist-driven tools. For example, the mountains in my current project are being created by:

* first a very low polygon mesh defining their overall shape is created.

* then in world machine, a few mountains are eroded to use as 'templates'.

* these 'templates' are then imported into zbrush as brushes that the artist can use to 'paint' on erosion details.

* the low-polygon mountains are then sculpted into highly-detailed mountains by using these "erostion brushes".

* texture masks are then automatically generated and/or painted onto the mesh (for grass/rock/dirt/paths/etc).

* at run-time, the terrain is textured using these masks, which may add more details via bump/parallax/displacement mapping.

 

For examples of having a stone path naturally emerge from terrain, using only texturing, see the QDM presentation.


Edited by Hodgman, 23 February 2013 - 07:22 PM.


#8 Zero01   Members   -  Reputation: 109

Like
0Likes
Like

Posted 24 February 2013 - 04:58 AM

The picture is becoming progressively clearer.smile.png

Thank you guys!

 

I'm searching for new erosion and also terrain generation algorithms. I found dozens of papers, but I don't get results like in World Machine or Terragen.

Which algorithms do they use? Where can I find new advanced algorithms? (e.g. the book "Texturing And Modeling - A Procedural Approach" was inspiring)






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS