Skip to content

Commit

Permalink
fix: add bounding sphere to grass shader demo (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac-mason authored Aug 26, 2024
1 parent dd07011 commit 1a56185
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions demos/grass-shader/src/Grass.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,20 @@ export default function Grass({ options = { bW: 0.12, bH: 1, joints: 5 }, width
geo.computeVertexNormals()
return geo
}, [width])
useFrame(state => (materialRef.current.uniforms.time.value = state.clock.elapsedTime / 4))
const boundingSphere = useMemo(() => {
return new THREE.Sphere(new THREE.Vector3(), (Math.sqrt(2) * width) / 2)
}, [width])

useFrame((state) => (materialRef.current.uniforms.time.value = state.clock.elapsedTime / 4))

return (
<group {...props}>
<mesh>
<instancedBufferGeometry index={baseGeom.index} attributes-position={baseGeom.attributes.position} attributes-uv={baseGeom.attributes.uv}>
<instancedBufferGeometry
index={baseGeom.index}
attributes-position={baseGeom.attributes.position}
attributes-uv={baseGeom.attributes.uv}
boundingSphere={boundingSphere}>
<instancedBufferAttribute attach="attributes-offset" args={[new Float32Array(attributeData.offsets), 3]} />
<instancedBufferAttribute attach="attributes-orientation" args={[new Float32Array(attributeData.orientations), 4]} />
<instancedBufferAttribute attach="attributes-stretch" args={[new Float32Array(attributeData.stretches), 1]} />
Expand Down

0 comments on commit 1a56185

Please sign in to comment.