Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/extras/render-passes/camera-frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,26 @@ import { CameraFrameOptions, RenderPassCameraFrame } from './render-pass-camera-
* Implementation of a simple to use camera rendering pass, which supports SSAO, Bloom and
* other rendering effects.
*
* Overriding compose shader chunks:
* The final compose pass registers its shader chunks in a way that does not override any chunks
* that were already provided. To customize the compose pass output, set your shader chunks on the
* {@link ShaderChunks} map before creating the `CameraFrame`. Those chunks will be picked up by
* the compose pass and preserved.
*
* Example (GLSL):
*
* @example
* // Provide custom compose chunk(s) before constructing CameraFrame
* ShaderChunks.get(graphicsDevice, SHADERLANGUAGE_GLSL).set('composeVignettePS', `
* #ifdef VIGNETTE
* vec3 applyVignette(vec3 color, vec2 uv) {
* return color * uv.u;
* }
* #endif
* `);
*
* // For WebGPU, use SHADERLANGUAGE_WGSL instead.
*
* @category Graphics
*/
class CameraFrame {
Expand Down
4 changes: 2 additions & 2 deletions src/extras/render-passes/render-pass-compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class RenderPassCompose extends RenderPassShaderQuad {
super(graphicsDevice);

// register compose shader chunks
ShaderChunks.get(graphicsDevice, SHADERLANGUAGE_GLSL).add(composeChunksGLSL);
ShaderChunks.get(graphicsDevice, SHADERLANGUAGE_WGSL).add(composeChunksWGSL);
ShaderChunks.get(graphicsDevice, SHADERLANGUAGE_GLSL).add(composeChunksGLSL, false);
ShaderChunks.get(graphicsDevice, SHADERLANGUAGE_WGSL).add(composeChunksWGSL, false);

const { scope } = graphicsDevice;
this.sceneTextureId = scope.resolve('sceneTexture');
Expand Down
7 changes: 5 additions & 2 deletions src/scene/shader-lib/shader-chunk-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ class ShaderChunkMap extends Map {
* same name already exists, the element will be updated.
*
* @param {Object} object - Object containing shader chunks.
* @param {boolean} override - Whether to override existing shader chunks. Defaults to true.
* @returns {this} The ShaderChunkMap instance.
*/
add(object) {
add(object, override = true) {
for (const [key, value] of Object.entries(object)) {
this.set(key, value);
if (override || !this.has(key)) {
this.set(key, value);
}
}
return this;
}
Expand Down