cvar_t r_deformvertexes = {0, "r_deformvertexes", "1", "allows use of deformvertexes in shader files (can be turned off to check performance impact)"};
cvar_t r_transparent = {0, "r_transparent", "1", "allows use of transparent surfaces (can be turned off to check performance impact)"};
cvar_t r_transparent_alphatocoverage = {0, "r_transparent_alphatocoverage", "1", "enables GL_ALPHA_TO_COVERAGE antialiasing technique on alphablend and alphatest surfaces when using vid_samples 2 or higher"};
+cvar_t r_transparent_sortsurfacesbynearest = {0, "r_transparent_sortsurfacesbynearest", "1", "sort entity and world surfaces by nearest point on bounding box instead of using the center of the bounding box, usually reduces sorting artifacts"};
+cvar_t r_transparent_useplanardistance = {0, "r_transparent_useplanardistance", "0", "sort transparent meshes by distance from view plane rather than spherical distance to the chosen point"};
cvar_t r_showoverdraw = {0, "r_showoverdraw", "0", "shows overlapping geometry"};
cvar_t r_showbboxes = {0, "r_showbboxes", "0", "shows bounding boxes of server entities, value controls opacity scaling (1 = 10%, 10 = 100%)"};
cvar_t r_showsurfaces = {0, "r_showsurfaces", "0", "1 shows surfaces as different colors, or a value of 2 shows triangle draw order (for analyzing whether meshes are optimized for vertex cache)"};
static cvar_t gl_combine = {CVAR_READONLY, "gl_combine", "1", "indicates whether the OpenGL 1.3 rendering path is active"};
static cvar_t r_glsl = {CVAR_READONLY, "r_glsl", "1", "indicates whether the OpenGL 2.0 rendering path is active"};
-cvar_t r_usedepthtextures = {CVAR_SAVE, "r_usedepthtextures", "0", "use depth texture instead of depth renderbuffer where possible, may not be slower on some hardware"};
+cvar_t r_usedepthtextures = {CVAR_SAVE, "r_usedepthtextures", "1", "use depth texture instead of depth renderbuffer where possible, uses less video memory but may render slower (or faster) depending on hardware"};
cvar_t r_viewfbo = {CVAR_SAVE, "r_viewfbo", "0", "enables use of an 8bit (1) or 16bit (2) or 32bit (3) per component float framebuffer render, which may be at a different resolution than the video mode"};
cvar_t r_viewscale = {CVAR_SAVE, "r_viewscale", "1", "scaling factor for resolution of the fbo rendering method, must be > 0, can be above 1 for a costly antialiasing behavior, typical values are 0.5 for 1/4th as many pixels rendered, or 1 for normal rendering"};
cvar_t r_viewscale_fpsscaling = {CVAR_SAVE, "r_viewscale_fpsscaling", "0", "change resolution based on framerate"};
{"#define USEOFFSETMAPPING\n", " offsetmapping"},
{"#define USEOFFSETMAPPING_RELIEFMAPPING\n", " reliefmapping"},
{"#define USESHADOWMAP2D\n", " shadowmap2d"},
- {"#define USESHADOWMAPPCF 1\n", " shadowmappcf"}, // TODO make this a static parm
- {"#define USESHADOWMAPPCF 2\n", " shadowmappcf2"}, // TODO make this a static parm
- {"#define USESHADOWSAMPLER\n", " shadowsampler"}, // TODO make this a static parm
{"#define USESHADOWMAPVSDCT\n", " shadowmapvsdct"}, // TODO make this a static parm
{"#define USESHADOWMAPORTHO\n", " shadowmaportho"},
{"#define USEDEFERREDLIGHTMAP\n", " deferredlightmap"},
{"#define USEBOUNCEGRIDDIRECTIONAL\n", " bouncegriddirectional"}, // TODO make this a static parm
{"#define USETRIPPY\n", " trippy"},
{"#define USEDEPTHRGB\n", " depthrgb"},
+ {"#define USEALPHAGENVERTEX\n", "alphagenvertex"}
};
// NOTE: MUST MATCH ORDER OF SHADERMODE_* ENUMS!
SHADERSTATICPARM_POSTPROCESS_USERVEC4 = 5, ///< postprocess uservec4 is enabled
SHADERSTATICPARM_VERTEXTEXTUREBLEND_USEBOTHALPHAS = 6, // use both alpha layers while blending materials, allows more advanced microblending
SHADERSTATICPARM_OFFSETMAPPING_USELOD = 7, ///< LOD for offsetmapping
+ SHADERSTATICPARM_SHADOWMAPPCF_1 = 8, ///< PCF 1
+ SHADERSTATICPARM_SHADOWMAPPCF_2 = 9, ///< PCF 2
+ SHADERSTATICPARM_SHADOWSAMPLER = 10, ///< sampler
};
-#define SHADERSTATICPARMS_COUNT 8
+#define SHADERSTATICPARMS_COUNT 11
static const char *shaderstaticparmstrings_list[SHADERSTATICPARMS_COUNT];
static int shaderstaticparms_count = 0;
static unsigned int r_compileshader_staticparms[(SHADERSTATICPARMS_COUNT + 0x1F) >> 5] = {0};
#define R_COMPILESHADER_STATICPARM_ENABLE(p) r_compileshader_staticparms[(p) >> 5] |= (1 << ((p) & 0x1F))
-static qboolean R_CompileShader_CheckStaticParms(void)
+
+extern qboolean r_shadow_shadowmapsampler;
+extern int r_shadow_shadowmappcf;
+qboolean R_CompileShader_CheckStaticParms(void)
{
static int r_compileshader_staticparms_save[1];
memcpy(r_compileshader_staticparms_save, r_compileshader_staticparms, sizeof(r_compileshader_staticparms));
}
if (r_glsl_offsetmapping_lod.integer && r_glsl_offsetmapping_lod_distance.integer > 0)
R_COMPILESHADER_STATICPARM_ENABLE(SHADERSTATICPARM_OFFSETMAPPING_USELOD);
+
+ if (r_shadow_shadowmapsampler)
+ R_COMPILESHADER_STATICPARM_ENABLE(SHADERSTATICPARM_SHADOWSAMPLER);
+ if (r_shadow_shadowmappcf > 1)
+ R_COMPILESHADER_STATICPARM_ENABLE(SHADERSTATICPARM_SHADOWMAPPCF_2);
+ else if (r_shadow_shadowmappcf)
+ R_COMPILESHADER_STATICPARM_ENABLE(SHADERSTATICPARM_SHADOWMAPPCF_1);
+
return memcmp(r_compileshader_staticparms, r_compileshader_staticparms_save, sizeof(r_compileshader_staticparms)) != 0;
}
R_COMPILESHADER_STATICPARM_EMIT(SHADERSTATICPARM_POSTPROCESS_USERVEC4, "USERVEC4");
R_COMPILESHADER_STATICPARM_EMIT(SHADERSTATICPARM_VERTEXTEXTUREBLEND_USEBOTHALPHAS, "USEBOTHALPHAS");
R_COMPILESHADER_STATICPARM_EMIT(SHADERSTATICPARM_OFFSETMAPPING_USELOD, "USEOFFSETMAPPING_LOD");
+ R_COMPILESHADER_STATICPARM_EMIT(SHADERSTATICPARM_SHADOWMAPPCF_1, "USESHADOWMAPPCF 1");
+ R_COMPILESHADER_STATICPARM_EMIT(SHADERSTATICPARM_SHADOWMAPPCF_2, "USESHADOWMAPPCF 2");
+ R_COMPILESHADER_STATICPARM_EMIT(SHADERSTATICPARM_SHADOWSAMPLER, "USESHADOWSAMPLER");
}
/// information about each possible shader permutation
DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_ClientTime, cl.time);
}
-static void R_GLSL_Restart_f(void)
+void R_GLSL_Restart_f(void)
{
unsigned int i, limit;
if (glslshaderstring && glslshaderstring != builtinshaderstring)
extern float r_shadow_shadowmap_texturescale[2];
extern float r_shadow_shadowmap_parameters[4];
extern qboolean r_shadow_shadowmapvsdct;
-extern qboolean r_shadow_shadowmapsampler;
-extern int r_shadow_shadowmappcf;
extern rtexture_t *r_shadow_shadowmap2ddepthbuffer;
extern rtexture_t *r_shadow_shadowmap2ddepthtexture;
extern rtexture_t *r_shadow_shadowmapvsdcttexture;
if (rsurface.texture->currentmaterialflags & MATERIALFLAG_WATERSHADER)
{
mode = SHADERMODE_WATER;
+ if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHAGEN_VERTEX)
+ permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX;
if((r_wateralpha.value < 1) && (rsurface.texture->currentmaterialflags & MATERIALFLAG_WATERALPHA))
{
// this is the right thing to do for wateralpha
else if (rsurface.texture->currentmaterialflags & MATERIALFLAG_REFRACTION)
{
mode = SHADERMODE_REFRACTION;
+ if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHAGEN_VERTEX)
+ permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX;
GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
blendfuncflags = R_BlendFuncFlags(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
}
if (rsurface.texture->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND)
permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND;
+ if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHAGEN_VERTEX)
+ permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX;
// light source
mode = SHADERMODE_LIGHTSOURCE;
if (rsurface.rtlight->currentcubemap != r_texture_whitecube)
if(r_shadow_shadowmapvsdct)
permutation |= SHADERPERMUTATION_SHADOWMAPVSDCT;
- if (r_shadow_shadowmapsampler)
- permutation |= SHADERPERMUTATION_SHADOWSAMPLER;
- if (r_shadow_shadowmappcf > 1)
- permutation |= SHADERPERMUTATION_SHADOWMAPPCF2;
- else if (r_shadow_shadowmappcf)
- permutation |= SHADERPERMUTATION_SHADOWMAPPCF;
if (r_shadow_shadowmap2ddepthbuffer)
permutation |= SHADERPERMUTATION_DEPTHRGB;
}
}
if (rsurface.texture->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND)
permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND;
+ if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHAGEN_VERTEX)
+ permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX;
// unshaded geometry (fullbright or ambient model lighting)
mode = SHADERMODE_FLATCOLOR;
ambientscale = diffusescale = specularscale = 0;
permutation |= SHADERPERMUTATION_SHADOWMAPORTHO;
permutation |= SHADERPERMUTATION_SHADOWMAP2D;
- if (r_shadow_shadowmapsampler)
- permutation |= SHADERPERMUTATION_SHADOWSAMPLER;
- if (r_shadow_shadowmappcf > 1)
- permutation |= SHADERPERMUTATION_SHADOWMAPPCF2;
- else if (r_shadow_shadowmappcf)
- permutation |= SHADERPERMUTATION_SHADOWMAPPCF;
if (r_shadow_shadowmap2ddepthbuffer)
permutation |= SHADERPERMUTATION_DEPTHRGB;
}
}
if (rsurface.texture->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND)
permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND;
+ if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHAGEN_VERTEX)
+ permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX;
// directional model lighting
mode = SHADERMODE_LIGHTDIRECTION;
if (rsurface.texture->glowtexture && r_hdr_glowintensity.value > 0 && !gl_lightmaps.integer)
permutation |= SHADERPERMUTATION_SHADOWMAPORTHO;
permutation |= SHADERPERMUTATION_SHADOWMAP2D;
- if (r_shadow_shadowmapsampler)
- permutation |= SHADERPERMUTATION_SHADOWSAMPLER;
- if (r_shadow_shadowmappcf > 1)
- permutation |= SHADERPERMUTATION_SHADOWMAPPCF2;
- else if (r_shadow_shadowmappcf)
- permutation |= SHADERPERMUTATION_SHADOWMAPPCF;
if (r_shadow_shadowmap2ddepthbuffer)
permutation |= SHADERPERMUTATION_DEPTHRGB;
}
}
if (rsurface.texture->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND)
permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND;
+ if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHAGEN_VERTEX)
+ permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX;
// ambient model lighting
mode = SHADERMODE_LIGHTDIRECTION;
if (rsurface.texture->glowtexture && r_hdr_glowintensity.value > 0 && !gl_lightmaps.integer)
permutation |= SHADERPERMUTATION_SHADOWMAPORTHO;
permutation |= SHADERPERMUTATION_SHADOWMAP2D;
- if (r_shadow_shadowmapsampler)
- permutation |= SHADERPERMUTATION_SHADOWSAMPLER;
- if (r_shadow_shadowmappcf > 1)
- permutation |= SHADERPERMUTATION_SHADOWMAPPCF2;
- else if (r_shadow_shadowmappcf)
- permutation |= SHADERPERMUTATION_SHADOWMAPPCF;
if (r_shadow_shadowmap2ddepthbuffer)
permutation |= SHADERPERMUTATION_DEPTHRGB;
}
}
if (rsurface.texture->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND)
permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND;
+ if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHAGEN_VERTEX)
+ permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX;
// lightmapped wall
if (rsurface.texture->glowtexture && r_hdr_glowintensity.value > 0 && !gl_lightmaps.integer)
permutation |= SHADERPERMUTATION_GLOW;
permutation |= SHADERPERMUTATION_SHADOWMAPORTHO;
permutation |= SHADERPERMUTATION_SHADOWMAP2D;
- if (r_shadow_shadowmapsampler)
- permutation |= SHADERPERMUTATION_SHADOWSAMPLER;
- if (r_shadow_shadowmappcf > 1)
- permutation |= SHADERPERMUTATION_SHADOWMAPPCF2;
- else if (r_shadow_shadowmappcf)
- permutation |= SHADERPERMUTATION_SHADOWMAPPCF;
if (r_shadow_shadowmap2ddepthbuffer)
permutation |= SHADERPERMUTATION_DEPTHRGB;
}
1.0 / max(1, (permutation & SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING) ? r_glsl_offsetmapping_reliefmapping_steps.integer : r_glsl_offsetmapping_steps.integer),
max(1, r_glsl_offsetmapping_reliefmapping_refinesteps.integer)
);
- hlslPSSetParameter1f(D3DPSREGISTER_OffsetMapping_LodDistance, r_glsl_offsetmapping_lod_distance.integer);
+ hlslPSSetParameter1f(D3DPSREGISTER_OffsetMapping_LodDistance, r_glsl_offsetmapping_lod_distance.integer * r_refdef.view.quality);
hlslPSSetParameter1f(D3DPSREGISTER_OffsetMapping_Bias, rsurface.texture->offsetbias);
hlslPSSetParameter2f(D3DPSREGISTER_ScreenToDepth, r_refdef.view.viewport.screentodepth[0], r_refdef.view.viewport.screentodepth[1]);
hlslPSSetParameter2f(D3DPSREGISTER_PixelToScreenTexCoord, 1.0f/vid.width, 1.0/vid.height);
1.0 / max(1, (permutation & SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING) ? r_glsl_offsetmapping_reliefmapping_steps.integer : r_glsl_offsetmapping_steps.integer),
max(1, r_glsl_offsetmapping_reliefmapping_refinesteps.integer)
);
- if (r_glsl_permutation->loc_OffsetMapping_LodDistance >= 0) qglUniform1f(r_glsl_permutation->loc_OffsetMapping_LodDistance, r_glsl_offsetmapping_lod_distance.integer);
+ if (r_glsl_permutation->loc_OffsetMapping_LodDistance >= 0) qglUniform1f(r_glsl_permutation->loc_OffsetMapping_LodDistance, r_glsl_offsetmapping_lod_distance.integer * r_refdef.view.quality);
if (r_glsl_permutation->loc_OffsetMapping_Bias >= 0) qglUniform1f(r_glsl_permutation->loc_OffsetMapping_Bias, rsurface.texture->offsetbias);
if (r_glsl_permutation->loc_ScreenToDepth >= 0) qglUniform2f(r_glsl_permutation->loc_ScreenToDepth, r_refdef.view.viewport.screentodepth[0], r_refdef.view.viewport.screentodepth[1]);
if (r_glsl_permutation->loc_PixelToScreenTexCoord >= 0) qglUniform2f(r_glsl_permutation->loc_PixelToScreenTexCoord, 1.0f/vid.width, 1.0f/vid.height);
1.0 / max(1, (permutation & SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING) ? r_glsl_offsetmapping_reliefmapping_steps.integer : r_glsl_offsetmapping_steps.integer),
max(1, r_glsl_offsetmapping_reliefmapping_refinesteps.integer)
);
- DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_OffsetMapping_LodDistance, r_glsl_offsetmapping_lod_distance.integer);
+ DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_OffsetMapping_LodDistance, r_glsl_offsetmapping_lod_distance.integer * r_refdef.view.quality);
DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_OffsetMapping_Bias, rsurface.texture->offsetbias);
DPSOFTRAST_Uniform2f(DPSOFTRAST_UNIFORM_ScreenToDepth, r_refdef.view.viewport.screentodepth[0], r_refdef.view.viewport.screentodepth[1]);
DPSOFTRAST_Uniform2f(DPSOFTRAST_UNIFORM_PixelToScreenTexCoord, 1.0f/vid.width, 1.0f/vid.height);
if (r_shadow_shadowmapvsdct)
permutation |= SHADERPERMUTATION_SHADOWMAPVSDCT;
- if (r_shadow_shadowmapsampler)
- permutation |= SHADERPERMUTATION_SHADOWSAMPLER;
- if (r_shadow_shadowmappcf > 1)
- permutation |= SHADERPERMUTATION_SHADOWMAPPCF2;
- else if (r_shadow_shadowmappcf)
- permutation |= SHADERPERMUTATION_SHADOWMAPPCF;
if (r_shadow_shadowmap2ddepthbuffer)
permutation |= SHADERPERMUTATION_DEPTHRGB;
}
Cvar_RegisterVariable(&r_deformvertexes);
Cvar_RegisterVariable(&r_transparent);
Cvar_RegisterVariable(&r_transparent_alphatocoverage);
+ Cvar_RegisterVariable(&r_transparent_sortsurfacesbynearest);
+ Cvar_RegisterVariable(&r_transparent_useplanardistance);
Cvar_RegisterVariable(&r_showoverdraw);
Cvar_RegisterVariable(&r_showbboxes);
Cvar_RegisterVariable(&r_showsurfaces);
{
ent = r_refdef.scene.entities[i];
- // skip unseen models and models that updated by CSQC
- if ((!r_refdef.viewcache.entityvisible[i] && skipunseen) || ent->flags & RENDER_CUSTOMIZEDMODELLIGHT)
+ // skip unseen models
+ if ((!r_refdef.viewcache.entityvisible[i] && skipunseen))
continue;
// skip bsp models
- if (ent->model && (ent->model == cl.worldmodel || ent->model->brush.parentmodel == cl.worldmodel))
+ if (ent->model && ent->model == cl.worldmodel)
{
// TODO: use modellight for r_ambient settings on world?
VectorSet(ent->modellight_ambient, 0, 0, 0);
VectorSet(ent->modellight_lightdir, 0, 0, 1);
continue;
}
-
- // fetch the lighting from the worldmodel data
- VectorClear(ent->modellight_ambient);
- VectorClear(ent->modellight_diffuse);
- VectorClear(tempdiffusenormal);
- if (ent->flags & RENDER_LIGHT)
+
+ if (ent->flags & RENDER_CUSTOMIZEDMODELLIGHT)
{
- vec3_t org;
- Matrix4x4_OriginFromMatrix(&ent->matrix, org);
-
- // complete lightning for lit sprites
- // todo: make a EF_ field so small ents could be lit purely by modellight and skipping real rtlight pass (like EF_NORTLIGHT)?
- if (ent->model->type == mod_sprite && !(ent->model->data_textures[0].basematerialflags & MATERIALFLAG_FULLBRIGHT))
+ // aleady updated by CSQC
+ // TODO: force modellight on BSP models in this case?
+ VectorCopy(ent->modellight_lightdir, tempdiffusenormal);
+ }
+ else
+ {
+ // fetch the lighting from the worldmodel data
+ VectorClear(ent->modellight_ambient);
+ VectorClear(ent->modellight_diffuse);
+ VectorClear(tempdiffusenormal);
+ if (ent->flags & RENDER_LIGHT)
{
- if (ent->model->sprite.sprnum_type == SPR_OVERHEAD) // apply offset for overhead sprites
- org[2] = org[2] + r_overheadsprites_pushback.value;
- R_LightPoint(ent->modellight_ambient, org, LP_LIGHTMAP | LP_RTWORLD | LP_DYNLIGHT);
- }
- else
- R_CompleteLightPoint(ent->modellight_ambient, ent->modellight_diffuse, tempdiffusenormal, org, LP_LIGHTMAP);
+ vec3_t org;
+ Matrix4x4_OriginFromMatrix(&ent->matrix, org);
- if(ent->flags & RENDER_EQUALIZE)
- {
- // first fix up ambient lighting...
- if(r_equalize_entities_minambient.value > 0)
+ // complete lightning for lit sprites
+ // todo: make a EF_ field so small ents could be lit purely by modellight and skipping real rtlight pass (like EF_NORTLIGHT)?
+ if (ent->model->type == mod_sprite && !(ent->model->data_textures[0].basematerialflags & MATERIALFLAG_FULLBRIGHT))
{
- fd = 0.299f * ent->modellight_diffuse[0] + 0.587f * ent->modellight_diffuse[1] + 0.114f * ent->modellight_diffuse[2];
- if(fd > 0)
+ if (ent->model->sprite.sprnum_type == SPR_OVERHEAD) // apply offset for overhead sprites
+ org[2] = org[2] + r_overheadsprites_pushback.value;
+ R_LightPoint(ent->modellight_ambient, org, LP_LIGHTMAP | LP_RTWORLD | LP_DYNLIGHT);
+ }
+ else
+ R_CompleteLightPoint(ent->modellight_ambient, ent->modellight_diffuse, tempdiffusenormal, org, LP_LIGHTMAP);
+
+ if(ent->flags & RENDER_EQUALIZE)
+ {
+ // first fix up ambient lighting...
+ if(r_equalize_entities_minambient.value > 0)
{
- fa = (0.299f * ent->modellight_ambient[0] + 0.587f * ent->modellight_ambient[1] + 0.114f * ent->modellight_ambient[2]);
- if(fa < r_equalize_entities_minambient.value * fd)
+ fd = 0.299f * ent->modellight_diffuse[0] + 0.587f * ent->modellight_diffuse[1] + 0.114f * ent->modellight_diffuse[2];
+ if(fd > 0)
{
- // 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
- VectorMA(ent->modellight_ambient, (1-f)*0.25f, ent->modellight_diffuse, ent->modellight_ambient);
- VectorScale(ent->modellight_diffuse, f, ent->modellight_diffuse);
+ fa = (0.299f * ent->modellight_ambient[0] + 0.587f * ent->modellight_ambient[1] + 0.114f * ent->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
+ VectorMA(ent->modellight_ambient, (1-f)*0.25f, ent->modellight_diffuse, ent->modellight_ambient);
+ VectorScale(ent->modellight_diffuse, f, ent->modellight_diffuse);
+ }
}
}
- }
- if(r_equalize_entities_to.value > 0 && r_equalize_entities_by.value != 0)
- {
- fa = 0.299f * ent->modellight_ambient[0] + 0.587f * ent->modellight_ambient[1] + 0.114f * ent->modellight_ambient[2];
- fd = 0.299f * ent->modellight_diffuse[0] + 0.587f * ent->modellight_diffuse[1] + 0.114f * ent->modellight_diffuse[2];
- f = fa + 0.25 * fd;
- if(f > 0)
+ if(r_equalize_entities_to.value > 0 && r_equalize_entities_by.value != 0)
{
- // adjust brightness and saturation to target
- avg[0] = avg[1] = avg[2] = fa / f;
- VectorLerp(ent->modellight_ambient, r_equalize_entities_by.value, avg, ent->modellight_ambient);
- avg[0] = avg[1] = avg[2] = fd / f;
- VectorLerp(ent->modellight_diffuse, r_equalize_entities_by.value, avg, ent->modellight_diffuse);
+ fa = 0.299f * ent->modellight_ambient[0] + 0.587f * ent->modellight_ambient[1] + 0.114f * ent->modellight_ambient[2];
+ fd = 0.299f * ent->modellight_diffuse[0] + 0.587f * ent->modellight_diffuse[1] + 0.114f * ent->modellight_diffuse[2];
+ f = fa + 0.25 * fd;
+ if(f > 0)
+ {
+ // adjust brightness and saturation to target
+ avg[0] = avg[1] = avg[2] = fa / f;
+ VectorLerp(ent->modellight_ambient, r_equalize_entities_by.value, avg, ent->modellight_ambient);
+ avg[0] = avg[1] = avg[2] = fd / f;
+ VectorLerp(ent->modellight_diffuse, r_equalize_entities_by.value, avg, ent->modellight_diffuse);
+ }
}
}
}
+ else // highly rare
+ VectorSet(ent->modellight_ambient, 1, 1, 1);
}
- else // highly rare
- VectorSet(ent->modellight_ambient, 1, 1, 1);
// move the light direction into modelspace coordinates for lighting code
Matrix4x4_Transform3x3(&ent->inversematrix, tempdiffusenormal, ent->modellight_lightdir);
R_RenderView_UpdateViewVectors
================
*/
-static void R_RenderView_UpdateViewVectors(void)
+void R_RenderView_UpdateViewVectors(void)
{
// break apart the view matrix into vectors for various purposes
// it is important that this occurs outside the RenderScene function because that can be called from reflection renders, where the vectors come out wrong
r_fb.bloomindex ^= 1;
R_Mesh_SetRenderTargets(r_fb.bloomfbo[r_fb.bloomindex], NULL, r_fb.bloomtexture[r_fb.bloomindex], NULL, NULL, NULL);
x *= 2;
- r = bound(0, r_bloom_colorexponent.value / x, 1);
- GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
- GL_Color(r,r,r,1);
+ r = bound(0, r_bloom_colorexponent.value / x, 1); // always 0.5 to 1
+ if (!r_fb.bloomfbo[r_fb.bloomindex])
+ {
+ GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR); // square it and multiply by two
+ GL_Color(r,r,r,1); // apply fix factor
+ }
+ else
+ {
+ if(x <= 2)
+ GL_Clear(GL_COLOR_BUFFER_BIT, NULL, 1.0f, 128);
+ GL_BlendFunc(GL_SRC_COLOR, GL_ZERO); // square it
+ GL_Color(1,1,1,1); // no fix factor supported here
+ }
R_Mesh_PrepareVertices_Generic_Arrays(4, r_screenvertex3f, NULL, r_fb.bloomtexcoord2f);
R_SetupShader_Generic(intex, NULL, GL_MODULATE, 1, false, true, false);
R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
{
r_refdef.lightmapintensity *= r_fakelight_intensity.value;
}
+ else if (r_refdef.scene.worldmodel)
+ {
+ r_refdef.lightmapintensity *= r_refdef.scene.worldmodel->lightmapscale;
+ }
if (r_showsurfaces.integer)
{
r_refdef.scene.rtworld = false;
r_refdef.view.colorscale = r_hdr_scenebrightness.value * r_hdr_irisadaptation_value.value;
+ if(vid_sRGB.integer && vid_sRGB_fallback.integer && !vid.sRGB3D)
+ // in sRGB fallback, behave similar to true sRGB: convert this
+ // value from linear to sRGB
+ r_refdef.view.colorscale = Image_sRGBFloatFromLinearFloat(r_refdef.view.colorscale);
+
R_RenderView_UpdateViewVectors();
R_Shadow_UpdateWorldLightSelection();
case SOLID_BBOX: Vector4Set(color, 0, 1, 0, 0.10);break;
case SOLID_SLIDEBOX: Vector4Set(color, 1, 0, 0, 0.10);break;
case SOLID_BSP: Vector4Set(color, 0, 0, 1, 0.05);break;
+ case SOLID_CORPSE: Vector4Set(color, 1, 0.5, 0, 0.05);break;
default: Vector4Set(color, 0, 0, 0, 0.50);break;
}
color[3] *= r_showbboxes.value;
if(PRVM_serveredictedict(edict, viewmodelforclient) != 0)
continue;
VectorLerp(edict->priv.server->areamins, 0.5f, edict->priv.server->areamaxs, center);
- R_MeshQueue_AddTransparent(center, R_DrawEntityBBoxes_Callback, (entity_render_t *)NULL, i, (rtlight_t *)NULL);
+ R_MeshQueue_AddTransparent(MESHQUEUE_SORT_DISTANCE, center, R_DrawEntityBBoxes_Callback, (entity_render_t *)NULL, i, (rtlight_t *)NULL);
}
}
vec3_t org;
Matrix4x4_OriginFromMatrix(&ent->matrix, org);
if ((ent->flags & RENDER_ADDITIVE) || (ent->alpha < 1))
- R_MeshQueue_AddTransparent(ent->flags & RENDER_NODEPTHTEST ? r_refdef.view.origin : org, R_DrawNoModel_TransparentCallback, ent, 0, rsurface.rtlight);
+ R_MeshQueue_AddTransparent((ent->flags & RENDER_NODEPTHTEST) ? MESHQUEUE_SORT_HUD : MESHQUEUE_SORT_DISTANCE, org, R_DrawNoModel_TransparentCallback, ent, 0, rsurface.rtlight);
else
R_DrawNoModel_TransparentCallback(ent, rsurface.rtlight, 0, NULL);
}
{
// no modellight if using fakelight for the map
}
- else if (rsurface.modeltexcoordlightmap2f == NULL && !(t->currentmaterialflags & MATERIALFLAG_FULLBRIGHT))
+ else if ((rsurface.modeltexcoordlightmap2f == NULL || (rsurface.ent_flags & (RENDER_DYNAMICMODELLIGHT | RENDER_CUSTOMIZEDMODELLIGHT))) && !(t->currentmaterialflags & MATERIALFLAG_FULLBRIGHT))
{
// pick a model lighting mode
if (VectorLength2(rsurface.modellight_diffuse) >= (1.0f / 256.0f))
rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveWorldEntity/RSurf_ActiveModelEntity
}
-static void R_ProcessTransparentTextureSurfaceList(int texturenumsurfaces, const msurface_t **texturesurfacelist, const entity_render_t *queueentity)
+static void R_ProcessTransparentTextureSurfaceList(int texturenumsurfaces, const msurface_t **texturesurfacelist)
{
// transparent surfaces get pushed off into the transparent queue
int surfacelistindex;
for (surfacelistindex = 0;surfacelistindex < texturenumsurfaces;surfacelistindex++)
{
surface = texturesurfacelist[surfacelistindex];
- tempcenter[0] = (surface->mins[0] + surface->maxs[0]) * 0.5f;
- tempcenter[1] = (surface->mins[1] + surface->maxs[1]) * 0.5f;
- tempcenter[2] = (surface->mins[2] + surface->maxs[2]) * 0.5f;
+ if (r_transparent_sortsurfacesbynearest.integer)
+ {
+ tempcenter[0] = bound(surface->mins[0], rsurface.localvieworigin[0], surface->maxs[0]);
+ tempcenter[1] = bound(surface->mins[1], rsurface.localvieworigin[1], surface->maxs[1]);
+ tempcenter[2] = bound(surface->mins[2], rsurface.localvieworigin[2], surface->maxs[2]);
+ }
+ else
+ {
+ tempcenter[0] = (surface->mins[0] + surface->maxs[0]) * 0.5f;
+ tempcenter[1] = (surface->mins[1] + surface->maxs[1]) * 0.5f;
+ tempcenter[2] = (surface->mins[2] + surface->maxs[2]) * 0.5f;
+ }
Matrix4x4_Transform(&rsurface.matrix, tempcenter, center);
- if (queueentity->transparent_offset) // transparent offset
+ if (rsurface.entity->transparent_offset) // transparent offset
{
- center[0] += r_refdef.view.forward[0]*queueentity->transparent_offset;
- center[1] += r_refdef.view.forward[1]*queueentity->transparent_offset;
- center[2] += r_refdef.view.forward[2]*queueentity->transparent_offset;
+ center[0] += r_refdef.view.forward[0]*rsurface.entity->transparent_offset;
+ center[1] += r_refdef.view.forward[1]*rsurface.entity->transparent_offset;
+ center[2] += r_refdef.view.forward[2]*rsurface.entity->transparent_offset;
}
- R_MeshQueue_AddTransparent(rsurface.texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST ? r_refdef.view.origin : center, R_DrawSurface_TransparentCallback, queueentity, surface - rsurface.modelsurfaces, rsurface.rtlight);
+ R_MeshQueue_AddTransparent((rsurface.texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST) ? MESHQUEUE_SORT_HUD : ((rsurface.entity->flags & RENDER_WORLDOBJECT) ? MESHQUEUE_SORT_SKY : MESHQUEUE_SORT_DISTANCE), center, R_DrawSurface_TransparentCallback, rsurface.entity, surface - rsurface.modelsurfaces, rsurface.rtlight);
}
}
static void R_ProcessWorldTextureSurfaceList(int texturenumsurfaces, const msurface_t **texturesurfacelist, qboolean writedepth, qboolean depthonly, qboolean prepass)
{
- const entity_render_t *queueentity = r_refdef.scene.worldentity;
CHECKGLERROR
if (depthonly)
R_DrawTextureSurfaceList_DepthOnly(texturenumsurfaces, texturesurfacelist);
if (!rsurface.texture->currentnumlayers)
return;
if (rsurface.texture->currentmaterialflags & MATERIALFLAGMASK_DEPTHSORTED)
- R_ProcessTransparentTextureSurfaceList(texturenumsurfaces, texturesurfacelist, queueentity);
+ R_ProcessTransparentTextureSurfaceList(texturenumsurfaces, texturesurfacelist);
else
R_DrawWorldTextureSurfaceList(texturenumsurfaces, texturesurfacelist, writedepth, prepass);
}
R_DrawTextureSurfaceList_Sky(texturenumsurfaces, texturesurfacelist);
else if (!rsurface.texture->currentnumlayers)
return;
- else if (((rsurface.texture->currentmaterialflags & MATERIALFLAGMASK_DEPTHSORTED) || (r_showsurfaces.integer == 3 && (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST))) && queueentity)
+ else if (((rsurface.texture->currentmaterialflags & MATERIALFLAGMASK_DEPTHSORTED) || (r_showsurfaces.integer == 3 && (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST))))
{
// in the deferred case, transparent surfaces were queued during prepass
if (!r_shadow_usingdeferredprepass)
- R_ProcessTransparentTextureSurfaceList(texturenumsurfaces, texturesurfacelist, queueentity);
+ R_ProcessTransparentTextureSurfaceList(texturenumsurfaces, texturesurfacelist);
}
else
{
R_FrameData_ReturnToMark();
}
-static void R_ProcessModelTextureSurfaceList(int texturenumsurfaces, const msurface_t **texturesurfacelist, qboolean writedepth, qboolean depthonly, const entity_render_t *queueentity, qboolean prepass)
+static void R_ProcessModelTextureSurfaceList(int texturenumsurfaces, const msurface_t **texturesurfacelist, qboolean writedepth, qboolean depthonly, qboolean prepass)
{
CHECKGLERROR
if (depthonly)
if (!rsurface.texture->currentnumlayers)
return;
if (rsurface.texture->currentmaterialflags & MATERIALFLAGMASK_DEPTHSORTED)
- R_ProcessTransparentTextureSurfaceList(texturenumsurfaces, texturesurfacelist, queueentity);
+ R_ProcessTransparentTextureSurfaceList(texturenumsurfaces, texturesurfacelist);
else
R_DrawModelTextureSurfaceList(texturenumsurfaces, texturesurfacelist, writedepth, prepass);
}
R_DrawTextureSurfaceList_Sky(texturenumsurfaces, texturesurfacelist);
else if (!rsurface.texture->currentnumlayers)
return;
- else if (((rsurface.texture->currentmaterialflags & MATERIALFLAGMASK_DEPTHSORTED) || (r_showsurfaces.integer == 3 && (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST))) && queueentity)
+ else if (((rsurface.texture->currentmaterialflags & MATERIALFLAGMASK_DEPTHSORTED) || (r_showsurfaces.integer == 3 && (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST))))
{
// in the deferred case, transparent surfaces were queued during prepass
if (!r_shadow_usingdeferredprepass)
- R_ProcessTransparentTextureSurfaceList(texturenumsurfaces, texturesurfacelist, queueentity);
+ R_ProcessTransparentTextureSurfaceList(texturenumsurfaces, texturesurfacelist);
}
else
{
;
}
// render the range of surfaces
- R_ProcessModelTextureSurfaceList(j - i, surfacelist + i, writedepth, depthonly, ent, prepass);
+ R_ProcessModelTextureSurfaceList(j - i, surfacelist + i, writedepth, depthonly, prepass);
}
R_FrameData_ReturnToMark();
}
for (loc = cl.locnodes, index = 0;loc;loc = loc->next, index++)
{
VectorLerp(loc->mins, 0.5f, loc->maxs, center);
- R_MeshQueue_AddTransparent(center, R_DrawLoc_Callback, (entity_render_t *)loc, loc == nearestloc ? -1 : index, NULL);
+ R_MeshQueue_AddTransparent(MESHQUEUE_SORT_DISTANCE, center, R_DrawLoc_Callback, (entity_render_t *)loc, loc == nearestloc ? -1 : index, NULL);
}
}