From 886221c0a4822afbb9328f3a5ddeee959a1010aa Mon Sep 17 00:00:00 2001 From: vortex Date: Mon, 12 Sep 2011 16:53:12 +0000 Subject: [PATCH] Added DP_CSQC_ENTITYMODELLIGHT extension (CSQC-updated modellight using modellight_* fields). RF_NOCULL transformed to RF_WORLDOBJECT which gives maximal transparent sorting distance (and disables culling), making transparent RF_WORLDOBJECT order-dependent. This is still a hacky thing and can change in the future since whole concept of this flag is not good (it's a quick trick to solve bugs with rendering of really large sky objects). git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11344 d7cf8633-e32d-0410-b094-e92efae38249 --- csprogs.c | 19 ++++++++++++++----- csprogs.h | 5 +++-- dpdefs/csprogsdefs.qc | 18 +++++++++++++----- gl_rmain.c | 13 +++++++------ meshqueue.c | 5 ++++- protocol.h | 3 ++- prvm_offsets.h | 6 ++++++ svvm_cmds.c | 3 ++- 8 files changed, 51 insertions(+), 21 deletions(-) diff --git a/csprogs.c b/csprogs.c index 8a9bf1dd..69483ae1 100644 --- 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); diff --git a/csprogs.h b/csprogs.h index c82974b2..a5f478c1 100644 --- 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 diff --git a/dpdefs/csprogsdefs.qc b/dpdefs/csprogsdefs.qc index 2100605d..1a08e588 100644 --- a/dpdefs/csprogsdefs.qc +++ b/dpdefs/csprogsdefs.qc @@ -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 diff --git a/gl_rmain.c b/gl_rmain.c index 5da6228f..438c5e42 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -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: diff --git a/meshqueue.c b/meshqueue.c index 34334e6d..e0e1e8c7 100644 --- a/meshqueue.c +++ b/meshqueue.c @@ -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); } diff --git a/protocol.h b/protocol.h index c101665d..50a5215b 100644 --- a/protocol.h +++ b/protocol.h @@ -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 diff --git a/prvm_offsets.h b/prvm_offsets.h index 1bd6c5e1..cfcf220a 100644 --- a/prvm_offsets.h +++ b/prvm_offsets.h @@ -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) diff --git a/svvm_cmds.c b/svvm_cmds.c index f5d3293b..30d17453 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -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 " -- 2.39.2