6#ifndef QSSGRENDERHELPERS_P_H
7#define QSSGRENDERHELPERS_P_H
20#include <QtQuick3DRuntimeRender/qtquick3druntimerenderglobal.h>
22#include <QtQuick3DUtils/private/qssgaosettings_p.h>
23#include <QtQuick3DRuntimeRender/private/qssgrenderableobjects_p.h>
28class QSSGRenderShadowMap;
29class QRhiRenderPassDescriptor;
30class QSSGRenderReflectionMap;
31class QSSGRenderMotionVectorMap;
34class QSSGRhiShaderPipeline;
39void rhiRenderShadowMap(QSSGRhiContext *rhiCtx,
41 QSSGRhiGraphicsPipelineState &ps,
42 QSSGRenderShadowMap &shadowMapManager,
43 const QSSGRenderCamera &camera,
44 QSSGRenderCamera *debugCamera,
45 const QSSGShaderLightList &globalLights,
46 const QSSGRenderableObjectList &sortedOpaqueObjects,
47 QSSGRenderer &renderer,
48 const QSSGBounds3 &castingObjectsBox,
49 const QSSGBounds3 &receivingObjectsBox);
51void rhiRenderReflectionMap(
const QSSGRenderContextInterface &context,
54 QSSGRhiGraphicsPipelineState *ps,
55 QSSGRenderReflectionMap &reflectionMapManager,
56 const std::vector<QSSGRenderReflectionProbe *> &reflectionProbes,
57 const QSSGRenderableObjectList &reflectionPassObjects,
58 QSSGRenderer &renderer);
62 const QSSGRhiGraphicsPipelineState &basePipelineState,
63 QRhiRenderPassDescriptor *rpDesc,
65 const QSSGRenderableObjectList &sortedOpaqueObjects,
66 const QSSGRenderableObjectList &sortedTransparentObjects,
71 const QSSGRenderableObjectList &sortedOpaqueObjects,
72 const QSSGRenderableObjectList &sortedTransparentObjects,
73 bool *needsSetViewport);
77 const QSSGRhiGraphicsPipelineState &basePipelineState,
78 QRhiRenderPassDescriptor *rpDesc,
80 const QSSGRenderableObjectList &sortedOpaqueObjects);
83 const QSSGRenderableObjectList &sortedOpaqueObjects,
84 bool *needsSetViewport);
88 QSSGRhiRenderableTexture *renderableTex,
91void rhiRenderAoTexture(QSSGRhiContext *rhiCtx,
93 QSSGRenderer &renderer,
94 QSSGRhiShaderPipeline &shaderPipeline,
95 QSSGRhiGraphicsPipelineState &ps,
96 const QSSGAmbientOcclusionSettings &ao,
97 const QSSGRhiRenderableTexture &rhiAoTexture,
98 const QSSGRhiRenderableTexture &rhiDepthTexture,
99 const QSSGRenderCamera &camera);
104 QSSGRhiRenderableTexture *renderableTex,
108 QSSGRhiShaderResourceBindingList &bindings);
110void rhiPrepareGrid(QSSGRhiContext *rhiCtx,
112 QSSGRenderLayer &layer,
113 QSSGRenderCameraList &cameras,
114 QSSGRenderer &renderer);
116void rhiPrepareSkyBox(
const QSSGRenderContextInterface &context,
118 QSSGRenderLayer &layer,
119 QSSGRenderCameraList &cameras,
120 QSSGRenderer &renderer,
121 uint tonemapMode = 0);
123void rhiPrepareSkyBoxForReflectionMap(
const QSSGRenderContextInterface &context,
125 QSSGRenderLayer &layer,
126 QSSGRenderCamera &inCamera,
127 QSSGRenderer &renderer,
129 QSSGRenderTextureCubeFace cubeFace);
131[[
nodiscard]] qsizetype rhiPrepareOverrideMaterialUserPass(QSSGRhiContext *rhiCtx,
133 const QSSGRhiGraphicsPipelineState &basePipelineState,
134 QRhiRenderPassDescriptor *rpDesc,
135 QSSGRenderGraphObject *overrideMaterial,
137 QSSGRenderableObjectList &inObjects,
138 QSSGShaderFeatures featureSet);
140[[
nodiscard]] qsizetype rhiPrepareOriginalMaterialUserPass(QSSGRhiContext *rhiCtx,
142 const QSSGRhiGraphicsPipelineState &basePipelineState,
143 QRhiRenderPassDescriptor *rpDesc,
145 QSSGRenderableObjectList &inObjects,
146 QSSGShaderFeatures featureSet);
148[[
nodiscard]] qsizetype rhiPrepareAugmentedUserPass(QSSGRhiContext *rhiCtx,
150 const QSSGRhiGraphicsPipelineState &basePipelineState,
151 QRhiRenderPassDescriptor *rpDesc,
152 const QSSGUserShaderAugmentation &shaderAugmentation,
154 QSSGRenderableObjectList &inObjects,
155 QSSGShaderFeatures featureSet);
158 QSSGRenderableObjectList &inObjects);
160Q_QUICK3DRUNTIMERENDER_EXPORT
void rhiPrepareRenderable(QSSGRhiContext *rhiCtx,
163 QSSGRenderableObject &inObject,
164 QRhiRenderPassDescriptor *renderPassDescriptor,
165 QSSGRhiGraphicsPipelineState *ps,
166 QSSGShaderFeatures featureSet,
169 QSSGRenderCamera *alteredCamera =
nullptr,
170 QMatrix4x4 *alteredModelViewProjection =
nullptr,
171 QSSGRenderTextureCubeFace cubeFace = QSSGRenderTextureCubeFaceNone,
175Q_QUICK3DRUNTIMERENDER_EXPORT
void rhiPrepareRenderableForScreenMapPass(QSSGRhiContext *rhiCtx,
178 QSSGRenderableObject &inObject,
179 QRhiRenderPassDescriptor *renderPassDescriptor,
180 QSSGRhiGraphicsPipelineState *ps,
181 QSSGShaderFeatures featureSet,
184 QSSGRenderCamera *alteredCamera =
nullptr,
185 QMatrix4x4 *alteredModelViewProjection =
nullptr,
186 QSSGRenderTextureCubeFace cubeFace = QSSGRenderTextureCubeFaceNone,
190Q_QUICK3DRUNTIMERENDER_EXPORT
void rhiRenderRenderable(QSSGRhiContext *rhiCtx,
191 const QSSGRhiGraphicsPipelineState &state,
192 QSSGRenderableObject &object,
193 bool *needsSetViewport,
194 QSSGRenderTextureCubeFace cubeFace = QSSGRenderTextureCubeFaceNone,
195 qsizetype userPassIndex = -1);
199 QSSGRhiRenderableTexture *renderableTex,
205 QSSGRhiRenderableTexture *renderableTex);
207void rhiPrepareMotionVectorRenderable(QSSGRhiContext *rhiCtx,
210 const QMatrix4x4 &viewProjection,
211 QSSGRenderableObject &inObject,
212 QRhiRenderPassDescriptor *renderPassDescriptor,
213 QSSGRhiGraphicsPipelineState *ps,
214 QSSGRenderMotionVectorMap &motionVectorMapManager);
217 const QSSGRhiGraphicsPipelineState &state,
218 const QSSGRenderableObjectList *motionVectorPassObjects,
223 const int y = deviceRect.bottom() - layerViewport.bottom() + 1;
224 return QRect(layerViewport.x(), y, layerViewport.width(), layerViewport.height());
233 return quint32(qCeil(qSqrt(
double(nodeCount))));
239 const quint64 s = quint64(qMax(0, size.width())) * quint64(qMax(0, size.height())) * quint64(qMax(0, levels));
240 return quint32(qCeil(qSqrt(
double(s))));
void drawLine(const QVector3D &startPoint, const QVector3D &endPoint, const QColor &color, bool isPersistent=false)
void recordRenderDebugObjects(QSSGRhiContext *rhiCtx, QSSGRhiGraphicsPipelineState *ps, QRhiShaderResourceBindings *srb, QRhiRenderPassDescriptor *rpDesc)
void drawPoint(const QVector3D &vertex, const QColor &color, bool isPersistent=false)
void prepareGeometry(QSSGRhiContext *rhiCtx, QRhiResourceUpdateBatch *rub)
void drawBounds(const QSSGBounds3 &bounds, const QColor &color, bool isPersistent=false)
friend class QSSGLayerRenderData
friend class QSSGRenderer
QSSGRenderableObjectFlags renderableFlags
friend class QSSGRenderContextInterface
Combined button and popup list for selecting options.
qsizetype rhiPrepareOverrideMaterialUserPass(QSSGRhiContext *rhiCtx, QSSGPassKey passKey, const QSSGRhiGraphicsPipelineState &basePipelineState, QRhiRenderPassDescriptor *rpDesc, QSSGRenderGraphObject *overrideMaterial, QSSGLayerRenderData &inData, QSSGRenderableObjectList &inObjects, QSSGShaderFeatures featureSet)
void rhiRenderUserAugmentedPass(QSSGRhiContext *rhiCtx, QSSGRenderableObjectList &inObjects)
quint32 rhiCalculateABufferSize(int nodeCount)
void rhiRenderAoTexture(QSSGRhiContext *rhiCtx, QSSGPassKey passKey, QSSGRenderer &renderer, QSSGRhiShaderPipeline &shaderPipeline, QSSGRhiGraphicsPipelineState &ps, const QSSGAmbientOcclusionSettings &ao, const QSSGRhiRenderableTexture &rhiAoTexture, const QSSGRhiRenderableTexture &rhiDepthTexture, const QSSGRenderCamera &camera)
bool rhiPrepareNormalPass(QSSGRhiContext *rhiCtx, QSSGPassKey passKey, const QSSGRhiGraphicsPipelineState &basePipelineState, QRhiRenderPassDescriptor *rpDesc, QSSGLayerRenderData &inData, const QSSGRenderableObjectList &sortedOpaqueObjects)
bool rhiPrepareMotionVectorTexture(QSSGRhiContext *rhiCtx, const QSize &size, QSSGRhiRenderableTexture *renderableTex)
void rhiRenderReflectionMap(const QSSGRenderContextInterface &context, QSSGPassKey passKey, const QSSGLayerRenderData &inData, QSSGRhiGraphicsPipelineState *ps, QSSGRenderReflectionMap &reflectionMapManager, const std::vector< QSSGRenderReflectionProbe * > &reflectionProbes, const QSSGRenderableObjectList &reflectionPassObjects, QSSGRenderer &renderer)
void rhiRenderNormalPass(QSSGRhiContext *rhiCtx, const QSSGRhiGraphicsPipelineState &ps, const QSSGRenderableObjectList &sortedOpaqueObjects, bool *needsSetViewport)
Q_QUICK3DRUNTIMERENDER_EXPORT void rhiRenderRenderable(QSSGRhiContext *rhiCtx, const QSSGRhiGraphicsPipelineState &state, QSSGRenderableObject &object, bool *needsSetViewport, QSSGRenderTextureCubeFace cubeFace=QSSGRenderTextureCubeFaceNone, qsizetype userPassIndex=-1)
qsizetype rhiPrepareAugmentedUserPass(QSSGRhiContext *rhiCtx, QSSGPassKey passKey, const QSSGRhiGraphicsPipelineState &basePipelineState, QRhiRenderPassDescriptor *rpDesc, const QSSGUserShaderAugmentation &shaderAugmentation, const QSSGLayerRenderData &inData, QSSGRenderableObjectList &inObjects, QSSGShaderFeatures featureSet)
bool rhiPrepareDepthPass(QSSGRhiContext *rhiCtx, QSSGPassKey passKey, const QSSGRhiGraphicsPipelineState &basePipelineState, QRhiRenderPassDescriptor *rpDesc, QSSGLayerRenderData &inData, const QSSGRenderableObjectList &sortedOpaqueObjects, const QSSGRenderableObjectList &sortedTransparentObjects, int samples, int viewCount)
qsizetype rhiPrepareOriginalMaterialUserPass(QSSGRhiContext *rhiCtx, QSSGPassKey passKey, const QSSGRhiGraphicsPipelineState &basePipelineState, QRhiRenderPassDescriptor *rpDesc, const QSSGLayerRenderData &inData, QSSGRenderableObjectList &inObjects, QSSGShaderFeatures featureSet)
bool rhiPrepareScreenTexture(QSSGRhiContext *rhiCtx, const QSize &size, bool wantsMips, QSSGRhiRenderableTexture *renderableTex, quint8 viewCount)
QRect correctViewportCoordinates(const QRectF &layerViewport, const QRect &deviceRect)
void addAccumulatorImageBindings(QSSGRhiShaderPipeline *shaderPipeline, QSSGRhiShaderResourceBindingList &bindings)
bool rhiPrepareDepthTexture(QSSGRhiContext *rhiCtx, const QSize &size, QSSGRhiRenderableTexture *renderableTex, quint8 viewCount, int samples=1)
void rhiRenderMotionVector(QSSGRhiContext *rhiCtx, const QSSGRhiGraphicsPipelineState &state, const QSSGRenderableObjectList *motionVectorPassObjects, int bucketsCount)
bool rhiPrepareAoTexture(QSSGRhiContext *rhiCtx, const QSize &size, QSSGRhiRenderableTexture *renderableTex, quint8 viewCount)
quint32 rhiCalculateABufferSize(const QSize &size, int levels)
void rhiRenderDepthPass(QSSGRhiContext *rhiCtx, const QSSGRhiGraphicsPipelineState &ps, const QSSGRenderableObjectList &sortedOpaqueObjects, const QSSGRenderableObjectList &sortedTransparentObjects, bool *needsSetViewport)
void addDebugFrustum(const QSSGBoxPoints &frustumPoints, const QColor &color, QSSGDebugDrawSystem *debugDrawSystem)
void addDebugBox(const QSSGBoxPoints &boxUnsorted, const QColor &color, QSSGDebugDrawSystem *debugDrawSystem)
void addDirectionalLightDebugBox(const QSSGBoxPoints &box, QSSGDebugDrawSystem *debugDrawSystem)
QVarLengthArray< QSSGShaderLight, 16 > QSSGShaderLightList
static void setupCubeShadowCameras(const QSSGLayerRenderData &inData, const QSSGRenderLight *inLight, float shadowMapFar, QSSGRenderCamera inCameras[6])
static void updateUniformsForDefaultMaterial(QSSGRhiShaderPipeline &shaderPipeline, QSSGRhiContext *rhiCtx, const QSSGLayerRenderData &inData, char *ubufData, QSSGRhiGraphicsPipelineState *ps, QSSGSubsetRenderable &subsetRenderable, const QSSGRenderCameraList &cameras, const QVector2D *depthAdjust, const QMatrix4x4 *alteredModelViewProjection, const QSSGRenderGraphObject *materialOverride=nullptr)
static QSSGRhiShaderPipelinePtr shadersForParticleMaterial(QSSGRhiGraphicsPipelineState *ps, QSSGParticlesRenderable &particleRenderable, const QSSGShaderFeatures &featureSet)
static QSSGRhiShaderPipelinePtr shadersForDefaultMaterial(QSSGRhiGraphicsPipelineState *ps, QSSGSubsetRenderable &subsetRenderable, const QSSGShaderFeatures &featureSet, const QSSGUserShaderAugmentation &shaderAugmentation={})
static std::unique_ptr< QSSGRenderCamera > computeShadowCameraFromFrustum(const QMatrix4x4 &lightMatrix, const QMatrix4x4 &lightMatrixInverted, const QVector3D &lightPivot, const QVector3D &lightForward, const QVector3D &lightUp, const float shadowMapResolution, const float pcfRadius, const QSSGBoxPoints &frustumPoints, float frustumStartT, float frustumEndT, float frustumRadius, bool lockShadowmapTexels, const QSSGBounds3 &castingBox, const QSSGBounds3 &receivingBox, QSSGDebugDrawSystem *debugDrawSystem, const bool drawCascades, const bool drawSceneCascadeIntersection)
static QRhiViewport calculateAtlasViewport(QSize atlasPixelSize, const QSSGShadowMapEntry::AtlasEntry &atlasEntry, bool yIsUp)
static QSSGBoxPoints sliceFrustum(const QSSGBoxPoints &frustumPoints, float t0, float t1)
static void rhiPrepareSkyBox_helper(const QSSGRenderContextInterface &context, QSSGPassKey passKey, QSSGRenderLayer &layer, QSSGRenderCameraList &cameras, QSSGRenderer &renderer, QSSGReflectionMapEntry *entry=nullptr, QSSGRenderTextureCubeFace cubeFace=QSSGRenderTextureCubeFaceNone, uint tonemapMode=0)
static QT_BEGIN_NAMESPACE constexpr float QSSG_PI
static void rhiPrepareResourcesForReflectionMap(const QSSGRenderContextInterface &context, QSSGPassKey passKey, const QSSGLayerRenderData &inData, QSSGReflectionMapEntry *pEntry, QSSGRhiGraphicsPipelineState *ps, const QSSGRenderableObjectList &sortedOpaqueObjects, QSSGRenderCamera &inCamera, QSSGRenderer &renderer, QSSGRenderTextureCubeFace cubeFace)
static void rhiPrepareResourcesForShadowMap(QSSGRhiContext *rhiCtx, const QSSGLayerRenderData &inData, QSSGPassKey passKey, QSSGShadowMapEntry *pEntry, QSSGRhiGraphicsPipelineState *ps, const QVector2D *depthAdjust, const QSSGRenderableObjectList &sortedOpaqueObjects, QSSGRenderCamera &inCamera, bool orthographic, QSSGRenderTextureCubeFace cubeFace, quint32 cascadeIndex)
static void addOpaqueDepthPrePassBindings(QSSGRhiContext *rhiCtx, QSSGRhiShaderPipeline *shaderPipeline, QSSGRenderableImage *renderableImage, QSSGRhiShaderResourceBindingList &bindings, bool isCustomMaterialMeshSubset=false)
static QSSGBoxPoints computeFrustumBounds(const QMatrix4x4 &projection)
static void addNormalTextureBindings(QSSGRhiContext *rhiCtx, QSSGRhiShaderPipeline *shaderPipeline, QSSGRhiShaderResourceBindingList &bindings)
static const QRhiShaderResourceBinding::StageFlags RENDERER_VISIBILITY_ALL
static QRhiShaderResourceBindings * drawCallDataSrb(QSSGRhiContextPrivate *rhiCtxD, QSSGRhiDrawCallData &dcd, const QSSGRhiShaderResourceBindingList &bindings)
static constexpr float QSSG_HALFPI
void rhiPrepareRenderableImp(QSSGRhiContext *rhiCtx, QSSGPassKey passKey, const QSSGLayerRenderData &inData, QSSGRenderableObject &inObject, QRhiRenderPassDescriptor *renderPassDescriptor, QSSGRhiGraphicsPipelineState *ps, QSSGShaderFeatures featureSet, int samples, int viewCount, bool screenMapPass, QSSGRenderCamera *alteredCamera, QMatrix4x4 *alteredModelViewProjection, QSSGRenderTextureCubeFace cubeFace, QSSGReflectionMapEntry *entry, bool oit)
static int setupInstancing(QSSGSubsetRenderable *renderable, QSSGRhiGraphicsPipelineState *ps, QSSGRhiContext *rhiCtx, const QVector3D &cameraDirection, const QVector3D &cameraPosition)
static void setupCubeReflectionCameras(const QSSGLayerRenderData &inData, const QSSGRenderReflectionProbe *inProbe, QSSGRenderCamera inCameras[6])
static void fillTargetBlend(QRhiGraphicsPipeline::TargetBlend *targetBlend, QSSGRenderDefaultMaterial::MaterialBlendMode materialBlend)
static void addDepthTextureBindings(QSSGRhiContext *rhiCtx, QSSGRhiShaderPipeline *shaderPipeline, QSSGRhiShaderResourceBindingList &bindings, QBitArray *specifiedBindings=nullptr)
static QVarLengthArray< std::unique_ptr< QSSGRenderCamera >, 4 > setupCascadingCamerasForShadowMap(const QSSGLayerRenderData &data, const QSSGRenderCamera &inCamera, const QSSGRenderLight *inLight, const int shadowMapResolution, const float pcfRadius, const float clipNear, const float clipFar, const QSSGBounds3 &castingObjectsBox, const QSSGBounds3 &receivingObjectsBox, bool lockShadowmapTexels, QSSGDebugDrawSystem *debugDrawSystem, bool drawCascades, bool drawSceneCascadeIntersection)
bool castsShadows() const
QSSGRenderableObject * obj