From 91b89c7a62c4e08847c7ead37b6102f7cbed8673 Mon Sep 17 00:00:00 2001 From: fincs Date: Thu, 30 Mar 2017 23:42:58 +0200 Subject: [PATCH] Allow for separate light amb/dif/spe colors --- include/c3d/light.h | 17 +++++++++++++++-- source/light.c | 43 +++++++++++++++++++++++++++++++++++-------- source/lightenv.c | 1 + 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/include/c3d/light.h b/include/c3d/light.h index da13c04..e68eb29 100644 --- a/include/c3d/light.h +++ b/include/c3d/light.h @@ -116,7 +116,10 @@ struct C3D_Light_t u16 flags, id; C3D_LightEnv* parent; C3D_LightLut *lut_SP, *lut_DA; - float color[3]; + float ambient[3]; + float diffuse[3]; + float specular0[3]; + float specular1[3]; C3D_LightConf conf; }; @@ -124,7 +127,10 @@ int C3D_LightInit(C3D_Light* light, C3D_LightEnv* env); void C3D_LightEnable(C3D_Light* light, bool enable); void C3D_LightTwoSideDiffuse(C3D_Light* light, bool enable); void C3D_LightGeoFactor(C3D_Light* light, int id, bool enable); -void C3D_LightColor(C3D_Light* light, float r, float g, float b); +void C3D_LightAmbient(C3D_Light* light, float r, float g, float b); +void C3D_LightDiffuse(C3D_Light* light, float r, float g, float b); +void C3D_LightSpecular0(C3D_Light* light, float r, float g, float b); +void C3D_LightSpecular1(C3D_Light* light, float r, float g, float b); void C3D_LightPosition(C3D_Light* light, C3D_FVec* pos); void C3D_LightShadowEnable(C3D_Light* light, bool enable); void C3D_LightSpotEnable(C3D_Light* light, bool enable); @@ -132,3 +138,10 @@ void C3D_LightSpotDir(C3D_Light* light, float x, float y, float z); void C3D_LightSpotLut(C3D_Light* light, C3D_LightLut* lut); void C3D_LightDistAttnEnable(C3D_Light* light, bool enable); void C3D_LightDistAttn(C3D_Light* light, C3D_LightLutDA* lut); + +static inline void C3D_LightColor(C3D_Light* light, float r, float g, float b) +{ + C3D_LightDiffuse(light, r, g, b); + C3D_LightSpecular0(light, r, g, b); + C3D_LightSpecular1(light, r, g, b); +} diff --git a/source/light.c b/source/light.c index 3b87d30..27f09ed 100644 --- a/source/light.c +++ b/source/light.c @@ -9,10 +9,10 @@ void C3Di_LightMtlBlend(C3D_Light* light) for (i = 0; i < 3; i ++) { - conf->specular0 |= ((u32)(255*(mtl->specular0[i]*light->color[i]))) << (i*10); - conf->specular1 |= ((u32)(255*(mtl->specular1[i]*light->color[i]))) << (i*10); - conf->diffuse |= ((u32)(255*(mtl->diffuse[i] *light->color[i]))) << (i*10); - conf->ambient |= ((u32)(255*(mtl->ambient[i] *light->color[i]))) << (i*10); + conf->specular0 |= ((u32)(255*(mtl->specular0[i]*light->specular0[i]))) << (i*10); + conf->specular1 |= ((u32)(255*(mtl->specular1[i]*light->specular1[i]))) << (i*10); + conf->diffuse |= ((u32)(255*(mtl->diffuse[i] *light->diffuse[i]))) << (i*10); + conf->ambient |= ((u32)(255*(mtl->ambient[i] *light->ambient[i]))) << (i*10); } } @@ -30,6 +30,9 @@ int C3D_LightInit(C3D_Light* light, C3D_LightEnv* env) light->flags = C3DF_Light_Enabled | C3DF_Light_Dirty | C3DF_Light_MatDirty; light->id = i; light->parent = env; + light->diffuse[0] = light->diffuse[1] = light->diffuse[2] = 1.0f; + light->specular0[0] = light->specular0[1] = light->specular0[2] = 1.0f; + light->specular1[0] = light->specular1[1] = light->specular1[2] = 1.0f; env->flags |= C3DF_LightEnv_LCDirty; return i; @@ -67,11 +70,35 @@ void C3D_LightGeoFactor(C3D_Light* light, int id, bool enable) light->flags |= C3DF_Light_Dirty; } -void C3D_LightColor(C3D_Light* light, float r, float g, float b) +void C3D_LightAmbient(C3D_Light* light, float r, float g, float b) { - light->color[0] = b; - light->color[1] = g; - light->color[2] = r; + light->ambient[0] = b; + light->ambient[1] = g; + light->ambient[2] = r; + light->flags |= C3DF_Light_MatDirty; +} + +void C3D_LightDiffuse(C3D_Light* light, float r, float g, float b) +{ + light->diffuse[0] = b; + light->diffuse[1] = g; + light->diffuse[2] = r; + light->flags |= C3DF_Light_MatDirty; +} + +void C3D_LightSpecular0(C3D_Light* light, float r, float g, float b) +{ + light->specular0[0] = b; + light->specular0[1] = g; + light->specular0[2] = r; + light->flags |= C3DF_Light_MatDirty; +} + +void C3D_LightSpecular1(C3D_Light* light, float r, float g, float b) +{ + light->specular1[0] = b; + light->specular1[1] = g; + light->specular1[2] = r; light->flags |= C3DF_Light_MatDirty; } diff --git a/source/lightenv.c b/source/lightenv.c index 901abf0..05a77d9 100644 --- a/source/lightenv.c +++ b/source/lightenv.c @@ -153,6 +153,7 @@ void C3D_LightEnvInit(C3D_LightEnv* env) { memset(env, 0, sizeof(*env)); env->flags = C3DF_LightEnv_Dirty; + env->ambient[0] = env->ambient[1] = env->ambient[2] = 1.0f; env->conf.config[0] = (4<<8) | BIT(27) | BIT(31); env->conf.config[1] = ~0; env->conf.lutInput.select = GPU_LIGHTLUTINPUT(GPU_LUT_SP, GPU_LUTINPUT_SP);