Added DP_CSQC_ENTITYMODELLIGHT extension (CSQC-updated modellight using modellight_...
authorvortex <vortex@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 12 Sep 2011 16:53:12 +0000 (16:53 +0000)
committervortex <vortex@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 12 Sep 2011 16:53:12 +0000 (16:53 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11344 d7cf8633-e32d-0410-b094-e92efae38249

csprogs.c
csprogs.h
dpdefs/csprogsdefs.qc
gl_rmain.c
meshqueue.c
protocol.h
prvm_offsets.h
svvm_cmds.c

index 8a9bf1d..69483ae 100644 (file)
--- a/csprogs.c
+++ b/csprogs.c
@@ -370,13 +370,22 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed, int edictnum)
        if (renderflags & RF_USETRANSPARENTOFFSET)
                entrender->transparent_offset = PRVM_clientglobalfloat(transparent_offset);
 
+       // model light
+       if (renderflags & RF_MODELLIGHT)
+       {
+               if(PRVM_clientedictvector(ed, modellight_ambient)) VectorCopy(PRVM_clientedictvector(ed, modellight_ambient), entrender->modellight_ambient);
+               if(PRVM_clientedictvector(ed, modellight_diffuse)) VectorCopy(PRVM_clientedictvector(ed, modellight_diffuse), entrender->modellight_diffuse);
+               if(PRVM_clientedictvector(ed, modellight_dir))     VectorCopy(PRVM_clientedictvector(ed, modellight_dir), entrender->modellight_lightdir);
+               entrender->flags |= RENDER_CUSTOMIZEDMODELLIGHT;
+       }
+
        if(renderflags)
        {
-               if(renderflags & RF_VIEWMODEL)  entrender->flags |= RENDER_VIEWMODEL | RENDER_NODEPTHTEST;
-               if(renderflags & RF_EXTERNALMODEL)entrender->flags |= RENDER_EXTERIORMODEL;
-               if(renderflags & RF_NOCULL)             entrender->flags |= RENDER_NOCULL;
-               if(renderflags & RF_DEPTHHACK)  entrender->flags |= RENDER_NODEPTHTEST;
-               if(renderflags & RF_ADDITIVE)           entrender->flags |= RENDER_ADDITIVE;
+               if(renderflags & RF_VIEWMODEL) entrender->flags |= RENDER_VIEWMODEL | RENDER_NODEPTHTEST;
+               if(renderflags & RF_EXTERNALMODEL) entrender->flags |= RENDER_EXTERIORMODEL;
+               if(renderflags & RF_WORLDOBJECT) entrender->flags |= RENDER_WORLDOBJECT;
+               if(renderflags & RF_DEPTHHACK) entrender->flags |= RENDER_NODEPTHTEST;
+               if(renderflags & RF_ADDITIVE) entrender->flags |= RENDER_ADDITIVE;
        }
 
        c = (int)PRVM_clientedictfloat(ed, colormap);
index c82974b..a5f478c 100644 (file)
--- a/csprogs.h
+++ b/csprogs.h
@@ -59,8 +59,9 @@
 #define RF_USEAXIS                     16      // When set, the entity will use the v_forward, v_right and v_up globals instead of it's angles field for orientation. Angles will be ignored compleatly.
                                                                // Note that to use this properly, you'll NEED to use the predraw function to set the globals.
 //#define RF_DOUBLESIDED               32
-#define RF_USETRANSPARENTOFFSET 64 // Allows QC to customize origin used for transparent sorting via transparent_origin global, helps to fix transparent sorting bugs on a very large entities
-#define RF_NOCULL                              128 // do not cull this entity using r_cullentities, for large outdoor entities (asteroids on the sky. etc)
+#define RF_USETRANSPARENTOFFSET 64   // Allows QC to customize origin used for transparent sorting via transparent_origin global, helps to fix transparent sorting bugs on a very large entities
+#define RF_WORLDOBJECT          128  // for large outdoor entities that should not be culled
+#define RF_MODELLIGHT           4096 // CSQC-set model light
 
 #define RF_FULLBRIGHT                  256
 #define RF_NOSHADOW                            512
index 2100605..1a08e58 100644 (file)
@@ -734,13 +734,21 @@ float transparent_offset; // should be set before entity is added
 // example: transparent_offset = 1000000; // entity always appear on background of other transparents
 // note: offset is done in view forward axis
 
-// DP_CSQC_ENTITYNOCULL
+// DP_CSQC_ENTITYWORLDOBJECT
 // idea: VorteX
 // darkplaces implementation: VorteX
-const float RF_NOCULL = 128;
+const float RF_WORLDOBJECT = 128;
 // description: when renderflag is set, engine will not use culling methods for this entity, e.g. it will always be drawn
-// useful for large outdoor objects (like asteriods on sky horizont or sky models)
-// also useful when culling is done at CSQC side
+// useful for large outdoor objects (like asteroids on sky horizon or sky models)
+
+// DP_CSQC_ENTITYMODELLIGHT
+// idea: VorteX
+// darkplaces implementation: VorteX
+const float RF_MODELLIGHT = 4096;
+.vector modellight_ambient;
+.vector modellight_diffuse;
+.vector modellight_dir;
+// description: allows CSQC to override directional model lightning on entity
 
 // DP_CSQC_SETPAUSE
 // idea: VorteX
@@ -868,4 +876,4 @@ string(string command, float bindmap) findkeysforcommand = #610;
 //builtin definitions: (CSQC)
 float(string url, float id, string content_type, string delim, float buf, float keyid) crypto_uri_postbuf = #513;
 //description:
-//use -1 as buffer handle to justs end delim as postdata
+//use -1 as buffer handle to justs end delim as postdata
\ No newline at end of file
index 5da6228..438c5e4 100644 (file)
@@ -4801,8 +4801,8 @@ static void R_View_UpdateEntityLighting (void)
        {
                ent = r_refdef.scene.entities[i];
 
-               // skip unseen models
-               if (!r_refdef.viewcache.entityvisible[i] && skipunseen)
+               // skip unseen models and models that updated by CSQC
+               if ((!r_refdef.viewcache.entityvisible[i] && skipunseen) || ent->flags & RENDER_CUSTOMIZEDMODELLIGHT)
                        continue;
 
                // skip bsp models
@@ -4958,7 +4958,7 @@ static void R_View_UpdateEntityVisible (void)
                        ent = r_refdef.scene.entities[i];
                        if (!(ent->flags & renderimask))
                        if (!R_CullBox(ent->mins, ent->maxs) || (ent->model && ent->model->type == mod_sprite && (ent->model->sprite.sprnum_type == SPR_LABEL || ent->model->sprite.sprnum_type == SPR_LABEL_SCALE)))
-                       if ((ent->flags & (RENDER_NODEPTHTEST | RENDER_VIEWMODEL)) || r_refdef.scene.worldmodel->brush.BoxTouchingVisibleLeafs(r_refdef.scene.worldmodel, r_refdef.viewcache.world_leafvisible, ent->mins, ent->maxs))
+                       if ((ent->flags & (RENDER_NODEPTHTEST | RENDER_WORLDOBJECT | RENDER_VIEWMODEL)) || r_refdef.scene.worldmodel->brush.BoxTouchingVisibleLeafs(r_refdef.scene.worldmodel, r_refdef.viewcache.world_leafvisible, ent->mins, ent->maxs))
                                r_refdef.viewcache.entityvisible[i] = true;
                }
        }
