diff --git a/bin/resources/deferred_frag.nzsl b/bin/resources/deferred_frag.nzsl index ce83f2179..cc4b2f578 100644 --- a/bin/resources/deferred_frag.nzsl +++ b/bin/resources/deferred_frag.nzsl @@ -62,8 +62,7 @@ fn main(input: InputData) -> OutputData diffuseColor *= MaterialDiffuseMap.Sample(input.uv); const if (HasAlphaTexture) - // TODO: diffuseColor.w *= MaterialAlphaMap.Sample(input.uv)).x - diffuseColor = vec4(diffuseColor.x, diffuseColor.y, diffuseColor.z, (MaterialAlphaMap.Sample(input.uv)).x * diffuseColor.w); + diffuseColor.w *= MaterialAlphaMap.Sample(input.uv).x; const if (AlphaTest) { diff --git a/src/Nazara/Graphics/Resources/Shaders/basic_material.nzsl b/src/Nazara/Graphics/Resources/Shaders/basic_material.nzsl index 94cc36511..c7311494e 100644 --- a/src/Nazara/Graphics/Resources/Shaders/basic_material.nzsl +++ b/src/Nazara/Graphics/Resources/Shaders/basic_material.nzsl @@ -75,8 +75,7 @@ fn main(input: FragIn) -> FragOut diffuseColor *= MaterialDiffuseMap.Sample(input.uv); const if (HasAlphaTexture) - // TODO: diffuseColor.w *= MaterialAlphaMap.Sample(input.uv)).x - diffuseColor = vec4(diffuseColor.x, diffuseColor.y, diffuseColor.z, MaterialAlphaMap.Sample(input.uv).x * diffuseColor.w); + diffuseColor.w *= MaterialAlphaMap.Sample(input.uv).x; const if (AlphaTest) { diff --git a/src/Nazara/Shader/SpirvExpressionStore.cpp b/src/Nazara/Shader/SpirvExpressionStore.cpp index 6aace3b0c..f01ef2ae7 100644 --- a/src/Nazara/Shader/SpirvExpressionStore.cpp +++ b/src/Nazara/Shader/SpirvExpressionStore.cpp @@ -80,7 +80,36 @@ namespace Nz void SpirvExpressionStore::Visit(ShaderAst::SwizzleExpression& node) { - throw std::runtime_error("not yet implemented"); + if (node.componentCount != 1) + throw std::runtime_error("swizzle with more than one component is not yet supported"); + + node.expression->Visit(*this); + + const ShaderAst::ExpressionType& exprType = GetExpressionType(node); + + std::visit(overloaded + { + [&](const Pointer& pointer) + { + UInt32 resultId = m_visitor.AllocateResultId(); + UInt32 pointerType = m_writer.RegisterPointerType(exprType, pointer.storage); //< FIXME + + Int32 indexCount = UnderlyingCast(node.components[0]) - UnderlyingCast(ShaderAst::SwizzleComponent::First); + UInt32 indexId = m_writer.GetConstantId(indexCount); + + m_block.Append(SpirvOp::OpAccessChain, pointerType, resultId, pointer.pointerId, indexId); + + m_value = Pointer { pointer.storage, resultId }; + }, + [&](const LocalVar& value) + { + throw std::runtime_error("not yet implemented"); + }, + [](std::monostate) + { + throw std::runtime_error("an internal error occurred"); + } + }, m_value); } void SpirvExpressionStore::Visit(ShaderAst::VariableExpression& node) diff --git a/src/Nazara/Shader/SpirvWriter.cpp b/src/Nazara/Shader/SpirvWriter.cpp index dc548e592..8e1503dc6 100644 --- a/src/Nazara/Shader/SpirvWriter.cpp +++ b/src/Nazara/Shader/SpirvWriter.cpp @@ -357,6 +357,12 @@ namespace Nz { AstRecursiveVisitor::Visit(node); + for (std::size_t i = 0; i < node.componentCount; ++i) + { + Int32 indexCount = UnderlyingCast(node.components[i]) - UnderlyingCast(ShaderAst::SwizzleComponent::First); + m_constantCache.Register(*m_constantCache.BuildConstant(indexCount)); + } + m_constantCache.Register(*m_constantCache.BuildType(node.cachedExpressionType.value())); }