mirror of
https://github.com/encounter/aurora.git
synced 2025-07-05 04:35:55 +00:00
Simplify lighting in build_uniform
This commit is contained in:
parent
3bba70d1ff
commit
6c27585cf9
@ -180,8 +180,8 @@ static inline wgpu::PrimitiveState to_primitive_state(GXPrimitive gx_prim, GXCul
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
.topology = primitive,
|
.topology = primitive,
|
||||||
.stripIndexFormat = gx_prim == GX_TRIANGLESTRIP || gx_prim == GX_LINESTRIP ? wgpu::IndexFormat::Uint16
|
.stripIndexFormat = primitive == wgpu::PrimitiveTopology::TriangleStrip ? wgpu::IndexFormat::Uint16
|
||||||
: wgpu::IndexFormat::Undefined,
|
: wgpu::IndexFormat::Undefined,
|
||||||
.frontFace = wgpu::FrontFace::CW,
|
.frontFace = wgpu::FrontFace::CW,
|
||||||
.cullMode = cullMode,
|
.cullMode = cullMode,
|
||||||
};
|
};
|
||||||
@ -328,19 +328,7 @@ Range build_uniform(const ShaderInfo& info) noexcept {
|
|||||||
}
|
}
|
||||||
buf.append(g_gxState.colorRegs[i]);
|
buf.append(g_gxState.colorRegs[i]);
|
||||||
}
|
}
|
||||||
bool lightingEnabled = false;
|
if (info.lightingEnabled) {
|
||||||
for (int i = 0; i < info.sampledColorChannels.size(); ++i) {
|
|
||||||
if (!info.sampledColorChannels.test(i)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const auto& ccc = g_gxState.colorChannelConfig[i * 2];
|
|
||||||
const auto& ccca = g_gxState.colorChannelConfig[i * 2 + 1];
|
|
||||||
if (ccc.lightingEnabled || ccca.lightingEnabled) {
|
|
||||||
lightingEnabled = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (lightingEnabled) {
|
|
||||||
// Lights
|
// Lights
|
||||||
static_assert(sizeof(g_gxState.lights) == 80 * GX::MaxLights);
|
static_assert(sizeof(g_gxState.lights) == 80 * GX::MaxLights);
|
||||||
buf.append(g_gxState.lights);
|
buf.append(g_gxState.lights);
|
||||||
@ -380,12 +368,11 @@ Range build_uniform(const ShaderInfo& info) noexcept {
|
|||||||
if (!info.usesTexMtx.test(i)) {
|
if (!info.usesTexMtx.test(i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const auto& state = g_gxState;
|
|
||||||
switch (info.texMtxTypes[i]) {
|
switch (info.texMtxTypes[i]) {
|
||||||
DEFAULT_FATAL("unhandled tex mtx type {}", underlying(info.texMtxTypes[i]));
|
DEFAULT_FATAL("unhandled tex mtx type {}", underlying(info.texMtxTypes[i]));
|
||||||
case GX_TG_MTX2x4:
|
case GX_TG_MTX2x4:
|
||||||
if (std::holds_alternative<Mat2x4<float>>(state.texMtxs[i])) {
|
if (std::holds_alternative<Mat2x4<float>>(g_gxState.texMtxs[i])) {
|
||||||
buf.append(std::get<Mat2x4<float>>(state.texMtxs[i]));
|
buf.append(std::get<Mat2x4<float>>(g_gxState.texMtxs[i]));
|
||||||
} else
|
} else
|
||||||
UNLIKELY FATAL("expected 2x4 mtx in idx {}", i);
|
UNLIKELY FATAL("expected 2x4 mtx in idx {}", i);
|
||||||
break;
|
break;
|
||||||
|
@ -420,6 +420,7 @@ struct ShaderInfo {
|
|||||||
std::array<GXTexGenType, MaxTexMtx> texMtxTypes{};
|
std::array<GXTexGenType, MaxTexMtx> texMtxTypes{};
|
||||||
u32 uniformSize = 0;
|
u32 uniformSize = 0;
|
||||||
bool usesFog : 1 = false;
|
bool usesFog : 1 = false;
|
||||||
|
bool lightingEnabled : 1 = false;
|
||||||
};
|
};
|
||||||
struct BindGroupRanges {
|
struct BindGroupRanges {
|
||||||
std::array<Range, GX_VA_MAX_ATTR> vaRanges{};
|
std::array<Range, GX_VA_MAX_ATTR> vaRanges{};
|
||||||
|
@ -581,19 +581,18 @@ ShaderInfo build_shader_info(const ShaderConfig& config) noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
info.uniformSize += info.loadsTevReg.count() * sizeof(Vec4<float>);
|
info.uniformSize += info.loadsTevReg.count() * sizeof(Vec4<float>);
|
||||||
bool lightingEnabled = false;
|
|
||||||
for (int i = 0; i < info.sampledColorChannels.size(); ++i) {
|
for (int i = 0; i < info.sampledColorChannels.size(); ++i) {
|
||||||
if (info.sampledColorChannels.test(i)) {
|
if (info.sampledColorChannels.test(i)) {
|
||||||
const auto& cc = config.colorChannels[i * 2];
|
const auto& cc = config.colorChannels[i * 2];
|
||||||
const auto& cca = config.colorChannels[i * 2 + 1];
|
const auto& cca = config.colorChannels[i * 2 + 1];
|
||||||
if (cc.lightingEnabled || cca.lightingEnabled) {
|
if (cc.lightingEnabled || cca.lightingEnabled) {
|
||||||
lightingEnabled = true;
|
info.lightingEnabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lightingEnabled) {
|
if (info.lightingEnabled) {
|
||||||
// Lights + light state for all channels
|
// Lights + light state for all channels
|
||||||
info.uniformSize += sizeof(Vec4<float>) + sizeof(Light) * GX::MaxLights;
|
info.uniformSize += 16 + sizeof(Light) * GX::MaxLights;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < info.sampledColorChannels.size(); ++i) {
|
for (int i = 0; i < info.sampledColorChannels.size(); ++i) {
|
||||||
if (info.sampledColorChannels.test(i)) {
|
if (info.sampledColorChannels.test(i)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user