22 lines
963 B
JavaScript
22 lines
963 B
JavaScript
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 <dithering_fragment>',
|
|
`
|
|
#include <dithering_fragment>
|
|
// 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;
|
|
`
|
|
);
|
|
};
|
|
} |