Created
June 2, 2021 20:23
-
-
Save 1502shivam-singh/70bf2cb5a010f995b65357d233736159 to your computer and use it in GitHub Desktop.
To extend shaderMaterial with three.js based lights, passing the light as uniform to the shader.
This file contains hidden or 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
| // To extend shaderMaterial with three.js based lights, passing | |
| let light = new THREE.DirectionalLight(0xff0000); | |
| light.position.set(0, 0, 1); | |
| scene.add(light); | |
| uniforms = THREE.UniformsUtils.merge( [ | |
| THREE.UniformsLib[ "lights" ], | |
| { | |
| u_time: { | |
| type: "f", | |
| value: 1.0 | |
| }, | |
| u_resolution: { | |
| type: "v2", | |
| value: new THREE.Vector2() | |
| }, | |
| u_mouse: { | |
| type: "v2", | |
| value: new THREE.Vector2() | |
| }, | |
| u_fragMouse: { | |
| type: "v2", | |
| value: new THREE.Vector2() | |
| }, | |
| u_texture: { | |
| value: new THREE.TextureLoader().load("ambience.png") // new THREE.VideoTexture( video ) | |
| }, | |
| u_scale: { | |
| type: "v2", | |
| value: new THREE.Vector2() | |
| }, | |
| u_zpos: { | |
| type: "f", | |
| value: 0.0 | |
| } | |
| } | |
| ]); | |
| /* | |
| In vertex shader, add this - | |
| #if NUM_DIR_LIGHTS > 0 | |
| struct DirectionalLight { | |
| vec3 direction; | |
| vec3 color; | |
| int shadow; | |
| float shadowBias; | |
| float shadowRadius; | |
| vec2 shadowMapSize; | |
| }; | |
| uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ]; | |
| #endif | |
| use this to access light as vec3 - | |
| vec3 color = directionalLights[0].color; | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment