Skip to content

Commit

Permalink
fix: updated breaking changes of three v152 color maangement
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed May 3, 2023
1 parent ff1dd13 commit 1e47a5f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
14 changes: 12 additions & 2 deletions docs/.vitepress/theme/components/FirstScene.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { sRGBEncoding } from 'three'
import { sRGBEncoding, BasicShadowMap,
NoToneMapping } from 'three'
import { TresCanvas } from '@tresjs/core'
import { OrbitControls } from '@tresjs/cientos'
const LightRef = ref()
Expand All @@ -14,10 +15,19 @@ onMounted(() => {
LightRef.value.shadow.camera.top = 10
LightRef.value.shadow.camera.bottom = -10
})
const gl = {
clearColor: '#82DBC5',
shadows: true,
alpha: false,
outputEncoding: sRGBEncoding,
shadowMapType: BasicShadowMap,
toneMapping: NoToneMapping,
}
</script>

<template>
<TresCanvas clear-color="#82DBC5" shadows alpha physically-correct-lights :output-encoding="sRGBEncoding">
<TresCanvas v-bind="gl">
<TresPerspectiveCamera :position="[11, 11, 11]" :fov="45" :aspect="1" :near="0.1" :far="1000" />

<OrbitControls />
Expand Down
4 changes: 2 additions & 2 deletions playground/src/components/TheExperience.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { ref, watchEffect } from 'vue'
import { BasicShadowMap, sRGBEncoding, NoToneMapping } from 'three'
import { BasicShadowMap, SRGBColorSpace, NoToneMapping } from 'three'
import { TresCanvas } from '/@/'
import TheSphere from './TheSphere.vue'
import { OrbitControls } from '@tresjs/cientos'
Expand All @@ -10,7 +10,7 @@ const gl = {
shadows: true,
alpha: false,
shadowMapType: BasicShadowMap,
outputEncoding: sRGBEncoding,
outputColorSpace: SRGBColorSpace,
toneMapping: NoToneMapping,
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/TresCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface TresCanvasProps {
shadowMapType?: ShadowMapType
physicallyCorrectLights?: boolean
useLegacyLights?: boolean
outputEncoding?: TextureEncoding
outputColorSpace?: TextureEncoding
toneMapping?: ToneMapping
toneMappingExposure?: number
context?: WebGLRenderingContext
Expand All @@ -32,7 +32,7 @@ export const TresCanvas = defineComponent<TresCanvasProps>({
'shadowMapType',
'physicallyCorrectLights',
'useLegacyLights',
'outputEncoding',
'outputColorSpace',
'toneMapping',
'toneMappingExposure',
'context',
Expand Down
4 changes: 2 additions & 2 deletions src/components/TresScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface TresSceneProps {
shadowMapType?: ShadowMapType
physicallyCorrectLights?: boolean
useLegacyLights?: boolean
outputEncoding?: TextureEncoding
outputColorSpace?: TextureEncoding
toneMapping?: ToneMapping
toneMappingExposure?: number
context?: WebGLRenderingContext
Expand All @@ -40,7 +40,7 @@ export const TresScene = defineComponent<TresSceneProps>({
'shadowMapType',
'physicallyCorrectLights',
'useLegacyLights',
'outputEncoding',
'outputColorSpace',
'toneMapping',
'toneMappingExposure',
'context',
Expand Down
4 changes: 2 additions & 2 deletions src/composables/useRenderer/const.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ACESFilmicToneMapping, PCFSoftShadowMap, sRGBEncoding } from 'three'
import { ACESFilmicToneMapping, PCFSoftShadowMap, SRGBColorSpace } from 'three'

export const rendererPresets = {
realistic: {
outputEncoding: sRGBEncoding,
outputColorSpace: SRGBColorSpace,
toneMapping: ACESFilmicToneMapping,
toneMappingExposure: 3,
shadowMap: {
Expand Down
15 changes: 8 additions & 7 deletions src/composables/useRenderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import {
WebGLRendererParameters,
NoToneMapping,
LinearEncoding,
LinearSRGBColorSpace,
WebGLRenderer,
ShadowMapType,
PCFShadowMap,
Expand Down Expand Up @@ -59,11 +59,11 @@ export interface UseRendererOptions extends WebGLRendererParameters {
useLegacyLights?: MaybeRefOrGetter<boolean>
/**
* Defines the output encoding of the renderer.
* Can be LinearEncoding, sRGBEncoding
* Can be LinearSRGBColorSpace, SRGBColorSpace
*
* @default LinearEncoding
* @default LinearSRGBColorSpace
*/
outputEncoding?: MaybeRefOrGetter<TextureEncoding>
outputColorSpace?: MaybeRefOrGetter<TextureEncoding>

/**
* Defines the tone mapping used by the renderer.
Expand Down Expand Up @@ -134,7 +134,7 @@ export function useRenderer(options: UseRendererOptions) {
shadows = false,
shadowMapType = PCFShadowMap,
useLegacyLights = false,
outputEncoding = LinearEncoding,
outputColorSpace = LinearSRGBColorSpace,
toneMapping = NoToneMapping,
toneMappingExposure = 1,
context = undefined,
Expand Down Expand Up @@ -189,7 +189,8 @@ You could set windowSize=true to force the canvas to be the size of the window.`
renderer.value.shadowMap.type = toValue(shadowMapType) as ShadowMapType
renderer.value.toneMapping = (toValue(toneMapping) as ToneMapping) || NoToneMapping
renderer.value.toneMappingExposure = toValue(toneMappingExposure) as number
renderer.value.outputEncoding = (toValue(outputEncoding) as TextureEncoding) || LinearEncoding
// Wating for https://github.com/DefinitelyTyped/DefinitelyTyped/pull/65356/files to be merged
renderer.value.outputColorSpace = (toValue(outputColorSpace) as TextureEncoding) || LinearSRGBColorSpace
if (clearColor?.value) renderer.value.setClearColor(normalizeColor(toValue(clearColor) as TresColor))

/* renderer.value.physicallyCorrectLights = toValue(physicallyCorrectLights) as boolean */
Expand Down Expand Up @@ -243,7 +244,7 @@ You could set windowSize=true to force the canvas to be the size of the window.`
watch([aspectRatio, pixelRatio], updateRendererSize)

watch(
[shadows, shadowMapType, outputEncoding, useLegacyLights, toneMapping, toneMappingExposure, clearColor],
[shadows, shadowMapType, outputColorSpace, useLegacyLights, toneMapping, toneMappingExposure, clearColor],
updateRendererOptions,
)

Expand Down

0 comments on commit 1e47a5f

Please sign in to comment.