From 31772afd1306035c402c691c48d206b85244920f Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 15 May 2012 19:15:51 +0900 Subject: [PATCH] Add in some ambient light for iqm models. Though the bsp loader doesn't yet support colored lighting, the ambient light will be colored when it does. With this, I guess iqm model support is done for glsl until I figure out how I want to do dual quaternion support. --- libs/video/renderer/glsl/glsl_iqm.c | 6 ++++++ libs/video/renderer/glsl/iqm.frag | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/video/renderer/glsl/glsl_iqm.c b/libs/video/renderer/glsl/glsl_iqm.c index cc294afc9..2d081d978 100644 --- a/libs/video/renderer/glsl/glsl_iqm.c +++ b/libs/video/renderer/glsl/glsl_iqm.c @@ -83,6 +83,7 @@ static struct { shaderparam_t vtangent; shaderparam_t vnormal; shaderparam_t vposition; + shaderparam_t ambient; lightpar_t lights[MAX_IQM_LIGHTS]; shaderparam_t texture; shaderparam_t normalmap; @@ -99,6 +100,7 @@ static struct { {"vtangent", 0}, {"vnormal", 0}, {"vposition", 0}, + {"ambient", 1}, { {{"lights[0].position", 1}, {"lights[0].color", 1}}, {{"lights[1].position", 1}, {"lights[1].color", 1}}, @@ -151,6 +153,7 @@ glsl_R_InitIQM (void) GLSL_ResolveShaderParam (iqm_shader.program, &iqm_shader.vtangent); GLSL_ResolveShaderParam (iqm_shader.program, &iqm_shader.vnormal); GLSL_ResolveShaderParam (iqm_shader.program, &iqm_shader.vposition); + GLSL_ResolveShaderParam (iqm_shader.program, &iqm_shader.ambient); for (i = 0; i < MAX_IQM_LIGHTS; i++) { GLSL_ResolveShaderParam (iqm_shader.program, &iqm_shader.lights[i].position); @@ -203,6 +206,8 @@ glsl_R_DrawIQM (void) float blend; iqmframe_t *frame; + R_LightPoint (ent->origin); //FIXME min_light? + VectorScale (ambientcolor, 1/255.0, ambientcolor); R_FindNearLights (ent->origin, MAX_IQM_LIGHTS, lights); // we need only the rotation for normals. @@ -233,6 +238,7 @@ glsl_R_DrawIQM (void) } #endif + qfeglUniform3fv (iqm_shader.ambient.location, 1, ambientcolor); for (i = 0; i < MAX_IQM_LIGHTS; i++) { quat_t val; lightpar_t *l = &iqm_shader.lights[i]; diff --git a/libs/video/renderer/glsl/iqm.frag b/libs/video/renderer/glsl/iqm.frag index 9919479d1..c87d00b5b 100644 --- a/libs/video/renderer/glsl/iqm.frag +++ b/libs/video/renderer/glsl/iqm.frag @@ -4,6 +4,7 @@ struct light { }; uniform sampler2D texture; uniform sampler2D normalmap; +uniform vec3 ambient; uniform light lights[8]; uniform vec4 fog; @@ -52,7 +53,8 @@ main (void) norm = (texture2D (normalmap, st).xyz - vec3(0.5)) * 2.0; norm = tbn * norm; - l = calc_light (norm, 0); + l = ambient; + l += calc_light (norm, 0); l += calc_light (norm, 1); l += calc_light (norm, 2); l += calc_light (norm, 3);