From: havoc Date: Mon, 29 Jun 2020 00:16:58 +0000 (+0000) Subject: Rename render_modellight_lightdir to render_modellight_lightdir_world and add a _loca... X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=f61fa5e99b4d2ef1bf8af59e243d6a083cd43e97 Rename render_modellight_lightdir to render_modellight_lightdir_world and add a _local variant, which is transformed into entity space, so that rotating entities are lit correctly. Thanks to kristus for persistently reporting this bug until it was understood. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12749 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_main.c b/cl_main.c index 1f079bb7..4eae2894 100644 --- a/cl_main.c +++ b/cl_main.c @@ -2488,7 +2488,8 @@ static void CL_MeshEntities_Init(void) VectorSet(ent->render.render_modellight_ambient, 1, 1, 1); VectorSet(ent->render.render_modellight_diffuse, 0, 0, 0); VectorSet(ent->render.render_modellight_specular, 0, 0, 0); - VectorSet(ent->render.render_modellight_lightdir, 0, 0, 1); + VectorSet(ent->render.render_modellight_lightdir_world, 0, 0, 1); + VectorSet(ent->render.render_modellight_lightdir_local, 0, 0, 1); // local doesn't matter because no diffuse/specular color VectorSet(ent->render.render_lightmap_ambient, 0, 0, 0); VectorSet(ent->render.render_lightmap_diffuse, 1, 1, 1); VectorSet(ent->render.render_lightmap_specular, 1, 1, 1); @@ -2664,7 +2665,7 @@ static void CL_UpdateEntityShading_Entity(entity_render_t *ent) ent->render_modellight_ambient[q] = a[q] * ent->colormod[q]; ent->render_modellight_diffuse[q] = c[q] * ent->colormod[q]; ent->render_modellight_specular[q] = c[q]; - ent->render_modellight_lightdir[q] = dir[q]; + ent->render_modellight_lightdir_world[q] = dir[q]; ent->render_lightmap_ambient[q] = ent->colormod[q] * r_refdef.scene.ambientintensity; ent->render_lightmap_diffuse[q] = ent->colormod[q] * r_refdef.scene.lightmapintensity; ent->render_lightmap_specular[q] = r_refdef.scene.lightmapintensity; @@ -2680,9 +2681,12 @@ static void CL_UpdateEntityShading_Entity(entity_render_t *ent) for (q = 0; q < 3; q++) ent->render_rtlight_diffuse[q] = ent->render_rtlight_specular[q] = q; - if (VectorLength2(ent->render_modellight_lightdir) == 0) - VectorSet(ent->render_modellight_lightdir, 0, 0, 1); // have to set SOME valid vector here - VectorNormalize(ent->render_modellight_lightdir); + if (VectorLength2(ent->render_modellight_lightdir_world) == 0) + VectorSet(ent->render_modellight_lightdir_world, 0, 0, 1); // have to set SOME valid vector here + VectorNormalize(ent->render_modellight_lightdir_world); + // transform into local space for the entity as well + Matrix4x4_Transform3x3(&ent->inversematrix, ent->render_modellight_lightdir_world, ent->render_modellight_lightdir_local); + VectorNormalize(ent->render_modellight_lightdir_local); } diff --git a/client.h b/client.h index 835acc9a..75af05c8 100644 --- a/client.h +++ b/client.h @@ -576,7 +576,8 @@ typedef struct entity_render_s // MATERIALFLAG_MODELLIGHT uses these parameters float render_modellight_ambient[3]; float render_modellight_diffuse[3]; - float render_modellight_lightdir[3]; + float render_modellight_lightdir_world[3]; + float render_modellight_lightdir_local[3]; float render_modellight_specular[3]; // lightmap rendering (not MATERIALFLAG_MODELLIGHT) float render_lightmap_ambient[3]; diff --git a/gl_rmain.c b/gl_rmain.c index 0a0f1b36..08c76845 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -1966,7 +1966,7 @@ void R_SetupShader_Surface(const float rtlightambient[3], const float rtlightdif if (r_glsl_permutation->loc_DeferredMod_Diffuse >= 0) qglUniform3f(r_glsl_permutation->loc_DeferredMod_Diffuse, t->render_rtlight_diffuse[0], t->render_rtlight_diffuse[1], t->render_rtlight_diffuse[2]); if (r_glsl_permutation->loc_DeferredMod_Specular >= 0) qglUniform3f(r_glsl_permutation->loc_DeferredMod_Specular, t->render_rtlight_specular[0], t->render_rtlight_specular[1], t->render_rtlight_specular[2]); if (r_glsl_permutation->loc_LightColor >= 0) qglUniform3f(r_glsl_permutation->loc_LightColor, 1, 1, 1); // DEPRECATED - if (r_glsl_permutation->loc_LightDir >= 0) qglUniform3f(r_glsl_permutation->loc_LightDir, t->render_modellight_lightdir[0], t->render_modellight_lightdir[1], t->render_modellight_lightdir[2]); + if (r_glsl_permutation->loc_LightDir >= 0) qglUniform3f(r_glsl_permutation->loc_LightDir, t->render_modellight_lightdir_local[0], t->render_modellight_lightdir_local[1], t->render_modellight_lightdir_local[2]); } else { @@ -6731,7 +6731,8 @@ texture_t *R_GetCurrentTexture(texture_t *t) for (q = 0; q < 3; q++) { t->render_glowmod[q] = rsurface.entity->glowmod[q]; - t->render_modellight_lightdir[q] = q == 2; + t->render_modellight_lightdir_world[q] = q == 2; + t->render_modellight_lightdir_local[q] = q == 2; t->render_modellight_ambient[q] = 1; t->render_modellight_diffuse[q] = 0; t->render_modellight_specular[q] = 0; @@ -6750,7 +6751,8 @@ texture_t *R_GetCurrentTexture(texture_t *t) { t->render_glowmod[q] = rsurface.entity->render_glowmod[q] * r_refdef.view.colorscale; t->render_modellight_ambient[q] = rsurface.entity->render_fullbright[q] * r_refdef.view.colorscale; - t->render_modellight_lightdir[q] = q == 2; + t->render_modellight_lightdir_world[q] = q == 2; + t->render_modellight_lightdir_local[q] = q == 2; t->render_modellight_diffuse[q] = 0; t->render_modellight_specular[q] = 0; t->render_lightmap_ambient[q] = 0; @@ -6766,7 +6768,8 @@ texture_t *R_GetCurrentTexture(texture_t *t) for (q = 0; q < 3; q++) { t->render_glowmod[q] = rsurface.entity->render_glowmod[q] * r_refdef.view.colorscale; - t->render_modellight_lightdir[q] = q == 2; + t->render_modellight_lightdir_world[q] = q == 2; + t->render_modellight_lightdir_local[q] = q == 2; t->render_modellight_ambient[q] = 0; t->render_modellight_diffuse[q] = 0; t->render_modellight_specular[q] = 0; @@ -6784,7 +6787,8 @@ texture_t *R_GetCurrentTexture(texture_t *t) for (q = 0; q < 3; q++) { t->render_glowmod[q] = rsurface.entity->render_glowmod[q] * r_refdef.view.colorscale; - t->render_modellight_lightdir[q] = rsurface.entity->render_modellight_lightdir[q]; + t->render_modellight_lightdir_world[q] = rsurface.entity->render_modellight_lightdir_world[q]; + t->render_modellight_lightdir_local[q] = rsurface.entity->render_modellight_lightdir_local[q]; t->render_modellight_ambient[q] = rsurface.entity->render_modellight_ambient[q] * r_refdef.view.colorscale; t->render_modellight_diffuse[q] = rsurface.entity->render_modellight_diffuse[q] * r_refdef.view.colorscale; t->render_modellight_specular[q] = rsurface.entity->render_modellight_specular[q] * r_refdef.view.colorscale; @@ -6801,7 +6805,8 @@ texture_t *R_GetCurrentTexture(texture_t *t) for (q = 0; q < 3; q++) { t->render_glowmod[q] = rsurface.entity->render_glowmod[q] * r_refdef.view.colorscale; - t->render_modellight_lightdir[q] = q == 2; + t->render_modellight_lightdir_world[q] = q == 2; + t->render_modellight_lightdir_local[q] = q == 2; t->render_modellight_ambient[q] = 0; t->render_modellight_diffuse[q] = 0; t->render_modellight_specular[q] = 0; @@ -6825,7 +6830,8 @@ texture_t *R_GetCurrentTexture(texture_t *t) for (q = 0; q < 3; q++) { t->render_glowmod[q] = rsurface.entity->render_glowmod[q] * r_refdef.view.colorscale; - t->render_modellight_lightdir[q] = q == 2; + t->render_modellight_lightdir_world[q] = q == 2; + t->render_modellight_lightdir_local[q] = q == 2; t->render_modellight_ambient[q] = 0; t->render_modellight_diffuse[q] = 0; t->render_modellight_specular[q] = 0; diff --git a/model_shared.h b/model_shared.h index 03456a02..807d1cab 100644 --- a/model_shared.h +++ b/model_shared.h @@ -573,7 +573,8 @@ typedef struct texture_s // MATERIALFLAG_MODELLIGHT uses these parameters float render_modellight_ambient[3]; float render_modellight_diffuse[3]; - float render_modellight_lightdir[3]; + float render_modellight_lightdir_world[3]; + float render_modellight_lightdir_local[3]; float render_modellight_specular[3]; // lightmap rendering (not MATERIALFLAG_MODELLIGHT) float render_lightmap_ambient[3];