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

8134 post processing settings are not reactive #8262

Merged
merged 13 commits into from
Jul 13, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Ethereal Engine. All Rights Reserved.
*/

import { debounce } from 'lodash'
import React, { useEffect, useState } from 'react'
import React, { useCallback, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Euler, Quaternion } from 'three'

Expand Down Expand Up @@ -92,7 +92,7 @@ export const PortalNodeEditor: EditorComponentType = (props) => {
setBufferUrl(url)
}

const updateCubeMapBakeDebounced = debounce(updateCubeMapBake, 500) //ms
const updateCubeMapBakeDebounced = useCallback(debounce(updateCubeMapBake, 500), []) //ms

useEffect(() => {
updateCubeMapBakeDebounced()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { useTranslation } from 'react-i18next'
import { Color } from 'three'

import { useComponent } from '@etherealengine/engine/src/ecs/functions/ComponentFunctions'
import { configureEffectComposer } from '@etherealengine/engine/src/renderer/functions/configureEffectComposer'
import { debouncedConfigureEffectComposer } from '@etherealengine/engine/src/renderer/functions/configureEffectComposer'
import { PostProcessingComponent } from '@etherealengine/engine/src/scene/components/PostProcessingComponent'
import { Effects } from '@etherealengine/engine/src/scene/constants/PostProcessing'

Expand Down Expand Up @@ -275,11 +275,12 @@ export const PostProcessingSettingsEditor: EditorComponentType = (props) => {
return value
}

// trigger re-render - @todo find out why just setting the value doesn't trigger the reactor
// action: debounced the set property value

const setPropertyValue = (prop, val) => {
prop.set(val)

// trigger re-render - @todo find out why just setting the value doesnt trigger the reactor
configureEffectComposer()
debouncedConfigureEffectComposer()
}

const renderProperty = (propertyDetail: EffectPropertyDetail, propertyPath: string[], index: number) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Ethereal Engine. All Rights Reserved.
*/

import { debounce } from 'lodash'
import React, { useEffect, useState } from 'react'
import React, { useCallback, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'

import { Engine } from '@etherealengine/engine/src/ecs/classes/Engine'
import { getComponent, setComponent, useComponent } from '@etherealengine/engine/src/ecs/functions/ComponentFunctions'
import { getComponent, useComponent } from '@etherealengine/engine/src/ecs/functions/ComponentFunctions'
import {
LocalTransformComponent,
TransformComponent
Expand Down Expand Up @@ -66,7 +66,7 @@ export const ScenePreviewCameraNodeEditor: EditorComponentType = (props) => {
setBufferUrl(url)
}

const updateCubeMapBakeDebounced = debounce(updateScenePreview, 500) //ms
const updateCubeMapBakeDebounced = useCallback(debounce(updateScenePreview, 500), []) //ms

useEffect(() => {
updateCubeMapBakeDebounced()
Expand Down
22 changes: 12 additions & 10 deletions packages/engine/src/renderer/functions/configureEffectComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

import { debounce } from 'lodash'
import {
BlendFunction,
BloomEffect,
DepthDownsamplingPass,
EffectComposer,
EffectPass,
Expand All @@ -40,11 +40,18 @@ import { getState } from '@etherealengine/hyperflux'

import { Engine } from '../../ecs/classes/Engine'
import { EngineState } from '../../ecs/classes/EngineState'
import { SceneState } from '../../ecs/classes/Scene'
import { getComponent } from '../../ecs/functions/ComponentFunctions'
import { PostProcessingComponent } from '../../scene/components/PostProcessingComponent'
import { EffectMap, EffectPropsSchema, Effects } from '../../scene/constants/PostProcessing'
import { RendererState } from '../RendererState'
import { EffectComposerWithSchema, EngineRenderer, PostProcessingSettingsState } from '../WebGLRendererSystem'
import { EffectComposerWithSchema, EngineRenderer } from '../WebGLRendererSystem'
import { changeRenderMode } from './changeRenderMode'

// can use both as needed
export const debouncedConfigureEffectComposer = debounce(() => {
HexaField marked this conversation as resolved.
Show resolved Hide resolved
configureEffectComposer()
}, 200) // in ms

export const configureEffectComposer = (remove?: boolean, camera: PerspectiveCamera = Engine.instance.camera): void => {
if (!EngineRenderer.instance) return

Expand All @@ -64,14 +71,10 @@ export const configureEffectComposer = (remove?: boolean, camera: PerspectiveCam
return
}

const postProcessingEnabled = getState(RendererState).usePostProcessing
if (!postProcessingEnabled && !getState(EngineState).isEditor) return

const postprocessing = getState(PostProcessingSettingsState)
const postprocessing = getComponent(getState(SceneState).sceneEntity, PostProcessingComponent)
if (!postprocessing.enabled) return

const postProcessingEffects = postprocessing.effects as EffectPropsSchema

const effects: any[] = []
const effectKeys = Object.keys(EffectMap)

Expand Down Expand Up @@ -144,7 +147,6 @@ export const configureEffectComposer = (remove?: boolean, camera: PerspectiveCam
effects.push(eff)
}
}

if (effects.length) {
if (useVelocityDepthNormalPass) composer.addPass(velocityDepthNormalPass)

Expand All @@ -156,9 +158,9 @@ export const configureEffectComposer = (remove?: boolean, camera: PerspectiveCam
})
effects.push(textureEffect)
}
console.log('DEBUG effects', effects)
HexaField marked this conversation as resolved.
Show resolved Hide resolved

composer.addPass(new EffectPass(camera, ...effects))
}

if (getState(EngineState).isEditor) changeRenderMode()
}