Skip to content

Commit

Permalink
feat(map): use defines to control layer blends in terrain fragment sh…
Browse files Browse the repository at this point in the history
…ader
  • Loading branch information
fallenoak committed Feb 11, 2024
1 parent bffa6a6 commit 29e2d15
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/lib/map/terrain/TerrainMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class TerrainMaterial extends THREE.RawShaderMaterial {
) {
super();

this.defines['LAYER_COUNT'] = layerCount;

this.uniforms = {
...uniforms,
layerCount: { value: layerCount },
layers: { value: layerTextures },
splat: { value: splatTexture },
};
Expand Down
13 changes: 6 additions & 7 deletions src/lib/map/terrain/shader/fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { composeShader } from '../../../shader/util.js';
const FRAGMENT_SHADER_PRECISIONS = ['highp float'];

const FRAGMENT_SHADER_UNIFORMS = [
{ name: 'layerCount', type: 'int' },
{ name: 'layers[4]', type: 'sampler2D' },
{ name: 'splat', type: 'sampler2D' },
{ name: 'sunDiffuseColor', type: 'vec3' },
Expand Down Expand Up @@ -36,21 +35,21 @@ color = texture(layers[0], vLayerCoord);
blend = texture(splat, vSplatCoord);
// 2nd layer
if (layerCount > 1) {
#if LAYER_COUNT > 1
layer = texture(layers[1], vLayerCoord);
color = blendLayer(color, layer, blend.rrrr);
}
#endif
if (layerCount > 2) {
#if LAYER_COUNT > 2
layer = texture(layers[2], vLayerCoord);
color = blendLayer(color, layer, blend.gggg);
}
#endif
// 3rd layer
if (layerCount > 3) {
#if LAYER_COUNT > 3
layer = texture(layers[3], vLayerCoord);
color = blendLayer(color, layer, blend.bbbb);
}
#endif
// Terrain is always opaque
color.a = 1.0;
Expand Down

0 comments on commit 29e2d15

Please sign in to comment.