Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtquick3d-userpasses.qdoc
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page qtquick3d-userpasses.html
6\title User-Defined Render Passes in Qt Quick 3D
7\brief Controlling the rendering pipeline with custom render passes
8
9\since 6.11
10
11Qt Quick 3D provides a high-level API for 3D rendering that handles most rendering
12details automatically. However, for advanced use cases, applications may need complete
13control over the rendering pipeline. User-defined render passes enable this by allowing
14applications to disable the internal rendering pipeline and define their own custom passes.
15
16User render passes enable advanced rendering techniques such as:
17
18\list
19\li Deferred shading and lighting
20\li Multi-pass rendering effects
21\li Custom post-processing pipelines
22\li Selective rendering with layer-based filtering
23\li Screen-space effects (ambient occlusion, reflections, etc.)
24\li Custom shadow mapping techniques
25\li Debug visualization passes
26\li Compute-based data preparation, such as procedural texture generation or light clustering
27\li GPU-driven data processing using storage buffers and images
28\endlist
29
30\section1 Levels of Customization
31
32Qt Quick 3D offers four complementary levels of rendering customization, each suited
33to different use cases:
34
35\table
36\header
37\li Level
38\li Scope
39\li Use Cases
40\row
41\li \l Effect
42\li Post-processing
43\li Applies effects after the scene is rendered (blur, color grading, etc.)
44\row
45\li \l CustomMaterial
46\li Per-material shaders
47\li Custom vertex and fragment shaders for individual materials
48\row
49\li \l RenderPass (User Render Passes)
50\li Complete pipeline control
51\li Deferred rendering, multiple passes, custom render targets
52\row
53\li \l ComputePass
54\li Data preparation
55\li Runs a compute shader before the main render to prepare data, such as light clusters,
56 procedural textures, or volumetric lighting, for the other three levels to consume
57\endtable
58
59User render passes (\l RenderPass) provide the most control over what gets rendered and how,
60allowing you to either supplement or completely replace the default rendering pipeline. This
61complements \l CustomMaterial and \l Effect: \l CustomMaterial customizes how individual objects
62are rendered, while user render passes control the overall rendering strategy and architecture.
63\l ComputePass is complementary again: rather than rendering or post-processing, it runs a GLSL
64compute shader to produce data -- typically into a \l ShaderImage or a \l ShaderStorageBuffer -- for
65any of the other three to read afterwards. See \l{Compute Passes} below.
66
67\section1 Using User Render Passes
68
69User render passes can be used in two ways:
70
71\section2 Supplementing Internal Passes
72
73You can add custom \l RenderPass objects alongside the default rendering pipeline without
74disabling internal passes. This is useful for rendering to textures that are then used by
75\l Effect or \l CustomMaterial, or for creating auxiliary render targets.
76
77\qml
78View3D {
79 // Internal passes still run normally
80
81 RenderPassTexture { id: customTexture; format: RenderPassTexture.RGBA16F }
82
83 RenderPass {
84 // Custom pass renders to texture
85 commands: [
86 ColorAttachment { target: customTexture },
87 DepthStencilAttachment { }
88 ]
89 }
90
91 // Use customTexture in an Effect or material
92}
93\endqml
94
95\section2 Replacing Internal Passes
96
97For complete control over the rendering pipeline, disable Qt Quick 3D's internal rendering
98by setting the \l{View3D::renderOverrides}{renderOverrides} property:
99
100\qml
101View3D {
102 renderOverrides: View3D.DisableInternalPasses
103
104 // Your custom render passes go here
105}
106\endqml
107
108When internal passes are disabled, Qt Quick 3D will not perform any default rendering.
109This means you must:
110
111\list
112\li Define at least one \l RenderPass to render your scene
113\li Provide the final output texture to display via \l SimpleQuadRenderer or similar mechanism
114\li Handle all rendering aspects including depth buffers, transparency, etc.
115\endlist
116
117\note Disabling internal passes gives you complete control, but also complete responsibility.
118Features like automatic shadow rendering, transparency sorting, and environment reflections
119must be implemented in your custom passes if needed.
120
121\section1 Core Concepts
122
123User-defined render passes are built from several key components:
124
125\section2 RenderPass
126
127The \l RenderPass type is the main building block. It defines a single rendering operation
128with a set of commands that control what gets rendered and how. Each pass can:
129
130\list
131\li Render to one or more color textures (up to 4 simultaneous render targets)
132\li Write depth and stencil information
133\li Filter which objects to render based on layers
134\li Override graphics pipeline state (blending, culling, etc.)
135\li Use original materials, augment them with custom shaders, or override them entirely
136\endlist
137
138\section2 Pass Ordering
139
140The pass hierarchy determines the render order: nested passes render \e before
141their parent, so a pass that produces a texture consumed by another pass is
142declared as a child of its consumer, and results merge towards the top of the
143hierarchy. A pass's nesting depth is the number of RenderPass and ComputePass
144ancestors it has; other ancestors, such as \l Node items used for grouping,
145are transparent and do not affect the order. A deeper-nested pass renders
146before all passes at shallower depths, so its output is available to every
147consumer that frame, not only its parent. The relative render order of passes
148at the same nesting depth is not defined; use nesting to express an ordering
149requirement.
150
151By default, user passes, \l RenderPass and \l ComputePass alike, run after the
152scene's internal preparation passes (depth, normal, and ambient occlusion
153textures, shadow maps, the screen texture, reflection probes, and texture
154provider extensions) and before the main pass, which renders the scene's opaque
155and transparent objects. Their output is available to the main pass of the same
156frame, but when the preparation passes use it, for example through a material
157that also renders into the shadow maps, they see the output of the previous
158frame. A ComputePass whose \l{ComputePass::executionStage}{executionStage} is
159\c ComputePass.StartOfFrame executes before the preparation passes instead, so
160they see its output from the same frame. Nesting still decides the order: a
161pass nested in a \c StartOfFrame ComputePass executes in that stage as well,
162before its ancestor.
163
164Nesting affects ordering only; a nested pass still renders into its own render
165target, and its output is consumed through a \l RenderOutputProvider. To render
166into the parent pass's render target instead, reference the pass from a
167\l SubRenderPass command; such a pass is invoked by its parent and never
168renders on its own.
169
170\section2 RenderPassTexture
171
172The \l RenderPassTexture type defines textures that serve as render targets. These can be
173color textures in various formats (RGBA8, RGBA16F, RGBA32F, etc.) or depth/stencil
174textures. Render pass textures are used as outputs from one pass and can be used as
175texture inputs to subsequent passes.
176
177\section2 RenderOutputProvider
178
179The \l RenderOutputProvider type connects render passes by exposing the output textures
180from one pass as texture inputs that can be used by materials or other passes. This is
181essential for multi-pass rendering where later passes need to read the results of
182earlier passes.
183
184\section2 ContentLayer
185
186The \l ContentLayer singleton provides layer constants (Layer0 through Layer23) used for
187filtering which objects render in which pass. By assigning objects to specific layers and
188using \l RenderablesFilter in your passes, you can control precisely what gets rendered
189in each pass.
190
191\section2 Render Commands
192
193Each \l RenderPass contains a list of commands that configure its behavior:
194
195\list
196\li \l ColorAttachment: Specifies a color render target
197\li \l DepthStencilAttachment: Specifies depth/stencil handling
198\li \l DepthTextureAttachment: Uses a texture for depth output
199\li \l RenderablesFilter: Filters objects by layer and type (opaque/transparent)
200\li \l PipelineStateOverride: Controls graphics pipeline state
201\li \c SubRenderPass: Executes another render pass within this pass
202\li \l AddDefine: Adds shader preprocessor defines
203\endlist
204
205\section1 Material Modes
206
207Each \l RenderPass has a \l{RenderPass::materialMode}{materialMode} property that controls
208how materials are handled during rendering. The three modes offer different levels of
209material control:
210
211\section2 OriginalMaterial Mode
212
213This mode renders objects with their assigned materials unchanged. It's useful when you
214want to control the rendering pipeline structure (multiple passes, custom render targets)
215but keep the material behavior standard.
216
217\qml
218RenderPass {
219 materialMode: RenderPass.OriginalMaterial
220 commands: [
221 ColorAttachment { target: myColorTexture },
222 DepthStencilAttachment { }
223 ]
224}
225\endqml
226
227\section2 AugmentMaterial Mode
228
229This mode injects custom shader code into the existing material pipeline. It's particularly
230useful for deferred rendering where you need to output additional data (like normals,
231positions, etc.) to multiple render targets while preserving the material's base behavior.
232
233\qml
234RenderPass {
235 materialMode: RenderPass.AugmentMaterial
236 augmentShader: "my_augment.glsl"
237 commands: [
238 ColorAttachment { target: gbuffer0; name: "GBUFFER0" },
239 ColorAttachment { target: gbuffer1; name: "GBUFFER1" },
240 DepthStencilAttachment { }
241 ]
242}
243\endqml
244
245The augment shader file contains a \c{MAIN_FRAGMENT_AUGMENT()} function:
246
247\badcode
248void MAIN_FRAGMENT_AUGMENT()
249{
250 // Access material properties
251 vec3 color = BASE_COLOR.rgb;
252 float metal = METALNESS;
253 float rough = ROUGHNESS;
254 vec3 normal = normalize(WORLD_NORMAL);
255
256 // Write to multiple render targets
257 GBUFFER0 = vec4(color, metal);
258 GBUFFER1 = vec4(normal * 0.5 + 0.5, rough);
259}
260\endcode
261
262See \l{Augment Shaders for Multiple Render Targets} for more details.
263
264\section2 OverrideMaterial Mode
265
266This mode replaces all object materials with a single material. It's useful for specialized
267passes like shadow mapping, depth prepass, or debug visualization.
268
269\qml
270RenderPass {
271 materialMode: RenderPass.OverrideMaterial
272 overrideMaterial: CustomMaterial {
273 fragmentShader: "depth_only.frag"
274 // All objects will use this material
275 }
276 commands: [
277 DepthTextureAttachment { target: depthTexture }
278 ]
279}
280\endqml
281
282\section1 Render Pass Commands
283
284Commands are specified in the \l{RenderPass::commands}{commands} property and execute
285in the order they are defined.
286
287\section2 Color Attachment
288
289The \l ColorAttachment command specifies a color render target. The \c name property
290defines how the attachment is accessed in augment shaders.
291
292\qml
293ColorAttachment {
294 target: myTexture // RenderPassTexture to render to
295 name: "GBUFFER0" // Name for shader access (optional)
296}
297\endqml
298
299You can have up to 4 color attachments per pass (for multiple render targets).
300
301\section2 Depth Attachments
302
303There are two ways to handle depth:
304
305\b{DepthStencilAttachment} uses an implicit depth/stencil buffer:
306
307\qml
308DepthStencilAttachment { } // Creates depth/stencil buffer automatically
309\endqml
310
311\b{DepthTextureAttachment} uses an explicit texture for depth output:
312
313\qml
314RenderPassTexture {
315 id: depthTex
316 format: RenderPassTexture.Depth24Stencil8
317}
318
319DepthTextureAttachment {
320 target: depthTex // Explicit depth texture
321}
322\endqml
323
324Use \l DepthTextureAttachment when you need to share the depth buffer between multiple
325passes or use it as a texture input in shaders.
326
327\section2 Renderables Filter
328
329The \l RenderablesFilter command controls which objects are rendered based on their layer
330assignment and renderable type.
331
332\qml
333RenderablesFilter {
334 layerMask: ContentLayer.Layer0 | ContentLayer.Layer1
335 renderableTypes: RenderablesFilter.Opaque
336}
337\endqml
338
339The \c layerMask property uses bitwise OR to combine layers. The \c renderableTypes
340property can be:
341\list
342\li \c RenderablesFilter.Opaque: Render only opaque objects
343\li \c RenderablesFilter.Transparent: Render only transparent objects
344\li \c RenderablesFilter.Opaque | RenderablesFilter.Transparent: Render both
345\endlist
346
347\section2 Pipeline State Override
348
349The \l PipelineStateOverride command provides fine-grained control over graphics pipeline
350state. It can override depth testing, blending, culling, polygon mode, and more.
351
352\qml
353PipelineStateOverride {
354 depthTestEnabled: true
355 depthWriteEnabled: false
356 blendEnabled: true
357 cullMode: PipelineStateOverride.Back
358 polygonMode: PipelineStateOverride.Fill
359}
360\endqml
361
362See \l{Pipeline State Control} for more examples.
363
364\section2 Sub Render Pass
365
366The \c SubRenderPass command allows hierarchical composition of render passes by executing
367another render pass within the current pass.
368
369\qml
370RenderPass {
371 id: parentPass
372 commands: [
373 ColorAttachment { target: colorTex },
374 SubRenderPass { renderPass: childPass },
375 // More commands after child pass
376 ]
377}
378
379RenderPass {
380 id: childPass
381 // This pass executes within parentPass
382}
383\endqml
384
385\section2 Add Define
386
387The \l AddDefine command adds shader preprocessor defines that affect shader compilation.
388
389\qml
390AddDefine {
391 name: "USE_SPECIAL_MODE"
392 value: 1
393}
394\endqml
395
396\section1 Compute Passes
397
398Alongside \l RenderPass, Qt Quick 3D also supports \l ComputePass: a way to run a GLSL compute
399shader as part of the scene's rendering pipeline. Unlike a \l RenderPass, a ComputePass does not
400render any geometry -- it is used to prepare or process data, typically into a \l ShaderImage
401(an explicitly-sized, formatted GPU image) or a \l ShaderStorageBuffer (a GPU storage buffer), that
402a \l RenderPass, a \l CustomMaterial, an \l Effect, or another ComputePass reads afterwards.
403
404By default, a ComputePass executes together with the \l RenderPass objects, before the scene's
405main pass, regardless of where it is declared relative to them in the same View3D. A ComputePass
406whose \l{ComputePass::executionStage}{executionStage} is \c ComputePass.StartOfFrame executes
407before every built-in pass instead, so that the shadow maps and the other built-in textures are
408also rendered from what it produces. Such a pass cannot rely on the built-in textures itself, and
409sees the output of texture and buffer provider extensions from the previous frame. The order among
410the passes themselves follows the nesting rules in \l{Pass Ordering}: a pass nested inside
411another runs before it, so a ComputePass that produces data for a pass, or for another
412ComputePass, is declared inside that consumer. This makes it naturally suited to preparing data
413that the rest of the frame consumes -- for example, building a light-cluster lookup table,
414generating a procedural texture, or computing per-voxel volumetric lighting data -- rather
415than to producing the final displayed image itself.
416
417A ComputePass executes in every rendered frame unless its
418\l{ComputePass::executionMode}{executionMode} is \c ComputePass.OnRequest, in which case it
419executes once when it first can, and after that once for each call to
420\l{ComputePass::requestExecution()}{requestExecution()}.
421
422\qml
423View3D {
424 ShaderImage {
425 id: proceduralImage
426 width: 256
427 height: 256
428 }
429
430 ComputePass {
431 computeShader: "generate.comp"
432 property ShaderImage targetImage: proceduralImage
433 commands: [
434 Dispatch {
435 groupCountX: Math.ceil(proceduralImage.width / 8)
436 groupCountY: Math.ceil(proceduralImage.height / 8)
437 }
438 ]
439 }
440
441 // Consume proceduralImage from a CustomMaterial, an Effect, a RenderPass's
442 // OverrideMaterial, or another ComputePass, via a ShaderImage property.
443}
444\endqml
445
446Like \l RenderPass, \l CustomMaterial, and \l Effect, a ComputePass exposes any custom
447QML property as a shader uniform automatically. Properties of type \l ShaderImage are
448exposed to the shader as a GLSL image, declared with the \c SHADER_IMAGE macro, and
449properties of type \l ShaderStorageBuffer as a shader storage buffer, declared with
450the \c STORAGE_BUFFER macro.
451
452A compute shader can also reference the same kind of built-in camera, screen/depth texture, and
453frame-counter identifiers as \l RenderPass, \l CustomMaterial, and \l Effect shaders, such as
454\c VIEW_MATRIX, \c CAMERA_POSITION, \c SCREEN_TEXTURE, \c DEPTH_TEXTURE, and \c FRAME.
455Lights and multiview rendering, however, are handled differently:
456
457\list
458\li \b{Lights}: a shaded \l CustomMaterial receives light data through per-light callback
459 functions such as \c DIRECTIONAL_LIGHT(), invoked once per active light, and an \l Effect has
460 no lighting model at all. Since there is no single "current fragment" being shaded for
461 the engine to invoke a callback for, a ComputePass instead exposes light data through
462 per-light-type counts and index-taking accessor functions. The compute shader loops over the
463 lights itself. The light counts are \c DIRECTIONAL_LIGHT_COUNT, \c POINT_LIGHT_COUNT,
464 and \c SPOT_LIGHT_COUNT. The accessor functions include \c{DIRECTIONAL_LIGHT_DIFFUSE(index)},
465 \c{POINT_LIGHT_DIFFUSE(index)}, and \c{SPOT_LIGHT_DIFFUSE(index)}.
466\li \b{Multiview rendering}: unlike a \l CustomMaterial's or an \l Effect's fragment shader, a
467 compute shader has no built-in \c VIEW_INDEX. Elsewhere, \c VIEW_INDEX is derived from the
468 vertex stage's \c gl_ViewIndex, which has no compute equivalent. A ComputePass is dispatched
469 exactly once regardless of the view count, \e{not} once per eye. A compute shader that needs
470 genuinely per-eye results under multiview must derive its own notion of "which eye" itself.
471\endlist
472
473See \l ComputePass for the complete list of built-in uniforms and textures a compute shader can
474reference, and \l ShaderImage and \l ShaderStorageBuffer for the two resource types it typically
475produces.
476
477\sa ComputePass, ShaderImage, ShaderStorageBuffer, Dispatch
478
479\section1 Simple Example: Single Pass Rendering
480
481Here's a minimal example showing user-defined render passes:
482
483\qml
484import QtQuick
485import QtQuick3D
486import QtQuick3D.Helpers
487
488View3D {
489 anchors.fill: parent
490 renderOverrides: View3D.DisableInternalPasses
491
492 // Camera and lights
493 PerspectiveCamera { z: 300 }
494 DirectionalLight { }
495
496 // Define render target texture
497 RenderPassTexture {
498 id: colorTarget
499 format: RenderPassTexture.RGBA16F
500 }
501
502 // Define the render pass
503 RenderPass {
504 id: mainPass
505 materialMode: RenderPass.OriginalMaterial
506 clearColor: "skyblue"
507
508 commands: [
509 ColorAttachment { target: colorTarget },
510 DepthStencilAttachment { }
511 ]
512 }
513
514 // Display the result
515 SimpleQuadRenderer {
516 texture: Texture {
517 textureProvider: RenderOutputProvider {
518 textureSource: RenderOutputProvider.UserPassTexture
519 renderPass: mainPass
520 attachmentSelector: RenderOutputProvider.Attachment0
521 }
522 }
523 }
524
525 // Scene content
526 Model {
527 source: "#Sphere"
528 materials: PrincipledMaterial {
529 baseColor: "red"
530 metalness: 0.0
531 roughness: 0.3
532 }
533 }
534}
535\endqml
536
537This example:
538\list 1
539\li Disables internal passes
540\li Creates a render target texture (colorTarget)
541\li Defines a render pass that renders to that texture
542\li Uses RenderOutputProvider to expose the texture
543\li Displays the result with SimpleQuadRenderer
544\li Renders a sphere with standard material
545\endlist
546
547\section1 Working with Layers
548
549The \l ContentLayer singleton provides constants for organizing objects into layers,
550allowing fine-grained control over what renders in each pass.
551
552\section2 Layer Constants
553
554Qt Quick 3D provides 24 user-assignable layers:
555\list
556\li \c ContentLayer.Layer0 through \c ContentLayer.Layer23: Individual layers
557\li \c ContentLayer.LayerAll: All user layers combined
558\li \c ContentLayer.LayerNone: No layers
559\endlist
560
561\note Layers 24-31 are reserved for internal use.
562
563\section2 Assigning Objects to Layers
564
565Assign objects to layers using the \l{Model::layers}{layers} property:
566
567\qml
568Model {
569 source: "#Cube"
570 layers: ContentLayer.Layer0
571 materials: PrincipledMaterial { baseColor: "red" }
572}
573
574Model {
575 source: "#Sphere"
576 layers: ContentLayer.Layer1 | ContentLayer.Layer2
577 materials: PrincipledMaterial { baseColor: "blue" }
578}
579\endqml
580
581Objects can belong to multiple layers using bitwise OR.
582
583\section2 Filtering by Layer
584
585Use \l RenderablesFilter in your render passes to select which layers to render:
586
587\qml
588RenderPass {
589 id: pass1
590 commands: [
591 ColorAttachment { target: texture1 },
592 RenderablesFilter {
593 layerMask: ContentLayer.Layer0
594 }
595 ]
596 // Only renders objects on Layer0 (red cube)
597}
598
599RenderPass {
600 id: pass2
601 commands: [
602 ColorAttachment { target: texture2 },
603 RenderablesFilter {
604 layerMask: ContentLayer.Layer1 | ContentLayer.Layer2
605 }
606 ]
607 // Only renders objects on Layer1 or Layer2 (blue sphere)
608}
609\endqml
610
611\section2 Use Case: Selective Rendering
612
613A practical example is rendering certain objects as wireframe overlays:
614
615\qml
616View3D {
617 renderOverrides: View3D.DisableInternalPasses
618
619 RenderPassTexture { id: colorTex; format: RenderPassTexture.RGBA16F }
620 RenderPassTexture { id: depthTex; format: RenderPassTexture.Depth24Stencil8 }
621
622 // Pass 1: Render solid objects
623 RenderPass {
624 id: solidPass
625 commands: [
626 ColorAttachment { target: colorTex },
627 DepthTextureAttachment { target: depthTex },
628 RenderablesFilter { layerMask: ContentLayer.Layer0 }
629 ]
630 }
631
632 // Pass 2: Render wireframe overlay
633 RenderPass {
634 id: wireframePass
635 commands: [
636 ColorAttachment { target: colorTex },
637 DepthTextureAttachment { target: depthTex },
638 PipelineStateOverride {
639 polygonMode: PipelineStateOverride.Line
640 depthTestEnabled: true
641 depthWriteEnabled: false
642 },
643 RenderablesFilter { layerMask: ContentLayer.Layer1 }
644 ]
645 }
646
647 SimpleQuadRenderer {
648 texture: Texture {
649 textureProvider: RenderOutputProvider {
650 textureSource: RenderOutputProvider.UserPassTexture
651 renderPass: wireframePass
652 attachmentSelector: RenderOutputProvider.Attachment0
653 }
654 }
655 }
656
657 Model {
658 source: "#Sphere"
659 layers: ContentLayer.Layer0 // Rendered solid
660 materials: PrincipledMaterial { baseColor: "blue" }
661 }
662
663 Model {
664 source: "#Sphere"
665 layers: ContentLayer.Layer1 // Rendered as wireframe
666 materials: PrincipledMaterial { baseColor: "yellow" }
667 }
668}
669\endqml
670
671\section1 Texture Management
672
673User render passes rely heavily on textures both as render targets and as inputs to
674subsequent passes or materials.
675
676\section2 Render Pass Texture Formats
677
678\l RenderPassTexture supports various formats for different use cases:
679
680\b{Color Formats:}
681\table
682\header
683\li Format
684\li Description
685\li Use Case
686\row
687\li RGBA8
688\li 8-bit per channel
689\li Standard color output, lower memory usage
690\row
691\li RGBA16F
692\li 16-bit floating point
693\li HDR rendering, intermediate buffers
694\row
695\li RGBA32F
696\li 32-bit floating point
697\li High precision calculations
698\row
699\li R8, R16, R16F, R32F
700\li Single channel variants
701\li Grayscale data, specialized buffers
702\endtable
703
704\b{Depth Formats:}
705\table
706\header
707\li Format
708\li Description
709\row
710\li Depth16
711\li 16-bit depth
712\row
713\li Depth24
714\li 24-bit depth
715\row
716\li Depth32
717\li 32-bit depth
718\row
719\li Depth24Stencil8
720\li 24-bit depth + 8-bit stencil
721\endtable
722
723Example texture definitions:
724
725\qml
726RenderPassTexture {
727 id: hdrColorBuffer
728 format: RenderPassTexture.RGBA16F // HDR color
729}
730
731RenderPassTexture {
732 id: depthBuffer
733 format: RenderPassTexture.Depth24Stencil8 // Depth + stencil
734}
735
736RenderPassTexture {
737 id: normalBuffer
738 format: RenderPassTexture.RGBA16F // Store normals
739}
740\endqml
741
742\section2 Sharing Textures Between Passes
743
744Multiple passes can share the same depth texture, allowing depth testing across passes:
745
746\qml
747RenderPassTexture {
748 id: sharedDepth
749 format: RenderPassTexture.Depth24Stencil8
750}
751
752RenderPass {
753 id: geometryPass
754 commands: [
755 ColorAttachment { target: colorTex1 },
756 DepthTextureAttachment { target: sharedDepth }
757 ]
758}
759
760RenderPass {
761 id: transparentPass
762 renderTargetFlags: RenderPass.PreserveDepthStencilContents
763 commands: [
764 ColorAttachment { target: colorTex2 },
765 DepthTextureAttachment { target: sharedDepth }
766 // Uses depth from geometryPass for depth testing
767 ]
768}
769\endqml
770
771\section2 Render Output Provider
772
773The \l RenderOutputProvider exposes render pass outputs as \l Texture inputs:
774
775\qml
776// Define a render pass with color output
777RenderPass {
778 id: firstPass
779 commands: [
780 ColorAttachment { target: intermediateTexture }
781 ]
782}
783
784// Expose its output
785RenderOutputProvider {
786 id: intermediateProvider
787 textureSource: RenderOutputProvider.UserPassTexture
788 renderPass: firstPass
789 attachmentSelector: RenderOutputProvider.Attachment0
790}
791
792// Use in a material
793CustomMaterial {
794 property Texture inputTex: Texture { textureProvider: intermediateProvider }
795 fragmentShader: "process.frag"
796}
797\endqml
798
799The \c attachmentSelector property specifies which color attachment to use when a pass
800has multiple render targets:
801\list
802\li \c RenderOutputProvider.Attachment0: First color attachment
803\li \c RenderOutputProvider.Attachment1: Second color attachment
804\li \c RenderOutputProvider.Attachment2: Third color attachment
805\li \c RenderOutputProvider.Attachment3: Fourth color attachment
806\endlist
807
808\section2 Pass Chaining Example
809
810Multiple passes can be chained together where each pass processes the output of
811the previous pass. Each producer is nested inside its consumer, so it renders
812first (see \l{Pass Ordering}):
813
814\qml
815View3D {
816 renderOverrides: View3D.DisableInternalPasses
817
818 // Intermediate textures
819 RenderPassTexture { id: tex0; format: RenderPassTexture.RGBA16F }
820 RenderPassTexture { id: tex1; format: RenderPassTexture.RGBA16F }
821 RenderPassTexture { id: tex2; format: RenderPassTexture.RGBA16F }
822
823 // Pass 3: Process tex1 -> tex2
824 RenderPass {
825 id: process2
826 commands: [
827 ColorAttachment { target: tex2 },
828 RenderablesFilter { layerMask: ContentLayer.Layer11 }
829 ]
830
831 // Pass 2: Process tex0 -> tex1; renders before process2
832 RenderPass {
833 id: process1
834 materialMode: RenderPass.OriginalMaterial
835 commands: [
836 ColorAttachment { target: tex1 }
837 ]
838
839 // Pass 1: Render scene; renders before process1
840 RenderPass {
841 id: scenePass
842 commands: [
843 ColorAttachment { target: tex0 },
844 DepthStencilAttachment { }
845 ]
846 }
847 }
848 }
849
850 Model {
851 layers: ContentLayer.Layer10
852 geometry: PlaneGeometry { }
853 materials: CustomMaterial {
854 property Texture input: Texture {
855 textureProvider: RenderOutputProvider {
856 textureSource: RenderOutputProvider.UserPassTexture
857 renderPass: scenePass
858 }
859 }
860 fragmentShader: "effect1.frag"
861 }
862 }
863
864 Model {
865 layers: ContentLayer.Layer11
866 geometry: PlaneGeometry { }
867 materials: CustomMaterial {
868 property Texture input: Texture {
869 textureProvider: RenderOutputProvider {
870 textureSource: RenderOutputProvider.UserPassTexture
871 renderPass: process1
872 }
873 }
874 fragmentShader: "effect2.frag"
875 }
876 }
877
878 // Display final result
879 SimpleQuadRenderer {
880 texture: Texture {
881 textureProvider: RenderOutputProvider {
882 textureSource: RenderOutputProvider.UserPassTexture
883 renderPass: process2
884 }
885 }
886 }
887}
888\endqml
889
890\section1 Pipeline State Control
891
892The \l PipelineStateOverride command provides detailed control over graphics pipeline state,
893allowing customization of depth testing, blending, culling, and more.
894
895\section2 Depth Testing and Writing
896
897Control how depth values are tested and written:
898
899\qml
900PipelineStateOverride {
901 depthTestEnabled: true
902 depthWriteEnabled: true
903 depthFunction: PipelineStateOverride.LessOrEqual
904}
905\endqml
906
907The \c depthFunction property can be:
908\list
909\li \c Never, \c Less, \c Equal, \c LessOrEqual
910\li \c Greater, \c NotEqual, \c GreaterOrEqual, \c Always
911\endlist
912
913\section2 Blending
914
915Enable and configure blending for transparency:
916
917\qml
918PipelineStateOverride {
919 blendEnabled: true
920 // Uses default blend mode (source alpha blending)
921}
922\endqml
923
924For multiple render targets, use per-target blend states. \l PipelineStateOverride
925exposes the per-attachment value-type properties \c targetBlend0 through
926\c targetBlend7 (of type \l renderTargetBlend) and the blend factor and
927operation enums are in the \c RenderTargetBlend namespace:
928
929\qml
930PipelineStateOverride {
931 targetBlend0.enable: true
932 targetBlend0.srcColor: RenderTargetBlend.SrcAlpha
933 targetBlend0.dstColor: RenderTargetBlend.OneMinusSrcAlpha
934 targetBlend0.opColor: RenderTargetBlend.Add
935
936 targetBlend1.enable: false // No blending for attachment 1
937}
938\endqml
939
940\section2 Culling
941
942Control face culling:
943
944\qml
945PipelineStateOverride {
946 cullMode: PipelineStateOverride.Back // Override material's cull mode to Back
947}
948\endqml
949
950Setting \c cullMode here overrides the value the material would otherwise specify
951for this pass. Options: \c None (no culling), \c Front (cull front faces),
952\c Back (cull back faces).
953
954\section2 Wireframe Rendering
955
956Render geometry as wireframes:
957
958\qml
959PipelineStateOverride {
960 polygonMode: PipelineStateOverride.Line
961 cullMode: PipelineStateOverride.None // Show both sides
962}
963\endqml
964
965The \c polygonMode can be \c Fill (default) or \c Line (wireframe).
966
967\section2 Scissor Rectangles
968
969Limit rendering to a rectangular region:
970
971\qml
972PipelineStateOverride {
973 usesScissor: true
974 scissor: Qt.rect(100, 100, 400, 300) // x, y, width, height
975}
976\endqml
977
978\section2 Viewport Control
979
980Override the viewport:
981
982\qml
983PipelineStateOverride {
984 viewport: Qt.rect(0, 0, 800, 600)
985}
986\endqml
987
988\section2 Complete Example: Wireframe Overlay
989
990This example renders a scene normally, then overlays a wireframe version:
991
992\qml
993View3D {
994 renderOverrides: View3D.DisableInternalPasses
995
996 RenderPassTexture { id: color; format: RenderPassTexture.RGBA16F }
997 RenderPassTexture { id: depth; format: RenderPassTexture.Depth24Stencil8 }
998
999 // Solid pass
1000 RenderPass {
1001 id: solidPass
1002 clearColor: "black"
1003 commands: [
1004 ColorAttachment { target: color },
1005 DepthTextureAttachment { target: depth },
1006 RenderablesFilter {
1007 layerMask: ContentLayer.Layer0
1008 renderableTypes: RenderablesFilter.Opaque
1009 }
1010 ]
1011 }
1012
1013 // Wireframe overlay
1014 RenderPass {
1015 id: wirePass
1016 renderTargetFlags: RenderPass.PreserveColorContents |
1017 RenderPass.PreserveDepthStencilContents
1018 commands: [
1019 ColorAttachment { target: color },
1020 DepthTextureAttachment { target: depth },
1021 PipelineStateOverride {
1022 polygonMode: PipelineStateOverride.Line
1023 depthTestEnabled: true
1024 depthWriteEnabled: false
1025 blendEnabled: true
1026 },
1027 RenderablesFilter { layerMask: ContentLayer.Layer0 }
1028 ]
1029 }
1030
1031 SimpleQuadRenderer {
1032 texture: Texture {
1033 textureProvider: RenderOutputProvider {
1034 textureSource: RenderOutputProvider.UserPassTexture
1035 renderPass: wirePass
1036 }
1037 }
1038 }
1039
1040 PerspectiveCamera { z: 300 }
1041 DirectionalLight { }
1042
1043 Model {
1044 source: "#Sphere"
1045 layers: ContentLayer.Layer0
1046 materials: PrincipledMaterial {
1047 baseColor: "blue"
1048 metalness: 0.5
1049 roughness: 0.3
1050 }
1051 }
1052}
1053\endqml
1054
1055\section1 Augment Shaders for Multiple Render Targets
1056
1057When using \c{RenderPass.AugmentMaterial} mode, you provide an augment shader that injects
1058custom code into the material's fragment shader. This is particularly useful for deferred
1059rendering where you need to output material data to multiple render targets (MRT).
1060
1061\section2 The MAIN_FRAGMENT_AUGMENT Function
1062
1063Your augment shader file must define a \c{MAIN_FRAGMENT_AUGMENT()} function:
1064
1065\badcode
1066void MAIN_FRAGMENT_AUGMENT()
1067{
1068 // Your custom shader code here
1069}
1070\endcode
1071
1072This function is called during the fragment shader after material calculations are complete,
1073giving you access to material properties and the ability to write to custom outputs.
1074
1075\section2 Available Built-in Variables
1076
1077Inside \c{MAIN_FRAGMENT_AUGMENT()}, the engine substitutes a set of macros
1078that expose material pipeline data. Only the macros listed below are part of
1079the augment shader API:
1080
1081\table
1082\header
1083\li Macro
1084\li Type
1085\li Description
1086\row
1087\li \c BASE_COLOR
1088\li vec4
1089\li Material base color (linear color space, after material processing).
1090\row
1091\li \c METALNESS
1092\li float
1093\li Material metalness in the range 0.0 to 1.0.
1094\row
1095\li \c ROUGHNESS
1096\li float
1097\li Material roughness in the range 0.0 to 1.0.
1098\row
1099\li \c WORLD_NORMAL
1100\li vec3
1101\li World-space surface normal (post normal-mapping).
1102\row
1103\li \c WORLD_TANGENT
1104\li vec3
1105\li World-space tangent vector.
1106\row
1107\li \c WORLD_BINORMAL
1108\li vec3
1109\li World-space binormal vector.
1110\row
1111\li \c DIFFUSE_LIGHT
1112\li vec3
1113\li Accumulated diffuse light contribution.
1114\row
1115\li \c SPECULAR_LIGHT
1116\li vec3
1117\li Accumulated specular light contribution.
1118\row
1119\li \c EMISSIVE_LIGHT
1120\li vec3
1121\li Material emissive contribution.
1122\row
1123\li \c F0
1124\li vec3
1125\li Fresnel reflectance at normal incidence.
1126\row
1127\li \c F90
1128\li vec3
1129\li Fresnel reflectance at grazing incidence.
1130\endtable
1131
1132\note Some examples (including the deferred-rendering one below) read the
1133world-space fragment position via \c qt_varWorldPos. This is the engine's
1134underlying varying name, not an augment-shader macro, and falls into the
1135same \e {semi-public} category as the \c .glsllib files described in
1136\l{Built-in Shader Facilities}: it works in practice but is not guaranteed
1137to remain stable across releases.
1138
1139\section2 Writing to Named Outputs
1140
1141Color attachments in your render pass can have names that correspond to output variables
1142in your shader:
1143
1144\qml
1145RenderPass {
1146 commands: [
1147 ColorAttachment { target: tex0; name: "GBUFFER0" },
1148 ColorAttachment { target: tex1; name: "GBUFFER1" },
1149 ColorAttachment { target: tex2; name: "GBUFFER2" }
1150 ]
1151}
1152\endqml
1153
1154In your augment shader:
1155
1156\badcode
1157void MAIN_FRAGMENT_AUGMENT()
1158{
1159 GBUFFER0 = vec4(...); // Writes to first attachment
1160 GBUFFER1 = vec4(...); // Writes to second attachment
1161 GBUFFER2 = vec4(...); // Writes to third attachment
1162}
1163\endcode
1164
1165Qt Quick 3D supports up to 4 simultaneous color attachments (GBUFFER0 through GBUFFER3).
1166
1167\section2 Exposing GPU Resources to the Augment Shader
1168
1169As with \l Effect and \l CustomMaterial, every property declared on the
1170\l RenderPass is exposed to the augment shader as a uniform. Properties
1171of type \l ShaderImage are exposed to
1172the shader as a GLSL image, declared with the \c SHADER_IMAGE macro, and
1173properties of type \l ShaderStorageBuffer as a shader storage buffer,
1174declared with the \c STORAGE_BUFFER macro. The name passed to the macro has
1175to match the name of the property.
1176
1177Unlike the built-in macros listed above, these declarations belong \e outside
1178\c{MAIN_FRAGMENT_AUGMENT()}. Everything around that function is emitted at file
1179scope, which is where a GLSL declaration has to be, whereas the function's body
1180is injected into the material's generated \c{main()}.
1181
1182\badcode
1183// tint_augment.glsl -- declarations at file scope, next to any helper functions
1184STORAGE_BUFFER(tintBuffer, readonly) {
1185 vec4 tints[];
1186}
1187
1188SHADER_IMAGE(rgba8, maskImage, image2D, readonly);
1189
1190void MAIN_FRAGMENT_AUGMENT()
1191{
1192 vec4 mask = imageLoad(maskImage, ivec2(gl_FragCoord.xy));
1193 GBUFFER0 = BASE_COLOR * tints[0] * mask;
1194}
1195\endcode
1196
1197\qml
1198RenderPass {
1199 materialMode: RenderPass.AugmentMaterial
1200 augmentShader: "tint_augment.glsl"
1201
1202 property ShaderImage maskImage: sharedImage
1203 property ShaderStorageBuffer tintBuffer: sharedBuffer
1204
1205 commands: [
1206 ColorAttachment { target: gbuffer0; name: "GBUFFER0" },
1207 DepthStencilAttachment { }
1208 ]
1209}
1210\endqml
1211
1212A resource can be written to as well, by declaring it without the \c readonly
1213qualifier, but keep in mind that the augment shader runs once per fragment of
1214every renderable the pass covers. Producing data is usually better placed in a
1215\l ComputePass, leaving the augment shader to read the result.
1216
1217See \l ShaderImage and \l ShaderStorageBuffer for the resource types themselves
1218and for the constraints the macro arguments have to satisfy.
1219
1220\section2 Complete Augment Shader Example
1221
1222Here's a complete example for a deferred rendering G-buffer pass:
1223
1224\badcode
1225// gbuffer_augment.glsl
1226void MAIN_FRAGMENT_AUGMENT()
1227{
1228 // Get material properties
1229 vec3 baseColor = BASE_COLOR.rgb;
1230 float metalness = METALNESS;
1231 float roughness = ROUGHNESS;
1232 vec3 worldNormal = normalize(WORLD_NORMAL);
1233 vec3 worldPos = qt_varWorldPos;
1234
1235 // GBuffer 0: Albedo (RGB) + Metalness (A)
1236 GBUFFER0 = vec4(baseColor, metalness);
1237
1238 // GBuffer 1: World Normal (RGB) + Roughness (A)
1239 // Encode normal from [-1,1] to [0,1] for storage
1240 GBUFFER1 = vec4(worldNormal * 0.5 + 0.5, roughness);
1241
1242 // GBuffer 2: World Position
1243 GBUFFER2 = vec4(worldPos, 1.0);
1244}
1245\endcode
1246
1247Used with a render pass (\c RenderPassTexture instances are declared as
1248direct children of the enclosing \c View3D and referenced by id):
1249
1250\qml
1251View3D {
1252 RenderPassTexture { id: gbuffer0; format: RenderPassTexture.RGBA16F }
1253 RenderPassTexture { id: gbuffer1; format: RenderPassTexture.RGBA16F }
1254 RenderPassTexture { id: gbuffer2; format: RenderPassTexture.RGBA16F }
1255
1256 RenderPass {
1257 id: gbufferPass
1258 materialMode: RenderPass.AugmentMaterial
1259 augmentShader: "gbuffer_augment.glsl"
1260 commands: [
1261 ColorAttachment { target: gbuffer0; name: "GBUFFER0" },
1262 ColorAttachment { target: gbuffer1; name: "GBUFFER1" },
1263 ColorAttachment { target: gbuffer2; name: "GBUFFER2" },
1264 DepthStencilAttachment { }
1265 ]
1266 }
1267}
1268\endqml
1269
1270\section2 Preserving Material Behavior
1271
1272The augment shader runs \e{in addition to} the normal material pipeline, not instead of it.
1273This means:
1274
1275\list
1276\li The material's textures, properties, and calculations still occur
1277\li You're adding extra outputs, not replacing the primary color output
1278\li The original material's RGBA output is still written to the first color attachment unless overridden
1279\endlist
1280
1281If you only need to output custom data and don't need the standard material calculations,
1282consider using \c{RenderPass.OverrideMaterial} instead.
1283
1284\section2 When to Use Augment vs Override
1285
1286Use \c AugmentMaterial when:
1287\list
1288\li You need material properties (metalness, roughness, normals) for G-buffers
1289\li You want to leverage existing material features like texture mapping
1290\li You need multiple render targets with material data
1291\endlist
1292
1293Use \c OverrideMaterial when:
1294\list
1295\li You need identical behavior for all objects (depth prepass, shadow maps)
1296\li You don't need per-material properties
1297\li You want maximum performance by bypassing material calculations
1298\endlist
1299
1300\section2 Built-in Shader Facilities
1301
1302Augment shaders and custom materials used in render passes have access to Qt Quick 3D's
1303built-in shader infrastructure through an include system. These shader library files
1304(\c{.glsllib}) provide functionality for lighting, shadows, tonemapping, and more.
1305
1306\b{Include Syntax:}
1307
1308Use \c{\#include} directives in your shader code to import functionality:
1309
1310\badcode
1311#include "tonemapping.glsllib"
1312#include "lightsData.glsllib"
1313#include "shadowMapping.glsllib"
1314#include "funcprocessPunctualLighting.glsllib"
1315
1316void MAIN()
1317{
1318 // Use included functions
1319 vec3 color = qt_tonemap(hdrColor);
1320}
1321\endcode
1322
1323\b{Available Shader Libraries:}
1324
1325These shader libraries are located in the engine at \c{src/runtimerender/res/effectlib/}
1326and are considered \e{semi-public}: they are usable in user shaders but do not have the
1327same binary compatibility guarantees as the rest of Qt's public API.
1328
1329\table
1330\header
1331\li Library
1332\li Description
1333\row
1334\li \c{tonemapping.glsllib}
1335\li Provides \c{qt_tonemap()} function for HDR to LDR conversion using the built-in
1336 tonemapping algorithm
1337\row
1338\li \c{lightsData.glsllib}
1339\li Contains scene lighting information (light positions, colors, directions, etc.)
1340 that can be accessed in custom lighting calculations
1341\row
1342\li \c{shadowMapping.glsllib}
1343\li Provides functions for sampling from the default shadow maps, enabling custom
1344 materials to receive shadows
1345\row
1346\li \c{funcprocessPunctualLighting.glsllib}
1347\li Contains \c{qt_processPunctualLighting()} and other built-in lighting functions
1348 for standard PBR lighting calculations
1349\row
1350\li \c{sampleProbe.glsllib}
1351\li Functions for sampling image-based lighting probes (\c{qt_sampleDiffuse()},
1352 \c{qt_sampleGlossyPrincipled()})
1353\endtable
1354
1355\b{Example: Custom Lighting with Built-in Functions}
1356
1357Here's an example fragment shader using the built-in lighting facilities:
1358
1359\badcode
1360#include "lightsData.glsllib"
1361#include "funcprocessPunctualLighting.glsllib"
1362#include "tonemapping.glsllib"
1363#include "sampleProbe.glsllib"
1364
1365void MAIN()
1366{
1367 vec3 worldPos = ...; // From G-buffer or varying
1368 vec3 normal = ...;
1369 vec3 viewDir = normalize(CAMERA_POSITION - worldPos);
1370 vec3 baseColor = ...;
1371 float roughness = ...;
1372 float metalness = ...;
1373
1374 vec3 F0 = mix(vec3(0.04), baseColor, metalness);
1375
1376 vec3 diffuseAccum = vec3(0.0);
1377 vec3 specAccum = vec3(0.0);
1378
1379 // Use built-in punctual lighting (directional, point, spot lights)
1380 qt_processPunctualLighting(diffuseAccum,
1381 specAccum,
1382 baseColor,
1383 worldPos,
1384 normal,
1385 viewDir,
1386 vec3(1.0), // specularAmount
1387 vec3(1.0), // specularTint
1388 roughness,
1389 metalness,
1390 F0,
1391 vec3(1.0)); // F90
1392
1393 // Add image-based lighting
1394 vec4 probeDiffuse = vec4(baseColor, 1.0) * qt_sampleDiffuse(normal);
1395 vec4 probeSpecular = qt_sampleGlossyPrincipled(normal, viewDir, F0, roughness);
1396 diffuseAccum += probeDiffuse.rgb;
1397 specAccum += probeSpecular.rgb;
1398
1399 vec3 color = diffuseAccum + specAccum;
1400
1401 // Apply tonemapping
1402 FRAGCOLOR = vec4(qt_tonemap(color), 1.0);
1403}
1404\endcode
1405
1406\note These shader libraries are semi-public API. While they are stable and intended for
1407use in custom shaders, Qt does not guarantee that their internal implementation or
1408available functions will remain unchanged between releases. However, commonly used functions
1409like \c{qt_tonemap()} and \c{qt_processPunctualLighting()} are unlikely to change
1410significantly.
1411
1412\section1 Advanced Example: Deferred Rendering
1413
1414Deferred rendering is a technique where geometry information is rendered to multiple textures
1415(called a G-buffer or geometry buffer) in a first pass, and lighting calculations are performed
1416in a second pass using the stored geometry data. This approach is particularly efficient when
1417you have many lights, as each pixel is shaded only once regardless of the number of lights.
1418
1419\section2 Deferred Rendering Architecture
1420
1421The deferred rendering pipeline consists of two main passes:
1422
1423\list 1
1424\li \b{Geometry Pass (G-Buffer Pass)}: Renders scene geometry to multiple render targets,
1425 storing material properties such as albedo, normals, roughness, metalness, and world position.
1426\li \b{Lighting Pass}: Renders a full-screen quad that samples the G-buffers and performs
1427 lighting calculations for each pixel based on the stored geometry data.
1428\endlist
1429
1430\section2 G-Buffer Pass Implementation
1431
1432First, define a G-buffer pass that outputs material data to multiple render targets:
1433
1434\b{GBufferPass.qml:} The G-buffer render targets are exposed as required
1435properties so the enclosing \c View3D supplies them and can read their
1436outputs:
1437
1438\qml
1439import QtQuick
1440import QtQuick3D
1441
1442RenderPass {
1443 id: gbufferPass
1444 clearColor: Qt.rgba(0.0, 0.0, 0.0, 0.0)
1445
1446 property alias layerMask: filter.layerMask
1447
1448 // Provided by the View3D that uses this pass
1449 required property RenderPassTexture gbuffer0 // rgb: baseColor, a: metalness
1450 required property RenderPassTexture gbuffer1 // rgb: normal, a: roughness
1451 required property RenderPassTexture gbuffer2 // rgb: world pos, a: spare
1452 required property RenderPassTexture depthTexture
1453
1454 materialMode: RenderPass.AugmentMaterial
1455 augmentShader: "gbuffer_augment.glsl"
1456
1457 commands: [
1458 ColorAttachment { target: gbufferPass.gbuffer0; name: "GBUFFER0" },
1459 ColorAttachment { target: gbufferPass.gbuffer1; name: "GBUFFER1" },
1460 ColorAttachment { target: gbufferPass.gbuffer2; name: "GBUFFER2" },
1461 DepthTextureAttachment { target: gbufferPass.depthTexture },
1462 RenderablesFilter {
1463 id: filter
1464 renderableTypes: RenderablesFilter.Opaque
1465 }
1466 ]
1467}
1468\endqml
1469
1470\b{gbuffer_augment.glsl:}
1471\badcode
1472void MAIN_FRAGMENT_AUGMENT()
1473{
1474 vec3 baseColor = BASE_COLOR.rgb;
1475 float metalness = METALNESS;
1476 float roughness = ROUGHNESS;
1477 vec3 worldNormal = normalize(WORLD_NORMAL);
1478
1479 // GBuffer 0: albedo + metalness
1480 GBUFFER0 = vec4(baseColor, metalness);
1481
1482 // GBuffer 1: normal (encoded to 0..1) + roughness
1483 GBUFFER1 = vec4(worldNormal * 0.5 + 0.5, roughness);
1484
1485 // GBuffer 2: world position
1486 GBUFFER2 = vec4(qt_varWorldPos, 1.0);
1487}
1488\endcode
1489
1490The augment shader accesses material properties computed by the material pipeline and
1491writes them to the three G-buffer attachments. Normals are encoded from [-1,1] to [0,1]
1492range for storage.
1493
1494\section2 Lighting Pass Implementation
1495
1496The lighting pass renders a full-screen quad that samples the G-buffers and computes lighting:
1497
1498\qml
1499// Lighting pass model (full-screen quad)
1500Model {
1501 id: deferredLightingQuad
1502 layers: ContentLayer.Layer13 // Dedicated layer for lighting quad
1503
1504 geometry: PlaneGeometry {
1505 plane: PlaneGeometry.XY // Quad in screen space
1506 }
1507
1508 materials: CustomMaterial {
1509 // Textures for the G-buffers
1510 property Texture gbuffer0: Texture { textureProvider: gbuffer0Provider }
1511 property Texture gbuffer1: Texture { textureProvider: gbuffer1Provider }
1512 property Texture gbuffer2: Texture { textureProvider: gbuffer2Provider }
1513
1514 shadingMode: CustomMaterial.Unshaded
1515 fragmentShader: "lighting.frag"
1516 vertexShader: "lighting.vert"
1517 }
1518}
1519
1520// Lighting pass renders the quad to main output
1521RenderPass {
1522 id: deferredLightingPass
1523 materialMode: RenderPass.OriginalMaterial
1524
1525 commands: [
1526 ColorAttachment { target: mainColorTexture },
1527 DepthStencilAttachment { },
1528 RenderablesFilter { layerMask: ContentLayer.Layer13 }
1529 ]
1530}
1531\endqml
1532
1533The lighting vertex shader (\c lighting.vert) creates a full-screen quad in normalized
1534device coordinates, and the fragment shader (\c lighting.frag) samples the G-buffers and
1535performs lighting calculations.
1536
1537\section2 Complete Integration
1538
1539Here's how to integrate both passes in a View3D:
1540
1541\qml
1542View3D {
1543 renderOverrides: View3D.DisableInternalPasses
1544
1545 // Main output texture
1546 RenderPassTexture { id: mainColorTexture; format: RenderPassTexture.RGBA16F }
1547
1548 // Shared depth texture
1549 RenderPassTexture { id: mainDepthStencilTexture; format: RenderPassTexture.Depth24Stencil8 }
1550
1551 // G-buffer render targets
1552 RenderPassTexture { id: gbuffer0Tex; format: RenderPassTexture.RGBA16F }
1553 RenderPassTexture { id: gbuffer1Tex; format: RenderPassTexture.RGBA16F }
1554 RenderPassTexture { id: gbuffer2Tex; format: RenderPassTexture.RGBA16F }
1555
1556 // Lighting pass (commands as defined above). The G-buffer pass is nested
1557 // inside its consumer, so it renders first and the lighting quad samples
1558 // this frame's G-buffers.
1559 RenderPass {
1560 id: deferredLightingPass
1561 materialMode: RenderPass.OriginalMaterial
1562 commands: [
1563 ColorAttachment { target: mainColorTexture },
1564 DepthStencilAttachment { },
1565 RenderablesFilter { layerMask: ContentLayer.Layer13 }
1566 ]
1567
1568 // G-buffer pass
1569 GBufferPass {
1570 id: gbufferPass
1571 layerMask: ContentLayer.Layer0 | ContentLayer.Layer1
1572 gbuffer0: gbuffer0Tex
1573 gbuffer1: gbuffer1Tex
1574 gbuffer2: gbuffer2Tex
1575 depthTexture: mainDepthStencilTexture
1576 }
1577 }
1578
1579 // Expose G-buffer outputs
1580 RenderOutputProvider {
1581 id: gbuffer0Provider
1582 textureSource: RenderOutputProvider.UserPassTexture
1583 renderPass: gbufferPass
1584 attachmentSelector: RenderOutputProvider.Attachment0
1585 }
1586
1587 RenderOutputProvider {
1588 id: gbuffer1Provider
1589 textureSource: RenderOutputProvider.UserPassTexture
1590 renderPass: gbufferPass
1591 attachmentSelector: RenderOutputProvider.Attachment1
1592 }
1593
1594 RenderOutputProvider {
1595 id: gbuffer2Provider
1596 textureSource: RenderOutputProvider.UserPassTexture
1597 renderPass: gbufferPass
1598 attachmentSelector: RenderOutputProvider.Attachment2
1599 }
1600
1601 // Display final result
1602 SimpleQuadRenderer {
1603 texture: Texture {
1604 textureProvider: RenderOutputProvider {
1605 textureSource: RenderOutputProvider.UserPassTexture
1606 renderPass: deferredLightingPass
1607 attachmentSelector: RenderOutputProvider.Attachment0
1608 }
1609 }
1610 }
1611
1612 // Scene objects
1613 Model {
1614 layers: ContentLayer.Layer0
1615 source: "#Sphere"
1616 materials: PrincipledMaterial {
1617 baseColor: "red"
1618 metalness: 0.5
1619 roughness: 0.3
1620 }
1621 }
1622
1623 // Camera and lights
1624 PerspectiveCamera { z: 300 }
1625 DirectionalLight { eulerRotation.x: -45 }
1626}
1627\endqml
1628
1629\section2 Rendering Flow
1630
1631The rendering proceeds as follows:
1632
1633\list 1
1634\li \b{G-buffer Pass}: Renders first because it is nested inside the lighting
1635 pass. Scene objects on Layer0 and Layer1 are rendered. For each object,
1636 the augment shader writes albedo, normals, roughness, metalness, and position to three
1637 color attachments. Depth is written to the shared depth texture.
1638\li \b{Lighting Pass}: The full-screen quad on Layer13 is rendered. Its custom material
1639 samples the three G-buffer textures and the depth texture, reconstructs the scene
1640 information, and performs lighting calculations (directional lights, image-based lighting,
1641 etc.) to produce the final lit color.
1642\li \b{Display}: The result of the lighting pass is displayed via SimpleQuadRenderer.
1643\endlist
1644
1645\section2 Advantages and Limitations
1646
1647\b{Advantages:}
1648\list
1649\li Efficient with many lights (each pixel lit once)
1650\li Lighting complexity independent of scene complexity
1651\li Easy to implement screen-space effects
1652\li Decouples geometry and lighting passes
1653\endlist
1654
1655\b{Limitations:}
1656\list
1657\li Higher memory bandwidth due to G-buffer reads/writes
1658\li No hardware MSAA (requires alternative anti-aliasing)
1659\li Transparency requires separate forward pass
1660\li More complex pipeline to set up and maintain
1661\endlist
1662
1663For a complete working example, see \l{Qt Quick 3D - User Passes Example}.
1664
1665\section1 Complete Rendering Pipeline Example
1666
1667A realistic custom rendering pipeline often needs to combine multiple pass types: opaque
1668geometry, skybox background, 2D overlays, and transparent objects. Here's a complete example
1669showing how to organize these using \c SubRenderPass for hierarchical composition:
1670
1671\qml
1672View3D {
1673 renderOverrides: View3D.DisableInternalPasses
1674
1675 environment: SceneEnvironment {
1676 backgroundMode: SceneEnvironment.SkyBox
1677 lightProbe: Texture {
1678 textureData: ProceduralSkyTextureData { }
1679 }
1680 }
1681
1682 RenderPassTexture {
1683 id: mainColorTexture
1684 format: RenderPassTexture.RGBA16F
1685 }
1686
1687 RenderPassTexture {
1688 id: mainDepthStencilTexture
1689 format: RenderPassTexture.Depth24Stencil8
1690 }
1691
1692 // Main pass orchestrates the complete render path:
1693 // 1. Opaque geometry (deferred)
1694 // 2. Skybox background
1695 // 3. 2D UI overlays
1696 // 4. Transparent objects (forward)
1697 RenderPass {
1698 id: mainColorPass
1699 clearColor: "black"
1700 renderTargetFlags: RenderPass.PreserveDepthStencilContents
1701
1702 commands: [
1703 ColorAttachment { target: mainColorTexture },
1704 DepthTextureAttachment { target: mainDepthStencilTexture },
1705 RenderablesFilter {
1706 renderableTypes: RenderablesFilter.None // Parent doesn't render
1707 },
1708
1709 // Sub-pass 1: Deferred lighting
1710 SubRenderPass {
1711 renderPass: RenderPass {
1712 id: deferredLightingPass
1713 materialMode: RenderPass.OriginalMaterial
1714 commands: [
1715 PipelineStateOverride {
1716 depthWriteEnabled: false
1717 depthTestEnabled: false
1718 },
1719 RenderablesFilter { layerMask: ContentLayer.Layer13 }
1720 ]
1721 }
1722 },
1723
1724 // Sub-pass 2: Skybox (behind everything)
1725 SubRenderPass {
1726 renderPass: RenderPass {
1727 passMode: RenderPass.SkyboxPass
1728 commands: [
1729 PipelineStateOverride {
1730 depthTestEnabled: true
1731 depthWriteEnabled: false
1732 }
1733 ]
1734 }
1735 },
1736
1737 // Sub-pass 3: 2D Qt Quick content
1738 SubRenderPass {
1739 renderPass: RenderPass {
1740 passMode: RenderPass.Item2DPass
1741 }
1742 },
1743
1744 // Sub-pass 4: Transparent objects (forward rendering)
1745 SubRenderPass {
1746 renderPass: RenderPass {
1747 materialMode: RenderPass.OriginalMaterial
1748 commands: [
1749 RenderablesFilter {
1750 renderableTypes: RenderablesFilter.Transparent
1751 layerMask: ContentLayer.Layer0 | ContentLayer.Layer1
1752 },
1753 PipelineStateOverride {
1754 blendEnabled: true
1755 depthTestEnabled: true
1756 depthWriteEnabled: false
1757 }
1758 ]
1759 }
1760 }
1761 ]
1762 }
1763
1764 // G-buffer pass (referenced by deferred lighting)
1765 GBufferPass {
1766 id: gbufferPass
1767 layerMask: ContentLayer.Layer0 | ContentLayer.Layer1
1768 depthTexture: mainDepthStencilTexture
1769 }
1770
1771 // Full-screen quad for deferred lighting
1772 Model {
1773 layers: ContentLayer.Layer13
1774 geometry: PlaneGeometry { plane: PlaneGeometry.XY }
1775 materials: CustomMaterial {
1776 property Texture gbuffer0: Texture {
1777 textureProvider: RenderOutputProvider {
1778 textureSource: RenderOutputProvider.UserPassTexture
1779 renderPass: gbufferPass
1780 attachmentSelector: RenderOutputProvider.Attachment0
1781 }
1782 }
1783 // ... other G-buffer inputs
1784 shadingMode: CustomMaterial.Unshaded
1785 fragmentShader: "lighting.frag"
1786 vertexShader: "lighting.vert"
1787 }
1788 }
1789
1790 // Display final result
1791 SimpleQuadRenderer {
1792 texture: Texture {
1793 textureProvider: RenderOutputProvider {
1794 textureSource: RenderOutputProvider.UserPassTexture
1795 renderPass: mainColorPass
1796 }
1797 }
1798 }
1799
1800 // Opaque 3D content
1801 Model {
1802 layers: ContentLayer.Layer0
1803 source: "#Sphere"
1804 materials: PrincipledMaterial { baseColor: "red" }
1805 }
1806
1807 // Transparent 3D content
1808 Model {
1809 layers: ContentLayer.Layer1
1810 source: "#Cone"
1811 materials: PrincipledMaterial {
1812 baseColor: Qt.rgba(0.0, 1.0, 0.0, 0.5)
1813 alphaMode: PrincipledMaterial.Blend
1814 }
1815 }
1816
1817 // 2D content in 3D space
1818 Node {
1819 x: -200
1820 y: 100
1821 Item {
1822 Button { text: "Click Me!" }
1823 Rectangle {
1824 color: "blue"
1825 width: 50; height: 50
1826 }
1827 }
1828 }
1829
1830 PerspectiveCamera { z: 300 }
1831 DirectionalLight { eulerRotation.x: -45 }
1832}
1833\endqml
1834
1835\section2 Key Concepts
1836
1837\b{SubRenderPass for Hierarchical Organization:}
1838
1839The main pass uses \c SubRenderPass commands to execute child passes in sequence. The
1840parent pass itself doesn't render anything (\c{RenderablesFilter.None}), it just
1841orchestrates the child passes. This provides a clear structure and allows depth buffer
1842sharing across all sub-passes.
1843
1844\b{Pass Modes:}
1845
1846\list
1847\li \c{RenderPass.UserPass} (default): Custom rendering with your geometry and materials
1848\li \c{RenderPass.SkyboxPass}: Renders the environment skybox from \l SceneEnvironment
1849\li \c{RenderPass.Item2DPass}: Renders 2D Qt Quick content embedded in the 3D scene
1850\endlist
1851
1852\b{Render Order:}
1853
1854\list 1
1855\li Opaque geometry rendered to G-buffer
1856\li Deferred lighting applied to full-screen quad
1857\li Skybox rendered behind geometry (depth test enabled, depth write disabled)
1858\li 2D UI overlays rendered on top
1859\li Transparent objects rendered last with blending
1860\endlist
1861
1862\b{Depth Buffer Sharing:}
1863
1864The \c mainDepthStencilTexture is shared across passes using \c PreserveDepthStencilContents.
1865This ensures skybox renders behind geometry and transparent objects test against opaque
1866geometry correctly.
1867
1868\b{Item2D Content:}
1869
1870Qt Quick 2D items (Button, Rectangle, Text, etc.) placed in \l Node objects are rendered
1871by \c{RenderPass.Item2DPass}. These items are positioned in 3D space but rendered as 2D
1872overlays that can receive mouse/touch input.
1873
1874\section1 Performance Considerations
1875
1876User-defined render passes provide maximum control but require careful consideration of
1877performance implications.
1878
1879\section2 Texture Format Choices
1880
1881Choose texture formats based on your needs:
1882
1883\table
1884\header
1885\li Format
1886\li Size per Pixel
1887\li Use Case
1888\row
1889\li RGBA8
1890\li 4 bytes
1891\li Final output, simple color buffers
1892\row
1893\li RGBA16F
1894\li 8 bytes
1895\li HDR content, intermediate buffers, normals
1896\row
1897\li RGBA32F
1898\li 16 bytes
1899\li High precision calculations, positions
1900\row
1901\li R16F
1902\li 2 bytes
1903\li Single-channel HDR (depth, AO, etc.)
1904\endtable
1905
1906For a 1920x1080 framebuffer:
1907\list
1908\li RGBA8: ~8 MB
1909\li RGBA16F: ~16 MB
1910\li RGBA32F: ~32 MB
1911\li Three RGBA16F G-buffers: ~48 MB
1912\endlist
1913
1914\b{Recommendation:} Use RGBA16F for intermediate buffers and RGBA8 or R8 where sufficient.
1915
1916\section2 Deferred vs Forward Rendering
1917
1918\table
1919\header
1920\li Aspect
1921\li Deferred Rendering
1922\li Forward Rendering
1923\row
1924\li Many lights
1925\li Efficient (O(lights + pixels))
1926\li Expensive (O(lights * objects))
1927\row
1928\li Memory bandwidth
1929\li High (G-buffer reads/writes)
1930\li Lower
1931\row
1932\li Transparency
1933\li Requires separate pass
1934\li Natural support
1935\row
1936\li MSAA
1937\li Not directly supported
1938\li Hardware MSAA works
1939\row
1940\li Setup complexity
1941\li More complex
1942\li Simpler
1943\endtable
1944
1945\b{Use deferred rendering when:}
1946\list
1947\li You have many lights (10+)
1948\li Screen-space effects are important
1949\li Scene is mostly opaque
1950\endlist
1951
1952\b{Use forward rendering when:}
1953\list
1954\li Few lights (<5)
1955\li Lots of transparency
1956\li Memory bandwidth is constrained
1957\li Simpler pipeline is preferable
1958\endlist
1959
1960\section2 Pass Ordering Optimization
1961
1962Render passes execute in nesting order: deeper-nested passes render first;
1963the relative order of passes at equal depth is not defined (see
1964\l{Pass Ordering}). Optimize by:
1965
1966\list
1967\li Rendering opaque geometry before transparent geometry
1968\li Using depth prepass when beneficial (reduces overdraw in complex scenes)
1969\li Minimizing render target switches
1970\li Reusing depth buffers across passes when possible
1971\endlist
1972
1973\section2 Render Target Flags
1974
1975The \l{RenderPass::renderTargetFlags}{renderTargetFlags} property controls memory behavior:
1976
1977\qml
1978RenderPass {
1979 // First pass: write new content
1980 renderTargetFlags: 0 // Default: clear render targets
1981}
1982
1983RenderPass {
1984 // Second pass: add to existing content
1985 renderTargetFlags: RenderPass.PreserveColorContents |
1986 RenderPass.PreserveDepthStencilContents
1987}
1988
1989RenderPass {
1990 // Depth not needed after this pass
1991 renderTargetFlags: RenderPass.DoNotStoreDepthStencilContents
1992}
1993\endqml
1994
1995\b{PreserveColorContents/PreserveDepthStencilContents:} Keep existing data (e.g., for
1996multi-pass rendering to same target).
1997
1998\b{DoNotStoreDepthStencilContents:} Hint that depth/stencil can be discarded (on some
1999hardware this can improve performance by avoiding memory writes).
2000
2001\section2 When to Use User Passes
2002
2003Consider using user render passes when:
2004
2005\list
2006\li Implementing deferred rendering
2007\li Creating complex multi-pass effects
2008\li Needing explicit control over render order
2009\li Implementing custom rendering techniques
2010\li Building screen-space effects that need geometry data
2011\endlist
2012
2013\b{Avoid user passes when:}
2014\list
2015\li Default rendering meets your needs
2016\li You only need post-processing (use \l Effect instead)
2017\li You only need custom material shaders (use \l CustomMaterial instead)
2018\li Performance is critical and extra passes would be wasteful
2019\endlist
2020
2021\section1 Common Patterns and Use Cases
2022
2023User render passes enable many advanced rendering techniques. Here are some common patterns:
2024
2025\section2 Deferred Shading/Lighting
2026
2027Store geometry attributes in G-buffers and perform lighting in screen space. Covered in
2028detail in \l{Advanced Example: Deferred Rendering}.
2029
2030\section2 Edge Detection and Outlining
2031
2032Render scene normally, then apply edge detection in a second pass:
2033
2034\qml
2035// Pass 1: Render scene with normals/depth
2036RenderPass {
2037 id: scenePass
2038 commands: [
2039 ColorAttachment { target: colorTex },
2040 DepthTextureAttachment { target: depthTex }
2041 ]
2042}
2043
2044// Pass 2: Edge detection using depth discontinuities
2045RenderPass {
2046 id: edgePass
2047 commands: [
2048 ColorAttachment { target: outlineTex },
2049 RenderablesFilter { layerMask: ContentLayer.Layer10 }
2050 ]
2051}
2052
2053Model {
2054 layers: ContentLayer.Layer10
2055 geometry: PlaneGeometry { }
2056 materials: CustomMaterial {
2057 // depthProvider is the id of a RenderOutputProvider that exposes
2058 // depthTex as a sampleable texture (see "Render Output Provider"
2059 // earlier in this page).
2060 property Texture depthInput: Texture { textureProvider: depthProvider }
2061 fragmentShader: "edge_detect.frag"
2062 // Shader samples depth, computes gradients, draws edges
2063 }
2064}
2065\endqml
2066
2067\section2 Custom Post-Processing Chains
2068
2069Chain multiple post-processing effects together by feeding each pass's output
2070into the next via \l RenderOutputProvider. See
2071\l{Pass Chaining Example} for a worked example of a multi-stage chain
2072(\c scenePass → \c process1 → \c process2 → display).
2073
2074\section2 Selective Wireframe Overlay
2075
2076Render some objects solid and others as wireframe overlays. See the example in
2077\l{Working with Layers}.
2078
2079\section2 Debug Visualization
2080
2081Create debug passes that visualize normals, depth, or other data:
2082
2083\qml
2084// Normal visualization pass
2085RenderPass {
2086 materialMode: RenderPass.OverrideMaterial
2087 overrideMaterial: CustomMaterial {
2088 fragmentShader: "debug_normals.frag"
2089 // FRAGCOLOR = vec4(normalize(NORMAL) * 0.5 + 0.5, 1.0);
2090 }
2091 commands: [
2092 ColorAttachment { target: debugTex }
2093 ]
2094}
2095\endqml
2096
2097\section2 Custom Shadow Mapping
2098
2099Implement custom shadow mapping with explicit control:
2100
2101\qml
2102// Shadow map pass (render from light's perspective)
2103RenderPass {
2104 id: shadowPass
2105 materialMode: RenderPass.OverrideMaterial
2106 overrideMaterial: CustomMaterial {
2107 fragmentShader: "depth_only.frag"
2108 }
2109 commands: [
2110 DepthTextureAttachment { target: shadowMapTex }
2111 ]
2112}
2113
2114// Main pass using shadow map
2115RenderPass {
2116 id: mainPass
2117 commands: [
2118 ColorAttachment { target: colorTex },
2119 DepthStencilAttachment { }
2120 ]
2121}
2122
2123// Materials in main pass sample shadowMapTex for shadow testing
2124\endqml
2125
2126\section1 Important Considerations
2127
2128When working with user render passes, keep these important points in mind:
2129
2130\section2 Shadow Handling
2131
2132User render passes do \b{not} automatically include Qt Quick 3D's internal shadow rendering.
2133If you disable internal passes and need shadows, you must:
2134
2135\list
2136\li Implement your own shadow mapping passes
2137\li Render the scene from light's perspective to a depth texture
2138\li Sample the shadow map in your lighting calculations
2139\endlist
2140
2141Alternatively, for simpler cases, you may not need shadows or can use pre-baked shadow maps.
2142
2143\section2 HDR and Tonemapping
2144
2145When using floating-point render targets (RGBA16F, RGBA32F), your rendering is in linear
2146HDR space. You must apply tonemapping in your final display pass to convert to displayable
2147LDR:
2148
2149\qml
2150CustomMaterial {
2151 fragmentShader: "tonemap.frag"
2152}
2153\endqml
2154
2155\badcode
2156// In tonemap.frag
2157vec3 tonemap(vec3 hdr) {
2158 // Simple Reinhard tonemapping
2159 return hdr / (hdr + vec3(1.0));
2160}
2161
2162void MAIN() {
2163 vec3 hdrColor = texture(hdrInput, UV0).rgb;
2164 FRAGCOLOR = vec4(tonemap(hdrColor), 1.0);
2165}
2166\endcode
2167
2168Qt Quick 3D provides \c{qt_tonemap()} function in shaders that can be used for this purpose.
2169
2170\section2 Depth Texture Generation
2171
2172When you need depth as a texture (for effects like depth-of-field), use
2173\l DepthTextureAttachment instead of \l DepthStencilAttachment:
2174
2175\qml
2176RenderPassTexture {
2177 id: depthTex
2178 format: RenderPassTexture.Depth24Stencil8
2179}
2180
2181RenderPass {
2182 commands: [
2183 ColorAttachment { target: colorTex },
2184 DepthTextureAttachment { target: depthTex }
2185 // depthTex can now be sampled in shaders
2186 ]
2187}
2188\endqml
2189
2190\section2 Clear Values and Render Target Management
2191
2192Each pass can specify clear values:
2193
2194\qml
2195RenderPass {
2196 clearColor: Qt.rgba(0.0, 0.0, 0.0, 0.0)
2197 depthClearValue: 1.0
2198 stencilClearValue: 0
2199}
2200\endqml
2201
2202When a pass doesn't preserve contents (default), render targets are cleared to these values
2203before rendering. When \c PreserveColorContents or \c PreserveDepthStencilContents is set,
2204existing content is kept and clear values are ignored.
2205
2206\section2 Layer Organization Best Practices
2207
2208Organize your layers logically:
2209
2210\list
2211\li \b{Layer0-2}: Main scene objects
2212\li \b{Layer3-4}: Transparent objects (separate pass)
2213\li \b{Layer10+}: Full-screen quads for post-processing
2214\li \b{Layer15+}: UI/debug overlays
2215\endlist
2216
2217Document your layer usage in comments and be consistent across your application.
2218
2219\section2 Shader Compatibility
2220
2221Augment shaders and custom materials used in render passes must be compatible with Qt Quick
22223D's shader infrastructure:
2223
2224\list
2225\li Use GLSL-compatible syntax
2226\li Include appropriate \c{\#include} directives for Qt Quick 3D functions
2227\li Be aware of available built-in variables
2228\li Test on all target platforms (OpenGL, Vulkan, Metal, D3D)
2229\endlist
2230
2231\section2 Multiple Render Targets Limitations
2232
2233When using multiple render targets (MRT):
2234
2235\list
2236\li Maximum of 4 color attachments
2237\li All attachments must have the same dimensions
2238\li Blend state can be specified per-attachment via \l PipelineStateOverride
2239\li Not all hardware supports MRT (check device capabilities)
2240\endlist
2241
2242\section2 Transparency
2243
2244Transparent objects are challenging with deferred rendering. Common approaches:
2245
2246\list
2247\li \b{Forward pass for transparent}: Render opaque geometry deferred, transparent geometry
2248 in a separate forward pass
2249\li \b{Separate transparent G-buffer}: Render transparent geometry to a separate set of
2250 G-buffers with blending enabled
2251\li \b{Weighted blended order-independent transparency}: Use specialized OIT techniques
2252\endlist
2253
2254For most cases, a separate forward pass for transparent objects is simplest.
2255
2256\section1 API Reference
2257
2258The following table provides a complete reference of all types related to user render passes:
2259
2260\table
2261\header
2262\li Feature
2263\li QML Type
2264\li Description
2265\row
2266\li Main render pass definition
2267\li \l RenderPass
2268\li Defines a rendering pass with commands and material mode
2269\row
2270\li Render target textures
2271\li \l RenderPassTexture
2272\li Texture used as render target (color or depth/stencil)
2273\row
2274\li Texture output provider
2275\li \l RenderOutputProvider
2276\li Exposes render pass output as texture input
2277\row
2278\li Layer constants
2279\li \l ContentLayer
2280\li Singleton providing layer filtering constants
2281\row
2282\li Color output
2283\li \l ColorAttachment
2284\li Specifies a color render target
2285\row
2286\li Depth/stencil (default)
2287\li \l DepthStencilAttachment
2288\li Uses implicit depth/stencil buffer
2289\row
2290\li Depth/stencil (texture)
2291\li \l DepthTextureAttachment
2292\li Uses explicit depth texture
2293\row
2294\li Object filtering
2295\li \l RenderablesFilter
2296\li Filters objects by layer and type
2297\row
2298\li Pipeline state
2299\li \l PipelineStateOverride
2300\li Overrides graphics pipeline state
2301\row
2302\li Nested pass execution
2303\li \c SubRenderPass
2304\li Executes another render pass
2305\row
2306\li Shader defines
2307\li \l AddDefine
2308\li Adds shader preprocessor define
2309\row
2310\li Per-target blend state
2311\li \l renderTargetBlend
2312\li Blend configuration for MRT
2313\row
2314\li Display helper
2315\li \l SimpleQuadRenderer
2316\li Renders final output to View3D
2317\row
2318\li Compute pass definition
2319\li \l ComputePass
2320\li Runs a GLSL compute shader before the main render
2321\row
2322\li Compute dispatch size
2323\li \l Dispatch
2324\li Specifies the work group count for a ComputePass
2325\row
2326\li GPU image resource
2327\li \l ShaderImage
2328\li A sized, formatted image a compute shader (or a material/effect) can read and/or write
2329\row
2330\li GPU storage buffer resource
2331\li \l ShaderStorageBuffer
2332\li A GPU buffer a compute shader (or a material/effect) can read and/or write
2333\endtable
2334
2335\section2 Related Types
2336
2337\table
2338\header
2339\li Type
2340\li Description
2341\row
2342\li \l CustomMaterial
2343\li Custom material with vertex/fragment shaders
2344\row
2345\li \l Effect
2346\li Post-processing effects
2347\row
2348\li \l View3D
2349\li 3D view with \l{View3D::renderOverrides}{renderOverrides} property
2350\row
2351\li \l Model
2352\li 3D model with \l{Model::layers}{layers} property
2353\endtable
2354
2355\section2 Examples
2356
2357\list
2358\li \l{Qt Quick 3D - User Passes Example}: Complete deferred rendering example
2359\endlist
2360
2361\section2 See Also
2362
2363\list
2364\li \l{Programmable Materials, Effects, Geometry, and Texture data}: Overview of Qt Quick 3D
2365 customization features
2366\li \l{Qt Quick 3D Architecture}: Understanding the rendering pipeline
2367\endlist
2368
2369*/