]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Rename render_modellight_lightdir to render_modellight_lightdir_world and add a _loca...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 29 Jun 2020 00:16:58 +0000 (00:16 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 29 Jun 2020 00:16:58 +0000 (00:16 +0000)
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

cl_main.c
client.h
gl_rmain.c
model_shared.h

index 1f079bb7b5fd1621abcf534a2b6d6511940e9afa..4eae28940e67a5e8d0ec511165d891b3d78101b2 100644 (file)
--- 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);
 }
 
 
index 835acc9a4e175226bb23459cd01a16b90b979ba2..75af05c88a70e753b2bfdd5e32669e279c6b7c0b 100644 (file)
--- 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];
index 0a0f1b365a21b1cf73a018ea1c33c654d2a1c850..08c76845f23b7b63b48b7e38646f083acc2bac4f 100644 (file)
@@ -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;
index 03456a02089abdb064bce89f65314240f3ba2c77..807d1cab0e202a19113bf1b114eca189396d2a46 100644 (file)
@@ -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];