From 363e56ff1882adc96163c46bcd4795e90da026d2 Mon Sep 17 00:00:00 2001 From: Dejvino Date: Sat, 22 Nov 2025 14:44:21 +0100 Subject: [PATCH] Feature: vibrant dancers --- party-cathedral/src/scene/dancers.js | 5 ++++- .../src/scene/medieval-musicians.js | 20 ++--------------- .../src/shaders/vibrant-billboard-shader.js | 22 +++++++++++++++++++ 3 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 party-cathedral/src/shaders/vibrant-billboard-shader.js diff --git a/party-cathedral/src/scene/dancers.js b/party-cathedral/src/scene/dancers.js index d525e98..45b200c 100644 --- a/party-cathedral/src/scene/dancers.js +++ b/party-cathedral/src/scene/dancers.js @@ -2,6 +2,7 @@ import * as THREE from 'three'; import { state } from '../state.js'; import { SceneFeature } from './SceneFeature.js'; import sceneFeatureManager from './SceneFeatureManager.js'; +import { applyVibrancyToMaterial } from '../shaders/vibrant-billboard-shader.js'; const dancerTextureUrls = [ '/textures/dancer1.png', ]; @@ -51,13 +52,15 @@ export class Dancers extends SceneFeature { // Configure texture for a 2x2 sprite sheet processedTexture.repeat.set(0.5, 0.5); - return new THREE.MeshStandardMaterial({ + const material = new THREE.MeshStandardMaterial({ map: processedTexture, side: THREE.DoubleSide, alphaTest: 0.5, roughness: 0.7, metalness: 0.1, }); + applyVibrancyToMaterial(material, processedTexture); + return material; })); const createDancers = () => { diff --git a/party-cathedral/src/scene/medieval-musicians.js b/party-cathedral/src/scene/medieval-musicians.js index 472973c..6f52513 100644 --- a/party-cathedral/src/scene/medieval-musicians.js +++ b/party-cathedral/src/scene/medieval-musicians.js @@ -2,6 +2,7 @@ import * as THREE from 'three'; import { state } from '../state.js'; import { SceneFeature } from './SceneFeature.js'; import sceneFeatureManager from './SceneFeatureManager.js'; +import { applyVibrancyToMaterial } from '../shaders/vibrant-billboard-shader.js'; const musicianTextureUrls = [ '/textures/musician1.png', '/textures/musician2.png', @@ -72,24 +73,7 @@ export class MedievalMusicians extends SceneFeature { metalness: 0.1, }); - // Inject custom shader code to boost vibrancy - material.onBeforeCompile = (shader) => { - // Pass the texture map to the fragment shader - shader.uniforms.vibrancyMap = { value: processedTexture }; - - shader.fragmentShader = 'uniform sampler2D vibrancyMap;\n' + shader.fragmentShader; - shader.fragmentShader = shader.fragmentShader.replace( - '#include ', - ` - #include - // Get the pure texture color - vec4 texColor = texture2D(vibrancyMap, vMapUv); - // Mix the final lit color with the pure texture color to keep it vibrant - float vibrancy = 0.3; // 0.0 = full lighting, 1.0 = full texture color - gl_FragColor.rgb = mix(gl_FragColor.rgb, texColor.rgb, vibrancy) + texColor.rgb * 0.2; - ` - ); - }; + applyVibrancyToMaterial(material, processedTexture); return material; })); diff --git a/party-cathedral/src/shaders/vibrant-billboard-shader.js b/party-cathedral/src/shaders/vibrant-billboard-shader.js new file mode 100644 index 0000000..c219915 --- /dev/null +++ b/party-cathedral/src/shaders/vibrant-billboard-shader.js @@ -0,0 +1,22 @@ +import * as THREE from 'three'; + +export function applyVibrancyToMaterial(material, texture) { + // Inject custom shader code to boost vibrancy + material.onBeforeCompile = (shader) => { + // Pass the texture map to the fragment shader + shader.uniforms.vibrancyMap = { value: texture }; + + shader.fragmentShader = 'uniform sampler2D vibrancyMap;\n' + shader.fragmentShader; + shader.fragmentShader = shader.fragmentShader.replace( + '#include ', + ` + #include + // Get the pure texture color + vec4 texColor = texture2D(vibrancyMap, vMapUv); + // Mix the final lit color with the pure texture color to keep it vibrant + float vibrancy = 0.3; // 0.0 = full lighting, 1.0 = full texture color + gl_FragColor.rgb = mix(gl_FragColor.rgb, texColor.rgb, vibrancy) + texColor.rgb * 0.2; + ` + ); + }; +} \ No newline at end of file