@@ -4979,7 +4979,7 @@ static void R_View_UpdateEntityVisible (void)
                        if (!r_refdef.viewcache.entityvisible[i])
                                continue;
                        ent = r_refdef.scene.entities[i];
-                       if(!(ent->flags & (RENDER_VIEWMODEL | RENDER_NOCULL | RENDER_NODEPTHTEST)) && !(ent->model && (ent->model->name[0] == '*')))
+                       if(!(ent->flags & (RENDER_VIEWMODEL | RENDER_WORLDOBJECT | RENDER_NODEPTHTEST)) && !(ent->model && (ent->model->name[0] == '*')))
                        {
                                samples = ent->entitynumber ? r_cullentities_trace_samples.integer : r_cullentities_trace_tempentitysamples.integer;
                                if (samples < 0)
@@ -7673,8 +7673,9 @@ void R_tcMod_ApplyToMatrix(matrix4x4_t *texmatrix, q3shaderinfo_layer_tcmod_t *t
                        Matrix4x4_CreateTranslate(&matrix, 0, 0, 0);
                        break;
                case Q3TCMOD_ROTATE:
+                       f = tcmod->parms[0] * rsurface.shadertime;
                        Matrix4x4_CreateTranslate(&matrix, 0.5, 0.5, 0);
-                       Matrix4x4_ConcatRotate(&matrix, tcmod->parms[0] * rsurface.shadertime, 0, 0, 1);
+                       Matrix4x4_ConcatRotate(&matrix, (f / 360 - floor(f / 360)) * 360, 0, 0, 1);
                        Matrix4x4_ConcatTranslate(&matrix, -0.5, -0.5, 0);
                        break;
                case Q3TCMOD_SCALE:
@@ -7695,7 +7696,7 @@ void R_tcMod_ApplyToMatrix(matrix4x4_t *texmatrix, q3shaderinfo_layer_tcmod_t *t
                        Matrix4x4_CreateTranslate(&matrix, (idx % w) / tcmod->parms[0], (idx / w) / tcmod->parms[1], 0);
                        break;
                case Q3TCMOD_STRETCH:
-                       f = 1.0f / R_EvaluateQ3WaveFunc(tcmod->wavefunc, tcmod->waveparms);
+                       f = 1.0f / R_EvaluateQ3WaveFunc(tcmod->wavefunc, tcmod->waveparms);ClientTime
                        Matrix4x4_CreateFromQuakeEntity(&matrix, 0.5f * (1 - f), 0.5 * (1 - f), 0, 0, 0, 0, f);
                        break;
                case Q3TCMOD_TRANSFORM:
index 34334e6..e0e1e8c 100644 (file)
@@ -53,7 +53,10 @@ void R_MeshQueue_AddTransparent(const vec3_t center, void (*callback)(const enti
        mq->ent = ent;
        mq->surfacenumber = surfacenumber;
        mq->rtlight = rtlight;
-       mq->dist = DotProduct(center, r_refdef.view.forward) - mqt_viewplanedist;
+       if (ent && (ent->flags & RENDER_WORLDOBJECT))
+               mq->dist = mqt_viewmaxdist;
+       else
+               mq->dist = DotProduct(center, r_refdef.view.forward) - mqt_viewplanedist;
        mq->next = NULL;
        mqt_viewmaxdist = max(mqt_viewmaxdist, mq->dist);
 }
index c101665..50a5215 100644 (file)
@@ -332,7 +332,7 @@ void Protocol_Names(char *buffer, size_t buffersize);
 #define RENDER_EXTERIORMODEL 8
 #define RENDER_LOWPRECISION 16 // send as low precision coordinates to save bandwidth
 #define RENDER_COLORMAPPED 32
-#define RENDER_NOCULL 64 // do not cull this entity with r_cullentities
+#define RENDER_WORLDOBJECT 64 // do not cull this entity with r_cullentities
 #define RENDER_COMPLEXANIMATION 128
 
 #define RENDER_SHADOW 65536 // cast shadow
@@ -343,6 +343,7 @@ void Protocol_Names(char *buffer, size_t buffersize);
 #define RENDER_NODEPTHTEST 1048576
 #define RENDER_ADDITIVE 2097152
 #define RENDER_DOUBLESIDED 4194304
+#define RENDER_CUSTOMIZEDMODELLIGHT 4096
 
 #define MAX_FRAMEGROUPBLENDS 4
 typedef struct framegroupblend_s
index 1bd6c5e..cfcf220 100644 (file)
@@ -68,6 +68,9 @@ PRVM_DECLARE_clientfieldvector(oldorigin)
 PRVM_DECLARE_clientfieldvector(origin)
 PRVM_DECLARE_clientfieldvector(size)
 PRVM_DECLARE_clientfieldvector(velocity)
+PRVM_DECLARE_clientfieldvector(modellight_ambient)
+PRVM_DECLARE_clientfieldvector(modellight_diffuse)
+PRVM_DECLARE_clientfieldvector(modellight_dir)
 PRVM_DECLARE_clientfunction(CSQC_ConsoleCommand)
 PRVM_DECLARE_clientfunction(CSQC_Ent_Remove)
 PRVM_DECLARE_clientfunction(CSQC_Ent_Spawn)
@@ -361,6 +364,9 @@ PRVM_DECLARE_field(userwavefunc_param2)
 PRVM_DECLARE_field(userwavefunc_param3)
 PRVM_DECLARE_field(v_angle)
 PRVM_DECLARE_field(velocity)
+PRVM_DECLARE_field(modellight_ambient)
+PRVM_DECLARE_field(modellight_diffuse)
+PRVM_DECLARE_field(modellight_dir)
 PRVM_DECLARE_field(view_ofs)
 PRVM_DECLARE_field(viewmodelforclient)
 PRVM_DECLARE_field(viewzoom)
index f5d3293..30d1745 100644 (file)
@@ -21,7 +21,8 @@ const char *vm_sv_extensions =
 "DP_CON_STARTMAP "
 "DP_CRYPTO "
 "DP_CSQC_BINDMAPS "
-"DP_CSQC_ENTITYNOCULL "
+"DP_CSQC_ENTITYWORLDOBJECT "
+"DP_CSQC_ENTITYMODELLIGHT "
 "DP_CSQC_ENTITYTRANSPARENTSORTING_OFFSET "
 "DP_CSQC_MULTIFRAME_INTERPOLATION "
 "DP_CSQC_BOXPARTICLES "