-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(performance): ACT-1219 performance optimisations #109
base: main
Are you sure you want to change the base?
Changes from all commits
dc959f7
26e9c27
8527e1f
a1b8f4d
13ab6c3
1375d99
e73c4f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,20 +10,21 @@ import { | |
EffectConfiguration, | ||
LightingProps, | ||
MaterialConfiguration, | ||
AnimationsT | ||
AnimationsT, | ||
CanvasConfiguration | ||
} from 'src/types'; | ||
import { BaseCanvas } from 'src/components/BaseCanvas'; | ||
import { AnimationModel, HalfBodyModel, StaticModel, PoseModel, MultipleAnimationModel } from 'src/components/Models'; | ||
import { isValidFormat, triggerCallback } from 'src/services'; | ||
import { Dpr } from '@react-three/fiber'; | ||
import { BrightnessContrast, EffectComposer, HueSaturation, SSAO, Vignette } from '@react-three/postprocessing'; | ||
import { BrightnessContrast, EffectComposer, HueSaturation, N8AO, Vignette } from '@react-three/postprocessing'; | ||
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 Loader from 'src/components/Loader'; | ||
import Bloom from 'src/components/Bloom/Bloom.component'; | ||
import { BlendFunction } from 'postprocessing'; | ||
|
||
import Lights from 'src/components/Lights/Lights.component'; | ||
import { spawnState } from 'src/state/spawnAtom'; | ||
|
||
|
@@ -162,6 +163,10 @@ export interface AvatarProps extends LightingProps, EnvironmentProps, Omit<BaseM | |
onAnimationEnd?: (action: AnimationAction) => void; | ||
controlsMinDistance?: number; | ||
controlsMaxDistance?: number; | ||
/** | ||
* Control properties of the BaseCanvas. | ||
*/ | ||
canvasConfig?: CanvasConfiguration; | ||
} | ||
|
||
/** | ||
|
@@ -209,7 +214,8 @@ const Avatar: FC<AvatarProps> = ({ | |
onAnimationEnd, | ||
materialConfig, | ||
controlsMinDistance, | ||
controlsMaxDistance | ||
controlsMaxDistance, | ||
canvasConfig | ||
}) => { | ||
const setSpawnState = useSetAtom(spawnState); | ||
|
||
|
@@ -336,6 +342,7 @@ const Avatar: FC<AvatarProps> = ({ | |
style={style} | ||
dpr={dpr} | ||
className={className} | ||
canvasConfig={canvasConfig} | ||
> | ||
<Environment environment={environment} enablePostProcessing={enablePostProcessing} /> | ||
<CameraControls | ||
|
@@ -348,28 +355,17 @@ const Avatar: FC<AvatarProps> = ({ | |
/> | ||
{AvatarModel} | ||
{children} | ||
{shadows && <ContactShadows position={[0, 0, 0]} opacity={2} scale={10} blur={1.0} far={1.0} />} | ||
{shadows && ( | ||
<ContactShadows opacity={effects?.ambientOcclusion ? 1 : 2} scale={4} blur={2} far={1.0} resolution={256} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ao and shadows don't behave well together, change the oopacity values depending on if its enabled or not. |
||
)} | ||
{background?.src && <Box {...background} />} | ||
{capture && <Capture {...capture} />} | ||
{background?.color && <BackgroundColor color={background.color} />} | ||
{enablePostProcessing && ( | ||
<EffectComposer autoClear multisampling={4} enableNormalPass={effects?.ambientOcclusion}> | ||
<EffectComposer autoClear enableNormalPass={effects?.ambientOcclusion}> | ||
<> | ||
{effects?.ambientOcclusion && ( | ||
<SSAO | ||
blendFunction={BlendFunction.MULTIPLY} | ||
distanceScaling={false} | ||
radius={0.08} | ||
bias={0.01} | ||
intensity={3} | ||
samples={31} | ||
worldDistanceThreshold={24} | ||
worldDistanceFalloff={0} | ||
worldProximityThreshold={0} | ||
worldProximityFalloff={6} | ||
fade={0.02} | ||
rings={8} | ||
/> | ||
<N8AO quality="performance" aoRadius={5} distanceFalloff={0.25} intensity={3} screenSpaceRadius halfRes /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing with a more performant ao |
||
)} | ||
{effects?.bloom && ( | ||
<Bloom | ||
|
@@ -381,8 +377,8 @@ const Avatar: FC<AvatarProps> = ({ | |
/> | ||
)} | ||
{effects?.vignette && <Vignette eskil={false} offset={0.5} darkness={0.5} />} | ||
<BrightnessContrast brightness={0.025} contrast={0.25} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently bugged alongside the ao causing white flickering, will see if there is a fix available rather than outright removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reintroduced with a small increase instead. |
||
<HueSaturation hue={0} saturation={-0.2} /> | ||
<BrightnessContrast brightness={0.025} contrast={0.1} /> | ||
<HueSaturation hue={0} saturation={-0.1} /> | ||
</> | ||
</EffectComposer> | ||
)} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,6 @@ const Lights: FC<LightingProps> = (lightingProps) => { | |
angle={LIGHT_CONFIG.keyLightAngle} | ||
color={keyLightColor} | ||
intensity={keyLightIntensity} | ||
castShadow | ||
/> | ||
{/* Lift light that creates soft light on body and shoes. */} | ||
<spotLight | ||
|
@@ -93,7 +92,6 @@ const Lights: FC<LightingProps> = (lightingProps) => { | |
angle={LIGHT_CONFIG.keyLightAngle} | ||
color={keyLightColor} | ||
intensity={keyLightIntensity * 0.25} | ||
castShadow | ||
/> | ||
{/* Silhouette light on arms and legs. */} | ||
<spotLight | ||
|
@@ -102,7 +100,6 @@ const Lights: FC<LightingProps> = (lightingProps) => { | |
angle={LIGHT_CONFIG.silhouetteLightAngle} | ||
color={keyLightColor} | ||
intensity={keyLightIntensity * 0.25} | ||
castShadow | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed castShadow from lights which shadows don't have an effect. |
||
/> | ||
</group> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,9 +67,6 @@ export const Model: FC<ModelProps> = ({ | |
|
||
if ((node as Mesh).isMesh) { | ||
node.castShadow = true; | ||
} | ||
|
||
if (node.type === 'SkinnedMesh') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As attachments are Mesh, lets not differentiate between mesh and skinnedmesh. |
||
node.receiveShadow = true; | ||
} | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ const Shadow: FC = () => ( | |
</group> | ||
); | ||
|
||
export default Shadow; | ||
export default Shadow; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alpha can be turned off for scenes which don't need.