threepipe
Version:
A modern 3D viewer framework built on top of three.js, written in TypeScript, designed to make creating high-quality, modular, and extensible 3D experiences on the web simple and enjoyable.
37 lines (34 loc) • 1.38 kB
text/typescript
import {IUniform, Texture} from 'three'
import {CopyShader} from 'three/examples/jsm/shaders/CopyShader.js'
import {ExtendedShaderPass} from './ExtendedShaderPass'
import {IPass} from './Pass'
export class GenericBlendTexturePass extends ExtendedShaderPass implements IPass {
constructor(uniforms: {[uniform: string]: IUniform}, blendFunc = 'c = a + b;', extraFrag = '', texture?: Texture, maxIntensity = 120) {
super({
vertexShader: CopyShader.vertexShader,
fragmentShader: `
varying vec2 vUv;
${extraFrag}
void main() {
vec4 a = tDiffuseTexelToLinear ( texture2D( tDiffuse, vUv ) );
vec4 b = tDiffuse2TexelToLinear ( texture2D( tDiffuse2, vUv ) );
vec4 c = vec4(0);
${blendFunc}
c = clamp(c, vec4(0), vec4(MAX_INTENSITY));
gl_FragColor = c;
#include <colorspace_fragment>
}
`,
uniforms: {
'tDiffuse': {value: null},
'tDiffuse2': {value: texture},
...uniforms,
},
defines: {
['MAX_INTENSITY']: maxIntensity,
},
}, 'tDiffuse', 'tDiffuse2')
this.clear = false
this.needsSwap = true
}
}