diff --git a/Runtime/Graphics/CGX.hpp b/Runtime/Graphics/CGX.hpp index 5bbe94b33..a09d656f9 100644 --- a/Runtime/Graphics/CGX.hpp +++ b/Runtime/Graphics/CGX.hpp @@ -28,7 +28,7 @@ struct STexState { struct SGXState { std::array x0_arrayPtrs{}; std::array x30_prevChanCtrls{}; - std::array x34_chanCtrls{}; + std::array x34_chanCtrls{0x4000, 0x4000}; std::array x38_chanAmbColors; std::array x40_chanMatColors; GX::VtxDescList* x48_descList = nullptr; @@ -150,6 +150,9 @@ static inline void SetChanAmbColor(EChannelId id, const GXColor& color) noexcept static inline void SetChanCtrl(EChannelId id, GXBool enable, GX::ColorSrc ambSrc, GX::ColorSrc matSrc, GX::LightMask lights, GX::DiffuseFn diffFn, GX::AttnFn attnFn) noexcept { const auto idx = std::underlying_type_t(id); + if (lights.none()) { + enable = false; + } const u32 flags = (attnFn & 3) << 13 | (diffFn & 3) << 11 | (lights.to_ulong() & 0xFF) << 3 | (matSrc & 1) << 2 | (ambSrc & 1) << 1 | (u8(enable) & 1); sGXState.x34_chanCtrls[idx] = flags; diff --git a/Runtime/Graphics/CGraphics.cpp b/Runtime/Graphics/CGraphics.cpp index a9e6314bb..30058dec4 100644 --- a/Runtime/Graphics/CGraphics.cpp +++ b/Runtime/Graphics/CGraphics.cpp @@ -589,22 +589,22 @@ void CGraphics::DrawPrimitive(GX::Primitive primitive, const zeus::CVector3f* po void CGraphics::SetTevStates(EStreamFlags flags) noexcept { if (flags & EStreamFlagBits::fHasTexture) { - CGX::SetNumChans(1); CGX::SetNumTexGens(0); CGX::SetNumTevStages(1); CGX::SetTevOrder(GX::TEVSTAGE0, GX::TEXCOORD0, GX::TEXMAP0, GX::COLOR0A0); CGX::SetTevOrder(GX::TEVSTAGE1, GX::TEXCOORD1, GX::TEXMAP1, GX::COLOR0A0); } else /* if (flags < 8) ? */ { - CGX::SetNumChans(1); CGX::SetNumTexGens(2); // sTextureUsed & 3? CGX::SetTevOrder(GX::TEVSTAGE0, GX::TEXCOORD_NULL, GX::TEXMAP_NULL, GX::COLOR0A0); CGX::SetTevOrder(GX::TEVSTAGE1, GX::TEXCOORD_NULL, GX::TEXMAP_NULL, GX::COLOR0A0); } + CGX::SetNumChans(1); CGX::SetNumIndStages(0); // TODO load TCGs const bool hasLights = g_LightActive.any(); CGX::SetChanCtrl(CGX::EChannelId::Channel0, hasLights, GX::SRC_REG, flags & EStreamFlagBits::fHasColor ? GX::SRC_VTX : GX::SRC_REG, g_LightActive, hasLights ? GX::DF_CLAMP : GX::DF_NONE, hasLights ? GX::AF_SPOT : GX::AF_NONE); + CGX::FlushState(); // normally would be handled in FullRender TODO } } // namespace metaforce diff --git a/aurora/include/aurora/gfx.hpp b/aurora/include/aurora/gfx.hpp index 3106a1b38..124ee2d13 100644 --- a/aurora/include/aurora/gfx.hpp +++ b/aurora/include/aurora/gfx.hpp @@ -146,7 +146,6 @@ void update_projection(const zeus::CMatrix4f& proj) noexcept; void update_fog_state(const metaforce::CFogState& state) noexcept; void load_light(GX::LightID id, const Light& light) noexcept; void load_light_ambient(GX::LightID id, const zeus::CColor& ambient) noexcept; -void set_light_state(GX::LightMask bits) noexcept; void set_viewport(const zeus::CRectangle& rect, float znear, float zfar) noexcept; void set_scissor(uint32_t x, uint32_t y, uint32_t w, uint32_t h) noexcept; diff --git a/aurora/lib/gfx/gx.cpp b/aurora/lib/gfx/gx.cpp index 26e358d13..59427b09a 100644 --- a/aurora/lib/gfx/gx.cpp +++ b/aurora/lib/gfx/gx.cpp @@ -332,10 +332,12 @@ wgpu::RenderPipeline build_pipeline(const PipelineConfig& config, const ShaderIn ShaderInfo populate_pipeline_config(PipelineConfig& config, GX::Primitive primitive, const BindGroupRanges& ranges) noexcept { - for (size_t i = 0; i < g_gxState.numTevStages; ++i) { + for (u8 i = 0; i < g_gxState.numTevStages; ++i) { config.shaderConfig.tevStages[i] = g_gxState.tevStages[i]; } - config.shaderConfig.colorChannels = g_gxState.colorChannelConfig; + for (u8 i = 0; i < g_gxState.numChans; ++i) { + config.shaderConfig.colorChannels[i] = g_gxState.colorChannelConfig[i]; + } config.shaderConfig.alphaDiscard = g_gxState.alphaDiscard; config = { .shaderConfig = config.shaderConfig, diff --git a/aurora/lib/gfx/gx_shader.cpp b/aurora/lib/gfx/gx_shader.cpp index db8908e21..294ab94b6 100644 --- a/aurora/lib/gfx/gx_shader.cpp +++ b/aurora/lib/gfx/gx_shader.cpp @@ -527,6 +527,11 @@ var v_packed_uvs: Vec2Block; uniBufAttrs += fmt::format(FMT_STRING("\n cc{0}_mat: vec4;"), i); info.uniformSize += 32; + if (config.denormalizedVertexAttributes && !info.usesVtxColor) { + vtxInAttrs += fmt::format(FMT_STRING("\n , @location({}) in_clr: vec4"), ++locIdx); + info.usesVtxColor = true; + } + if (config.colorChannels[i].lightingEnabled) { if (!addedLightStruct) { uniformPre += @@ -570,16 +575,12 @@ var v_packed_uvs: Vec2Block; fragmentFnPre += fmt::format(FMT_STRING("\n var rast{0} = in.cc{0};"), i); } else if (config.colorChannels[i].matSrc == GX::SRC_VTX) { if (config.denormalizedVertexAttributes) { - if (!info.usesVtxColor) { - vtxInAttrs += fmt::format(FMT_STRING("\n , @location({}) in_clr: vec4"), locIdx); - } - vtxOutAttrs += fmt::format(FMT_STRING("\n @location({}) cc{}: vec4;"), locIdx++, i); + vtxOutAttrs += fmt::format(FMT_STRING("\n @location({}) cc{}: vec4;"), locIdx - 1, i); vtxXfrAttrs += fmt::format(FMT_STRING("\n out.cc{} = in_clr;"), i); fragmentFnPre += fmt::format(FMT_STRING("\n var rast{0} = in.cc{0};"), i); } else { Log.report(logvisor::Fatal, FMT_STRING("SRC_VTX unsupported with normalized vertex attributes")); } - info.usesVtxColor = true; } else { fragmentFnPre += fmt::format(FMT_STRING("\n var rast{0} = ubuf.cc{0}_mat;"), i); }