From 16cfaa6ea55ade73329d1256e84b3215a10153e7 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 23 Sep 2014 13:28:00 -0700 Subject: [PATCH] Use cubic texture coordinate generation for the dual contour surfaces. --- .../shaders/metavoxel_voxel_splat.frag | 15 ++++++++++---- .../shaders/metavoxel_voxel_splat.vert | 20 ++++++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/interface/resources/shaders/metavoxel_voxel_splat.frag b/interface/resources/shaders/metavoxel_voxel_splat.frag index 66ce2721ac..c6c9860c1a 100644 --- a/interface/resources/shaders/metavoxel_voxel_splat.frag +++ b/interface/resources/shaders/metavoxel_voxel_splat.frag @@ -17,13 +17,20 @@ const int SPLAT_COUNT = 4; // the splat textures uniform sampler2D diffuseMaps[SPLAT_COUNT]; +// the model space normal +varying vec3 normal; + // alpha values for the four splat textures varying vec4 alphaValues; void main(void) { + // determine the cube face to use for texture coordinate generation + vec3 absNormal = abs(normal); + vec2 parameters = step(absNormal.yy, absNormal.xz) * step(absNormal.zx, absNormal.xz); + // blend the splat textures - gl_FragColor = (texture2D(diffuseMaps[0], gl_TexCoord[0].st) * alphaValues.x + - texture2D(diffuseMaps[1], gl_TexCoord[1].st) * alphaValues.y + - texture2D(diffuseMaps[2], gl_TexCoord[2].st) * alphaValues.z + - texture2D(diffuseMaps[3], gl_TexCoord[3].st) * alphaValues.w); + gl_FragColor = (texture2D(diffuseMaps[0], mix(gl_TexCoord[0].xw, gl_TexCoord[0].zy, parameters)) * alphaValues.x + + texture2D(diffuseMaps[1], mix(gl_TexCoord[1].xw, gl_TexCoord[1].zy, parameters)) * alphaValues.y + + texture2D(diffuseMaps[2], mix(gl_TexCoord[2].xw, gl_TexCoord[2].zy, parameters)) * alphaValues.z + + texture2D(diffuseMaps[3], mix(gl_TexCoord[3].xw, gl_TexCoord[3].zy, parameters)) * alphaValues.w); } diff --git a/interface/resources/shaders/metavoxel_voxel_splat.vert b/interface/resources/shaders/metavoxel_voxel_splat.vert index 150a9e7d2e..31ddbef395 100644 --- a/interface/resources/shaders/metavoxel_voxel_splat.vert +++ b/interface/resources/shaders/metavoxel_voxel_splat.vert @@ -29,6 +29,9 @@ attribute vec4 materials; // the weights of each material attribute vec4 materialWeights; +// the model space normal +varying vec3 normal; + // alpha values for the four splat textures varying vec4 alphaValues; @@ -36,12 +39,19 @@ void main(void) { // use the fixed-function position gl_Position = ftransform(); + // pass along the normal + normal = gl_Normal; + // pass along the scaled/offset texture coordinates - vec4 textureSpacePosition = vec4(gl_Vertex.xz, 0.0, 1.0); - gl_TexCoord[0] = textureSpacePosition * vec4(splatTextureScalesS[0], splatTextureScalesT[0], 0.0, 1.0); - gl_TexCoord[1] = textureSpacePosition * vec4(splatTextureScalesS[1], splatTextureScalesT[1], 0.0, 1.0); - gl_TexCoord[2] = textureSpacePosition * vec4(splatTextureScalesS[2], splatTextureScalesT[2], 0.0, 1.0); - gl_TexCoord[3] = textureSpacePosition * vec4(splatTextureScalesS[3], splatTextureScalesT[3], 0.0, 1.0); + vec4 textureSpacePosition = gl_Vertex.xyyz; + gl_TexCoord[0] = textureSpacePosition * vec4(splatTextureScalesS[0], splatTextureScalesT[0], + splatTextureScalesS[0], splatTextureScalesT[0]); + gl_TexCoord[1] = textureSpacePosition * vec4(splatTextureScalesS[1], splatTextureScalesT[1], + splatTextureScalesS[1], splatTextureScalesT[1]); + gl_TexCoord[2] = textureSpacePosition * vec4(splatTextureScalesS[2], splatTextureScalesT[2], + splatTextureScalesS[2], splatTextureScalesT[2]); + gl_TexCoord[3] = textureSpacePosition * vec4(splatTextureScalesS[3], splatTextureScalesT[3], + splatTextureScalesS[3], splatTextureScalesT[3]); // compute the alpha values for each texture float value = materials[0];