@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
38 lines (37 loc) • 1.04 kB
JavaScript
;
import { ShaderMaterial } from "three";
export const UV_LIGHT_MAP_FLIPPED_ATTRIB_NAME = "uvLightmapFlipped";
export function setRenderTargetsCombineMaterial(mat, options) {
mat.uniforms.rt1.value = options.rt1.texture;
mat.uniforms.rt2.value = options.rt2.texture;
}
export function createRenderTargetsCombineMaterial() {
const mat = new ShaderMaterial();
mat.uniforms = {
rt1: { value: null },
rt2: { value: null }
};
mat.name = "renderTargetsCombineMaterial";
mat.onBeforeCompile = (shader) => {
shader.vertexShader = `
varying vec2 vUv;
void main(){
vUv = uv;
gl_Position = vec4((uv - 0.5) * 2.0, 1.0, 1.0);
}`;
shader.fragmentShader = `
uniform sampler2D rt1;
uniform sampler2D rt2;
varying vec2 vUv;
void main(){
vec3 rt1Value = texture2D(rt1, vUv).rgb;
vec3 rt2Value = texture2D(rt2, vUv).rgb;
gl_FragColor.rgb = rt1Value + rt2Value;
}
`;
shader.uniforms.rt1 = mat.uniforms.rt1;
shader.uniforms.rt2 = mat.uniforms.rt2;
mat.userData.shader = shader;
};
return mat;
}