Last active
February 6, 2021 10:07
-
-
Save gonnavis/9d5e4801ce473abab8eb87ae3780c1ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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