UNPKG

glodrei

Version:

useful add-ons for react-three-fiber

53 lines (45 loc) 1.32 kB
--- title: MeshRefractionMaterial sourcecode: src/core/MeshRefractionMaterial.tsx --- <Grid cols={4}> <li> <Codesandbox id="zqrreo" /> </li> </Grid> A convincing Glass/Diamond refraction material. ```tsx type MeshRefractionMaterialProps = JSX.IntrinsicElements['shaderMaterial'] & { /** Environment map */ envMap: THREE.CubeTexture | THREE.Texture /** Number of ray-cast bounces, it can be expensive to have too many, 2 */ bounces?: number /** Refraction index, 2.4 */ ior?: number /** Fresnel (strip light), 0 */ fresnel?: number /** RGB shift intensity, can be expensive, 0 */ aberrationStrength?: number /** Color, white */ color?: ReactThreeFiber.Color /** If this is on it uses fewer ray casts for the RGB shift sacrificing physical accuracy, true */ fastChroma?: boolean } ``` If you want it to reflect other objects in the scene you best pair it with a cube-camera. ```jsx <CubeCamera> {(texture) => ( <mesh geometry={diamondGeometry} {...props}> <MeshRefractionMaterial envMap={texture} /> </mesh> )} </CubeCamera> ``` Otherwise just pass it an environment map. ```jsx const texture = useLoader(RGBELoader, "/textures/royal_esplanade_1k.hdr") return ( <mesh geometry={diamondGeometry} {...props}> <MeshRefractionMaterial envMap={texture} /> ```