Skip to content

Commit

Permalink
Merge branch 'tile-textures'
Browse files Browse the repository at this point in the history
# Conflicts:
#	example/landformSite.js
#	example/src/plugins/overlays/TextureOverlayMaterial.js
#	example/src/plugins/overlays/TextureOverlayTilesRenderer.js
  • Loading branch information
gkjohnson committed Jul 6, 2024
2 parents 432f25d + 692e2db commit 778ec01
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
32 changes: 28 additions & 4 deletions example/landformSite.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let camera, controls, scene, renderer;
const params = {

errorTarget: 12,
slopeLayer: false,
slopeDisplay: 'NONE',

};

Expand Down Expand Up @@ -130,6 +130,7 @@ function init() {
const newMaterial = new TextureOverlayMaterial();
newMaterial.copy( c.material );
newMaterial.textures = Object.values( tiles.getTexturesForTile( tile ) );
newMaterial.displayAsOverlay = params.slopeDisplay === 'OVERLAY';
c.material = newMaterial;

}
Expand Down Expand Up @@ -179,11 +180,34 @@ function init() {

const gui = new GUI();
gui.add( params, 'errorTarget', 0, 100 );
gui.add( params, 'slopeLayer' ).onChange( v => {
gui.add( params, 'slopeDisplay', [ 'NONE', 'OVERLAY', 'SOLID' ] ).onChange( v => {

if ( v ) {
if ( v !== 'NONE' ) {

tileSets.forEach( t => t.registerLayer( 'slopeLayer', layerFunction ) );
tileSets.forEach( t => {

if ( ! t.hasLayer( 'slopeLayer' ) ) {

t.registerLayer( 'slopeLayer', layerFunction );

}

t.forEachLoadedModel( scene => {

scene.traverse( c => {

if ( c.material ) {

c.material.displayAsOverlay = v === 'OVERLAY';
c.material.needsUpdate = true;

}

} );

} );

} );

} else {

Expand Down
21 changes: 18 additions & 3 deletions example/src/plugins/overlays/TextureOverlayMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const TextureOverlayMaterialMixin = base => class extends base {

super( ...args );
this.textures = [];
this.displayAsOverlay = false;

}

Expand All @@ -20,6 +21,12 @@ export const TextureOverlayMaterialMixin = base => class extends base {
},
};

shader.defines = {
DISPLAY_AS_OVERLAY: Number( this.displayAsOverlay ),
};

console.log('UPDATE')

// WebGL does not seem to like empty texture arrays
if ( textures.length !== 0 ) {

Expand All @@ -38,8 +45,16 @@ export const TextureOverlayMaterialMixin = base => class extends base {
for ( int i = 0; i < ${ textures.length }; i ++ ) {
col = texture( textures[ i ], vMapUv );
col = vec4( 0, 0, 1, col.r );
diffuseColor = mix( diffuseColor, vec4( 0.35, 0.65, 1, 1 ), col.a );
#if DISPLAY_AS_OVERLAY
diffuseColor = mix( diffuseColor, vec4( 0.22, 0.73, 0.82, 1 ), col.r * 0.5 );
#else
diffuseColor = mix( diffuseColor, col, col.a );
#endif
}
#pragma unroll_loop_end
Expand All @@ -52,7 +67,7 @@ export const TextureOverlayMaterialMixin = base => class extends base {

customProgramCacheKey() {

return this.textures.length + this.onBeforeCompile.toString();
return String( this.displayAsOverlay ) + String( this.textures.length ) + this.onBeforeCompile.toString();

}

Expand Down
6 changes: 6 additions & 0 deletions example/src/plugins/overlays/TextureOverlayTilesRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ export const TextureOverlayTilesRendererMixin = base => class extends base {

}

hasLayer( name ) {

return name in this.caches;

}

registerLayer( name, customTextureCallback ) {

if ( name in this.caches ) {
Expand Down

0 comments on commit 778ec01

Please sign in to comment.