Skip to content

Commit

Permalink
fix: reduce lagging on the reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Dec 17, 2023
1 parent 5cccaa9 commit dca5c31
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/core/controls/OrbitControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ const props = withDefaults(defineProps<OrbitControlsProps>(), {
makeDefault: false,
autoRotate: false,
autoRotateSpeed: 2,
enableDamping: false,
enableDamping: true,
dampingFactor: 0.05,
enablePan: true,
keyPanSpeed: 7,
Expand Down
13 changes: 7 additions & 6 deletions src/core/materials/meshReflectionMaterial/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { shallowRef, onBeforeUnmount, watchEffect, toRefs, reactive, computed, useAttrs } from 'vue'
import { shallowRef, onBeforeUnmount, watchEffect, toRefs, shallowReactive, computed, useAttrs } from 'vue'
import { useRenderLoop, useTresContext } from '@tresjs/core'
import type { TresObject } from '@tresjs/core'
import type {
Expand Down Expand Up @@ -171,7 +171,7 @@ const computedBlur = computed(() => {
const hasBlur = computed(() => computedBlur.value[0] > 0 || computedBlur.value[1] > 0)
const state = reactive({
const state = shallowReactive({
reflectorPlane: new Plane(),
normal: new Vector3(),
reflectorWorldPosition: new Vector3(),
Expand All @@ -188,8 +188,6 @@ const state = reactive({
watchEffect(() => {
fbo.value?.texture.dispose()
fbo.value?.dispose()
outputFbo.value?.dispose()
const parameters = {
minFilter: LinearFilter,
Expand Down Expand Up @@ -255,11 +253,13 @@ onLoop(() => {
const parent: TresObject = findMeshByMaterialUuid(scene.value as unknown as TresObject, materialRef.value.uuid)
if (!parent) return
beforeRender(parent)
parent.visible = false // Avoid re-rendering the reflected object
const currentXrEnabled = renderer.value.xr.enabled
const currentShadowAutoUpdate = renderer.value.shadowMap.autoUpdate
console.time('beforeRender')
beforeRender(parent)
console.timeEnd('beforeRender')
renderer.value.shadowMap.autoUpdate = false
renderer.value.setRenderTarget(fbo.value)
Expand All @@ -272,6 +272,7 @@ onLoop(() => {
renderer.value.shadowMap.autoUpdate = currentShadowAutoUpdate
parent.visible = true
renderer.value.setRenderTarget(null)
})
const attrs = useAttrs()
Expand Down

0 comments on commit dca5c31

Please sign in to comment.