Sign in to follow this  

GLSL texture splatting with several textures and just one texture coordinate system.

Recommended Posts

xnewagex    122
I'm working in a terrain renderer/editor for a game. Well I'm using shaders and I have several textures (2 RGBA textures with the masks + 8 ground textures) to blend in a chunk. But I just need a texture coordinate system because all the textures will have te same size without <<offsets?>> (Well, English isn't my native language, sorry). [QUOTE]// We can blend 6 ground textures uniform int NumTextures; // We have 2 textures, with 4 masks (RGBA) eachone uniform sampler2D Mask1; uniform sampler2D Mask2; // There are to textures for the traks, one of sand and another one of stone uniform sampler2D Path1; uniform sampler2D Path2; // We have to link the textures with the shadders before uniform sampler2D Ground1; uniform sampler2D Ground2; uniform sampler2D Ground3; uniform sampler2D Ground4; uniform sampler2D Ground5; uniform sampler2D Ground6; // Get the masks vec4 mask1 = texture2D(Mask1, gl_TexCoord[0].xy); vec4 mask2 = texture2D(Mask2, gl_TexCoord[0].xy); // Get the path textures vec4 path1 = texture2D(Path1, gl_TexCoord[0].xy); vec4 path2 = texture2D(Path2, gl_TexCoord[0].xy); // Get the ground textures vec4 ground1 = texture2D(Ground1, gl_TexCoord[0].xy); vec4 ground2 = texture2D(Ground2, gl_TexCoord[0].xy); vec4 ground3 = texture2D(Ground3, gl_TexCoord[0].xy); vec4 ground4 = texture2D(Ground4, gl_TexCoord[0].xy); vec4 ground5 = texture2D(Ground5, gl_TexCoord[0].xy); vec4 ground6 = texture2D(Ground6, gl_TexCoord[0].xy); void main() { // Sets the first ground vec4 out_color = ground1; // Iterate and blend textures with the paths for(int idx=1;idx<NumTextures;idx++) { if(idx==1) { out_color = out_color * mask1.r; out_color = mix(out_color, ground2, mask1.g); } else if(idx==2) out_color = mix(out_color, ground3, mask1.b); else if(idx==3) out_color = mix(out_color, ground4, mask1.a); else if(idx==4) out_color = mix(out_color, ground5, mask2.r); else if(idx==5) out_color = mix(out_color, ground6, mask2.g); } // Blend paths out_color = mix(out_color, path1, mask2.b); out_color = mix(out_color, path2, mask2.a); gl_FragColor = out_color; } [/QUOTE]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this