Shader/SPIRV: Add support for swizzling with one component
This commit is contained in:
parent
a6b8caa5ba
commit
9bd411e53c
|
|
@ -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<f32>(diffuseColor.x, diffuseColor.y, diffuseColor.z, (MaterialAlphaMap.Sample(input.uv)).x * diffuseColor.w);
|
||||
diffuseColor.w *= MaterialAlphaMap.Sample(input.uv).x;
|
||||
|
||||
const if (AlphaTest)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<f32>(diffuseColor.x, diffuseColor.y, diffuseColor.z, MaterialAlphaMap.Sample(input.uv).x * diffuseColor.w);
|
||||
diffuseColor.w *= MaterialAlphaMap.Sample(input.uv).x;
|
||||
|
||||
const if (AlphaTest)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue