51 #include "../shared/examplefw.h"
52 #include "../shared/cube.h"
57 static float quadVertexData[] =
65 static quint16 quadIndexData[] =
96 qFatal(
"Depth texture is not supported");
100 d.releasePool <<
d.vbuf;
104 d.releasePool <<
d.ibuf;
109 d.releasePool <<
d.ubuf;
112 d.releasePool <<
d.shadowMap;
113 d.shadowMap->create();
117 d.releasePool <<
d.shadowSampler;
119 d.shadowSampler->create();
122 d.releasePool <<
d.srb;
129 d.releasePool <<
d.ps;
130 d.ps->setShaderStages({
134 d.ps->setDepthTest(
true);
135 d.ps->setDepthWrite(
true);
139 { 3 *
sizeof(float) }
144 d.ps->setVertexInputLayout(inputLayout);
145 d.ps->setShaderResourceBindings(
d.srb);
146 d.ps->setRenderPassDescriptor(
m_rp);
150 d.initialUpdates->uploadStaticBuffer(
d.vbuf, 0,
sizeof(quadVertexData), quadVertexData);
151 d.initialUpdates->uploadStaticBuffer(
d.vbuf,
sizeof(quadVertexData),
sizeof(cube), cube);
152 d.initialUpdates->uploadStaticBuffer(
d.ibuf, quadIndexData);
157 d.releasePool <<
d.rt;
158 d.rtRp =
d.rt->newCompatibleRenderPassDescriptor();
159 d.releasePool <<
d.rtRp;
160 d.rt->setRenderPassDescriptor(
d.rtRp);
164 d.releasePool <<
d.shadowSrb;
166 d.shadowSrb->create();
169 d.releasePool <<
d.shadowPs;
170 d.shadowPs->setShaderStages({
174 d.shadowPs->setDepthTest(
true);
175 d.shadowPs->setDepthWrite(
true);
177 { 3 *
sizeof(float) }
182 d.shadowPs->setVertexInputLayout(inputLayout);
183 d.shadowPs->setShaderResourceBindings(
d.shadowSrb);
184 d.shadowPs->setRenderPassDescriptor(
d.rtRp);
185 d.shadowPs->create();
191 d.releasePool.clear();
198 cb->setShaderResources(
srb, 1, &ubufOffset);
205 ubufOffset.second += oneRoundedUniformBlockSize;
206 cb->setShaderResources(
srb, 1, &ubufOffset);
207 vbufBinding.second =
sizeof(quadVertexData);
208 cb->setVertexInput(0, 1, &vbufBinding);
214 const QSize outputSizeInPixels =
m_sc->currentPixelSize();
217 if (
d.initialUpdates) {
218 u->merge(
d.initialUpdates);
219 d.initialUpdates->release();
220 d.initialUpdates =
nullptr;
227 float *sbp = shadowBias.
data();
230 *sbp++ = 0.5f; *sbp++ = 0.0f; *sbp++ = 0.0f; *sbp++ = 0.0f;
231 *sbp++ = 0.0f; *sbp++ =
m_r->
isYUpInNDC() ? -0.5f : 0.5f; *sbp++ = 0.0f; *sbp++ = 0.0f;
232 *sbp++ = 0.0f; *sbp++ = 0.0f; *sbp++ = 1.0f; *sbp++ = 0.0f;
233 *sbp++ = 0.5f; *sbp++ = 0.5f; *sbp++ = 0.0f; *sbp++ = 1.0f;
236 *sbp++ = 0.5f; *sbp++ = 0.0f; *sbp++ = 0.0f; *sbp++ = 0.0f;
237 *sbp++ = 0.0f; *sbp++ = 0.5f; *sbp++ = 0.0f; *sbp++ = 0.0f;
238 *sbp++ = 0.0f; *sbp++ = 0.0f; *sbp++ = 0.5f; *sbp++ = 0.0f;
239 *sbp++ = 0.5f; *sbp++ = 0.5f; *sbp++ = 0.5f; *sbp++ = 1.0f;
253 m.rotate(-60, 1, 0, 0);
257 u->updateDynamicBuffer(
d.ubuf, 0, 64, mvp.
constData());
259 u->updateDynamicBuffer(
d.ubuf, 64, 64, shadowMvp.
constData());
260 u->updateDynamicBuffer(
d.ubuf, 128, 64, shadowBias.
constData());
262 u->updateDynamicBuffer(
d.ubuf, 192, 4, &useShadows);
265 u->updateDynamicBuffer(
d.ubuf, 2 * oneRoundedUniformBlockSize, 64, shadowMvp.
constData());
270 m.translate(0, 0.5f, 2);
272 m.rotate(
d.cubeRot, 0, 1, 0);
273 m.rotate(45, 1, 0, 0);
278 u->updateDynamicBuffer(
d.ubuf, oneRoundedUniformBlockSize, 64, mvp.
constData());
280 u->updateDynamicBuffer(
d.ubuf, oneRoundedUniformBlockSize + 64, 64, shadowMvp.
constData());
281 u->updateDynamicBuffer(
d.ubuf, oneRoundedUniformBlockSize + 128, 64, shadowBias.
constData());
283 u->updateDynamicBuffer(
d.ubuf, oneRoundedUniformBlockSize + 192, 4, &useShadows);
286 u->updateDynamicBuffer(
d.ubuf, 3 * oneRoundedUniformBlockSize, 64, shadowMvp.
constData());
288 cb->resourceUpdate(
u);
291 const QSize shadowMapSize =
d.shadowMap->pixelSize();
292 cb->beginPass(
d.rt,
QColor(), { 1.0f, 0 });
293 cb->setGraphicsPipeline(
d.shadowPs);
294 cb->setViewport({ 0, 0, float(shadowMapSize.
width()), float(shadowMapSize.
height()) });
295 enqueueScene(
cb,
d.shadowSrb, oneRoundedUniformBlockSize, 2);
300 cb->setGraphicsPipeline(
d.ps);
301 cb->setViewport({ 0, 0, float(outputSizeInPixels.
width()), float(outputSizeInPixels.
height()) });
302 enqueueScene(
cb,
d.srb, oneRoundedUniformBlockSize, 0);
small capitals from c petite p scientific f u
The QColor class provides colors based on RGB, HSV or CMYK values.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
void lookAt(const QVector3D &eye, const QVector3D ¢er, const QVector3D &up)
void perspective(float verticalAngle, float aspectRatio, float nearPlane, float farPlane)
const float * constData() const
QPair< QRhiBuffer *, quint32 > VertexInput
QPair< int, quint32 > DynamicOffset
bool isClipDepthZeroToOne() const
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags={}) const
int ubufAligned(int v) const
QMatrix4x4 clipSpaceCorrMatrix() const
QRhiShaderResourceBindings * newShaderResourceBindings()
QRhiBuffer * newBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, int size)
QRhiSampler * newSampler(QRhiSampler::Filter magFilter, QRhiSampler::Filter minFilter, QRhiSampler::Filter mipmapMode, QRhiSampler::AddressMode addressU, QRhiSampler::AddressMode addressV, QRhiSampler::AddressMode addressW=QRhiSampler::Repeat)
QRhiTextureRenderTarget * newTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc, QRhiTextureRenderTarget::Flags flags={})
QRhiGraphicsPipeline * newGraphicsPipeline()
QRhiTexture * newTexture(QRhiTexture::Format format, const QSize &pixelSize, int sampleCount=1, QRhiTexture::Flags flags={})
QRhiResourceUpdateBatch * nextResourceUpdateBatch()
static QRhiShaderResourceBinding uniformBufferWithDynamicOffset(int binding, StageFlags stage, QRhiBuffer *buf, int size)
static QRhiShaderResourceBinding sampledTexture(int binding, StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler)
void setDepthTexture(QRhiTexture *texture)
The QSize class defines the size of a two-dimensional object using integer point precision.
constexpr int height() const noexcept
constexpr int width() const noexcept
The QVector3D class represents a vector or vertex in 3D space.
std::unique_ptr< QRhiSwapChain > m_sc
std::unique_ptr< QRhiRenderPassDescriptor > m_rp
virtual void customRender()
virtual void customInit()
qDeleteAll(list.begin(), list.end())
QShader getShader(const QString &name)
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
QRhiSampler * shadowSampler
QRhiShaderResourceBindings * shadowSrb
QList< QRhiResource * > releasePool
QRhiTextureRenderTarget * rt
QRhiRenderPassDescriptor * rtRp
QRhiGraphicsPipeline * shadowPs
const int SHADOW_UBLOCK_SIZE
QRhiShaderResourceBindings * srb
QRhiGraphicsPipeline * ps
QRhiResourceUpdateBatch * initialUpdates