Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
let uniforms = THREE.UniformsUtils.merge([
THREE.ShaderLib.standard.uniforms,
{
diffuse: { value: new THREE.Color(1, 1, 1) },
cameraLengthInverse: { value: 0 },
},
]);
let material = new THREE.ShaderMaterial({
lights: true,
vertexColors: true,
defines: {
// USE_MAP: true,
},
uniforms: uniforms,
vertexShader: THREE.ShaderLib.standard.vertexShader,
fragmentShader: THREE.ShaderLib.standard.fragmentShader,
extensions: {
derivatives: true, // set to use derivatives
fragDepth: false, // set to use fragment depth values
drawBuffers: false, // set to use draw buffers
shaderTextureLOD: false, // set to use shader texture LOD
},
});
material.onBeforeCompile = function (shader) {
shader.vertexShader = shader.vertexShader.replace(
"void main() {",
`
uniform float cameraLengthInverse;
void main() {
`
);
shader.vertexShader = shader.vertexShader.replace(
"#include <project_vertex>",
`
vec4 mvPosition = vec4( transformed, 1.0 );
#ifdef USE_INSTANCING
mvPosition = instanceMatrix * mvPosition;
#endif
mvPosition = modelViewMatrix * mvPosition;
mvPosition.xy*=-mvPosition.z;
mvPosition.xy*=cameraLengthInverse;
gl_Position = projectionMatrix * mvPosition;
`
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment