Skip to content

Commit f147379

Browse files
itsdougesmommysgoodpuppy
authored andcommitted
Fix postprocessing not working (#312)
adeira-source-id: f61dd89 Co-authored-by: mommysgoodpuppy <[email protected]>
1 parent 3cb475a commit f147379

7 files changed

Lines changed: 157 additions & 15 deletions

File tree

.changeset/famous-bugs-camp.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@triplex/renderer": patch
3+
"@triplex/electron": patch
4+
"triplex-vsce": patch
5+
---
6+
7+
Testing a fix for running postprocessing, it will be gradually rolled out.

examples/caustics/.triplex/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"$schema": "https://triplex.dev/config.schema.json",
33
"components": ["../src/components/**/*.tsx"],
44
"files": ["../src/**/*.tsx"],
5-
"renderer": "../../../packages/renderer/src/index.tsx"
5+
"renderer": "../../../packages/renderer/src/index.tsx",
6+
"provider": "./provider.tsx"
67
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {
2+
Bloom,
3+
DepthOfField,
4+
EffectComposer,
5+
Noise,
6+
Vignette,
7+
} from "@react-three/postprocessing";
8+
import { ReactNode } from "react";
9+
10+
export function CanvasProvider({
11+
children,
12+
postProcessing = true,
13+
}: {
14+
children: ReactNode;
15+
postProcessing?: boolean;
16+
}) {
17+
return (
18+
<>
19+
<EffectComposer enabled={postProcessing}>
20+
<DepthOfField
21+
focusDistance={0}
22+
focalLength={0.02}
23+
bokehScale={2}
24+
height={480}
25+
/>
26+
<Bloom luminanceThreshold={0} luminanceSmoothing={0.9} height={300} />
27+
<Noise opacity={0.02} />
28+
<Vignette eskil={false} offset={0.1} darkness={1.1} />
29+
</EffectComposer>
30+
{children}
31+
</>
32+
);
33+
}

examples/caustics/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"dependencies": {
1010
"@react-three/drei": "^10.0.0",
1111
"@react-three/fiber": "^9.0.4",
12+
"@react-three/postprocessing": "^3.0.4",
1213
"@types/react": "^19.0.8",
1314
"@types/three": "^0.171.0",
1415
"react": "^19.0.0",

examples/caustics/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"skipLibCheck": true,
1515
"strict": true
1616
},
17-
"include": ["."],
17+
"include": [".", ".triplex/*"],
1818
"exclude": ["node_modules"]
1919
}

packages/renderer/src/features/camera-new/cameras.tsx

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
import { useFrame, useThree } from "@react-three/fiber";
88
import { on } from "@triplex/bridge/client";
9+
import { fg } from "@triplex/lib/fg";
910
import {
1011
useContext,
1112
useEffect,
@@ -133,11 +134,54 @@ export function Cameras({ children }: { children: ReactNode }) {
133134
}
134135
}, [activeCamera, playState]);
135136

