Merge pull request #3539 from ey6es/metavoxels

Blend between directional textures on dual contour surfaces.
This commit is contained in:
AndrewMeadows 2014-10-06 08:00:24 -07:00
commit f284fc548f

View file

@ -26,12 +26,20 @@ varying vec4 alphaValues;
void main(void) {
// determine the cube face to use for texture coordinate generation
vec3 absNormal = abs(normal);
vec3 steps = step(absNormal.zzy, absNormal.xyx);
vec2 parameters = mix(vec2(0.0, steps.y), vec2(steps.x, steps.x), steps.z);
vec3 steps = smoothstep(absNormal.zzy - vec3(0.05, 0.05, 0.05), absNormal.zzy + vec3(0.05, 0.05, 0.05), absNormal.xyx);
// blend the splat textures
gl_FragColor = (texture2D(diffuseMaps[0], mix(gl_TexCoord[0].xy, gl_TexCoord[0].zw, parameters)) * alphaValues.x +
texture2D(diffuseMaps[1], mix(gl_TexCoord[1].xy, gl_TexCoord[1].zw, parameters)) * alphaValues.y +
texture2D(diffuseMaps[2], mix(gl_TexCoord[2].xy, gl_TexCoord[2].zw, parameters)) * alphaValues.z +
texture2D(diffuseMaps[3], mix(gl_TexCoord[3].xy, gl_TexCoord[3].zw, parameters)) * alphaValues.w);
vec4 base0 = texture2D(diffuseMaps[0], gl_TexCoord[0].xy);
vec4 base1 = texture2D(diffuseMaps[1], gl_TexCoord[1].xy);
vec4 base2 = texture2D(diffuseMaps[2], gl_TexCoord[2].xy);
vec4 base3 = texture2D(diffuseMaps[3], gl_TexCoord[3].xy);
gl_FragColor =
mix(mix(base0, texture2D(diffuseMaps[0], gl_TexCoord[0].xw), steps.y),
mix(base0, texture2D(diffuseMaps[0], gl_TexCoord[0].zw), steps.x), steps.z) * alphaValues.x +
mix(mix(base1, texture2D(diffuseMaps[1], gl_TexCoord[1].xw), steps.y),
mix(base1, texture2D(diffuseMaps[1], gl_TexCoord[1].zw), steps.x), steps.z) * alphaValues.y +
mix(mix(base2, texture2D(diffuseMaps[2], gl_TexCoord[2].xw), steps.y),
mix(base2, texture2D(diffuseMaps[2], gl_TexCoord[2].zw), steps.x), steps.z) * alphaValues.z +
mix(mix(base3, texture2D(diffuseMaps[3], gl_TexCoord[3].xw), steps.y),
mix(base3, texture2D(diffuseMaps[3], gl_TexCoord[3].zw), steps.x), steps.z) * alphaValues.w;
}