forked from BabylonJS/Babylon.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request BabylonJS#1 from torchesburn/decal-map-uv-seam-fix
MeshUVSpaceRenderer UV Seam Fix
- Loading branch information
Showing
6 changed files
with
286 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/dev/core/src/Shaders/meshUVSpaceRendererFinaliser.fragment.fx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Fragment shader | ||
precision highp float; | ||
|
||
// Varyings | ||
varying vec2 vUV; | ||
|
||
// Uniforms | ||
uniform sampler2D textureSampler; | ||
uniform sampler2D maskTextureSampler; | ||
uniform vec2 textureSize; | ||
|
||
void main() { | ||
vec4 mask = texture2D(maskTextureSampler, vUV).rgba; | ||
|
||
if (mask.r > 0.5) { | ||
gl_FragColor = texture2D(textureSampler, vUV); | ||
} else { | ||
vec2 texelSize = 4.0 / textureSize; | ||
|
||
vec2 uv_p01 = vUV + vec2(-1.0, 0.0) * texelSize; | ||
vec2 uv_p21 = vUV + vec2(1.0, 0.0) * texelSize; | ||
vec2 uv_p10 = vUV + vec2(0.0, -1.0) * texelSize; | ||
vec2 uv_p12 = vUV + vec2(0.0, 1.0) * texelSize; | ||
|
||
float mask_p01 = texture2D(maskTextureSampler, uv_p01).r; | ||
float mask_p21 = texture2D(maskTextureSampler, uv_p21).r; | ||
float mask_p10 = texture2D(maskTextureSampler, uv_p10).r; | ||
float mask_p12 = texture2D(maskTextureSampler, uv_p12).r; | ||
|
||
vec4 col = vec4(0.0, 0.0, 0.0, 0.0); | ||
float total_weight = 0.0; | ||
|
||
if (mask_p01 > 0.5) { | ||
col += texture2D(textureSampler, uv_p01); | ||
total_weight += 1.0; | ||
} | ||
if (mask_p21 > 0.5) { | ||
col += texture2D(textureSampler, uv_p21); | ||
total_weight += 1.0; | ||
} | ||
if (mask_p10 > 0.5) { | ||
col += texture2D(textureSampler, uv_p10); | ||
total_weight += 1.0; | ||
} | ||
if (mask_p12 > 0.5) { | ||
col += texture2D(textureSampler, uv_p12); | ||
total_weight += 1.0; | ||
} | ||
|
||
if (total_weight > 0.0) { | ||
gl_FragColor = col / total_weight; | ||
} else { | ||
gl_FragColor = col; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/dev/core/src/Shaders/meshUVSpaceRendererFinaliser.vertex.fx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Vertex shader | ||
precision highp float; | ||
|
||
// Attributes | ||
attribute vec3 position; | ||
attribute vec2 uv; | ||
|
||
// Uniforms | ||
uniform mat4 worldViewProjection; | ||
|
||
// Varyings | ||
varying vec2 vUV; | ||
|
||
void main() { | ||
gl_Position = worldViewProjection * vec4(position, 1.0); | ||
vUV = uv; | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/dev/core/src/Shaders/meshUVSpaceRendererMasker.fragment.fx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
varying vec2 vUV; | ||
|
||
void main(void) { | ||
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/dev/core/src/Shaders/meshUVSpaceRendererMasker.vertex.fx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
attribute vec2 uv; | ||
|
||
varying vec2 vUV; | ||
|
||
void main(void) { | ||
gl_Position = vec4(vec2(uv.x, uv.y) * 2.0 - 1.0, 0., 1.0); | ||
vUV = uv; | ||
} |