Skip to content

Commit 78b0bb7

Browse files
authored
chore: removal of default prop values (#163)
* chore: removed prop defaults for scanline effect, improved blendMode watcher * - removed defaults from chromatic aberration effect - added workaround * remove default prop values from HueSaturationPmndrs component * chore: removed default prop values for NoisePmndrs component * chore: removed default prop values for VignettePmndrs component
1 parent 0ee8267 commit 78b0bb7

File tree

5 files changed

+42
-34
lines changed

5 files changed

+42
-34
lines changed

src/core/pmndrs/ChromaticAberrationPmndrs.vue

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<script lang="ts" setup>
2-
import type { BlendFunction } from 'postprocessing'
32
import { ChromaticAberrationEffect } from 'postprocessing'
4-
import { Vector2 } from 'three'
53
import { makePropWatchers } from '../../util/prop'
64
import { useEffectPmndrs } from './composables/useEffectPmndrs'
5+
import type { Vector2 } from 'three'
6+
import type { BlendFunction } from 'postprocessing'
77
88
export interface ChromaticAberrationPmndrsProps {
99
/**
@@ -30,13 +30,21 @@ export interface ChromaticAberrationPmndrsProps {
3030
const props = withDefaults(
3131
defineProps<ChromaticAberrationPmndrsProps>(),
3232
{
33-
offset: () => new Vector2(0.01, 0.01),
34-
radialModulation: false,
35-
modulationOffset: 0.15,
33+
radialModulation: undefined,
3634
},
3735
)
3836
39-
const { pass, effect } = useEffectPmndrs(() => new ChromaticAberrationEffect(props), props)
37+
const plainEffect = new ChromaticAberrationEffect()
38+
39+
const { pass, effect } = useEffectPmndrs(() => new ChromaticAberrationEffect({
40+
...props,
41+
// Unfortunately, these defaults must be set this way as the type in postprocessing is not correct.
42+
// The arguments are optional in the actual constructor, but not in the type.
43+
radialModulation: props.radialModulation ?? plainEffect.radialModulation,
44+
modulationOffset: props.modulationOffset ?? plainEffect.modulationOffset,
45+
}), props)
46+
47+
plainEffect.dispose()
4048
4149
defineExpose({ pass, effect })
4250

src/core/pmndrs/HueSaturationPmndrs.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ export interface HueSaturationPmndrsProps {
2323
blendFunction?: BlendFunction
2424
}
2525
26-
const props = withDefaults(
27-
defineProps<HueSaturationPmndrsProps>(),
28-
{
29-
saturation: 0.0,
30-
hue: 0.0,
31-
},
32-
)
26+
const props = defineProps<HueSaturationPmndrsProps>()
3327
3428
const { pass, effect } = useEffectPmndrs(() => new HueSaturationEffect(props), props)
3529

src/core/pmndrs/NoisePmndrs.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import { useLoop } from '@tresjs/core'
3-
import { BlendFunction, NoiseEffect } from 'postprocessing'
3+
import type { BlendFunction } from 'postprocessing'
4+
import { NoiseEffect } from 'postprocessing'
45
import { omit } from '../../util/object'
56
import { makePropWatchersUsingAllProps } from '../../util/prop'
67
import { useEffectPmndrs } from './composables/useEffectPmndrs'
@@ -16,8 +17,7 @@ export interface NoisePmndrsProps {
1617

1718
<script lang="ts" setup>
1819
const props = withDefaults(defineProps<NoisePmndrsProps>(), {
19-
premultiply: false,
20-
blendFunction: BlendFunction.SCREEN,
20+
premultiply: undefined,
2121
})
2222
2323
const { pass, effect } = useEffectPmndrs(() => new NoiseEffect(props), props)

src/core/pmndrs/ScanlinePmndrs.vue

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts" setup>
2+
import { watch } from 'vue'
23
import type { BlendFunction } from 'postprocessing'
34
import { ScanlineEffect } from 'postprocessing'
45
import { makePropWatchers } from '../../util/prop'
@@ -26,14 +27,7 @@ export interface ScanlinePmndrsProps {
2627
opacity?: number
2728
}
2829
29-
const props = withDefaults(
30-
defineProps<ScanlinePmndrsProps>(),
31-
{
32-
density: 1.25,
33-
opacity: 1.0,
34-
scrollSpeed: 0.0,
35-
},
36-
)
30+
const props = defineProps<ScanlinePmndrsProps>()
3731
3832
const { pass, effect } = useEffectPmndrs(() => new ScanlineEffect(props), props)
3933
@@ -42,11 +36,27 @@ defineExpose({ pass, effect })
4236
makePropWatchers(
4337
[
4438
[() => props.blendFunction, 'blendMode.blendFunction'],
45-
[() => props.opacity, 'blendMode.opacity.value'],
4639
[() => props.density, 'density'],
4740
[() => props.scrollSpeed, 'scrollSpeed'],
4841
],
4942
effect,
5043
() => new ScanlineEffect(),
5144
)
45+
46+
watch(
47+
[() => props.opacity],
48+
() => {
49+
if (props.opacity !== undefined) {
50+
effect.value?.blendMode.setOpacity(props.opacity)
51+
}
52+
else {
53+
const plainEffect = new ScanlineEffect()
54+
effect.value?.blendMode.setOpacity(plainEffect.blendMode.getOpacity())
55+
plainEffect.dispose()
56+
}
57+
},
58+
{
59+
immediate: true,
60+
},
61+
)
5262
</script>

src/core/pmndrs/VignettePmndrs.vue

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
2-
import { BlendFunction, VignetteEffect, VignetteTechnique } from 'postprocessing'
2+
import type { BlendFunction, VignetteTechnique } from 'postprocessing'
3+
import { VignetteEffect } from 'postprocessing'
34
import { omit } from '../../util/object'
45
import { makePropWatchersUsingAllProps } from '../../util/prop'
56
import { useEffectPmndrs } from './composables/useEffectPmndrs'
@@ -10,18 +11,13 @@ export interface VignettePmndrsProps {
1011
*/
1112
technique?: VignetteTechnique
1213
blendFunction?: BlendFunction
13-
offset: number
14-
darkness: number
14+
offset?: number
15+
darkness?: number
1516
}
1617
</script>
1718

1819
<script lang="ts" setup>
19-
const props = withDefaults(defineProps<VignettePmndrsProps>(), {
20-
technique: VignetteTechnique.DEFAULT,
21-
blendFunction: BlendFunction.NORMAL,
22-
offset: 0.5,
23-
darkness: 0.5,
24-
})
20+
const props = defineProps<VignettePmndrsProps>()
2521
2622
const { pass, effect } = useEffectPmndrs(() => new VignetteEffect(props), props)
2723
defineExpose({ pass, effect })

0 commit comments

Comments
 (0)