-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from readyplayerme/ACT-32-Reflective-surfaces-…
…in-scene Act 32 reflective surfaces in scene
- Loading branch information
Showing
4 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
69 changes: 69 additions & 0 deletions
69
src/components/FloorReflection/FloorReflection.component.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { FC } from 'react'; | ||
import { MeshReflectorMaterial } from '@react-three/drei'; | ||
|
||
export interface FloorReflectionProps { | ||
resolution?: number; | ||
mixBlur?: number; | ||
mixStrength?: number; | ||
metalness?: number; | ||
blur?: [number, number] | number; | ||
mirror: number; | ||
minDepthThreshold?: number; | ||
maxDepthThreshold?: number; | ||
depthScale?: number; | ||
depthToBlurRatioBias?: number; | ||
distortion?: number; | ||
mixContrast?: number; | ||
reflectorOffset?: number; | ||
roughness?: number; | ||
/** | ||
* The color should match the canvas background color to provide a seamless transition from background to the reflective plane. | ||
*/ | ||
color: string; | ||
} | ||
export const FloorReflection: FC<FloorReflectionProps> = ({ | ||
resolution = 512, | ||
mixBlur = 0.8, | ||
mixStrength = 80, | ||
metalness = 0.5, | ||
blur = [300, 200], | ||
mirror = 1, | ||
minDepthThreshold = 0.4, | ||
maxDepthThreshold = 1.4, | ||
depthScale = 1.2, | ||
depthToBlurRatioBias = 1, | ||
distortion = 0, | ||
mixContrast = 1, | ||
reflectorOffset = 0, | ||
roughness = 1, | ||
color, | ||
...props | ||
}) => ( | ||
<> | ||
<fog attach="fog" args={[color, 4, 8]} /> | ||
<group position={[0, 0, 0]}> | ||
<mesh rotation={[-Math.PI / 2, 0, 0]}> | ||
<planeGeometry args={[20, 10]} /> | ||
<MeshReflectorMaterial | ||
resolution={resolution} | ||
mixBlur={mixBlur} | ||
mixStrength={mixStrength} | ||
metalness={metalness} | ||
blur={blur} | ||
mirror={mirror} | ||
minDepthThreshold={minDepthThreshold} | ||
maxDepthThreshold={maxDepthThreshold} | ||
depthScale={depthScale} | ||
depthToBlurRatioBias={depthToBlurRatioBias} | ||
distortion={distortion} | ||
mixContrast={mixContrast} | ||
reflectorOffset={reflectorOffset} | ||
roughness={roughness} | ||
color={color} | ||
envMapIntensity={0} | ||
{...props} | ||
/> | ||
</mesh> | ||
</group> | ||
</> | ||
); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { FloorReflection } from './FloorReflection.component'; | ||
export type { FloorReflectionProps } from './FloorReflection.component'; |
This file contains 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