Commit b761eb6b authored by havoc's avatar havoc Committed by Rudolf Polzer

Refactored R_UpdateEntityLighting to CL_UpdateEntityShading, which sets fields...

Refactored R_UpdateEntityLighting to CL_UpdateEntityShading, which sets fields like ent->render_modellight_ambient.

Added texture->render_modellight_ambient and similar fields which concretely define how the material is to be rendered, so all of the various tweaks and modifiers are no longer buried in R_SetupShader_Surface which has now been refactored heavily.

Removed R_LightPoint as it's really not necessary - this change will make lit particles a little bit slower as R_CompleteLightPoint is a slightly more expensive function.

Refactored R_CompleteLightPoint to have more consistent code, changed the final color math so that it passes q1bsp/q2bsp lighting through unmodified.

Changed shading of tag_entity attachments - they now use the root entity's origin for shading, this fixes r_shadows where the shadows could go in different directions on CSQC entities (r_shadows code already contained a hack to work around this problem for network entities).

Renamed r_refdef.lightmapintensity and ambient to r_refdef.scene.lightmapintensity and ambientintensity.

git-svn-id: svn://svn.icculus.org/twilight/trunk/[email protected] d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=4e1f3f76
parent cb77c846
......@@ -2406,14 +2406,14 @@ void CL_MeshEntities_Init(void)
ent->state_current.active = true;
ent->render.model = cl_meshentitymodels + i;
ent->render.alpha = 1;
ent->render.flags = RENDER_SHADOW | RENDER_LIGHT;
ent->render.flags = RENDER_SHADOW | RENDER_LIGHT | RENDER_CUSTOMIZEDMODELLIGHT;
ent->render.framegroupblend[0].lerp = 1;
ent->render.frameblend[0].lerp = 1;
VectorSet(ent->render.colormod, 1, 1, 1);
VectorSet(ent->render.glowmod, 1, 1, 1);
VectorSet(ent->render.modellight_ambient, 1, 1, 1);
VectorSet(ent->render.modellight_diffuse, 0, 0, 0);
VectorSet(ent->render.modellight_lightdir, 0, 0, 1);
VectorSet(ent->render.custommodellight_ambient, 1, 1, 1);
VectorSet(ent->render.custommodellight_diffuse, 0, 0, 0);
VectorSet(ent->render.custommodellight_lightdir, 0, 0, 1);
Matrix4x4_CreateIdentity(&ent->render.matrix);
CL_UpdateRenderEntity(&ent->render);
}
......@@ -2451,6 +2451,221 @@ void CL_MeshEntities_Shutdown(void)
{
}
extern cvar_t r_overheadsprites_pushback;
extern cvar_t r_fullbright_directed_pitch_relative;
extern cvar_t r_fullbright_directed_pitch;
extern cvar_t r_fullbright_directed_ambient;
extern cvar_t r_fullbright_directed_diffuse;
extern cvar_t r_fullbright_directed;
extern cvar_t r_equalize_entities_minambient;
extern cvar_t r_equalize_entities_to;
extern cvar_t r_equalize_entities_by;
extern cvar_t r_hdr_glowintensity;
static void CL_UpdateEntityShading_GetDirectedFullbright(vec3_t ambient, vec3_t diffuse, vec3_t worldspacenormal)
{
vec3_t angles;
VectorSet(ambient, r_fullbright_directed_ambient.value, r_fullbright_directed_ambient.value, r_fullbright_directed_ambient.value);
VectorSet(diffuse, r_fullbright_directed_diffuse.value, r_fullbright_directed_diffuse.value, r_fullbright_directed_diffuse.value);
// Use cl.viewangles and not r_refdef.view.forward here so it is the
// same for all stereo views, and to better handle pitches outside
// [-90, 90] (in_pitch_* cvars allow that).
VectorCopy(cl.viewangles, angles);
if (r_fullbright_directed_pitch_relative.integer) {
angles[PITCH] += r_fullbright_directed_pitch.value;
}
else {
angles[PITCH] = r_fullbright_directed_pitch.value;
}
AngleVectors(angles, worldspacenormal, NULL, NULL);
VectorNegate(worldspacenormal, worldspacenormal);
}
static void CL_UpdateEntityShading_Entity(entity_render_t *ent)
{
float shadingorigin[3], f, fa, fd, fdd, a[3], c[3], dir[3];
int q;
for (q = 0; q < 3; q++)
a[q] = c[q] = dir[q] = 0;
ent->render_modellight_forced = false;
ent->render_rtlight_disabled = false;
// pick an appropriate value for render_modellight_origin - if this is an
// attachment we want to use the parent's render_modellight_origin so that
// shading is the same (also important for r_shadows to cast shadows in the
// same direction)
if (VectorLength2(ent->custommodellight_origin))
{
// CSQC entities always provide this (via CL_GetTagMatrix)
for (q = 0; q < 3; q++)
shadingorigin[q] = ent->custommodellight_origin[q];
}
else if (ent->entitynumber > 0 && ent->entitynumber < cl.num_entities)
{
// network entity - follow attachment chain back to a root entity,
int entnum = ent->entitynumber, recursion;
for (recursion = 32; recursion > 0; --recursion)
{
int parentnum = cl.entities[entnum].state_current.tagentity;
if (parentnum < 1 || parentnum >= cl.num_entities || !cl.entities_active[parentnum])
break;
entnum = parentnum;
}
// grab the root entity's origin
Matrix4x4_OriginFromMatrix(&cl.entities[entnum].render.matrix, shadingorigin);
}
else
{
// not a CSQC entity (which sets custommodellight_origin), not a network
// entity - so it's probably not attached to anything
Matrix4x4_OriginFromMatrix(&ent->matrix, shadingorigin);
}
if (!(ent->flags & RENDER_LIGHT) || r_fullbright.integer)
{
// intentionally EF_FULLBRIGHT entity
// the only type that is not scaled by r_refdef.scene.lightmapintensity
// CSQC can still provide its own customized modellight values
ent->render_rtlight_disabled = true;
ent->render_modellight_forced = true;
if (ent->flags & RENDER_CUSTOMIZEDMODELLIGHT)
{
// custom colors provided by CSQC
for (q = 0; q < 3; q++)
{
a[q] = ent->custommodellight_ambient[q];
c[q] = ent->custommodellight_diffuse[q];
dir[q] = ent->custommodellight_lightdir[q];
}
}
else if (r_fullbright_directed.integer)
CL_UpdateEntityShading_GetDirectedFullbright(a, c, dir);
else
for (q = 0; q < 3; q++)
a[q] = 1;
}
else
{
// fetch the lighting from the worldmodel data
// CSQC can provide its own customized modellight values
if (ent->flags & RENDER_CUSTOMIZEDMODELLIGHT)
{
ent->render_modellight_forced = true;
for (q = 0; q < 3; q++)
{
a[q] = ent->custommodellight_ambient[q];
c[q] = ent->custommodellight_diffuse[q];
dir[q] = ent->custommodellight_lightdir[q];
}
}
else if (ent->model->type == mod_sprite && !(ent->model->data_textures[0].basematerialflags & MATERIALFLAG_FULLBRIGHT))
{
if (ent->model->sprite.sprnum_type == SPR_OVERHEAD) // apply offset for overhead sprites
shadingorigin[2] = shadingorigin[2] + r_overheadsprites_pushback.value;
R_CompleteLightPoint(a, c, dir, shadingorigin, LP_LIGHTMAP | LP_RTWORLD | LP_DYNLIGHT, r_refdef.scene.lightmapintensity, r_refdef.scene.ambientintensity);
ent->render_modellight_forced = true;
ent->render_rtlight_disabled = true;
}
else if (r_refdef.scene.worldmodel && r_refdef.scene.worldmodel->lit && r_refdef.scene.worldmodel->brush.LightPoint)
R_CompleteLightPoint(a, c, dir, shadingorigin, LP_LIGHTMAP, r_refdef.scene.lightmapintensity, r_refdef.scene.ambientintensity);
else if (r_fullbright_directed.integer)
CL_UpdateEntityShading_GetDirectedFullbright(a, c, dir);
else
R_CompleteLightPoint(a, c, dir, shadingorigin, LP_LIGHTMAP, r_refdef.scene.lightmapintensity, r_refdef.scene.ambientintensity);
if (ent->flags & RENDER_EQUALIZE)
{
// first fix up ambient lighting...
if (r_equalize_entities_minambient.value > 0)
{
fd = 0.299f * ent->render_modellight_diffuse[0] + 0.587f * ent->render_modellight_diffuse[1] + 0.114f * ent->render_modellight_diffuse[2];
if (fd > 0)
{
fa = (0.299f * ent->render_modellight_ambient[0] + 0.587f * ent->render_modellight_ambient[1] + 0.114f * ent->render_modellight_ambient[2]);
if (fa < r_equalize_entities_minambient.value * fd)
{
// solve:
// fa'/fd' = minambient
// fa'+0.25*fd' = fa+0.25*fd
// ...
// fa' = fd' * minambient
// fd'*(0.25+minambient) = fa+0.25*fd
// ...
// fd' = (fa+0.25*fd) * 1 / (0.25+minambient)
// fa' = (fa+0.25*fd) * minambient / (0.25+minambient)
// ...
fdd = (fa + 0.25f * fd) / (0.25f + r_equalize_entities_minambient.value);
f = fdd / fd; // f>0 because all this is additive; f<1 because fdd<fd because this follows from fa < r_equalize_entities_minambient.value * fd
for (q = 0; q < 3; q++)
{
a[q] = (1 - f)*0.25f * c[q];
c[q] *= f;
}
}
}
}
if (r_equalize_entities_to.value > 0 && r_equalize_entities_by.value != 0)
{
fa = 0.299f * a[0] + 0.587f * a[1] + 0.114f * a[2];
fd = 0.299f * c[0] + 0.587f * c[1] + 0.114f * c[2];
f = fa + 0.25 * fd;
if (f > 0)
{
// adjust brightness and saturation to target
float l2 = r_equalize_entities_by.value, l1 = 1 - l2;
for (q = 0; q < 3; q++)
{
a[q] = l1 * a[q] + l2 * (fa / f);
c[q] = l1 * c[q] + l2 * (fd / f);
}
}
}
}
}
for (q = 0; q < 3; q++)
{
ent->render_fullbright[q] = ent->colormod[q];
ent->render_glowmod[q] = ent->glowmod[q] * r_hdr_glowintensity.value;
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_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;
ent->render_rtlight_diffuse[q] = ent->colormod[q];
ent->render_rtlight_specular[q] = 1;
}
// these flags disable code paths, make sure it's obvious if they're ignored by storing 0 1 2
if (ent->render_modellight_forced)
for (q = 0; q < 3; q++)
ent->render_lightmap_ambient[q] = ent->render_lightmap_diffuse[q] = ent->render_lightmap_specular[q] = q;
if (ent->render_rtlight_disabled)
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);
}
void CL_UpdateEntityShading(void)
{
int i;
CL_UpdateEntityShading_Entity(r_refdef.scene.worldentity);
for (i = 0; i < r_refdef.scene.numentities; i++)
CL_UpdateEntityShading_Entity(r_refdef.scene.entities[i]);
}
/*
===========
CL_Shutdown
......
......@@ -2723,10 +2723,14 @@ static void R_DrawParticle_TransparentCallback(const entity_render_t *ent, const
// note: lighting is not cheap!
if (particletype[p->typeindex].lighting)
{
float a[3], c[3], dir[3];
vecorg[0] = p->org[0];
vecorg[1] = p->org[1];
vecorg[2] = p->org[2];
R_LightPoint(c4f, vecorg, LP_LIGHTMAP | LP_RTWORLD | LP_DYNLIGHT);
R_CompleteLightPoint(a, c, dir, vecorg, LP_LIGHTMAP | LP_RTWORLD | LP_DYNLIGHT, r_refdef.scene.lightmapintensity, r_refdef.scene.ambientintensity);
c4f[0] = p->color[0] * colormultiplier[0] * (a[0] + 0.25f * c[0]);
c4f[1] = p->color[1] * colormultiplier[1] * (a[1] + 0.25f * c[1]);
c4f[2] = p->color[2] * colormultiplier[2] * (a[2] + 0.25f * c[2]);
}
// mix in the fog color
if (r_refdef.fogenabled)
......
......@@ -1894,6 +1894,7 @@ static void R_Envmap_f (void)
buffer1 = (unsigned char *)Mem_Alloc(tempmempool, size * size * 4);
buffer2 = (unsigned char *)Mem_Alloc(tempmempool, size * size * 3);
CL_UpdateEntityShading();
for (j = 0;j < 12;j++)
{
dpsnprintf(filename, sizeof(filename), "env/%s%s.tga", basename, envmapinfo[j].name);
......@@ -2186,7 +2187,10 @@ static void SCR_DrawScreen (void)
if (cl.csqc_loaded)
CL_VM_UpdateView(r_stereo_side ? 0.0 : max(0.0, cl.time - cl.oldtime));
else
{
CL_UpdateEntityShading();
R_RenderView();
}
}
if (!r_stereo_sidebyside.integer && !r_stereo_horizontal.integer && !r_stereo_vertical.integer)
......
......@@ -573,10 +573,37 @@ typedef struct entity_render_s
int animcache_skeletaltransform3x4offset;
int animcache_skeletaltransform3x4size;
// current lighting from map (updated ONLY by client code, not renderer)
vec3_t modellight_ambient;
vec3_t modellight_diffuse; // q3bsp
vec3_t modellight_lightdir; // q3bsp
// CL_UpdateEntityShading reads these fields
// used only if RENDER_CUSTOMIZEDMODELLIGHT is set
vec3_t custommodellight_ambient;
vec3_t custommodellight_diffuse;
vec3_t custommodellight_lightdir;
// CSQC entities get their shading from the root of their attachment chain
float custommodellight_origin[3];
// derived lighting parameters (CL_UpdateEntityShading)
// used by MATERIALFLAG_FULLBRIGHT which is MATERIALFLAG_MODELLIGHT with
// this as ambient color, along with MATERIALFLAG_NORTLIGHT
float render_fullbright[3];
// color tint for the base pass glow textures if any
float render_glowmod[3];
// MATERIALFLAG_MODELLIGHT uses these parameters
float render_modellight_ambient[3];
float render_modellight_diffuse[3];
float render_modellight_lightdir[3];
float render_modellight_specular[3];
// lightmap rendering (not MATERIALFLAG_MODELLIGHT)
float render_lightmap_ambient[3];
float render_lightmap_diffuse[3];
float render_lightmap_specular[3];
// rtlights use these colors for the materials on this entity
float render_rtlight_diffuse[3];
float render_rtlight_specular[3];
// ignore lightmap and use lightgrid on this entity (e.g. FULLBRIGHT)
qboolean render_modellight_forced;
// do not process per pixel lights on this entity at all (like MATERIALFLAG_NORTLIGHT)
qboolean render_rtlight_disabled;
// storage of decals on this entity
// (note: if allowdecals is set, be sure to call R_DecalSystem_Reset on removal!)
......@@ -1886,7 +1913,12 @@ typedef struct r_refdef_scene_s {
// controls intensity lightmap layers
unsigned short lightstylevalue[MAX_LIGHTSTYLES]; // 8.8 fraction of base light value
float ambient;
// adds brightness to the whole scene, separate from lightmapintensity
// see CL_UpdateEntityShading
float ambientintensity;
// brightness of lightmap and modellight lighting on materials
// see CL_UpdateEntityShading
float lightmapintensity;
qboolean rtworld;
qboolean rtworldshadows;
......@@ -1956,9 +1988,6 @@ typedef struct r_refdef_s
// true during envmap command capture
qboolean envmap;
// brightness of world lightmaps and related lighting
// (often reduced when world rtlights are enabled)
float lightmapintensity;
// whether to draw world lights realtime, dlights realtime, and their shadows
float polygonfactor;
float polygonoffset;
......@@ -2032,6 +2061,7 @@ extern const char *cl_meshentitynames[NUM_MESHENTITIES];
#define CL_Mesh_UI() (&cl_meshentitymodels[MESH_UI])
void CL_MeshEntities_AddToScene(void);
void CL_MeshEntities_Reset(void);
void CL_UpdateEntityShading(void);
void CL_NewFrameReceived(int num);
void CL_ParseEntityLump(char *entitystring);
......
......@@ -696,17 +696,12 @@ static void VM_CL_getlight (prvm_prog_t *prog)
{
vec3_t ambientcolor, diffusecolor, diffusenormal;
vec3_t p;
int flags = prog->argc >= 2 ? PRVM_G_FLOAT(OFS_PARM1) : LP_LIGHTMAP;
VM_SAFEPARMCOUNTRANGE(1, 3, VM_CL_getlight);
VectorCopy(PRVM_G_VECTOR(OFS_PARM0), p);
VectorClear(ambientcolor);
VectorClear(diffusecolor);
VectorClear(diffusenormal);
if (prog->argc >= 2)
R_CompleteLightPoint(ambientcolor, diffusecolor, diffusenormal, p, PRVM_G_FLOAT(OFS_PARM1));
else if (cl.worldmodel && cl.worldmodel->brush.LightPoint)
cl.worldmodel->brush.LightPoint(cl.worldmodel, p, ambientcolor, diffusecolor, diffusenormal);
R_CompleteLightPoint(ambientcolor, diffusecolor, diffusenormal, p, flags, r_refdef.scene.lightmapintensity, r_refdef.scene.ambientintensity);
VectorMA(ambientcolor, 0.5, diffusecolor, PRVM_G_VECTOR(OFS_RETURN));
if (PRVM_clientglobalvector(getlight_ambient))
VectorCopy(ambientcolor, PRVM_clientglobalvector(getlight_ambient));
......@@ -2453,7 +2448,7 @@ static int CL_GetEntityLocalTagMatrix(prvm_prog_t *prog, prvm_edict_t *ent, int
extern cvar_t cl_bob;
extern cvar_t cl_bobcycle;
extern cvar_t cl_bobup;
int CL_GetTagMatrix (prvm_prog_t *prog, matrix4x4_t *out, prvm_edict_t *ent, int tagindex)
int CL_GetTagMatrix (prvm_prog_t *prog, matrix4x4_t *out, prvm_edict_t *ent, int tagindex, prvm_vec_t *shadingorigin)
{
int ret;
int attachloop;
......@@ -2526,6 +2521,16 @@ int CL_GetTagMatrix (prvm_prog_t *prog, matrix4x4_t *out, prvm_edict_t *ent, int
Matrix4x4_AdjustOrigin(out, 0, 0, bound(-7, bob, 4));
}
*/
// return the origin of the view
if (shadingorigin)
Matrix4x4_OriginFromMatrix(&r_refdef.view.matrix, shadingorigin);
}
else
{
// return the origin of the root entity in the chain
if (shadingorigin)
Matrix4x4_OriginFromMatrix(out, shadingorigin);
}
return 0;
}
......@@ -2582,7 +2587,7 @@ static void VM_CL_gettaginfo (prvm_prog_t *prog)
e = PRVM_G_EDICT(OFS_PARM0);
tagindex = (int)PRVM_G_FLOAT(OFS_PARM1);
returncode = CL_GetTagMatrix(prog, &tag_matrix, e, tagindex);
returncode = CL_GetTagMatrix(prog, &tag_matrix, e, tagindex, NULL);
Matrix4x4_ToVectors(&tag_matrix, forward, left, up, origin);
VectorCopy(forward, PRVM_clientglobalvector(v_forward));
VectorScale(left, -1, PRVM_clientglobalvector(v_right));
......@@ -3230,7 +3235,7 @@ static void VM_CL_GetEntity (prvm_prog_t *prog)
VectorAdd(cl.entities[entnum].render.maxs, org, PRVM_G_VECTOR(OFS_RETURN));
break;
case 16: // light
VectorMA(cl.entities[entnum].render.modellight_ambient, 0.5, cl.entities[entnum].render.modellight_diffuse, PRVM_G_VECTOR(OFS_RETURN));
VectorMA(cl.entities[entnum].render.render_modellight_ambient, 0.5, cl.entities[entnum].render.render_modellight_diffuse, PRVM_G_VECTOR(OFS_RETURN));
break;
default:
PRVM_G_FLOAT(OFS_RETURN) = 0;
......@@ -3266,6 +3271,7 @@ static void VM_CL_R_RenderScene (prvm_prog_t *prog)
// we need to update any RENDER_VIEWMODEL entities at this point because
// csqc supplies its own view matrix
CL_UpdateViewEntities();
CL_UpdateEntityShading();
// now draw stuff!
R_RenderView();
......@@ -4250,7 +4256,7 @@ static void VM_CL_V_CalcRefdef(prvm_prog_t *prog)
flags = PRVM_G_FLOAT(OFS_PARM1);
// use the CL_GetTagMatrix function on self to ensure consistent behavior (duplicate code would be bad)
CL_GetTagMatrix(prog, &entrendermatrix, ent, 0);
CL_GetTagMatrix(prog, &entrendermatrix, ent, 0, NULL);
VectorCopy(cl.csqc_viewangles, clviewangles);
teleported = (flags & REFDEFFLAG_TELEPORTED) != 0;
......
......@@ -346,8 +346,9 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed, int edictnum)
if (!VectorLength2(entrender->glowmod))
VectorSet(entrender->glowmod, 1, 1, 1);
// LordHavoc: use the CL_GetTagMatrix function on self to ensure consistent behavior (duplicate code would be bad)
CL_GetTagMatrix(prog, &entrender->matrix, ed, 0);
// LadyHavoc: use the CL_GetTagMatrix function on self to ensure consistent behavior (duplicate code would be bad)
// this also sets the custommodellight_origin for us
CL_GetTagMatrix(prog, &entrender->matrix, ed, 0, entrender->custommodellight_origin);
// set up the animation data
VM_GenerateFrameGroupBlend(prog, ed->priv.server->framegroupblend, ed);
......@@ -363,9 +364,9 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed, int edictnum)
// model light
if (renderflags & RF_MODELLIGHT)
{
if (PRVM_clientedictvector(ed, modellight_ambient)) VectorCopy(PRVM_clientedictvector(ed, modellight_ambient), entrender->modellight_ambient); else VectorClear(entrender->modellight_ambient);
if (PRVM_clientedictvector(ed, modellight_diffuse)) VectorCopy(PRVM_clientedictvector(ed, modellight_diffuse), entrender->modellight_diffuse); else VectorClear(entrender->modellight_diffuse);
if (PRVM_clientedictvector(ed, modellight_dir)) VectorCopy(PRVM_clientedictvector(ed, modellight_dir), entrender->modellight_lightdir); else VectorClear(entrender->modellight_lightdir);
if (PRVM_clientedictvector(ed, modellight_ambient)) VectorCopy(PRVM_clientedictvector(ed, modellight_ambient), entrender->custommodellight_ambient); else VectorClear(entrender->custommodellight_ambient);
if (PRVM_clientedictvector(ed, modellight_diffuse)) VectorCopy(PRVM_clientedictvector(ed, modellight_diffuse), entrender->custommodellight_diffuse); else VectorClear(entrender->custommodellight_diffuse);
if (PRVM_clientedictvector(ed, modellight_dir)) VectorCopy(PRVM_clientedictvector(ed, modellight_dir), entrender->custommodellight_lightdir); else VectorClear(entrender->custommodellight_lightdir);
entrender->flags |= RENDER_CUSTOMIZEDMODELLIGHT;
}
......@@ -1189,15 +1190,13 @@ qboolean CL_VM_GetEntitySoundOrigin(int entnum, vec3_t out)
CSQC_BEGIN;
// FIXME consider attachments here!
ed = PRVM_EDICT_NUM(entnum - MAX_EDICTS);
if(!ed->priv.required->free)
{
mod = CL_GetModelFromEdict(ed);
VectorCopy(PRVM_clientedictvector(ed, origin), out);
if(CL_GetTagMatrix(prog, &matrix, ed, 0) == 0)
if(CL_GetTagMatrix(prog, &matrix, ed, 0, NULL) == 0)
Matrix4x4_OriginFromMatrix(&matrix, out);
if (mod && mod->soundfromcenter)
VectorMAMAM(1.0f, out, 0.5f, mod->normalmins, 0.5f, mod->normalmaxs, out);
......
......@@ -98,7 +98,7 @@ qboolean CL_VM_Parse_TempEntity(void);
void CL_VM_Parse_StuffCmd(const char *msg);
void CL_VM_Parse_CenterPrint(const char *msg);
int CL_GetPitchSign(prvm_prog_t *prog, prvm_edict_t *ent);
int CL_GetTagMatrix(prvm_prog_t *prog, matrix4x4_t *out, prvm_edict_t *ent, int tagindex);
int CL_GetTagMatrix(prvm_prog_t *prog, matrix4x4_t *out, prvm_edict_t *ent, int tagindex, prvm_vec_t *shadingorigin);
void CL_GetEntityMatrix(prvm_prog_t *prog, prvm_edict_t *ent, matrix4x4_t *out, qboolean viewmatrix);
/* VMs exposing the polygon calls must call this on Init/Reset */
void VM_Polygons_Reset(prvm_prog_t *prog);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -583,10 +583,7 @@ void R_Q1BSP_DrawSky(entity_render_t *ent)
{
if (ent->model == NULL)
return;
if (ent == r_refdef.scene.worldentity)
R_DrawWorldSurfaces(true, true, false, false, false);
else
R_DrawModelSurfaces(ent, true, true, false, false, false);
R_DrawModelSurfaces(ent, true, true, false, false, false);
}
void R_Q1BSP_DrawAddWaterPlanes(entity_render_t *ent)
......@@ -597,10 +594,7 @@ void R_Q1BSP_DrawAddWaterPlanes(entity_render_t *ent)
if (model == NULL)
return;
if (ent == r_refdef.scene.worldentity)
RSurf_ActiveWorldEntity();
else
RSurf_ActiveModelEntity(ent, true, false, false);
RSurf_ActiveModelEntity(ent, true, false, false);
surfaces = model->data_surfaces;
flagsmask = MATERIALFLAG_WATERSHADER | MATERIALFLAG_REFRACTION | MATERIALFLAG_REFLECTION | MATERIALFLAG_CAMERA;
......@@ -629,7 +623,7 @@ void R_Q1BSP_DrawAddWaterPlanes(entity_render_t *ent)
R_Water_AddWaterPlane(surfaces + j, n);
}
}
rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveWorldEntity/RSurf_ActiveModelEntity
rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveModelEntity
}
void R_Q1BSP_Draw(entity_render_t *ent)
......@@ -637,10 +631,7 @@ void R_Q1BSP_Draw(entity_render_t *ent)
dp_model_t *model = ent->model;
if (model == NULL)
return;
if (ent == r_refdef.scene.worldentity)
R_DrawWorldSurfaces(false, true, false, false, false);
else
R_DrawModelSurfaces(ent, false, true, false, false, false);
R_DrawModelSurfaces(ent, false, true, false, false, false);
}
void R_Q1BSP_DrawDepth(entity_render_t *ent)
......@@ -654,10 +645,7 @@ void R_Q1BSP_DrawDepth(entity_render_t *ent)
GL_BlendFunc(GL_ONE, GL_ZERO);
GL_DepthMask(true);
// R_Mesh_ResetTextureState();
if (ent == r_refdef.scene.worldentity)
R_DrawWorldSurfaces(false, false, true, false, false);
else
R_DrawModelSurfaces(ent, false, false, true, false, false);
R_DrawModelSurfaces(ent, false, false, true, false, false);
GL_ColorMask(r_refdef.view.colormask[0], r_refdef.view.colormask[1], r_refdef.view.colormask[2], 1);
}
......@@ -665,10 +653,7 @@ void R_Q1BSP_DrawDebug(entity_render_t *ent)
{
if (ent->model == NULL)
return;
if (ent == r_refdef.scene.worldentity)
R_DrawWorldSurfaces(false, false, false, true, false);
else
R_DrawModelSurfaces(ent, false, false, false, true, false);
R_DrawModelSurfaces(ent, false, false, false, true, false);
}
void R_Q1BSP_DrawPrepass(entity_render_t *ent)
......@@ -676,10 +661,7 @@ void R_Q1BSP_DrawPrepass(entity_render_t *ent)
dp_model_t *model = ent->model;
if (model == NULL)
return;
if (ent == r_refdef.scene.worldentity)
R_DrawWorldSurfaces(false, true, false, false, true);
else
R_DrawModelSurfaces(ent, false, true, false, false, true);
R_DrawModelSurfaces(ent, false, true, false, false, true);
}
typedef struct r_q1bsp_getlightinfo_s
......@@ -1257,7 +1239,7 @@ void R_Q1BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, floa
info.pvs = info.model->brush.GetPVS(info.model, info.relativelightorigin);
else
info.pvs = NULL;
RSurf_ActiveWorldEntity();
RSurf_ActiveModelEntity(r_refdef.scene.worldentity, false, false, false);
if (!info.noocclusion && r_shadow_compilingrtlight && r_shadow_realtime_world_compileportalculling.integer && info.model->brush.data_portals)
{
......@@ -1278,7 +1260,7 @@ void R_Q1BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, floa
R_Q1BSP_CallRecursiveGetLightInfo(&info, !info.noocclusion && (r_shadow_compilingrtlight ? r_shadow_realtime_world_compilesvbsp.integer : r_shadow_realtime_dlight_svbspculling.integer) != 0);
}
rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveWorldEntity/RSurf_ActiveModelEntity
rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveModelEntity
// limit combined leaf box to light boundaries
outmins[0] = max(info.outmins[0] - 1, info.lightmins[0]);
......@@ -1518,7 +1500,7 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, int numsurfaces, const int *surface
;
// now figure out what to do with this particular range of surfaces
// VorteX: added MATERIALFLAG_NORTLIGHT
if ((rsurface.texture->currentmaterialflags & (MATERIALFLAG_WALL | MATERIALFLAG_FULLBRIGHT | MATERIALFLAG_NORTLIGHT)) != MATERIALFLAG_WALL)
if ((rsurface.texture->currentmaterialflags & (MATERIALFLAG_WALL | MATERIALFLAG_NORTLIGHT)) != MATERIALFLAG_WALL)
continue;
if (r_fb.water.renderingscene && (rsurface.texture->currentmaterialflags & (MATERIALFLAG_WATERSHADER | MATERIALFLAG_REFRACTION | MATERIALFLAG_REFLECTION | MATERIALFLAG_CAMERA)))
continue;
......
......@@ -115,15 +115,13 @@ mplane_t;
#define MATERIALFLAG_REFLECTION 0x00100000
// use model lighting on this material (q1bsp lightmap sampling or q3bsp lightgrid, implies FULLBRIGHT is false)
#define MATERIALFLAG_MODELLIGHT 0x00200000
// add directional model lighting to this material (q3bsp lightgrid only)
#define MATERIALFLAG_MODELLIGHT_DIRECTIONAL 0x00400000
// causes RSurf_GetCurrentTexture to leave alone certain fields
#define MATERIALFLAG_CUSTOMSURFACE 0x00800000
// causes MATERIALFLAG_BLENDED to render a depth pass before rendering, hiding backfaces and other hidden geometry
#define MATERIALFLAG_TRANSDEPTH 0x01000000
// like refraction, but doesn't distort etc.
#define MATERIALFLAG_CAMERA 0x02000000
// disable rtlight on surface, use R_LightPoint instead
// disable rtlight on surface - does not disable other types of lighting (LIGHTMAP, MODELLIGHT)
#define MATERIALFLAG_NORTLIGHT 0x04000000
// alphagen vertex
#define MATERIALFLAG_ALPHAGEN_VERTEX 0x08000000
......
......@@ -614,14 +614,29 @@ typedef struct texture_s
rtexture_t *backgroundnmaptexture; // normalmap (bumpmap for dot3)
rtexture_t *backgroundglosstexture; // glossmap (for dot3)
rtexture_t *backgroundglowtexture; // glow only (fullbrights)
float specularscale;
float specularpower;
// color tint (colormod * currentalpha) used for rtlighting this material
float dlightcolor[3];
// color tint (colormod * 2) used for lightmapped lighting on this material
// includes alpha as 4th component
// replaces role of gl_Color in GLSL shader
float lightmapcolor[4];
// rendering parameters - updated by R_GetCurrentTexture using rsurface.render_* fields
// (almost) all map textures are lightmap (no MATERIALFLAG_MODELLIGHT set),
// (almost) all model textures are MATERIALFLAG_MODELLIGHT,
// MATERIALFLAG_FULLBRIGHT is rendered as a forced MATERIALFLAG_MODELLIGHT with rtlights disabled
float render_glowmod[3];
// MATERIALFLAG_MODELLIGHT uses these parameters
float render_modellight_ambient[3];
float render_modellight_diffuse[3];
float render_modellight_lightdir[3];
float render_modellight_specular[3];
// lightmap rendering (not MATERIALFLAG_MODELLIGHT)
float render_lightmap_ambient[3];
float render_lightmap_diffuse[3];
float render_lightmap_specular[3];
// rtlights use these colors for the materials on this entity
float render_rtlight_diffuse[3];
float render_rtlight_specular[3];
// tint applied on top of render_*_diffuse for pants layer
float render_colormap_pants[3];
// tint applied on top of render_*_diffuse for shirt layer
float render_colormap_shirt[3];
// from q3 shaders
int customblendfunc[2];
......
......@@ -1624,7 +1624,8 @@ void MVM_init_cmd(prvm_prog_t *prog)
scene->maxentities = MAX_EDICTS + 256 + 512;
scene->entities = (entity_render_t **)Mem_Alloc(prog->progs_mempool, sizeof(entity_render_t *) * scene->maxentities);
scene->ambient = 32.0f;
// LadyHavoc: what is this for?
scene->ambientintensity = 32.0f;
}
void MVM_reset_cmd(prvm_prog_t *prog)
......
This diff is collapsed.
......@@ -159,8 +159,7 @@ void R_Shadow_PrepareModelShadows(void);
#define LP_LIGHTMAP 1
#define LP_RTWORLD 2
#define LP_DYNLIGHT 4
void R_LightPoint(float *color, const vec3_t p, const int flags);
void R_CompleteLightPoint(float *ambientcolor, float *diffusecolor, float *diffusenormal, const vec3_t p, const int flags);
void R_CompleteLightPoint(float *ambient, float *diffuse, float *lightdir, const vec3_t p, const int flags, float lightmapintensity, float ambientintensity);
void R_Shadow_DrawShadowMaps(void);
void R_Shadow_DrawModelShadows(void);
......
......@@ -392,9 +392,15 @@ static void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent,
frame = model->sprite.sprdata_frames + ent->frameblend[i].subframe;
texture = R_GetCurrentTexture(model->data_textures + ent->frameblend[i].subframe);
// lit sprite by lightgrid if it is not fullbright, lit only ambient
// sprites are fullbright by default, but if this one is not fullbright we
// need to combine the lighting into ambient as sprite lighting is not
// directional
if (!(texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT))
VectorAdd(ent->modellight_ambient, ent->modellight_diffuse, rsurface.modellight_ambient); // sprites dont use lightdirection
{
VectorMAM(1.0f, texture->render_modellight_ambient, 0.25f, texture->render_modellight_diffuse, texture->render_modellight_ambient);
VectorClear(texture->render_modellight_diffuse);
VectorClear(texture->render_modellight_specular);
}
// SPR_LABEL should not use depth test AT ALL
if(model->sprite.sprnum_type == SPR_LABEL || model->sprite.sprnum_type == SPR_LABEL_SCALE)
......
......@@ -127,7 +127,7 @@ extern cvar_t r_wateralpha;
extern cvar_t r_dynamic;
void R_UpdateVariables(void); // must call after setting up most of r_refdef, but before calling R_RenderView
void R_RenderView(void); // must set r_refdef and call R_UpdateVariables first
void R_RenderView(void); // must set r_refdef and call R_UpdateVariables and CL_UpdateEntityShading first
void R_RenderView_UpdateViewVectors(void); // just updates r_refdef.view.{forward,left,up,origin,right,inverse_matrix}
typedef enum r_refdef_scene_type_s {
......@@ -404,18 +404,6 @@ typedef struct rsurfacestate_s
// animation blending state from entity