1 | // Copyright (C) 2008-2012 NVIDIA Corporation. |
2 | // Copyright (C) 2019 The Qt Company Ltd. |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
4 | |
5 | #include <QtQuick3DRuntimeRender/private/qssgrenderer_p.h> |
6 | #include <QtQuick3DRuntimeRender/private/qssgrenderlight_p.h> |
7 | #include <QtQuick3DRuntimeRender/private/qssgrendercontextcore_p.h> |
8 | #include <QtQuick3DRuntimeRender/private/qssgrendershadercache_p.h> |
9 | #include <QtQuick3DRuntimeRender/private/qssgrendershaderlibrarymanager_p.h> |
10 | #include <QtQuick3DRuntimeRender/private/qssgrendershadercodegenerator_p.h> |
11 | #include <QtQuick3DRuntimeRender/private/qssgrenderdefaultmaterialshadergenerator_p.h> |
12 | #include <QtQuick3DRuntimeRender/private/qssgvertexpipelineimpl_p.h> |
13 | |
14 | // this file contains the getXxxxShader implementations suitable for the QRhi-based rendering path |
15 | |
16 | QT_BEGIN_NAMESPACE |
17 | |
18 | QSSGRhiShaderPipelinePtr QSSGRenderer::getBuiltinRhiShader(const QByteArray &name, |
19 | QSSGRhiShaderPipelinePtr &storage) |
20 | { |
21 | QSSGRhiShaderPipelinePtr &result = storage; |
22 | if (!result) { |
23 | // loadBuiltin must always return a valid QSSGRhiShaderPipeline. |
24 | // There will just be no stages if loading fails. |
25 | result = m_contextInterface->shaderCache()->loadBuiltinForRhi(inKey: name); |
26 | } |
27 | return result; |
28 | } |
29 | |
30 | QSSGRhiShaderPipelinePtr QSSGRenderer::getRhiCubemapShadowBlurXShader() |
31 | { |
32 | return getBuiltinRhiShader(QByteArrayLiteral("cubeshadowblurx" ), storage&: m_cubemapShadowBlurXRhiShader); |
33 | } |
34 | |
35 | QSSGRhiShaderPipelinePtr QSSGRenderer::getRhiCubemapShadowBlurYShader() |
36 | { |
37 | return getBuiltinRhiShader(QByteArrayLiteral("cubeshadowblury" ), storage&: m_cubemapShadowBlurYRhiShader); |
38 | } |
39 | |
40 | QSSGRhiShaderPipelinePtr QSSGRenderer::getRhiGridShader() |
41 | { |
42 | return getBuiltinRhiShader(QByteArrayLiteral("grid" ), storage&: m_gridShader); |
43 | } |
44 | |
45 | QSSGRhiShaderPipelinePtr QSSGRenderer::getRhiOrthographicShadowBlurXShader() |
46 | { |
47 | return getBuiltinRhiShader(QByteArrayLiteral("orthoshadowblurx" ), storage&: m_orthographicShadowBlurXRhiShader); |
48 | } |
49 | |
50 | QSSGRhiShaderPipelinePtr QSSGRenderer::getRhiOrthographicShadowBlurYShader() |
51 | { |
52 | return getBuiltinRhiShader(QByteArrayLiteral("orthoshadowblury" ), storage&: m_orthographicShadowBlurYRhiShader); |
53 | } |
54 | |
55 | QSSGRhiShaderPipelinePtr QSSGRenderer::getRhiSsaoShader() |
56 | { |
57 | return getBuiltinRhiShader(QByteArrayLiteral("ssao" ), storage&: m_ssaoRhiShader); |
58 | } |
59 | |
60 | QSSGRhiShaderPipelinePtr QSSGRenderer::getRhiSkyBoxCubeShader() |
61 | { |
62 | return getBuiltinRhiShader(QByteArrayLiteral("skyboxcube" ), storage&: m_skyBoxCubeRhiShader); |
63 | } |
64 | |
65 | QSSGRhiShaderPipelinePtr QSSGRenderer::getRhiSkyBoxShader(QSSGRenderLayer::TonemapMode tonemapMode, bool isRGBE) |
66 | { |
67 | // Skybox shader is special and has multiple possible shaders so we have to do |
68 | // a bit of manual work here. |
69 | |
70 | QSSGRhiShaderPipelinePtr &result = m_skyBoxRhiShader; |
71 | if (!result || tonemapMode != m_skyboxTonemapMode || isRGBE != m_isSkyboxRGBE) { |
72 | QByteArray name = QByteArrayLiteral("skybox" ); |
73 | if (isRGBE) |
74 | name.append(QByteArrayLiteral("_rgbe" )); |
75 | else |
76 | name.append(QByteArrayLiteral("_hdr" )); |
77 | |
78 | switch (tonemapMode) { |
79 | case QSSGRenderLayer::TonemapMode::None: |
80 | name.append(QByteArrayLiteral("_none" )); |
81 | break; |
82 | case QSSGRenderLayer::TonemapMode::Aces: |
83 | name.append(QByteArrayLiteral("_aces" )); |
84 | break; |
85 | case QSSGRenderLayer::TonemapMode::HejlDawson: |
86 | name.append(QByteArrayLiteral("_hejldawson" )); |
87 | break; |
88 | case QSSGRenderLayer::TonemapMode::Filmic: |
89 | name.append(QByteArrayLiteral("_filmic" )); |
90 | break; |
91 | case QSSGRenderLayer::TonemapMode::Linear: |
92 | default: |
93 | name.append(QByteArrayLiteral("_linear" )); |
94 | } |
95 | |
96 | result = m_contextInterface->shaderCache()->loadBuiltinForRhi(inKey: name); |
97 | m_skyboxTonemapMode = tonemapMode; |
98 | m_isSkyboxRGBE = isRGBE; |
99 | } |
100 | return result; |
101 | } |
102 | |
103 | QSSGRhiShaderPipelinePtr QSSGRenderer::getRhiSupersampleResolveShader() |
104 | { |
105 | return getBuiltinRhiShader(QByteArrayLiteral("ssaaresolve" ), storage&: m_supersampleResolveRhiShader); |
106 | } |
107 | |
108 | QSSGRhiShaderPipelinePtr QSSGRenderer::getRhiProgressiveAAShader() |
109 | { |
110 | return getBuiltinRhiShader(QByteArrayLiteral("progressiveaa" ), storage&: m_progressiveAARhiShader); |
111 | } |
112 | |
113 | QSSGRhiShaderPipelinePtr QSSGRenderer::getRhiTexturedQuadShader() |
114 | { |
115 | return getBuiltinRhiShader(QByteArrayLiteral("texturedquad" ), storage&: m_texturedQuadRhiShader); |
116 | } |
117 | |
118 | QSSGRhiShaderPipelinePtr QSSGRenderer::getRhiParticleShader(QSSGRenderParticles::FeatureLevel featureLevel) |
119 | { |
120 | switch (featureLevel) { |
121 | case QSSGRenderParticles::FeatureLevel::Simple: |
122 | return getBuiltinRhiShader(QByteArrayLiteral("particlesnolightsimple" ), storage&: m_particlesNoLightingSimpleRhiShader); |
123 | break; |
124 | case QSSGRenderParticles::FeatureLevel::Mapped: |
125 | return getBuiltinRhiShader(QByteArrayLiteral("particlesnolightmapped" ), storage&: m_particlesNoLightingMappedRhiShader); |
126 | break; |
127 | case QSSGRenderParticles::FeatureLevel::Animated: |
128 | return getBuiltinRhiShader(QByteArrayLiteral("particlesnolightanimated" ), storage&: m_particlesNoLightingAnimatedRhiShader); |
129 | break; |
130 | case QSSGRenderParticles::FeatureLevel::SimpleVLight: |
131 | return getBuiltinRhiShader(QByteArrayLiteral("particlesvlightsimple" ), storage&: m_particlesVLightingSimpleRhiShader); |
132 | break; |
133 | case QSSGRenderParticles::FeatureLevel::MappedVLight: |
134 | return getBuiltinRhiShader(QByteArrayLiteral("particlesvlightmapped" ), storage&: m_particlesVLightingMappedRhiShader); |
135 | break; |
136 | case QSSGRenderParticles::FeatureLevel::AnimatedVLight: |
137 | return getBuiltinRhiShader(QByteArrayLiteral("particlesvlightanimated" ), storage&: m_particlesVLightingAnimatedRhiShader); |
138 | break; |
139 | case QSSGRenderParticles::FeatureLevel::Line: |
140 | return getBuiltinRhiShader(QByteArrayLiteral("lineparticles" ), storage&: m_lineParticlesRhiShader); |
141 | break; |
142 | case QSSGRenderParticles::FeatureLevel::LineMapped: |
143 | return getBuiltinRhiShader(QByteArrayLiteral("lineparticlesmapped" ), storage&: m_lineParticlesMappedRhiShader); |
144 | break; |
145 | case QSSGRenderParticles::FeatureLevel::LineAnimated: |
146 | return getBuiltinRhiShader(QByteArrayLiteral("lineparticlesanimated" ), storage&: m_lineParticlesAnimatedRhiShader); |
147 | break; |
148 | case QSSGRenderParticles::FeatureLevel::LineVLight: |
149 | return getBuiltinRhiShader(QByteArrayLiteral("lineparticlesvlightsimple" ), storage&: m_lineParticlesVLightRhiShader); |
150 | break; |
151 | case QSSGRenderParticles::FeatureLevel::LineMappedVLight: |
152 | return getBuiltinRhiShader(QByteArrayLiteral("lineparticlesvlightmapped" ), storage&: m_lineParticlesMappedVLightRhiShader); |
153 | break; |
154 | case QSSGRenderParticles::FeatureLevel::LineAnimatedVLight: |
155 | return getBuiltinRhiShader(QByteArrayLiteral("lineparticlesvlightanimated" ), storage&: m_lineParticlesAnimatedVLightRhiShader); |
156 | break; |
157 | } |
158 | return getBuiltinRhiShader(QByteArrayLiteral("particlesnolightanimated" ), storage&: m_particlesNoLightingAnimatedRhiShader); |
159 | } |
160 | |
161 | QSSGRhiShaderPipelinePtr QSSGRenderer::getRhiSimpleQuadShader() |
162 | { |
163 | return getBuiltinRhiShader(QByteArrayLiteral("simplequad" ), storage&: m_simpleQuadRhiShader); |
164 | } |
165 | |
166 | QSSGRhiShaderPipelinePtr QSSGRenderer::getRhiLightmapUVRasterizationShader(LightmapUVRasterizationShaderMode mode) |
167 | { |
168 | switch (mode) { |
169 | case LightmapUVRasterizationShaderMode::Uv: |
170 | return getBuiltinRhiShader(QByteArrayLiteral("lightmapuvraster_uv" ), storage&: m_lightmapUVRasterShader_uv); |
171 | case LightmapUVRasterizationShaderMode::UvTangent: |
172 | return getBuiltinRhiShader(QByteArrayLiteral("lightmapuvraster_uv_tangent" ), storage&: m_lightmapUVRasterShader_uv_tangent); |
173 | default: |
174 | break; |
175 | } |
176 | return getBuiltinRhiShader(QByteArrayLiteral("lightmapuvraster" ), storage&: m_lightmapUVRasterShader); |
177 | } |
178 | |
179 | QSSGRhiShaderPipelinePtr QSSGRenderer::getRhiLightmapDilateShader() |
180 | { |
181 | return getBuiltinRhiShader(QByteArrayLiteral("lightmapdilate" ), storage&: m_lightmapDilateShader); |
182 | } |
183 | |
184 | QSSGRhiShaderPipelinePtr QSSGRenderer::getRhiDebugObjectShader() |
185 | { |
186 | return getBuiltinRhiShader(QByteArrayLiteral("debugobject" ), storage&: m_debugObjectShader); |
187 | } |
188 | |
189 | QT_END_NAMESPACE |
190 | |