Skip to content

Commit

Permalink
feat: 492 set tone mapping default to acesfilmictonemapping (#498)
Browse files Browse the repository at this point in the history
* feat: set ACESFilmicToneMapping as default toneMapping

* chore: usage of nullish coealescing operator instead of ternaries
  • Loading branch information
alvarosabu authored Jan 23, 2024
1 parent 8bbafde commit c4547f9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
6 changes: 0 additions & 6 deletions playground/src/components/TheExperience.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang="ts">
import { ref, watchEffect } from 'vue'
import { BasicShadowMap, SRGBColorSpace, NoToneMapping } from 'three'
import { TresCanvas } from '@tresjs/core'
import { OrbitControls } from '@tresjs/cientos'
import { TresLeches, useControls } from '@tresjs/leches'
Expand All @@ -10,10 +9,6 @@ import TheSphere from './TheSphere.vue'
const gl = {
clearColor: '#82DBC5',
shadows: true,
alpha: false,
shadowMapType: BasicShadowMap,
outputColorSpace: SRGBColorSpace,
toneMapping: NoToneMapping,
}
const wireframe = ref(true)
Expand All @@ -39,7 +34,6 @@ watchEffect(() => {
ref="canvas"
window-size
class="awiwi"
:style="{ background: '#008080' }"
>
<TresPerspectiveCamera
:position="[7, 7, 7]"
Expand Down
6 changes: 5 additions & 1 deletion src/composables/useRenderer/const.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ACESFilmicToneMapping, PCFSoftShadowMap, SRGBColorSpace } from 'three'
import { ACESFilmicToneMapping, NoToneMapping, PCFSoftShadowMap, SRGBColorSpace } from 'three'

export const rendererPresets = {
realistic: {
Expand All @@ -12,6 +12,10 @@ export const rendererPresets = {
type: PCFSoftShadowMap,
},
},
flat: {
toneMapping: NoToneMapping,
toneMappingExposure: 1,
},
}

export type RendererPresetsType = keyof typeof rendererPresets
15 changes: 7 additions & 8 deletions src/composables/useRenderer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Color, WebGLRenderer } from 'three'
import { shallowRef, watchEffect, onUnmounted, type MaybeRef, computed, watch, nextTick } from 'vue'
import { ACESFilmicToneMapping, Color, WebGLRenderer } from 'three'
import { shallowRef, watchEffect, onUnmounted, type MaybeRef, computed, watch } from 'vue'

import {
toValue,
unrefElement,
Expand Down Expand Up @@ -77,7 +78,7 @@ export interface UseRendererOptions extends TransformToMaybeRefOrGetter<WebGLRen
* CineonToneMapping, ACESFilmicToneMapping,
* CustomToneMapping
*
* @default NoToneMapping
* @default ACESFilmicToneMapping
*/
toneMapping?: MaybeRefOrGetter<ToneMapping>

Expand Down Expand Up @@ -124,14 +125,12 @@ export function useRenderer(
) {

const webGLRendererConstructorParameters = computed<WebGLRendererParameters>(() => ({
alpha: toValue(options.alpha),
alpha: toValue(options.alpha) ?? true,
depth: toValue(options.depth),
canvas: unrefElement(canvas),
context: toValue(options.context),
stencil: toValue(options.stencil),
antialias: toValue(options.antialias) === undefined // an opinionated default of tres
? true
: toValue(options.antialias),
antialias: toValue(options.antialias) ?? true,
precision: toValue(options.precision),
powerPreference: toValue(options.powerPreference),
premultipliedAlpha: toValue(options.premultipliedAlpha),
Expand Down Expand Up @@ -273,7 +272,7 @@ export function useRenderer(
set(renderer.value, pathInThree, getValue(option, pathInThree))

setValueOrDefault(options.shadows, 'shadowMap.enabled')
setValueOrDefault(options.toneMapping, 'toneMapping')
setValueOrDefault(options.toneMapping ?? ACESFilmicToneMapping, 'toneMapping')
setValueOrDefault(options.shadowMapType, 'shadowMap.type')

if (revision < 150)
Expand Down

0 comments on commit c4547f9

Please sign in to comment.