three.js - Lights not effecting InstanceBufferGeometry as expected -
i attempting use point light instancebuffergeometry. shadermaterial i'm using implements of shaderchunks make lambert shader modified vertex shader offset , orientate instances within instancebuffergeometry.
my shader lights mesh using normal geometry fine. however, when lighting instancebuffergeometry same shader doesn't respond point light in same way. doesn't take on color of point light instance, although respond values passed "emissive" , "ambient" uniforms - setting emissive 0xff0000 example shade flat red.
here fiddle: https://jsfiddle.net/dsxmdgx5/2/
the red feather in example mesh normal geometry. other darker feathers mesh instancebuffergeometry. i'm expecting these match (the dark feathers should respond red point light , render red, mesh normal geometry).
i'm not sure if i'm confused how emissive/ambient uniforms working in conjunction colors set on pointlight or if i've made mistake in shader?
in addition fiddle, here uniforms have setup:
var defines = {}; defines[ "use_map" ] = ""; var uniforms = three.uniformsutils.merge( [ three.uniformslib[ "common" ], three.uniformslib[ "fog" ], three.uniformslib[ "lights" ], three.uniformslib[ "shadowmap" ], { "ambient" : { type: "c", value: new three.color( 0xffffff ) }, "emissive" : { type: "c", value: new three.color( 0x454545 ) }, "wraprgb" : { type: "v3", value: new three.vector3( 1, 1, 1 ) } } ]); uniforms.map = { type: 't', value: sourcemesh.material.map }; var shadermaterial = new three.shadermaterial( { vertexshader: vertexshaderibglight, defines : defines, uniforms : uniforms, fragmentshader: fragmentshaderibglight, transparent: true, lights: true }); and vertex shader:
const vertexshaderibglight = ` uniform vec3 diffuse; uniform vec3 emissive; uniform float opacity; varying vec3 vlightfront; #ifdef double_sided varying vec3 vlightback; #endif ${three.shaderchunk['common']} ${three.shaderchunk['uv_pars_vertex']} ${three.shaderchunk['uv2_pars_vertex']} ${three.shaderchunk['envmap_pars_vertex']} ${three.shaderchunk['bsdfs']} ${three.shaderchunk['lights_pars']} ${three.shaderchunk['color_pars_vertex']} ${three.shaderchunk['morphtarget_pars_vertex']} ${three.shaderchunk['skinning_pars_vertex']} ${three.shaderchunk['shadowmap_pars_vertex']} ${three.shaderchunk['logdepthbuf_pars_vertex']} ${three.shaderchunk['clipping_planes_pars_vertex']} precision highp float; attribute vec3 offset; attribute vec4 orientation; void main() { ${three.shaderchunk['uv_vertex']} ${three.shaderchunk['uv2_vertex']} ${three.shaderchunk['color_vertex']} ${three.shaderchunk['beginnormal_vertex']} ${three.shaderchunk['morphnormal_vertex']} ${three.shaderchunk['skinbase_vertex']} ${three.shaderchunk['skinnormal_vertex']} ${three.shaderchunk['defaultnormal_vertex']} ${three.shaderchunk['begin_vertex']} ${three.shaderchunk['morphtarget_vertex']} ${three.shaderchunk['skinning_vertex']} ${three.shaderchunk['project_vertex']} //begin custom vertex shader code vec3 vposition = transformed; vec3 vcv = cross(orientation.xyz, vposition); vposition = vcv * (2.0 * orientation.w) + (cross(orientation.xyz, vcv) * 2.0 + vposition); mvposition = modelviewmatrix * vec4( offset + vposition, 1.0 ); gl_position = projectionmatrix * mvposition; //end custom vertex shader code ${three.shaderchunk['logdepthbuf_vertex']} ${three.shaderchunk['clipping_planes_vertex']} ${three.shaderchunk['worldpos_vertex']} ${three.shaderchunk['envmap_vertex']} ${three.shaderchunk['lights_lambert_vertex']} ${three.shaderchunk['shadowmap_vertex']} } `; thank you help!
Comments
Post a Comment