From 2acda6f6ee7b8ae523bdcafa41e847ab492f59d1 Mon Sep 17 00:00:00 2001 From: Elar Date: Tue, 20 Feb 2024 14:39:48 +0200 Subject: [PATCH] feat: add soft shadows --- src/components/Avatar/Avatar.component.tsx | 4 ++-- src/components/Avatar/Avatar.stories.tsx | 2 +- src/components/Avatar/Examples.stories.tsx | 2 +- src/components/Lights/Lights.component.tsx | 15 ++++++++++----- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/components/Avatar/Avatar.component.tsx b/src/components/Avatar/Avatar.component.tsx index 9dd24881..1bf59b1d 100644 --- a/src/components/Avatar/Avatar.component.tsx +++ b/src/components/Avatar/Avatar.component.tsx @@ -1,5 +1,6 @@ import React, { Suspense, FC, useMemo, CSSProperties, ReactNode, useEffect } from 'react'; import { Vector3 } from 'three'; +import { ContactShadows } from "@react-three/drei"; import { CameraControls } from 'src/components/Scene/CameraControls.component'; import { Environment } from 'src/components/Scene/Environment.component'; import { BaseModelProps, EnvironmentProps, SpawnState, EffectConfiguration, LightingProps } from 'src/types'; @@ -12,7 +13,6 @@ import { Provider, useSetAtom } from 'jotai'; import Capture, { CaptureType } from 'src/components/Capture/Capture.component'; import { Box, Background } from 'src/components/Background/Box/Box.component'; import { BackgroundColor } from 'src/components/Background'; -import Shadow from 'src/components/Shadow/Shadow.component'; import Loader from 'src/components/Loader'; import Bloom from 'src/components/Bloom/Bloom.component'; import { BlendFunction } from 'postprocessing'; @@ -260,7 +260,7 @@ const Avatar: FC = ({ /> {AvatarModel} {children} - {shadows && } + {shadows && } {background?.src && } {capture && } {background?.color && } diff --git a/src/components/Avatar/Avatar.stories.tsx b/src/components/Avatar/Avatar.stories.tsx index 94349434..c0f10a68 100644 --- a/src/components/Avatar/Avatar.stories.tsx +++ b/src/components/Avatar/Avatar.stories.tsx @@ -104,7 +104,7 @@ export const Showcase: StoryFn = (args: AvatarProps & { ambientOc return ( - + ); }; diff --git a/src/components/Avatar/Examples.stories.tsx b/src/components/Avatar/Examples.stories.tsx index 58f1f7f7..6b6d02d1 100644 --- a/src/components/Avatar/Examples.stories.tsx +++ b/src/components/Avatar/Examples.stories.tsx @@ -98,7 +98,7 @@ FloatingSparkles.argTypes = { export const SpawnEffectAndAnimation: StoryFn = (args) => ( - + ); SpawnEffectAndAnimation.args = { diff --git a/src/components/Lights/Lights.component.tsx b/src/components/Lights/Lights.component.tsx index 621e9059..96fe5945 100644 --- a/src/components/Lights/Lights.component.tsx +++ b/src/components/Lights/Lights.component.tsx @@ -15,14 +15,14 @@ export const LIGHT_CONFIG = Object.freeze({ silhouetteLightPosition: new Vector3(-1.5, 0.1, -1.5), defaultProps: { keyLightIntensity: 1.2, - keyLightColor: '#FFFFFF', fillLightIntensity: 0.8, - fillLightColor: '#6794FF', - fillLightPosition: new Vector3(-0.5, 1.6, -0.5), backLightIntensity: 2.2, - backLightColor: '#FFB878', + fillLightPosition: new Vector3(-0.5, 1.6, -0.5), backLightPosition: new Vector3(0.5, 1.6, -1.0), - lightTarget: new Vector3(0.0, 1.7, 0.0) + lightTarget: new Vector3(0.0, 1.7, 0.0), + keyLightColor: '#FFFFFF', + fillLightColor: '#6794FF', + backLightColor: '#FFB878', } as Required }); @@ -66,6 +66,7 @@ const Lights: FC = (lightingProps) => { angle={LIGHT_CONFIG.fillLightAngle} color={fillLightColor} intensity={fillLightIntensity} + castShadow /> {/* Back light that by default creates light warm rim on the left face side. */} = (lightingProps) => { angle={LIGHT_CONFIG.backLightAngle} color={backLightColor} intensity={backLightIntensity} + castShadow /> {/* Key light that creates soft face light. */} = (lightingProps) => { angle={LIGHT_CONFIG.keyLightAngle} color={keyLightColor} intensity={keyLightIntensity} + castShadow /> {/* Lift light that creates soft light on body and shoes. */} = (lightingProps) => { angle={LIGHT_CONFIG.keyLightAngle} color={keyLightColor} intensity={keyLightIntensity * 0.25} + castShadow /> {/* Silhouette light on arms and legs. */} = (lightingProps) => { angle={LIGHT_CONFIG.silhouetteLightAngle} color={keyLightColor} intensity={keyLightIntensity * 0.25} + castShadow /> {/* Dummy directional light for shadow casting from behind avatar. */}