136-
useFrame(({ gl, scene }) => {
137-
if (activeCamera) {
138-
gl.render(scene, activeCamera);
137+
useEffect(() => {
138+
if (!gl || !activeCamera || !fg("camera_pp_fix")) {
139+
return;
139140
}
140-
}, 1);
141+
142+
const originalRender = gl.render;
143+
144+
/**
145+
* This hijacks the existing GL render function to forcibly switch what
146+
* camera is being used. This enables postprocessing to do its thing without
147+
* Triplex having to do more work to support it.
148+
*/
149+
gl.render = function (scene, camera, ...args) {
150+
// only patch defaultCamera calls to preserve triplex ui correctly
151+
if (activeState === "editor" && camera === defaultCamera) {
152+
return originalRender.call(this, scene, activeCamera, ...args);
153+
}
154+
155+
return originalRender.call(this, scene, camera, ...args);
156+
};
157+
158+
return () => {
159+
gl.render = originalRender;
160+
};
161+
}, [gl, activeCamera, activeState, defaultCamera]);
162+
163+
useFrame(
164+
({ gl, scene }) => {
165+
if (fg("camera_pp_fix")) {
166+
if (activeCamera) {
167+
/**
168+
* This is complementary to the render hijack above, postprocessing
169+
* effects can disable clear which causes selection outlines to hang.
170+
*/
171+
gl.autoClear = true;
172+
// gl.render call needed components without pp
173+
gl.render(scene, activeCamera);
174+
}
175+
} else {
176+
if (activeCamera) {
177+
gl.render(scene, activeCamera);
178+
}
179+
}
180+
},
181+
// We use 0.5 here so it's ran before postprocessing.
182+
// See: https://github.com/pmndrs/react-postprocessing/blob/master/src/EffectComposer.tsx#L63
183+
fg("camera_pp_fix") ? 0.5 : 1,
184+
);
141185

142186
const context: ActiveCameraContextValue = useMemo(
143187
() => (activeCamera ? { camera: activeCamera, type: activeState } : null),

yarn.lock

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@
11181118
resolved "https://registry.yarnpkg.com/@radix-ui/react-icons/-/react-icons-1.3.0.tgz#c61af8f323d87682c5ca76b856d60c2312dbcb69"
11191119
integrity sha512-jQxj/0LKgp+j9BiTXz3O3sgs26RNet2iLWmsPyRz2SIcR4q/4SbazXfnYwbAr+vLYKSfc7qxzyGQA1HLlYiuNw==
11201120

1121-
"@react-three/drei@^10.0.0", "triplex-drei@npm:@react-three/drei@^10.0.0":
1121+
"@react-three/drei@^10.0.0":
11221122
version "10.0.3"
11231123
resolved "https://registry.yarnpkg.com/@react-three/drei/-/drei-10.0.3.tgz#323aaa5c6779244a0f68a29ec6080deb9b79ae2b"
11241124
integrity sha512-uDjYCH1zmVGlFwGSpxKkq71doETdvZnO6ZKcNG5EXACGGpdfxEff4yO5qb9VYuAGyS0uEcb4dowVruJgXDCqEA==
@@ -1163,6 +1163,15 @@
11631163
use-sync-external-store "^1.4.0"
11641164
zustand "^5.0.3"
11651165

1166+
"@react-three/postprocessing@^3.0.4":
1167+
version "3.0.4"
1168+
resolved "https://registry.yarnpkg.com/@react-three/postprocessing/-/postprocessing-3.0.4.tgz#e2379eb0b953d1cc0c4b8ac94dc76256f4c07062"
1169+
integrity sha512-e4+F5xtudDYvhxx3y0NtWXpZbwvQ0x1zdOXWTbXMK6fFLVDd4qucN90YaaStanZGS4Bd5siQm0lGL/5ogf8iDQ==
1170+
dependencies:
1171+
maath "^0.6.0"
1172+
n8ao "^1.9.4"
1173+
postprocessing "^6.36.6"
1174+
11661175
"@react-three/rapier@^1.4.0":
11671176
version "1.5.0"
11681177
resolved "https://registry.yarnpkg.com/@react-three/rapier/-/rapier-1.5.0.tgz#f6af5b1dd6895a73df0d09e15576eed1f0398379"
@@ -6673,6 +6682,11 @@ mz@^2.7.0:
66736682
object-assign "^4.0.1"
66746683
thenify-all "^1.0.0"
66756684

6685+
n8ao@^1.9.4:
6686+
version "1.9.4"
6687+
resolved "https://registry.yarnpkg.com/n8ao/-/n8ao-1.9.4.tgz#be222531fddcb5099614be452fc492db98a2947d"
6688+
integrity sha512-gbpAorQecZn2oGK/rheHxPTNwOxVsEC6216+Jr9tXHUk9L5VCE2q/uxsSrQpfNkZDoCmQHf7oSg3SYFWCAt0wg==
6689+
66766690
nanoid@^3.3.6, nanoid@^3.3.8:
66776691
version "3.3.8"
66786692
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.8.tgz#b1be3030bee36aaff18bacb375e5cce521684baf"
@@ -7304,6 +7318,11 @@ postcss@^8.4.23, postcss@^8.4.32, postcss@^8.5.1:
73047318
picocolors "^1.1.1"
73057319
source-map-js "^1.2.1"
73067320

7321+
postprocessing@^6.36.6:
7322+
version "6.37.1"
7323+
resolved "https://registry.yarnpkg.com/postprocessing/-/postprocessing-6.37.1.tgz#643c9acf1d4addc4f98f91dc1ee578a258b462f3"
7324+
integrity sha512-fZszlSB8j+PaxtS8g4qMxdj+ifzvoCPnbHSOjclTlr4mbhd6/huQqOViM6lhhPIrW2fiZc+IRcnReoKYvyMwNg==
7325+
73077326
potpack@^1.0.1:
73087327
version "1.0.2"
73097328
resolved "https://registry.yarnpkg.com/potpack/-/potpack-1.0.2.tgz#23b99e64eb74f5741ffe7656b5b5c4ddce8dfc14"
@@ -8245,8 +8264,16 @@ streamsearch@^1.1.0:
82458264
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764"
82468265
integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==
82478266

8248-
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0:
8249-
name string-width-cjs
8267+
"string-width-cjs@npm:string-width@^4.2.0":
8268+
version "4.2.3"
8269+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
8270+
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
8271+
dependencies:
8272+
emoji-regex "^8.0.0"
8273+
is-fullwidth-code-point "^3.0.0"
8274+
strip-ansi "^6.0.1"
8275+
8276+
string-width@^4.1.0:
82508277
version "4.2.3"
82518278
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
82528279
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -8352,7 +8379,14 @@ stringify-entities@^4.0.0:
83528379
character-entities-html4 "^2.0.0"
83538380
character-entities-legacy "^3.0.0"
83548381

8355-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
8382+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
8383+
version "6.0.1"
8384+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
8385+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
8386+
dependencies:
8387+
ansi-regex "^5.0.1"
8388+
8389+
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
83568390
version "6.0.1"
83578391
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
83588392
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -8679,6 +8713,33 @@ trim-repeated@^2.0.0:
86798713
dependencies:
86808714
escape-string-regexp "^5.0.0"
86818715

8716+
"triplex-drei@npm:@react-three/drei@^10.0.0":
8717+
version "10.0.3"
8718+
resolved "https://registry.yarnpkg.com/@react-three/drei/-/drei-10.0.3.tgz#323aaa5c6779244a0f68a29ec6080deb9b79ae2b"
8719+
integrity sha512-uDjYCH1zmVGlFwGSpxKkq71doETdvZnO6ZKcNG5EXACGGpdfxEff4yO5qb9VYuAGyS0uEcb4dowVruJgXDCqEA==
8720+
dependencies:
8721+
"@babel/runtime" "^7.26.0"
8722+
"@mediapipe/tasks-vision" "0.10.17"
8723+
"@monogrid/gainmap-js" "^3.0.6"
8724+
"@use-gesture/react" "^10.3.1"
8725+
camera-controls "^2.9.0"
8726+
cross-env "^7.0.3"
8727+
detect-gpu "^5.0.56"
8728+
glsl-noise "^0.0.0"
8729+
hls.js "^1.5.17"
8730+
maath "^0.10.8"
8731+
meshline "^3.3.1"
8732+
stats-gl "^2.2.8"
8733+
stats.js "^0.17.0"
8734+
suspend-react "^0.1.3"
8735+
three-mesh-bvh "^0.8.3"
8736+
three-stdlib "^2.35.6"
8737+
troika-three-text "^0.52.0"
8738+
tunnel-rat "^0.1.2"
8739+
use-sync-external-store "^1.4.0"
8740+
utility-types "^3.11.0"
8741+
zustand "^5.0.1"
8742+
86828743
troika-three-text@^0.52.0:
86838744
version "0.52.3"
86848745
resolved "https://registry.yarnpkg.com/troika-three-text/-/troika-three-text-0.52.3.tgz#38fe68a9642aba562830323dee6708710cf36a61"
@@ -9044,11 +9105,6 @@ universalify@^0.2.0:
90449105
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.2.0.tgz#6451760566fa857534745ab1dde952d1b1761be0"
90459106
integrity sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==
90469107

9047-
upath@^2.0.1:
9048-
version "2.0.1"
9049-
resolved "https://registry.yarnpkg.com/upath/-/upath-2.0.1.tgz#50c73dea68d6f6b990f51d279ce6081665d61a8b"
9050-
integrity sha512-1uEe95xksV1O0CYKXo8vQvN1JEbtJp7lb7C5U9HMsIp6IVwntkH/oNUzyVNQSd4S1sYk2FpSSW44FqMc8qee5w==
9051-
90529108
update-browserslist-db@^1.1.1:
90539109
version "1.1.3"
90549110
resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.1.3.tgz#348377dd245216f9e7060ff50b15a1b740b75420"

0 commit comments

Comments
 (0)