[SOLVED] How to add 6 textures on map?

Hi. I red the terrain tutorial. So I know how to add 3 textures to map and it works preety good. But I wanna add for example 6 textures. I red that I have to edit Terrain.j3md file. So I added tex4,5 and 6. And I modified the Terrain.frag file. But it doesn’t work. My new colours are rocognizing as older 3 colours (RGB). Here is this 2 files, maybe I’m adding colours in wrong way:



Terrain.j3md

[java]MaterialDef Terrain {



MaterialParameters {



// use tri-planar mapping

Boolean useTriPlanarMapping



Texture2D Alpha

Texture2D Tex1

Texture2D Tex2

Texture2D Tex3

Texture2D Tex4

Texture2D Tex5

Texture2D Tex6

Float Tex1Scale

Float Tex2Scale

Float Tex3Scale

Float Tex4Scale

Float Tex5Scale

Float Tex6Scale

}



Technique {

VertexShader GLSL100: Common/MatDefs/Terrain/Terrain.vert

FragmentShader GLSL100: Common/MatDefs/Terrain/Terrain.frag



WorldParameters {

WorldViewProjectionMatrix

}



Defines {

TRI_PLANAR_MAPPING : useTriPlanarMapping

}

}



Technique {

}

}[/java]





Terrain.frag

[java]uniform sampler2D m_Alpha;

uniform sampler2D m_Tex1; //grass

uniform sampler2D m_Tex2; //snow

uniform sampler2D m_Tex3; //path

uniform sampler2D m_Tex4; //sand

uniform sampler2D m_Tex5; //rock

uniform sampler2D m_Tex6; //water?

uniform float m_Tex1Scale;

uniform float m_Tex2Scale;

uniform float m_Tex3Scale;

uniform float m_Tex4Scale;

uniform float m_Tex5Scale;

uniform float m_Tex6Scale;



varying vec2 texCoord;



#ifdef TRI_PLANAR_MAPPING

varying vec4 vVertex;

varying vec3 vNormal;

#endif



void main(void)

{



// get the alpha value at this 2D texture coord

vec4 alpha = texture2D( m_Alpha, texCoord.xy );



#ifdef TRI_PLANAR_MAPPING

// tri-planar texture bending factor for this fragment’s normal

vec3 blending = abs( vNormal );

blending = (blending -0.2) * 0.7;

blending = normalize(max(blending, 0.00001)); // Force weights to sum to 1.0 (very important!)

float b = (blending.x + blending.y + blending.z);

blending /= vec3(b, b, b);



// texture coords

vec4 coords = vVertex;



vec4 col1 = texture2D( m_Tex1, coords.yz * m_Tex1Scale );

vec4 col2 = texture2D( m_Tex1, coords.xz * m_Tex1Scale );

vec4 col3 = texture2D( m_Tex1, coords.xy * m_Tex1Scale );

// blend the results of the 3 planar projections.

vec4 tex1 = col1 * blending.x + col2 * blending.y + col3 * blending.z;



col1 = texture2D( m_Tex2, coords.yz * m_Tex2Scale );

col2 = texture2D( m_Tex2, coords.xz * m_Tex2Scale );

col3 = texture2D( m_Tex2, coords.xy * m_Tex2Scale );

// blend the results of the 3 planar projections.

vec4 tex2 = col1 * blending.x + col2 * blending.y + col3 * blending.z;



col1 = texture2D( m_Tex3, coords.yz * m_Tex3Scale );

col2 = texture2D( m_Tex3, coords.xz * m_Tex3Scale );

col3 = texture2D( m_Tex3, coords.xy * m_Tex3Scale );

// blend the results of the 3 planar projections.

vec4 tex3 = col1 * blending.x + col2 * blending.y + col3 * blending.z;



col1 = texture2D( m_Tex4, coords.yz * m_Tex4Scale );

col2 = texture2D( m_Tex4, coords.xz * m_Tex4Scale );

col3 = texture2D( m_Tex4, coords.xy * m_Tex4cale );

// blend the results of the 3 planar projections.

vec4 tex4 = col1 * blending.x + col2 * blending.y + col3 * blending.z;



col1 = texture2D( m_Tex5, coords.yz * m_Tex5Scale );

col2 = texture2D( m_Tex5, coords.xz * m_Tex5Scale );

col3 = texture2D( m_Tex5, coords.xy * m_Tex5Scale );

// blend the results of the 3 planar projections.

vec4 tex5 = col1 * blending.x + col2 * blending.y + col3 * blending.z;



col1 = texture2D( m_Tex6, coords.yz * m_Tex6Scale );

col2 = texture2D( m_Tex6, coords.xz * m_Tex6Scale );

col3 = texture2D( m_Tex6, coords.xy * m_Tex6Scale );

// blend the results of the 3 planar projections.

vec4 tex6 = col1 * blending.x + col2 * blending.y + col3 * blending.z;



#else

vec4 tex1 = texture2D( m_Tex1, texCoord.xy * m_Tex1Scale ); // Tile

vec4 tex2 = texture2D( m_Tex2, texCoord.xy * m_Tex2Scale ); // Tile

vec4 tex3 = texture2D( m_Tex3, texCoord.xy * m_Tex3Scale ); // Tile

vec4 tex1 = texture2D( m_Tex4, texCoord.xy * m_Tex4Scale ); // Tile

vec4 tex2 = texture2D( m_Tex5, texCoord.xy * m_Tex5Scale ); // Tile

vec4 tex3 = texture2D( m_Tex6, texCoord.xy * m_Tex6Scale ); // Tile



#endif



vec4 outColor = tex1 * alpha.r; // Red channel

outColor += tex2 * alpha.g; // Green channel

outColor += tex3 * alpha.b; // Blue channel

outColor += tex4 * ((alpha.r + alpha.g)/2); // Red Green channel

outColor += tex5 * ((alpha.r + alpha.b)/2); // Red Blue channel

outColor += tex6 * ((alpha.g + alpha.b)/2); // Green Blue channel

gl_FragColor = outColor;

}



[/java]







And here is my alphamap:

http://imageshack.us/a/img189/8573/alphamap2.png





OK, I found solution, I have wrong paths in my first file :slight_smile: EOT

TerrainLighting.j3md supports 12 textures, and does lighting.