From e978abefe1d41e691aecf7210c27164de7b222f0 Mon Sep 17 00:00:00 2001 From: Berthold Krevert Date: Fri, 8 Mar 2024 12:43:27 +0100 Subject: [PATCH] Revert "Add Multisampling Support. This drops support for older GL ES Versions. The plugin now also respects Device Pixel Ratio." This reverts commit 82996e6ff4f62c7acdc4478d47dfe02a523cf7a5. --- src/RiveQtQuickItem/CMakeLists.txt | 1 - .../renderer/riveqtfactory.cpp | 21 +++++- src/RiveQtQuickItem/renderer/riveqtfactory.h | 6 +- .../renderer/riveqtrhirenderer.cpp | 38 +++++----- .../rhi/postprocessingsmaa.cpp | 28 +++----- src/RiveQtQuickItem/rhi/postprocessingsmaa.h | 6 +- src/RiveQtQuickItem/rhi/texturetargetnode.cpp | 17 +++-- src/RiveQtQuickItem/riveqsgrhirendernode.cpp | 58 ++++++--------- src/RiveQtQuickItem/riveqsgrhirendernode.h | 8 +-- src/RiveQtQuickItem/riveqtquickitem.cpp | 12 ++-- .../shaders/qt6/blendRiveTextureNode.frag | 21 ++---- .../shaders/qt6/drawRiveTextureNode.frag | 1 + .../shaders/qt6/edges-luma.frag | 30 +++----- .../shaders/qt6/finalDraw.frag | 21 ++---- .../shaders/qt6/smaa-blend.frag | 30 +++----- .../shaders/qt6/smaa-weights.frag | 70 ++++++++----------- 16 files changed, 153 insertions(+), 215 deletions(-) diff --git a/src/RiveQtQuickItem/CMakeLists.txt b/src/RiveQtQuickItem/CMakeLists.txt index d4c871d..b9a421d 100644 --- a/src/RiveQtQuickItem/CMakeLists.txt +++ b/src/RiveQtQuickItem/CMakeLists.txt @@ -108,7 +108,6 @@ include_directories(${Qt${QT_VERSION_MAJOR}Gui_PRIVATE_INCLUDE_DIRS}) if (${QT_VERSION_MAJOR} EQUAL 6) find_package(Qt6 COMPONENTS ShaderTools) qt6_add_shaders(${PROJECT_NAME} "graph-shaders" - GLSL "300es,330" BATCHABLE PRECOMPILE OPTIMIZED diff --git a/src/RiveQtQuickItem/renderer/riveqtfactory.cpp b/src/RiveQtQuickItem/renderer/riveqtfactory.cpp index 4086ffc..fb9320c 100644 --- a/src/RiveQtQuickItem/renderer/riveqtfactory.cpp +++ b/src/RiveQtQuickItem/renderer/riveqtfactory.cpp @@ -48,10 +48,24 @@ RiveQSGRenderNode *RiveQtFactory::renderNode(QQuickWindow *window, std::weak_ptr } } -rive::rcp RiveQtFactory::makeRenderBuffer(rive::RenderBufferType renderBufferType, - rive::RenderBufferFlags renderBufferFlags, size_t size) +rive::rcp RiveQtFactory::makeBufferU16(rive::Span data) { - return rive::make_rcp(renderBufferType, renderBufferFlags, size); + return nullptr; +} + +rive::rcp RiveQtFactory::makeBufferU32(rive::Span data) +{ + return nullptr; +} + +rive::rcp RiveQtFactory::makeBufferF32(rive::Span data) +{ + return nullptr; +} + +rive::rcp RiveQtFactory::makeRenderBuffer(rive::RenderBufferType renderBufferType, rive::RenderBufferFlags renderBufferFlags, size_t size) +{ + return rive::make_rcp(renderBufferType, renderBufferFlags, size);; } rive::rcp RiveQtFactory::makeLinearGradient(float x1, float y1, float x2, float y2, const rive::ColorInt *colors, @@ -146,6 +160,7 @@ rive::rcp RiveQtFactory::decodeFont(rive::Span span) QFont font(fontFamilies.first()); return rive::rcp(new RiveQtFont(font));*/ + } unsigned int RiveQtFactory::levelOfDetail() diff --git a/src/RiveQtQuickItem/renderer/riveqtfactory.h b/src/RiveQtQuickItem/renderer/riveqtfactory.h index cc507c9..ebcc8dc 100644 --- a/src/RiveQtQuickItem/renderer/riveqtfactory.h +++ b/src/RiveQtQuickItem/renderer/riveqtfactory.h @@ -16,7 +16,7 @@ #include #ifdef WITH_RIVE_TEXT -# include +#include #endif #include "datatypes.h" @@ -44,6 +44,10 @@ class RiveQtFactory : public rive::Factory RiveQSGRenderNode *renderNode(QQuickWindow *window, std::weak_ptr artboardInstance, const QRectF &geometry); + rive::rcp makeBufferU16(rive::Span data); + rive::rcp makeBufferU32(rive::Span data); + rive::rcp makeBufferF32(rive::Span data); + rive::rcp makeRenderBuffer(rive::RenderBufferType, rive::RenderBufferFlags, size_t) override; rive::rcp makeLinearGradient(float, float, float, float, const rive::ColorInt[], const float[], size_t) override; diff --git a/src/RiveQtQuickItem/renderer/riveqtrhirenderer.cpp b/src/RiveQtQuickItem/renderer/riveqtrhirenderer.cpp index d1fbb92..150946e 100644 --- a/src/RiveQtQuickItem/renderer/riveqtrhirenderer.cpp +++ b/src/RiveQtQuickItem/renderer/riveqtrhirenderer.cpp @@ -97,30 +97,28 @@ void RiveQtRhiRenderer::drawPath(rive::RenderPath *path, rive::RenderPaint *pain } RiveQtPath clipResult; - if (!m_rhiRenderStack.back().m_allClipPainterPathesApplied.empty()) { - QPair firstLevel = m_rhiRenderStack.back().m_allClipPainterPathesApplied.first(); - - clipResult.setQPainterPath(firstLevel.first); - clipResult.applyMatrix(firstLevel.second); - - for (int i = 1; i < m_rhiRenderStack.back().m_allClipPainterPathesApplied.count(); ++i) { - RiveQtPath a; - const auto &entry = m_rhiRenderStack.back().m_allClipPainterPathesApplied[i]; - a.setQPainterPath(entry.first); - a.applyMatrix(entry.second); - clipResult.intersectWith(a.toQPainterPath()); - } + QPair firstLevel = m_rhiRenderStack.back().m_allClipPainterPathesApplied.first(); - // #if 0 // this allows to draw the clipping area which it useful for debugging :) - // TextureTargetNode *drawClipping = getRiveDrawTargetNode(); - // drawClipping->setOpacity(currentOpacity()); // inherit the opacity from the parent - // drawClipping->setColor(QColor(255, 0, 0, 29)); - // drawClipping->updateGeometry(clipResult.toVertices(), QMatrix4x4()); - // #endif + clipResult.setQPainterPath(firstLevel.first); + clipResult.applyMatrix(firstLevel.second); - node->updateClippingGeometry(clipResult.toVertices()); + for (int i = 1; i < m_rhiRenderStack.back().m_allClipPainterPathesApplied.count(); ++i) { + RiveQtPath a; + const auto &entry = m_rhiRenderStack.back().m_allClipPainterPathesApplied[i]; + a.setQPainterPath(entry.first); + a.applyMatrix(entry.second); + clipResult.intersectWith(a.toQPainterPath()); } + // #if 0 // this allows to draw the clipping area which it useful for debugging :) + // TextureTargetNode *drawClipping = getRiveDrawTargetNode(); + // drawClipping->setOpacity(currentOpacity()); // inherit the opacity from the parent + // drawClipping->setColor(QColor(255, 0, 0, 29)); + // drawClipping->updateGeometry(clipResult.toVertices(), QMatrix4x4()); + // #endif + + node->updateClippingGeometry(clipResult.toVertices()); + node->updateGeometry(pathData, transformMatrix()); } diff --git a/src/RiveQtQuickItem/rhi/postprocessingsmaa.cpp b/src/RiveQtQuickItem/rhi/postprocessingsmaa.cpp index 8c503b9..5190647 100644 --- a/src/RiveQtQuickItem/rhi/postprocessingsmaa.cpp +++ b/src/RiveQtQuickItem/rhi/postprocessingsmaa.cpp @@ -21,8 +21,8 @@ static float vertexData[] = { // Y up, CCW static quint16 indexData[] = { 0, 1, 2, 0, 2, 3 }; -// resolution (2 * 4) + flip (4) + sampleCount(4) -const int UBUFSIZE = 16; +// resolution (2 * 4) + flip (4) +const int UBUFSIZE = 12; QShader getShader(const QString &name) { @@ -105,11 +105,10 @@ QByteArray PostprocessingSMAA::loadSearchTextureAsR8Array() } // void PostprocessingSMAA::initializePostprocessingPipeline(QRhi* rhi, const QSizeF &size, std::weak_ptr frameTexture) -void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommandBuffer *commandBuffer, int samples, const QSize &size, +void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommandBuffer *commandBuffer, const QSize &size, QRhiTexture *frameTextureA, QRhiTexture *frameTextureB) { - m_samples = samples; // maybe cleanup (check in method) m_targetSize = size; QRhiResourceUpdateBatch *resourceUpdates = rhi->nextResourceUpdateBatch(); @@ -143,7 +142,7 @@ void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommand if (!m_edgesPass.edgesTexture) { // Target for edges - m_edgesPass.edgesTexture = rhi->newTexture(QRhiTexture::RGBA8, size, m_samples, QRhiTexture::RenderTarget); + m_edgesPass.edgesTexture = rhi->newTexture(QRhiTexture::RGBA8, size, 1, QRhiTexture::RenderTarget); m_releasePool << m_edgesPass.edgesTexture; m_edgesPass.edgesTexture->create(); } @@ -203,13 +202,12 @@ void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommand m_edgesPass.edgesPipeline->setVertexInputLayout(quadInputLayout); m_edgesPass.edgesPipeline->setShaderResourceBindings(m_edgesPass.edgesResourceBindingsA); m_edgesPass.edgesPipeline->setRenderPassDescriptor(m_edgesPass.edgesRenderPassDescriptor); - m_edgesPass.edgesPipeline->setSampleCount(m_samples); m_edgesPass.edgesPipeline->create(); } if (!m_weightsPass.weightsTexture) { // Target for weights - m_weightsPass.weightsTexture = rhi->newTexture(QRhiTexture::RGBA8, size, m_samples, QRhiTexture::RenderTarget); + m_weightsPass.weightsTexture = rhi->newTexture(QRhiTexture::RGBA8, size, 1, QRhiTexture::RenderTarget); m_releasePool << m_weightsPass.weightsTexture; m_weightsPass.weightsTexture->create(); } @@ -224,13 +222,13 @@ void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommand if (!m_lookup.areaTexture) { // load Search and Area textures for weight processing (second pass) // Qt doesnt support RG8 16 bit format, so just vonvert it to RGBA8 for now - m_lookup.areaTexture = rhi->newTexture(QRhiTexture::RGBA8, QSize(AREATEX_WIDTH, AREATEX_HEIGHT), m_samples); + m_lookup.areaTexture = rhi->newTexture(QRhiTexture::RGBA8, QSize(AREATEX_WIDTH, AREATEX_HEIGHT)); m_releasePool << m_lookup.areaTexture; m_lookup.areaTexture->create(); if (!m_lookup.areaSampler) { m_lookup.areaSampler = rhi->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None, QRhiSampler::ClampToEdge, - QRhiSampler::ClampToEdge); + QRhiSampler::ClampToEdge); m_releasePool << m_lookup.areaSampler; m_lookup.areaSampler->create(); } @@ -245,13 +243,13 @@ void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommand } if (!m_lookup.searchTexture) { - m_lookup.searchTexture = rhi->newTexture(QRhiTexture::R8, QSize(SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT), m_samples); + m_lookup.searchTexture = rhi->newTexture(QRhiTexture::R8, QSize(SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT)); m_releasePool << m_lookup.searchTexture; m_lookup.searchTexture->create(); if (!m_lookup.searchSampler) { - m_lookup.searchSampler = rhi->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None, QRhiSampler::ClampToEdge, - QRhiSampler::ClampToEdge); + m_lookup.searchSampler = + rhi->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None, QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge); m_releasePool << m_lookup.searchSampler; m_lookup.searchSampler->create(); } @@ -302,13 +300,12 @@ void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommand m_weightsPass.weightsPipeline->setVertexInputLayout(quadInputLayout); m_weightsPass.weightsPipeline->setShaderResourceBindings(m_weightsPass.weightsResourceBindings); m_weightsPass.weightsPipeline->setRenderPassDescriptor(m_weightsPass.weightsRenderPassDescriptor); - m_weightsPass.weightsPipeline->setSampleCount(m_samples); m_weightsPass.weightsPipeline->create(); } if (!m_blendPass.blendTexture) { // Target for blending pass - m_blendPass.blendTexture = rhi->newTexture(QRhiTexture::RGBA8, size, m_samples, QRhiTexture::RenderTarget); + m_blendPass.blendTexture = rhi->newTexture(QRhiTexture::RGBA8, size, 1, QRhiTexture::RenderTarget); m_releasePool << m_blendPass.blendTexture; m_blendPass.blendTexture->create(); } @@ -362,7 +359,6 @@ void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommand m_blendPass.blendPipeline->setVertexInputLayout(quadInputLayout); m_blendPass.blendPipeline->setShaderResourceBindings(m_blendPass.blendResourceBindingsA); m_blendPass.blendPipeline->setRenderPassDescriptor(m_blendPass.blendRenderPassDescriptor); - m_blendPass.blendPipeline->setSampleCount(m_samples); m_blendPass.blendPipeline->create(); } // set resolution @@ -376,8 +372,6 @@ void PostprocessingSMAA::initializePostprocessingPipeline(QRhi *rhi, QRhiCommand flip = 1; } resourceUpdates->updateDynamicBuffer(m_common.quadUbuffer, 8, 4, &flip); - int sampleCount = m_samples; - resourceUpdates->updateDynamicBuffer(m_common.quadUbuffer, 12, 4, &sampleCount); commandBuffer->resourceUpdate(resourceUpdates); m_postprocessingRenderTexture = m_blendPass.blendTexture; diff --git a/src/RiveQtQuickItem/rhi/postprocessingsmaa.h b/src/RiveQtQuickItem/rhi/postprocessingsmaa.h index f6a96ee..a055bef 100644 --- a/src/RiveQtQuickItem/rhi/postprocessingsmaa.h +++ b/src/RiveQtQuickItem/rhi/postprocessingsmaa.h @@ -23,8 +23,8 @@ class PostprocessingSMAA bool isInitialized() const { return m_isInitialized; } // void initializePostprocessingPipeline(QRhi *rhi, const QSizeF &size, std::weak_ptr frameTexture); - void initializePostprocessingPipeline(QRhi *rhi, QRhiCommandBuffer *commandBuffer, int samples, const QSize &size, - QRhiTexture *frameTextureA, QRhiTexture *frameTextureB); + void initializePostprocessingPipeline(QRhi *rhi, QRhiCommandBuffer *commandBuffer, const QSize &size, QRhiTexture *frameTextureA, + QRhiTexture *frameTextureB); void postprocess(QRhi *rhi, QRhiCommandBuffer *commandBuffer, bool useTextureBufferA); void cleanup(); @@ -105,6 +105,4 @@ class PostprocessingSMAA QRhiTexture *m_postprocessingRenderTexture { nullptr }; QSGRendererInterface::GraphicsApi m_api; - - int m_samples { 4 }; }; diff --git a/src/RiveQtQuickItem/rhi/texturetargetnode.cpp b/src/RiveQtQuickItem/rhi/texturetargetnode.cpp index 0fd2b74..3fea41c 100644 --- a/src/RiveQtQuickItem/rhi/texturetargetnode.cpp +++ b/src/RiveQtQuickItem/rhi/texturetargetnode.cpp @@ -453,11 +453,9 @@ void TextureTargetNode::renderBlend(QRhiCommandBuffer *cb) QMatrix4x4 mvp = (*m_projectionMatrix); mvp.translate(-m_rect.x(), -m_rect.y()); int flipped = rhi->isYUpInFramebuffer() ? 1 : 0; - int sampleCount = m_node->currentBlendTarget()->sampleCount(); m_blendResourceUpdates->updateDynamicBuffer(m_blendUniformBuffer, 0, 64, mvp.constData()); m_blendResourceUpdates->updateDynamicBuffer(m_blendUniformBuffer, 64, 4, &m_blendMode); m_blendResourceUpdates->updateDynamicBuffer(m_blendUniformBuffer, 68, 4, &flipped); - m_blendResourceUpdates->updateDynamicBuffer(m_blendUniformBuffer, 72, 4, &sampleCount); auto *currentDisplayBufferTarget = m_node->currentBlendTarget(); auto *blendPipeline = m_node->currentBlendPipeline(); @@ -530,10 +528,15 @@ void TextureTargetNode::setGradient(const QGradient *gradient) } } -void TextureTargetNode::setTexture(const QImage &image, rive::rcp vertices, rive::rcp uvCoords, - rive::rcp indices, uint32_t vertexCount, uint32_t indexCount, bool recreate, - const QMatrix4x4 &transform) +void TextureTargetNode::setTexture(const QImage &image, + rive::rcp vertices, + rive::rcp uvCoords, + rive::rcp indices, + uint32_t vertexCount, uint32_t indexCount, + bool recreate, + const QMatrix4x4 &transform) { + if (m_texture.size() != image.size()) { if (m_sampler) { m_cleanupList.removeAll(m_sampler); @@ -641,8 +644,8 @@ void TextureTargetNode::setTexture(const QImage &image, rive::rcpsizeInBytes() == indexCount * sizeof(uint16_t)); auto *vertexData = rive::DataRenderBuffer::Cast(vertices.get())->f32s(); - auto *uvData = rive::DataRenderBuffer::Cast(uvCoords.get())->f32s(); - auto *indexData = rive::DataRenderBuffer::Cast(indices.get())->u16s(); + auto *uvData = rive::DataRenderBuffer::Cast(uvCoords.get())->f32s(); + auto *indexData = rive::DataRenderBuffer::Cast(indices.get())->u16s(); m_geometryData.resize(vertices->sizeInBytes()); memcpy(m_geometryData.data(), vertexData, vertices->sizeInBytes()); diff --git a/src/RiveQtQuickItem/riveqsgrhirendernode.cpp b/src/RiveQtQuickItem/riveqsgrhirendernode.cpp index 0cf428f..e003f9e 100644 --- a/src/RiveQtQuickItem/riveqsgrhirendernode.cpp +++ b/src/RiveQtQuickItem/riveqsgrhirendernode.cpp @@ -19,11 +19,6 @@ RiveQSGRHIRenderNode::RiveQSGRHIRenderNode(QQuickWindow *window, std::weak_ptrrendererInterface(); - QRhi *rhi = static_cast(renderInterface->getResource(m_window, QSGRendererInterface::RhiResource)); - auto sampleCounts = rhi->supportedSampleCounts(); - m_samples = sampleCounts.last(); - QFile file; file.setFileName(":/shaders/qt6/finalDraw.vert.qsb"); file.open(QFile::ReadOnly); @@ -208,8 +203,6 @@ void RiveQSGRHIRenderNode::render(const RenderState *state) commandBuffer->setGraphicsPipeline(m_finalDrawPipeline); QSize renderTargetSize = QSGRenderNodePrivate::get(this)->m_rt.rt->pixelSize(); - m_pixelRatio = QSGRenderNodePrivate::get(this)->m_rt.rt->devicePixelRatio(); - commandBuffer->setViewport(QRhiViewport(0, 0, renderTargetSize.width(), renderTargetSize.height())); commandBuffer->setShaderResources(m_finalDrawResourceBindings); @@ -348,17 +341,14 @@ void RiveQSGRHIRenderNode::prepare() QRhiCommandBuffer *commandBuffer = swapChain->currentFrameCommandBuffer(); if (!m_stencilClippingBuffer) { - m_stencilClippingBuffer = rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, - QSize(m_rect.width() * m_pixelRatio, m_rect.height() * m_pixelRatio), m_samples); + m_stencilClippingBuffer = rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, QSize(m_rect.width(), m_rect.height()), 1); m_stencilClippingBuffer->create(); m_cleanupList.append(m_stencilClippingBuffer); } - bool textureCreated = m_renderSurfaceA.create(rhi, m_samples, QSize(m_rect.width() * m_pixelRatio, m_rect.height() * m_pixelRatio), - m_stencilClippingBuffer); - m_renderSurfaceB.create(rhi, m_samples, QSize(m_rect.width() * m_pixelRatio, m_rect.height() * m_pixelRatio), m_stencilClippingBuffer); - m_renderSurfaceIntern.create(rhi, m_samples, QSize(m_rect.width() * m_pixelRatio, m_rect.height() * m_pixelRatio), - m_stencilClippingBuffer, {}); + bool textureCreated = m_renderSurfaceA.create(rhi, QSize(m_rect.width(), m_rect.height()), m_stencilClippingBuffer); + m_renderSurfaceB.create(rhi, QSize(m_rect.width(), m_rect.height()), m_stencilClippingBuffer); + m_renderSurfaceIntern.create(rhi, QSize(m_rect.width(), m_rect.height()), m_stencilClippingBuffer, {}); // only set the renderSurface to A in case we created a new texture if (textureCreated) { @@ -386,7 +376,7 @@ void RiveQSGRHIRenderNode::prepare() } if (!m_sampler) { - m_sampler = rhi->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None, QRhiSampler::ClampToEdge, + m_sampler = rhi->newSampler(QRhiSampler::Nearest, QRhiSampler::Nearest, QRhiSampler::None, QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge); m_sampler->create(); m_cleanupList.append(m_sampler); @@ -401,7 +391,7 @@ void RiveQSGRHIRenderNode::prepare() // only for bindings if (!m_dummyTexture) { - m_dummyTexture = rhi->newTexture(QRhiTexture::BGRA8, QSize(1, 1), m_samples); + m_dummyTexture = rhi->newTexture(QRhiTexture::BGRA8, QSize(1, 1), 1); m_cleanupList.append(m_dummyTexture); m_dummyTexture->create(); } @@ -453,12 +443,12 @@ void RiveQSGRHIRenderNode::prepare() } if (!m_drawPipeline) { - m_drawPipeline = createDrawPipeline(rhi, m_samples, true, true, m_renderSurfaceA.desc, QRhiGraphicsPipeline::Triangles, - m_pathShader, m_drawPipelineResourceBindings); + m_drawPipeline = createDrawPipeline(rhi, true, true, m_renderSurfaceA.desc, QRhiGraphicsPipeline::Triangles, m_pathShader, + m_drawPipelineResourceBindings); } if (!m_drawPipelineIntern) { - m_drawPipelineIntern = createDrawPipeline(rhi, m_samples, false, true, m_renderSurfaceIntern.desc, QRhiGraphicsPipeline::Triangles, + m_drawPipelineIntern = createDrawPipeline(rhi, false, true, m_renderSurfaceIntern.desc, QRhiGraphicsPipeline::Triangles, m_pathShader, m_drawPipelineResourceBindings); } @@ -570,9 +560,8 @@ void RiveQSGRHIRenderNode::prepare() } if (m_postprocessing) { - m_postprocessing->initializePostprocessingPipeline(rhi, commandBuffer, m_samples, - QSize(m_rect.width() * m_pixelRatio, m_rect.height() * m_pixelRatio), - m_renderSurfaceA.texture, m_renderSurfaceB.texture); + m_postprocessing->initializePostprocessingPipeline(rhi, commandBuffer, QSize(m_rect.width(), m_rect.height()), + m_renderSurfaceA.texture, m_renderSurfaceB.texture); } m_verticesDirty = false; @@ -603,7 +592,7 @@ void RiveQSGRHIRenderNode::prepare() } if (!m_finalDrawUniformBuffer) { - m_finalDrawUniformBuffer = rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 96); + m_finalDrawUniformBuffer = rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 92); m_finalDrawUniformBuffer->create(); m_cleanupList.append(m_finalDrawUniformBuffer); } @@ -632,7 +621,7 @@ void RiveQSGRHIRenderNode::prepare() } if (!m_finalDrawPipeline) { - m_finalDrawPipeline = createDrawPipeline(rhi, m_samples, true, false, QSGRenderNodePrivate::get(this)->m_rt.rpDesc, + m_finalDrawPipeline = createDrawPipeline(rhi, true, false, QSGRenderNodePrivate::get(this)->m_rt.rpDesc, QRhiGraphicsPipeline::TriangleStrip, m_finalDrawShader, m_finalDrawResourceBindings); } @@ -647,7 +636,6 @@ void RiveQSGRHIRenderNode::prepare() int flipped = rhi->isYUpInFramebuffer() ? 1 : 0; int useTextureNumber = 0; - int sampleCount = m_samples; if (!isCurrentRenderBufferA()) { useTextureNumber = 1; @@ -665,7 +653,6 @@ void RiveQSGRHIRenderNode::prepare() resourceUpdates->updateDynamicBuffer(m_finalDrawUniformBuffer, 80, 4, &top); resourceUpdates->updateDynamicBuffer(m_finalDrawUniformBuffer, 84, 4, &bottom); resourceUpdates->updateDynamicBuffer(m_finalDrawUniformBuffer, 88, 4, &useTextureNumber); - resourceUpdates->updateDynamicBuffer(m_finalDrawUniformBuffer, 92, 4, &sampleCount); commandBuffer->resourceUpdate(resourceUpdates); @@ -690,8 +677,12 @@ QRhiGraphicsPipeline *RiveQSGRHIRenderNode::createClipPipeline(QRhi *rhi, QRhiRe clipPipeLine->setTargetBlends({ disabledColorWrite }); QRhiVertexInputLayout inputLayout; - inputLayout.setBindings({ { sizeof(QVector2D) } }); - inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float2, 0 } }); + inputLayout.setBindings({ + { sizeof(QVector2D) } + }); + inputLayout.setAttributes({ + { 0, 0, QRhiVertexInputAttribute::Float2, 0 } + }); // Configure stencil operations for writing stencil values QRhiGraphicsPipeline::StencilOpState stencilOpState = { QRhiGraphicsPipeline::Keep, QRhiGraphicsPipeline::Keep, @@ -703,7 +694,6 @@ QRhiGraphicsPipeline *RiveQSGRHIRenderNode::createClipPipeline(QRhi *rhi, QRhiRe clipPipeLine->setTopology(QRhiGraphicsPipeline::Triangles); clipPipeLine->setVertexInputLayout(inputLayout); clipPipeLine->setRenderPassDescriptor(renderPassDescriptor); - clipPipeLine->setSampleCount(m_samples); clipPipeLine->setShaderResourceBindings(bindings); clipPipeLine->create(); @@ -712,7 +702,7 @@ QRhiGraphicsPipeline *RiveQSGRHIRenderNode::createClipPipeline(QRhi *rhi, QRhiRe return clipPipeLine; } -QRhiGraphicsPipeline *RiveQSGRHIRenderNode::createDrawPipeline(QRhi *rhi, int samples, bool srcOverBlend, bool stencilBuffer, +QRhiGraphicsPipeline *RiveQSGRHIRenderNode::createDrawPipeline(QRhi *rhi, bool srcOverBlend, bool stencilBuffer, QRhiRenderPassDescriptor *renderPassDescriptor, QRhiGraphicsPipeline::Topology t, const QList &shader, QRhiShaderResourceBindings *bindings) @@ -728,7 +718,6 @@ QRhiGraphicsPipeline *RiveQSGRHIRenderNode::createDrawPipeline(QRhi *rhi, int sa drawPipeLine->setFrontFace(rhi->isYUpInFramebuffer() ? QRhiGraphicsPipeline::CW : QRhiGraphicsPipeline::CCW); drawPipeLine->setCullMode(QRhiGraphicsPipeline::None); drawPipeLine->setTopology(t); - drawPipeLine->setSampleCount(samples); if (srcOverBlend) { QRhiGraphicsPipeline::TargetBlend blend; @@ -791,7 +780,7 @@ QRhiGraphicsPipeline *RiveQSGRHIRenderNode::createBlendPipeline(QRhi *rhi, QRhiR blendPipeLine->setStencilTest(false); blendPipeLine->setShaderResourceBindings(bindings); blendPipeLine->setShaderStages(m_blendShaders.cbegin(), m_blendShaders.cend()); - blendPipeLine->setSampleCount(m_samples); + QRhiVertexInputLayout inputLayout; inputLayout.setBindings({ { sizeof(QVector2D) }, @@ -838,13 +827,12 @@ void RiveQSGRHIRenderNode::RenderSurface::cleanUp() } } -bool RiveQSGRHIRenderNode::RenderSurface::create(QRhi *rhi, int samples, const QSize &surfaceSize, QRhiRenderBuffer *stencilClippingBuffer, +bool RiveQSGRHIRenderNode::RenderSurface::create(QRhi *rhi, const QSize &surfaceSize, QRhiRenderBuffer *stencilClippingBuffer, QRhiTextureRenderTarget::Flags flags) { - bool textureCreated = false; if (!texture) { - texture = rhi->newTexture(QRhiTexture::RGBA8, surfaceSize, samples, QRhiTexture::RenderTarget); + texture = rhi->newTexture(QRhiTexture::RGBA8, surfaceSize, 1, QRhiTexture::RenderTarget); texture->create(); textureCreated = true; } diff --git a/src/RiveQtQuickItem/riveqsgrhirendernode.h b/src/RiveQtQuickItem/riveqsgrhirendernode.h index 89d6d9c..dba561a 100644 --- a/src/RiveQtQuickItem/riveqsgrhirendernode.h +++ b/src/RiveQtQuickItem/riveqsgrhirendernode.h @@ -73,7 +73,6 @@ class RiveQSGRHIRenderNode : public RiveQSGRenderNode QRhiRenderPassDescriptor *blendDesc { nullptr }; QRhiTextureRenderTarget *target { nullptr }; QRhiTextureRenderTarget *blendTarget { nullptr }; - QRhiTexture *resolveTexture { nullptr }; ~RenderSurface() { cleanUp(); } @@ -82,7 +81,7 @@ class RiveQSGRHIRenderNode : public RiveQSGRenderNode bool valid() { return texture != nullptr; } // this creates all resources needed to have a texture to draw on - bool create(QRhi *rhi, int samples, const QSize &surfaceSize, QRhiRenderBuffer *stencilClippingBuffer, + bool create(QRhi *rhi, const QSize &surfaceSize, QRhiRenderBuffer *stencilClippingBuffer, QRhiTextureRenderTarget::Flags flags = QRhiTextureRenderTarget::PreserveColorContents); }; @@ -159,14 +158,11 @@ class RiveQSGRHIRenderNode : public RiveQSGRenderNode PostprocessingSMAA *m_postprocessing { nullptr }; - private: - float m_pixelRatio { 1.0f }; - int m_samples { 4 }; QRhiGraphicsPipeline *createBlendPipeline(QRhi *rhi, QRhiRenderPassDescriptor *renderPass, QRhiShaderResourceBindings *bindings); QRhiGraphicsPipeline *createClipPipeline(QRhi *rhi, QRhiRenderPassDescriptor *renderPassDescriptor, QRhiShaderResourceBindings *bindings); - QRhiGraphicsPipeline *createDrawPipeline(QRhi *rhi, int samples, bool srcOverBlend, bool stencilBuffer, + QRhiGraphicsPipeline *createDrawPipeline(QRhi *rhi, bool srcOverBlend, bool stencilBuffer, QRhiRenderPassDescriptor *renderPassDescriptor, QRhiGraphicsPipeline::Topology t, const QList &shader, QRhiShaderResourceBindings *bindings); }; diff --git a/src/RiveQtQuickItem/riveqtquickitem.cpp b/src/RiveQtQuickItem/riveqtquickitem.cpp index 455c100..ee92cd6 100644 --- a/src/RiveQtQuickItem/riveqtquickitem.cpp +++ b/src/RiveQtQuickItem/riveqtquickitem.cpp @@ -141,9 +141,7 @@ void RiveQtQuickItem::updateInternalArtboard() if (m_currentArtboardIndex == -1) { m_currentArtboardInstance = m_riveFile->artboardDefault(); } else { - if (!m_currentArtboardInstance || m_riveFile->artboardAt(m_currentArtboardIndex).get() != m_currentArtboardInstance->artboard()) { - m_currentArtboardInstance = m_riveFile->artboardAt(m_currentArtboardIndex); - } + m_currentArtboardInstance = m_riveFile->artboardAt(m_currentArtboardIndex); } if (!m_currentArtboardInstance) { @@ -195,13 +193,11 @@ QSGNode *RiveQtQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData // of course the calls to the stateMachineInterface wont do anything m_renderNode->updateArtboardInstance(std::weak_ptr()); - m_currentArtboardInstance.reset(); + // reset all m_riveFile = nullptr; m_scheduleArtboardChange = true; m_scheduleStateMachineChange = true; - m_currentArtboardIndex = -1; - m_initialArtboardIndex = -1; // now load the file from the main thread -> connected as Queued Connection to make sure its called in its owning thread emit loadFileAfterUnloading(m_fileSource); @@ -489,6 +485,10 @@ void RiveQtQuickItem::loadRiveFile(const QString &source) return; } + if (m_currentArtboardInstance) { + m_currentArtboardInstance.reset(); + } + QByteArray fileData = file.readAll(); file.close(); diff --git a/src/RiveQtQuickItem/shaders/qt6/blendRiveTextureNode.frag b/src/RiveQtQuickItem/shaders/qt6/blendRiveTextureNode.frag index 0b4ca69..9962864 100644 --- a/src/RiveQtQuickItem/shaders/qt6/blendRiveTextureNode.frag +++ b/src/RiveQtQuickItem/shaders/qt6/blendRiveTextureNode.frag @@ -13,11 +13,10 @@ layout(std140, binding = 0) uniform buf { mat4 qt_Matrix; int blendMode; int flipped; - int sampleCount; }; -layout(binding = 1) uniform sampler2DMS u_texture_src; -layout(binding = 2) uniform sampler2DMS u_texture_dest; +layout(binding = 1) uniform sampler2D u_texture_src; +layout(binding = 2) uniform sampler2D u_texture_dest; vec4 blendColor(vec4 color, vec4 src, vec4 dst) { float blendColor = src.a * dst.a; @@ -331,22 +330,10 @@ vec4 blend(vec4 srcColor, vec4 destColor, int blendMode) { return blendedColor; } -vec4 textureColor(sampler2DMS tex, vec2 texCoord) { - - ivec2 tc = ivec2(floor(vec2(textureSize(tex)) * texCoord)); - - vec4 c = vec4(0.0); - for (int i = 0; i < sampleCount; ++i) { - c += texelFetch(tex, tc, i); - } - c /= float(sampleCount); - return vec4(c.rgb * c.a, c.a); -} - void main() { - vec4 srcColor = textureColor(u_texture_src, texCoord); - vec4 destColor = textureColor(u_texture_dest, texCoord); + vec4 srcColor = texture(u_texture_src, texCoord); + vec4 destColor = texture(u_texture_dest, texCoord); vec4 finalColor = blend(srcColor, destColor, blendMode); diff --git a/src/RiveQtQuickItem/shaders/qt6/drawRiveTextureNode.frag b/src/RiveQtQuickItem/shaders/qt6/drawRiveTextureNode.frag index 40df383..940778e 100644 --- a/src/RiveQtQuickItem/shaders/qt6/drawRiveTextureNode.frag +++ b/src/RiveQtQuickItem/shaders/qt6/drawRiveTextureNode.frag @@ -45,6 +45,7 @@ vec4 getGradientColor( float gradientCoord) { return gradientColor; } + void main() { if (useTexture == 1) { diff --git a/src/RiveQtQuickItem/shaders/qt6/edges-luma.frag b/src/RiveQtQuickItem/shaders/qt6/edges-luma.frag index e0c0379..3b89f08 100644 --- a/src/RiveQtQuickItem/shaders/qt6/edges-luma.frag +++ b/src/RiveQtQuickItem/shaders/qt6/edges-luma.frag @@ -57,31 +57,19 @@ layout(location = 0) out vec4 fragColor; layout(std140, binding = 0) uniform buf { vec2 resolution; int flip; - int sampleCount; } ubuf; -layout(binding = 1) uniform sampler2DMS colorTex; - -vec4 textureColor(sampler2DMS tex, vec2 texCoord) { - ivec2 tc = ivec2(floor(vec2(textureSize(tex)) * texCoord)); - - vec4 c = vec4(0.0); - for (int i = 0; i < ubuf.sampleCount; ++i) { - c += texelFetch(tex, tc, i); - } - c /= float(ubuf.sampleCount); - return vec4(c.rgb * c.a, c.a); -} +layout(binding = 1) uniform sampler2D colorTex; void main() { vec2 threshold = vec2(SMAA_THRESHOLD); // Calculate lumas: vec3 weights = vec3(0.2126, 0.7152, 0.0722); - float L = dot(textureColor(colorTex, v_texcoord).rgb, weights); + float L = dot(texture(colorTex, v_texcoord).rgb, weights); - float Lleft = dot(textureColor(colorTex, vOffset[0].xy).rgb, weights); - float Ltop = dot(textureColor(colorTex, vOffset[0].zw).rgb, weights); + float Lleft = dot(texture(colorTex, vOffset[0].xy).rgb, weights); + float Ltop = dot(texture(colorTex, vOffset[0].zw).rgb, weights); // We do the usual threshold: vec4 delta; @@ -93,16 +81,16 @@ void main() { discard; // Calculate right and bottom deltas: - float Lright = dot(textureColor(colorTex, vOffset[1].xy).rgb, weights); - float Lbottom = dot(textureColor(colorTex, vOffset[1].zw).rgb, weights); + float Lright = dot(texture(colorTex, vOffset[1].xy).rgb, weights); + float Lbottom = dot(texture(colorTex, vOffset[1].zw).rgb, weights); delta.zw = abs(L - vec2(Lright, Lbottom)); // Calculate the maximum delta in the direct neighborhood: vec2 maxDelta = max(delta.xy, delta.zw); // Calculate left-left and top-top deltas: - float Lleftleft = dot(textureColor(colorTex, vOffset[2].xy).rgb, weights); - float Ltoptop = dot(textureColor(colorTex, vOffset[2].zw).rgb, weights); + float Lleftleft = dot(texture(colorTex, vOffset[2].xy).rgb, weights); + float Ltoptop = dot(texture(colorTex, vOffset[2].zw).rgb, weights); delta.zw = abs(vec2(Lleft, Ltop) - vec2(Lleftleft, Ltoptop)); // Calculate the final maximum delta: @@ -113,4 +101,4 @@ void main() { edges.xy *= step(finalDelta, SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR * delta.xy); fragColor = vec4(edges, 0.0, 1.0); -} +} \ No newline at end of file diff --git a/src/RiveQtQuickItem/shaders/qt6/finalDraw.frag b/src/RiveQtQuickItem/shaders/qt6/finalDraw.frag index d9a9f41..ad064b6 100644 --- a/src/RiveQtQuickItem/shaders/qt6/finalDraw.frag +++ b/src/RiveQtQuickItem/shaders/qt6/finalDraw.frag @@ -18,30 +18,21 @@ layout(std140, binding = 0) uniform buf { float top; float bottom; int useTextureNumber; - int sampleCount; }; -layout(binding = 1) uniform sampler2DMS u_textureA; -layout(binding = 2) uniform sampler2DMS u_textureB; -layout(binding = 3) uniform sampler2DMS u_texturePP; +layout(binding = 1) uniform sampler2D u_textureA; +layout(binding = 2) uniform sampler2D u_textureB; +layout(binding = 3) uniform sampler2D u_texturePP; -vec4 drawTexture(sampler2DMS tex, vec2 texCoord) { +vec4 drawTexture(sampler2D s_texture, vec2 texCoord) { if (texCoord.x >= left && texCoord.x <= right && texCoord.y >= top && texCoord.y <= bottom) { - ivec2 tc = ivec2(floor(vec2(textureSize(tex)) * texCoord)); - - vec4 c = vec4(0.0); - for (int i = 0; i < sampleCount; ++i) { - c += texelFetch(tex, tc, i); - } - c /= float(sampleCount); - return vec4(c.rgb * c.a, c.a); + return texture(s_texture, texCoord); } else { - return vec4(0.0); // Return a transparent color for pixels outside the viewport + return vec4(0.0, 0.0, 0.0, 0.0); // Return a transparent color for pixels outside the viewport } } - void main() { if (useTextureNumber == 0) { diff --git a/src/RiveQtQuickItem/shaders/qt6/smaa-blend.frag b/src/RiveQtQuickItem/shaders/qt6/smaa-blend.frag index 5f6f021..8778ec5 100644 --- a/src/RiveQtQuickItem/shaders/qt6/smaa-blend.frag +++ b/src/RiveQtQuickItem/shaders/qt6/smaa-blend.frag @@ -44,11 +44,10 @@ layout(location = 0) out vec4 fragColor; layout(std140, binding = 0) uniform buf { vec2 resolution; int flip; - int sampleCount; } ubuf; -layout(binding = 1) uniform sampler2DMS colorTex; -layout(binding = 2) uniform sampler2DMS blendTex; +layout(binding = 1) uniform sampler2D colorTex; +layout(binding = 2) uniform sampler2D blendTex; /** * Conditional move: @@ -63,30 +62,19 @@ void SMAAMovc(bvec4 cond, inout vec4 variable, vec4 value) { SMAAMovc(cond.zw, variable.zw, value.zw); } -vec4 textureColor(sampler2DMS tex, vec2 texCoord) { - ivec2 tc = ivec2(floor(vec2(textureSize(tex)) * texCoord)); - - vec4 c = vec4(0.0); - for (int i = 0; i < ubuf.sampleCount; ++i) { - c += texelFetch(tex, tc, i); - } - c /= float(ubuf.sampleCount); - return vec4(c.rgb * c.a, c.a); -} - void main() { vec4 SMAA_RT_METRICS = vec4(1.0 / ubuf.resolution.x, 1.0 / ubuf.resolution.y, ubuf.resolution.x, ubuf.resolution.y); vec4 color; // Fetch the blending weights for current pixel: vec4 a; - a.x = textureColor(blendTex, vOffset.xy).a; // Right - a.y = textureColor(blendTex, vOffset.zw).g; // Top - a.wz = textureColor(blendTex, v_texcoord).xz; // Bottom / Left + a.x = texture(blendTex, vOffset.xy).a; // Right + a.y = texture(blendTex, vOffset.zw).g; // Top + a.wz = texture(blendTex, v_texcoord).xz; // Bottom / Left // Is there any blending weight with a value greater than 0.0? if (dot(a, vec4(1.0, 1.0, 1.0, 1.0)) <= 1e-5) { - color = textureColor(colorTex, v_texcoord); // LinearSampler + color = texture(colorTex, v_texcoord); // LinearSampler } else { bool h = max(a.x, a.z) > max(a.y, a.w); // max(horizontal) > max(vertical) @@ -102,9 +90,9 @@ void main() { // We exploit bilinear filtering to mix current pixel with the chosen // neighbor: - color = blendingWeight.x * textureColor(colorTex, blendingCoord.xy); // LinearSampler - color += blendingWeight.y * textureColor(colorTex, blendingCoord.zw); // LinearSampler + color = blendingWeight.x * texture(colorTex, blendingCoord.xy); // LinearSampler + color += blendingWeight.y * texture(colorTex, blendingCoord.zw); // LinearSampler } fragColor = color; -} +} \ No newline at end of file diff --git a/src/RiveQtQuickItem/shaders/qt6/smaa-weights.frag b/src/RiveQtQuickItem/shaders/qt6/smaa-weights.frag index d239843..a0ebb53 100644 --- a/src/RiveQtQuickItem/shaders/qt6/smaa-weights.frag +++ b/src/RiveQtQuickItem/shaders/qt6/smaa-weights.frag @@ -51,7 +51,7 @@ #define mad(a, b, c) (a * b + c) #define saturate(a) clamp(a, 0.0, 1.0) #define round(v) floor(v + 0.5) -#define SMAASampleLevelZeroOffset(tex, coord, offset) textureColor(tex, coord + offset * SMAA_RT_METRICS.xy) +#define SMAASampleLevelZeroOffset(tex, coord, offset) texture(tex, coord + offset * SMAA_RT_METRICS.xy) // Non-Configurable Defines #define SMAA_AREATEX_MAX_DISTANCE 16 @@ -80,23 +80,11 @@ layout(location = 0) out vec4 fragColor; layout(std140, binding = 0) uniform buf { vec2 resolution; int flip; - int sampleCount; } ubuf; -layout(binding = 1) uniform sampler2DMS edgesTex; -layout(binding = 2) uniform sampler2DMS areaTex; -layout(binding = 3) uniform sampler2DMS searchTex; - -vec4 textureColor(sampler2DMS tex, vec2 texCoord) { - ivec2 tc = ivec2(floor(vec2(textureSize(tex)) * texCoord)); - - vec4 c = vec4(0.0); - for (int i = 0; i < ubuf.sampleCount; ++i) { - c += texelFetch(tex, tc, i); - } - c /= float(ubuf.sampleCount); - return vec4(c.rgb * c.a, c.a); -} +layout(binding = 1) uniform sampler2D edgesTex; +layout(binding = 2) uniform sampler2D areaTex; +layout(binding = 3) uniform sampler2D searchTex; // globals vec4 SMAA_RT_METRICS; @@ -143,20 +131,20 @@ vec4 SMAADecodeDiagBilinearAccess(vec4 e) { /** * These functions allows to perform diagonal pattern searches. */ -vec2 SMAASearchDiag1(sampler2DMS edgesTex, vec2 texcoord, vec2 dir, out vec2 e) { +vec2 SMAASearchDiag1(sampler2D edgesTex, vec2 texcoord, vec2 dir, out vec2 e) { vec4 coord = vec4(texcoord, -1.0, 1.0); vec3 t = vec3(SMAA_RT_METRICS.xy, 1.0); for (int i = 0; i < SMAA_MAX_SEARCH_STEPS; i++) { if (!(coord.z < float(SMAA_MAX_SEARCH_STEPS_DIAG - 1) && coord.w > 0.9)) break; coord.xyz = mad(t, vec3(dir, 1.0), coord.xyz); - e = textureColor(edgesTex, coord.xy).rg; // LinearSampler + e = texture(edgesTex, coord.xy).rg; // LinearSampler coord.w = dot(e, vec2(0.5, 0.5)); } return coord.zw; } -vec2 SMAASearchDiag2(sampler2DMS edgesTex, vec2 texcoord, vec2 dir, out vec2 e) { +vec2 SMAASearchDiag2(sampler2D edgesTex, vec2 texcoord, vec2 dir, out vec2 e) { vec4 coord = vec4(texcoord, -1.0, 1.0); coord.x += 0.25 * SMAA_RT_METRICS.x; // See @SearchDiag2Optimization vec3 t = vec3(SMAA_RT_METRICS.xy, 1.0); @@ -167,11 +155,11 @@ vec2 SMAASearchDiag2(sampler2DMS edgesTex, vec2 texcoord, vec2 dir, out vec2 e) // @SearchDiag2Optimization // Fetch both edges at once using bilinear filtering: - e = textureColor(edgesTex, coord.xy).rg; // LinearSampler + e = texture(edgesTex, coord.xy).rg; // LinearSampler e = SMAADecodeDiagBilinearAccess(e); // Non-optimized version: - // e.g = textureColor(edgesTex, coord.xy).g; // LinearSampler + // e.g = texture(edgesTex, coord.xy).g; // LinearSampler // e.r = SMAASampleLevelZeroOffset(edgesTex, coord.xy, vec2(1, 0)).r; coord.w = dot(e, vec2(0.5, 0.5)); @@ -183,7 +171,7 @@ vec2 SMAASearchDiag2(sampler2DMS edgesTex, vec2 texcoord, vec2 dir, out vec2 e) * Similar to SMAAArea, this calculates the area corresponding to a certain * diagonal distance and crossing edges 'e'. */ -vec2 SMAAAreaDiag(sampler2DMS areaTex, vec2 dist, vec2 e, float offset) { +vec2 SMAAAreaDiag(sampler2D areaTex, vec2 dist, vec2 e, float offset) { vec2 texcoord = mad(vec2(SMAA_AREATEX_MAX_DISTANCE_DIAG, SMAA_AREATEX_MAX_DISTANCE_DIAG), e, dist); // We do a scale and bias for mapping to texel space: @@ -196,13 +184,13 @@ vec2 SMAAAreaDiag(sampler2DMS areaTex, vec2 dist, vec2 e, float offset) { texcoord.y += SMAA_AREATEX_SUBTEX_SIZE * offset; // Do it! - return SMAA_AREATEX_SELECT(textureColor(areaTex, texcoord)); // LinearSampler + return SMAA_AREATEX_SELECT(texture(areaTex, texcoord)); // LinearSampler } /** * This searches for diagonal patterns and returns the corresponding weights. */ -vec2 SMAACalculateDiagWeights(sampler2DMS edgesTex, sampler2DMS areaTex, vec2 texcoord, vec2 e, vec4 subsampleIndices) { +vec2 SMAACalculateDiagWeights(sampler2D edgesTex, sampler2D areaTex, vec2 texcoord, vec2 e, vec4 subsampleIndices) { vec2 weights = vec2(0.0, 0.0); // Search for the line ends: @@ -275,7 +263,7 @@ vec2 SMAACalculateDiagWeights(sampler2DMS edgesTex, sampler2DMS areaTex, vec2 te * @PSEUDO_GATHER4), and adds 0, 1 or 2, depending on which edges and * crossing edges are active. */ -float SMAASearchLength(sampler2DMS searchTex, vec2 e, float offset) { +float SMAASearchLength(sampler2D searchTex, vec2 e, float offset) { // The texture is flipped vertically, with left and right cases taking half // of the space horizontally: vec2 scale = SMAA_SEARCHTEX_SIZE * vec2(0.5, -1.0); @@ -291,13 +279,13 @@ float SMAASearchLength(sampler2DMS searchTex, vec2 e, float offset) { bias *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE; // Lookup the search texture: - return SMAA_SEARCHTEX_SELECT(textureColor(searchTex, mad(scale, e, bias))); // LinearSampler + return SMAA_SEARCHTEX_SELECT(texture(searchTex, mad(scale, e, bias))); // LinearSampler } /** * Horizontal/vertical search functions for the 2nd pass. */ -float SMAASearchXLeft(sampler2DMS edgesTex, sampler2DMS searchTex, vec2 texcoord, float end) { +float SMAASearchXLeft(sampler2D edgesTex, sampler2D searchTex, vec2 texcoord, float end) { /** * @PSEUDO_GATHER4 * This texcoord has been offset by (-0.25, -0.125) in the vertex shader to @@ -308,7 +296,7 @@ float SMAASearchXLeft(sampler2DMS edgesTex, sampler2DMS searchTex, vec2 texcoord vec2 e = vec2(0.0, 1.0); for (int i = 0; i < SMAA_MAX_SEARCH_STEPS; i++) { if (!(texcoord.x > end && e.g > 0.8281 && e.r == 0.0)) break; - e = textureColor(edgesTex, texcoord).rg; // LinearSampler + e = texture(edgesTex, texcoord).rg; // LinearSampler texcoord = mad(-vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord); } @@ -328,30 +316,30 @@ float SMAASearchXLeft(sampler2DMS edgesTex, sampler2DMS searchTex, vec2 texcoord // return mad(SMAA_RT_METRICS.x, offset, texcoord.x); } -float SMAASearchXRight(sampler2DMS edgesTex, sampler2DMS searchTex, vec2 texcoord, float end) { +float SMAASearchXRight(sampler2D edgesTex, sampler2D searchTex, vec2 texcoord, float end) { vec2 e = vec2(0.0, 1.0); for (int i = 0; i < SMAA_MAX_SEARCH_STEPS; i++) { if (!(texcoord.x < end && e.g > 0.8281 && e.r == 0.0)) break; - e = textureColor(edgesTex, texcoord).rg; // LinearSampler + e = texture(edgesTex, texcoord).rg; // LinearSampler texcoord = mad(vec2(2.0, 0.0), SMAA_RT_METRICS.xy, texcoord); } float offset = mad(-(255.0 / 127.0), SMAASearchLength(searchTex, e, 0.5), 3.25); return mad(-SMAA_RT_METRICS.x, offset, texcoord.x); } -float SMAASearchYUp(sampler2DMS edgesTex, sampler2DMS searchTex, vec2 texcoord, float end) { +float SMAASearchYUp(sampler2D edgesTex, sampler2D searchTex, vec2 texcoord, float end) { vec2 e = vec2(1.0, 0.0); for (int i = 0; i < SMAA_MAX_SEARCH_STEPS; i++) { if (!(texcoord.y > end && e.r > 0.8281 && e.g == 0.0)) break; - e = textureColor(edgesTex, texcoord).rg; // LinearSampler + e = texture(edgesTex, texcoord).rg; // LinearSampler texcoord = mad(-vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord); } float offset = mad(-(255.0 / 127.0), SMAASearchLength(searchTex, e.gr, 0.0), 3.25); return mad(SMAA_RT_METRICS.y, offset, texcoord.y); } -float SMAASearchYDown(sampler2DMS edgesTex, sampler2DMS searchTex, vec2 texcoord, float end) { +float SMAASearchYDown(sampler2D edgesTex, sampler2D searchTex, vec2 texcoord, float end) { vec2 e = vec2(1.0, 0.0); for (int i = 0; i < SMAA_MAX_SEARCH_STEPS; i++) { if (!(texcoord.y < end && e.r > 0.8281 && e.g == 0.0)) break; - e = textureColor(edgesTex, texcoord).rg; // LinearSampler + e = texture(edgesTex, texcoord).rg; // LinearSampler texcoord = mad(vec2(0.0, 2.0), SMAA_RT_METRICS.xy, texcoord); } float offset = mad(-(255.0 / 127.0), SMAASearchLength(searchTex, e.gr, 0.5), 3.25); @@ -362,7 +350,7 @@ float SMAASearchYDown(sampler2DMS edgesTex, sampler2DMS searchTex, vec2 texcoord * Ok, we have the distance and both crossing edges. So, what are the areas * at each side of current edge? */ -vec2 SMAAArea(sampler2DMS areaTex, vec2 dist, float e1, float e2, float offset) { +vec2 SMAAArea(sampler2D areaTex, vec2 dist, float e1, float e2, float offset) { // Rounding prevents precision errors of bilinear filtering: vec2 texcoord = mad(vec2(SMAA_AREATEX_MAX_DISTANCE, SMAA_AREATEX_MAX_DISTANCE), round(4.0 * vec2(e1, e2)), dist); @@ -373,11 +361,11 @@ vec2 SMAAArea(sampler2DMS areaTex, vec2 dist, float e1, float e2, float offset) texcoord.y = mad(SMAA_AREATEX_SUBTEX_SIZE, offset, texcoord.y); // Do it! - return SMAA_AREATEX_SELECT(textureColor(areaTex, texcoord)); // LinearSampler + return SMAA_AREATEX_SELECT(texture(areaTex, texcoord)); // LinearSampler } // Corner Detection Functions -void SMAADetectHorizontalCornerPattern(sampler2DMS edgesTex, inout vec2 weights, vec4 texcoord, vec2 d) { +void SMAADetectHorizontalCornerPattern(sampler2D edgesTex, inout vec2 weights, vec4 texcoord, vec2 d) { #if !defined(SMAA_DISABLE_CORNER_DETECTION) vec2 leftRight = step(d.xy, d.yx); vec2 rounding = (1.0 - SMAA_CORNER_ROUNDING_NORM) * leftRight; @@ -394,7 +382,7 @@ void SMAADetectHorizontalCornerPattern(sampler2DMS edgesTex, inout vec2 weights, #endif } -void SMAADetectVerticalCornerPattern(sampler2DMS edgesTex, inout vec2 weights, vec4 texcoord, vec2 d) { +void SMAADetectVerticalCornerPattern(sampler2D edgesTex, inout vec2 weights, vec4 texcoord, vec2 d) { #if !defined(SMAA_DISABLE_CORNER_DETECTION) vec2 leftRight = step(d.xy, d.yx); vec2 rounding = (1.0 - SMAA_CORNER_ROUNDING_NORM) * leftRight; @@ -416,7 +404,7 @@ void main() { vec4 subsampleIndices = vec4(0.0); // Just pass zero for SMAA 1x, see @SUBSAMPLE_INDICES. // subsampleIndices = vec4(1.0, 1.0, 1.0, 0.0); vec4 weights = vec4(0.0, 0.0, 0.0, 0.0); - vec2 e = textureColor(edgesTex, v_texcoord).rg; + vec2 e = texture(edgesTex, v_texcoord).rg; if (e.g > 0.0) { // Edge at north @@ -441,7 +429,7 @@ void main() { // Now fetch the left crossing edges, two at a time using bilinear // filtering. Sampling at -0.25 (see @CROSSING_OFFSET) enables to // discern what value each edge has: - float e1 = textureColor(edgesTex, coords.xy).r; // LinearSampler + float e1 = texture(edgesTex, coords.xy).r; // LinearSampler // Find the distance to the right: coords.z = SMAASearchXRight(edgesTex, searchTex, vOffset[0].zw, vOffset[2].y); @@ -482,7 +470,7 @@ void main() { d.x = coords.y; // Fetch the top crossing edges: - float e1 = textureColor(edgesTex, coords.xy).g; // LinearSampler + float e1 = texture(edgesTex, coords.xy).g; // LinearSampler // Find the distance to the bottom: coords.z = SMAASearchYDown(edgesTex, searchTex, vOffset[1].zw, vOffset[2].w);