pmndrs / react-three-next

React Three Fiber, Threejs, Nextjs starter
https://react-three-next.vercel.app/
MIT License
2.52k stars 342 forks source link

SoftShadows do not work #138

Closed hatchli closed 1 year ago

hatchli commented 1 year ago

Replacing the Dog in the starter code with a simple example of Soft Shadows on a simple cube or sphere demonstrate that Soft Shadows do not work. Contact Shadows are rendered instead.

https://github.com/pmndrs/react-three-next/assets/57643179/ec52da64-fb2d-47c2-baa4-ad6bcf08ce5f

The same code in a starter Vite project function as expected.

https://github.com/pmndrs/react-three-next/assets/57643179/55db7f91-a8f2-4d4b-87ee-0164b0807ea7

Activating Shadows on the element in Layout.jsx

  `<Scene shadows ... />`

The code difference in Example.jsx

import { useFrame } from '@react-three/fiber'
import {... useHelper, SoftShadows, OrbitControls } from '@react-three/drei'
import { useControls } from 'leva'

...

export function Dog(props) {
  const cube = useRef()
  const directionalLight = useRef()
  useHelper(directionalLight, THREE.DirectionalLightHelper, 1)
  const { sunPosition } = useControls('sky', {
    sunPosition: { value: [1, 2, 3] }
  })
  useFrame((state, delta) => {
    cube.current.rotation.y += delta * 0.2
  })

  return <>
    <SoftShadows frustum={4.75} size={0.05} near={9.5} samples={16} rings={11} />

    <OrbitControls makeDefault />

    <directionalLight
      ref={directionalLight}
      position={sunPosition}
      intensity={1.5}
      castShadow
      shadow-mapSize={[1024, 1024]}
      shadow-camera-near={1}
      shadow-camera-far={10}
      shadow-camera-top={5}
      shadow-camera-right={5}
      shadow-camera-bottom={- 5}
      shadow-camera-left={- 5}
    />
    <ambientLight intensity={0.5} />

    <mesh receiveShadow position-y={0} rotation-x={- Math.PI * 0.5} scale={10}>
      <planeGeometry />
      <shadowMaterial />
    </mesh>

    <mesh castShadow position-y={1} position-x={- 2}>
      <sphereGeometry />
      <meshStandardMaterial color="orange" />
    </mesh>
    <mesh ref={cube} castShadow position-y={1} position-x={2} scale={1.5}>
      <boxGeometry />
      <meshStandardMaterial color="mediumpurple" />
    </mesh>
  </>
}