From 133d10c62901ddd6206239e03ffb3632e9ff18fd Mon Sep 17 00:00:00 2001 From: fincs Date: Mon, 14 Sep 2015 17:00:58 +0200 Subject: [PATCH] Some corrections, fragment lighting still not working --- include/c3d/light.h | 2 +- source/effect.c | 2 +- source/light.c | 5 +++-- source/lightenv.c | 11 ++++++----- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/c3d/light.h b/include/c3d/light.h index 46488e2..99b4f29 100644 --- a/include/c3d/light.h +++ b/include/c3d/light.h @@ -61,7 +61,7 @@ struct C3D_LightEnv_t void C3D_LightEnvInit(C3D_LightEnv* env); void C3D_LightEnvBind(C3D_LightEnv* env); -void C3D_LightEnvMaterial(C3D_LightEnv* env, C3D_Material* mtl); +void C3D_LightEnvMaterial(C3D_LightEnv* env, const C3D_Material* mtl); void C3D_LightEnvAmbient(C3D_LightEnv* env, float r, float g, float b); //----------------------------------------------------------------------------- diff --git a/source/effect.c b/source/effect.c index 7bdb41d..a9aa76c 100644 --- a/source/effect.c +++ b/source/effect.c @@ -66,7 +66,7 @@ void C3Di_EffectBind(C3D_Effect* e) GPUCMD_AddWrite(GPUREG_BLEND_CONFIG, e->alphaBlend); GPUCMD_AddMaskedWrite(GPUREG_BLEND_ENABLE, 2, 0x00000100); - // Wat + // Disable early depth test? GPUCMD_AddMaskedWrite(GPUREG_0062, 1, 0); GPUCMD_AddWrite(GPUREG_0118, 0); } diff --git a/source/light.c b/source/light.c index 72f9082..0eb9c88 100644 --- a/source/light.c +++ b/source/light.c @@ -27,6 +27,7 @@ int C3D_LightInit(C3D_Light* light, C3D_LightEnv* env) break; if (i == 8) return -1; + env->lights[i] = light; light->flags = C3DF_Light_Enabled | C3DF_Light_Dirty | C3DF_Light_MatDirty; light->id = i; light->parent = env; @@ -92,10 +93,10 @@ static void C3Di_EnableCommon(C3D_Light* light, bool enable, u32 bit) C3D_LightEnv* env = light->parent; u32* var = &env->conf.config[1]; - if ((*var & bit) == bit) + if ((*var & bit) ^ bit) return; - if (enable) + if (!enable) *var |= bit; else *var &= ~bit; diff --git a/source/lightenv.c b/source/lightenv.c index b2086e3..1e2fcc0 100644 --- a/source/lightenv.c +++ b/source/lightenv.c @@ -32,14 +32,15 @@ static void C3Di_LightEnvUpdate(C3D_LightEnv* env) if (!(light->flags & C3DF_Light_Enabled)) continue; conf->permutation |= GPU_LIGHTPERM(conf->numLights++, i); } + if (conf->numLights > 0) conf->numLights --; env->flags &= ~C3DF_LightEnv_LCDirty; env->flags |= C3DF_LightEnv_Dirty; } - if (env->flags & C3DF_Light_MatDirty) + if (env->flags & C3DF_LightEnv_MtlDirty) { C3Di_LightEnvMtlBlend(env); - env->flags &= ~C3DF_Light_MatDirty; + env->flags &= ~C3DF_LightEnv_MtlDirty; env->flags |= C3DF_LightEnv_Dirty; } @@ -124,7 +125,7 @@ void C3D_LightEnvInit(C3D_LightEnv* env) env->flags = C3DF_LightEnv_Dirty; env->conf.config[0] = (4<<8) | BIT(27) | BIT(31); env->conf.config[1] = ~0; - env->conf.lutInput.abs = 0xFF; + env->conf.lutInput.abs = 0x2222222; } void C3D_LightEnvBind(C3D_LightEnv* env) @@ -141,10 +142,10 @@ void C3D_LightEnvBind(C3D_LightEnv* env) ctx->lightEnv = env; } -void C3D_LightEnvMaterial(C3D_LightEnv* env, C3D_Material* mtl) +void C3D_LightEnvMaterial(C3D_LightEnv* env, const C3D_Material* mtl) { int i; - memcpy(&env->material, mtl, sizeof(C3D_Material)); + memcpy(&env->material, mtl, sizeof(*mtl)); env->flags |= C3DF_LightEnv_MtlDirty; for (i = 0; i < 8; i ++) {