pmndrs / drei

🥉 useful helpers for react-three-fiber
https://drei.pmnd.rs/
MIT License
7.83k stars 642 forks source link

Grid not receiving shadow #2012

Open sabinayakc opened 3 days ago

sabinayakc commented 3 days ago

When using the Grid Component, I am trying to cast shadows onto it using a GTLF model. But it doesn't seem to work. Am I missing anything?

Here is my simple code

const GroundGrid: React.FC = () => {
  const gridConfig = {
    cellSize: 0.5,
    cellThickness: 0.5,
    cellColor: '#6f6f6f',
    sectionSize: 3,
    sectionThickness: 1,
    sectionColor: '#9d4b4b',
    fadeDistance: 100,
    fadeStrength: 1,
    followCamera: false,
    infiniteGrid: true
  }
  return <Grid position={[0, -0.01, 0]} args={[10.5, 10.5]} {...gridConfig} receiveShadow/>
}

<Canvas shadows camera={{ position: [2, 3, -6], fov: 45, near: 1, far: 1000 }}>
    <color attach="background" args={[theme==='light' ? '#ffffff' : '#000000']} />
    <directionalLight color={0xffffff} intensity={3} position={[-3, 10, -10]} castShadow />
    <group>
        <Suspense fallback={null}>
            <Gltf src="/models/jump-transformed.glb" position={new Vector3()} castShadow receiveShadow />

        </Suspense>
        <GroundGrid />
    </group>
    <OrbitControls />
</Canvas>

image

However, if I use a planeGeometry it works.

       <mesh rotation={[-Math.PI / 2, 0, 0]} receiveShadow>
              <planeGeometry args={[200, 200]} />
              <meshPhongMaterial color={0xcbcbcb} depthWrite={false} />
            </mesh>

image

How do I enable shadows properly on the Grid itself without having to add another plane geometry?