Skip to content

Commit

Permalink
fix(performance): ACT-1219 shadow and ao tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarvv committed Dec 18, 2024
1 parent 489c1d9 commit 1db4087
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 52 deletions.
3 changes: 3 additions & 0 deletions src/App/components/Nova.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export const AvatarNova: FC = () => {
style={{ background: 'rgb(9,20,26)' }}
fov={45}
cameraInitialDistance={CAMERA.CONTROLS.FULL_BODY.MAX_DISTANCE}
effects={{
ambientOcclusion: false
}}
>
<StatsGl />
</Avatar>
Expand Down
25 changes: 6 additions & 19 deletions src/components/Avatar/Avatar.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ 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 { 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';

Expand Down Expand Up @@ -330,28 +330,15 @@ const Avatar: FC<AvatarProps> = ({
/>
{AvatarModel}
{children}
{shadows && <ContactShadows position={[0, 0, 0]} opacity={2} scale={10} blur={1.0} far={1.0} />}
{shadows && <ContactShadows position={[0, 0, 0]} opacity={2} scale={10} blur={1.0} far={1.0} resolution={256} />}
{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 />
)}
{effects?.bloom && (
<Bloom
Expand All @@ -363,7 +350,7 @@ const Avatar: FC<AvatarProps> = ({
/>
)}
{effects?.vignette && <Vignette eskil={false} offset={0.5} darkness={0.5} />}
<BrightnessContrast brightness={0.025} contrast={0.25} />

<HueSaturation hue={0} saturation={-0.2} />
</>
</EffectComposer>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Background/Box/Box.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const Box: FC<Background> = ({ src = '', ...baseProps }) => {
const texture = useLoader(TextureLoader, src);

return (
<mesh ref={ref} castShadow receiveShadow {...baseProps}>
<mesh ref={ref} {...baseProps}>
<boxGeometry />
<meshPhysicalMaterial map={texture} />
</mesh>
Expand Down
5 changes: 2 additions & 3 deletions src/components/BaseCanvas/BaseCanvas.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ export const BaseCanvas: FC<BaseCanvasProps> = ({
fov = 50,
position = new Vector3(0, 0, 5),
style,
dpr = [BASE_DPR * 0.5, 2],
dpr = [BASE_DPR * 0.5, BASE_DPR * 0.75],
className
}) => (
<Canvas
key={fov}
className={`${styles['base-canvas']} ${className ?? ''}`}
shadows="soft"
gl={{
preserveDrawingBuffer: true,
alpha: true,
toneMapping: ACESFilmicToneMapping,
toneMappingExposure: 1.8
toneMappingExposure: 1.8,
}}
flat={enablePostProcessing}
dpr={dpr}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Exhibit/Exhibit.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const Exhibit: FC<ExhibitProps> = ({
<BaseCanvas position={position} style={style} className={className}>
<Suspense fallback={null}>
<ambientLight intensity={0.5} />
<spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} shadow-mapSize={[512, 512]} castShadow />
<spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} />
<PresentationControls
global
config={{ mass: 2, tension: 500 }}
Expand Down
5 changes: 0 additions & 5 deletions src/components/Lights/Lights.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const Lights: FC<LightingProps> = (lightingProps) => {
angle={LIGHT_CONFIG.fillLightAngle}
color={fillLightColor}
intensity={fillLightIntensity}
castShadow
/>
{/* Back light that by default creates light warm rim on the left face side. */}
<spotLight
Expand All @@ -75,7 +74,6 @@ const Lights: FC<LightingProps> = (lightingProps) => {
angle={LIGHT_CONFIG.backLightAngle}
color={backLightColor}
intensity={backLightIntensity}
castShadow
/>
{/* Key light that creates soft face light. */}
<spotLight
Expand All @@ -84,7 +82,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
Expand All @@ -93,7 +90,6 @@ const Lights: FC<LightingProps> = (lightingProps) => {
angle={LIGHT_CONFIG.keyLightAngle}
color={keyLightColor}
intensity={keyLightIntensity * 0.25}
castShadow
/>
{/* Silhouette light on arms and legs. */}
<spotLight
Expand All @@ -102,7 +98,6 @@ const Lights: FC<LightingProps> = (lightingProps) => {
angle={LIGHT_CONFIG.silhouetteLightAngle}
color={keyLightColor}
intensity={keyLightIntensity * 0.25}
castShadow
/>
</group>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const EnvironmentModel: FC<EnvironmentModelProps> = ({ environment, scale
if (node.type === 'Mesh') {
return (
<mesh
receiveShadow
key={node.name}
scale={scale}
position={transform.position}
Expand Down
9 changes: 3 additions & 6 deletions src/components/Models/Model/Model.component.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC, Ref, useEffect, useState, useCallback, useMemo } from 'react';
import { Group, Mesh } from 'three';
import { Group } from 'three';
import { normaliseMaterialsConfig, triggerCallback, usePersistantRotation } from 'src/services';
import { useThree } from '@react-three/fiber';
import { hasWindow } from 'src/services/Client.service';
Expand Down Expand Up @@ -65,12 +65,8 @@ export const Model: FC<ModelProps> = ({
scene.traverse((object) => {
const node = object;

if ((node as Mesh).isMesh) {
node.castShadow = true;
}

if (node.type === 'SkinnedMesh') {
node.receiveShadow = true;
node.frustumCulled = false;
}
});

Expand Down Expand Up @@ -110,3 +106,4 @@ export const Model: FC<ModelProps> = ({
</group>
);
};

12 changes: 0 additions & 12 deletions src/components/Shadow/Shadow.component.tsx

This file was deleted.

4 changes: 0 additions & 4 deletions src/services/Models.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,6 @@ function buildFallback(nodes: Nodes, transform: Transform = new Transform()): JS
if (node.type === 'SkinnedMesh') {
return (
<skinnedMesh
castShadow
receiveShadow
key={node.name}
scale={transform.scale}
position={transform.position}
Expand All @@ -416,8 +414,6 @@ function buildFallback(nodes: Nodes, transform: Transform = new Transform()): JS
self.parent = node.parent;
return () => parent.remove(self);
}}
castShadow
receiveShadow
key={node.name}
scale={node.scale}
position={node.position}
Expand Down

0 comments on commit 1db4087

Please sign in to comment.