Fix lighting issues; fix CPatterned damage color

This commit is contained in:
Luke Street 2022-03-14 01:10:29 -04:00
parent f3635c740a
commit 40a3d361dc
4 changed files with 16 additions and 20 deletions

View File

@ -1651,11 +1651,11 @@ void CPatterned::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) {
}
if (x401_29_laggedBurnDeath) {
int stripedAlpha = 255;
u32 stripedAlpha = 255;
if (alpha > 127) {
stripedAlpha = (alpha - 128) * 2;
stripedAlpha = u32(alpha) * 2;
}
xb4_drawFlags = CModelFlags(3, 0, 3, zeus::CColor(0.f, float(stripedAlpha * stripedAlpha) / 65025.f));
xb4_drawFlags = CModelFlags(3, 0, 3, zeus::CColor(0.f, float((stripedAlpha * stripedAlpha) >> 8) / 255.f));
} else if (x401_28_burning) {
xb4_drawFlags = CModelFlags(5, 0, 3, zeus::CColor(0.f, 1.f));
} else {
@ -1667,10 +1667,8 @@ void CPatterned::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) {
if (col.r() != 0.f || col.g() != 0.f || col.b() != 0.f) {
/* Being damaged */
zeus::CColor col2 = col;
col2.a() = float(alpha) / 255.f;
xb4_drawFlags = CModelFlags(2, 0, 3, zeus::skWhite);
/* Make color additive */
// TODO xb4_drawFlags.addColor = col2;
col2.a() = 1.f;
xb4_drawFlags = CModelFlags(2, 0, 3, col2);
} else {
xb4_drawFlags = CModelFlags(0, 0, 3, zeus::skWhite);
}

View File

@ -149,7 +149,6 @@ void load_light(GX::LightID id, const Light& light) noexcept { gx::g_gxState.lig
void load_light_ambient(GX::LightID id, const zeus::CColor& ambient) noexcept {
gx::g_gxState.lights[std::log2<u32>(id)] = ambient;
}
void set_light_state(GX::LightMask bits) noexcept { gx::g_gxState.lightState = bits; }
namespace gx {
using gpu::g_device;
@ -384,8 +383,9 @@ Range build_uniform(const ShaderInfo& info) noexcept {
if (g_gxState.colorChannelConfig[i].lightingEnabled) {
zeus::CColor ambient = zeus::skClear;
int addedLights = 0;
for (int li = 0; li < g_gxState.lightState.size(); ++li) {
if (!g_gxState.lightState.test(li)) {
const auto& lightState = g_gxState.colorChannelState[i].lightState;
for (int li = 0; li < lightState.size(); ++li) {
if (!lightState.test(li)) {
continue;
}
const auto& variant = g_gxState.lights[li];

View File

@ -83,7 +83,6 @@ struct GXState {
std::array<LightVariant, GX::MaxLights> lights;
std::array<TevStage, MaxTevStages> tevStages;
std::array<TextureBind, MaxTextures> textures;
GX::LightMask lightState;
bool depthCompare = true;
bool depthUpdate = true;
bool alphaUpdate = true;

View File

@ -433,7 +433,7 @@ var<storage, read> v_packed_uvs: Vec2Block;
vtxOutAttrs += "\n @builtin(position) pos: vec4<f32>;";
vtxXfrAttrsPre +=
"\n var obj_pos = vec4<f32>(v_verts.data[in_pos_nrm_idx[0]].xyz, 1.0);"
"\n var obj_norm = vec4<f32>(v_verts.data[in_pos_nrm_idx[1]].xyz, 0.0);"
"\n var obj_norm = vec4<f32>(v_norms.data[in_pos_nrm_idx[1]].xyz, 0.0);"
"\n var mv_pos = ubuf.mv * obj_pos;"
"\n var mv_norm = ubuf.mv_inv * obj_norm;"
"\n out.pos = ubuf.proj * mv_pos;";
@ -555,14 +555,13 @@ var<storage, read> v_packed_uvs: Vec2Block;
var dist = length(delta);
var delta_norm = delta / dist;
var ang_dot = max(dot(delta_norm, light.dir), 0.0);
var lin_att = light.lin_att;
var att = 1.0 / (lin_att.z * dist * dist * lin_att.y * dist + lin_att.x);
var ang_att = light.ang_att;
var ang_att_d = ang_att.z * ang_dot * ang_dot * ang_att.y * ang_dot + ang_att.x;
var this_color = light.color.xyz * ang_att_d * att * max(dot(-delta_norm, mv_norm.xyz), 0.0);
// if (i == 0 && c_traits.shader.world_shadow == 1u) {{
// // TODO ExtTex0 sample
// }}
var att = 1.0 / (light.lin_att.z * dist * dist +
light.lin_att.y * dist +
light.lin_att.x);
var ang_att = light.ang_att.z * ang_dot * ang_dot +
light.ang_att.y * ang_dot +
light.ang_att.x;
var this_color = light.color.xyz * ang_att * att * max(dot(-delta_norm, mv_norm.xyz), 0.0);
lighting = lighting + vec4<f32>(this_color, 0.0);
}}
out.cc{0} = clamp(lighting, vec4<f32>(0.0), vec4<f32>(1.0));