Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
add postprocessing editor back (#10472)
Browse files Browse the repository at this point in the history
* add parameter back to postprocessing editor

* Fix Performance State bug, Fix PostP editing, Fix Select keys

* fix test

* fix slider

* modify fix to be  more general

* Fix effect ordering

---------

Co-authored-by: Daniel Belmes <[email protected]>
Co-authored-by: Michael Estes <[email protected]>
  • Loading branch information
3 people authored Jun 27, 2024
1 parent 5a2972c commit 76cec33
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
4 changes: 4 additions & 0 deletions packages/spatial/src/renderer/PerformanceState.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import sinon from 'sinon'
import { destroyEngine } from '@etherealengine/ecs'
import { getMutableState, getState, useHookstate } from '@etherealengine/hyperflux'

import { EngineState } from '../EngineState'
import { createEngine, initializeSpatialEngine } from '../initializeEngine'
import { PerformanceManager, PerformanceState } from './PerformanceState'
import { RendererState } from './RendererState'
Expand Down Expand Up @@ -63,6 +64,9 @@ describe('PerformanceState', () => {
}
dpr = globalThis.window.devicePixelRatio
globalThis.window.devicePixelRatio = 3
getMutableState(EngineState).isEditing.set(false)
getMutableState(RendererState).automatic.set(true)
getMutableState(PerformanceState).enabled.set(true)
})

after(() => {
Expand Down
14 changes: 7 additions & 7 deletions packages/spatial/src/renderer/PerformanceState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const PerformanceState = defineState({
name: 'PerformanceState',

initial: () => ({
enabled: true,
enabled: false,

isMobileGPU: false,
gpuTier: 3 as PerformanceTier,
Expand Down Expand Up @@ -188,27 +188,27 @@ export const PerformanceState = defineState({
})
}

useEffect(() => {
performanceState.enabled.set(!engineState.isEditing.value && engineSettings.automatic.value)
}, [engineState.isEditing, engineSettings.automatic])

useEffect(() => {
recreateEMA()
}, [performanceState.targetFPS])

useEffect(() => {
if (engineState.isEditing.value) return
if (!performanceState.enabled.value) return

const performanceTier = performanceState.gpuTier.value
const settings = tieredSettings[performanceTier]
engineSettings.merge(settings.engine)
renderSettings.merge(settings.render)
}, [performanceState.gpuTier])
}, [performanceState.gpuTier, performanceState.enabled])

useEffect(() => {
recreateEMA()
performanceState.performanceSmoothingAccum.set(0)
}, [performanceState.gpuPerformanceOffset, performanceState.cpuPerformanceOffset])

useEffect(() => {
performanceState.enabled.set(!engineState.isEditing.value && engineSettings.automatic.value)
}, [engineState.isEditing, engineSettings.automatic])
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const PostProcessingReactor = (props: { entity: Entity; rendererEntity: Entity }
}
} else {
renderer.value.effectComposer.removePass(renderer.value.effectComposer.EffectPass as EffectPass)
return
}

//always have the smaa effect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const PostProcessingSettingsEditor: EditorComponentType = (props) => {
min={effectSettingState.min}
max={effectSettingState.max}
step={effectSettingState.step}
value={effectSettingState.value}
value={effectSettingValue}
onChange={updateProperty(PostProcessingComponent, `effects.${effectName}.${property}` as any)}
onRelease={commitProperty(PostProcessingComponent, `effects.${effectName}.${property}` as any)}
/>
Expand All @@ -140,7 +140,7 @@ export const PostProcessingSettingsEditor: EditorComponentType = (props) => {
renderVal = (
<BooleanInput
onChange={commitProperty(PostProcessingComponent, `effects.${effectName}.${property}` as any)}
value={effectSettingState.value}
value={effectSettingValue}
/>
)
break
Expand All @@ -158,7 +158,7 @@ export const PostProcessingSettingsEditor: EditorComponentType = (props) => {
<SelectInput
options={BlendFunctionSelect}
onChange={commitProperty(PostProcessingComponent, `effects.${effectName}.${property}` as any)}
value={effectSettingState.value}
value={effectSettingValue}
/>
)
break
Expand All @@ -168,7 +168,7 @@ export const PostProcessingSettingsEditor: EditorComponentType = (props) => {
<SelectInput
options={VignetteTechniqueSelect}
onChange={commitProperty(PostProcessingComponent, `effects.${effectName}.${property}` as any)}
value={effectSettingState.value}
value={effectSettingValue}
/>
)
break
Expand Down Expand Up @@ -202,7 +202,7 @@ export const PostProcessingSettingsEditor: EditorComponentType = (props) => {
case PropertyTypes.Color:
renderVal = (
<ColorInput
value={new Color(effectSettingState.value)}
value={new Color(effectSettingValue)}
onChange={(value) =>
commitProperty(PostProcessingComponent, `effects.${effectName}.${property}` as any)('#' + value)
}
Expand All @@ -215,7 +215,7 @@ export const PostProcessingSettingsEditor: EditorComponentType = (props) => {
<SelectInput
options={KernelSizeSelect}
onChange={commitProperty(PostProcessingComponent, `effects.${effectName}.${property}` as any)}
value={effectSettingState.value}
value={effectSettingValue}
/>
)
break
Expand All @@ -224,7 +224,7 @@ export const PostProcessingSettingsEditor: EditorComponentType = (props) => {
<SelectInput
options={EdgeDetectionMode}
onChange={commitProperty(PostProcessingComponent, `effects.${effectName}.${property}` as any)}
value={effectSettingState.value}
value={effectSettingValue}
/>
)
break
Expand All @@ -234,7 +234,7 @@ export const PostProcessingSettingsEditor: EditorComponentType = (props) => {
<SelectInput
options={PredicationMode}
onChange={commitProperty(PostProcessingComponent, `effects.${effectName}.${property}` as any)}
value={effectSettingState.value}
value={effectSettingValue}
/>
)
break
Expand Down Expand Up @@ -264,7 +264,7 @@ export const PostProcessingSettingsEditor: EditorComponentType = (props) => {
}

const renderEffects = () => {
const items = Object.keys(PostProcessingEffectState).map((effect) => {
const items = Object.keys(getState(PostProcessingEffectState)).map((effect) => {
return (
<div className="py-1" key={effect}>
<Checkbox
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/primitives/tailwind/Select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const Select = <T extends OptionValueType>({
<ul className={twMerge('max-h-40 overflow-auto [&>li]:px-4 [&>li]:py-2', menuClassname)}>
{filteredOptions.value.map((option) => (
<li
key={option.value}
key={option.label + option.value}
value={option.value}
className={twMerge(
'cursor-pointer px-4 py-2 text-theme-secondary',
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/primitives/tailwind/Slider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const Slider = ({ value, min = 0, max = 100, step = 1, width = 200, onChange, on
max={max}
value={value}
onChange={handleChange}
onBlur={() => onRelease(value)}
onPointerUp={() => onRelease(value)}
step={step}
type="range"
style={sliderStyle}
Expand Down

0 comments on commit 76cec33

Please sign in to comment.