cvar_t r_transparent_sortmaxdist = {CVAR_CLIENT | CVAR_SAVE, "r_transparent_sortmaxdist", "32768", "upper distance limit for transparent sorting"};
cvar_t r_transparent_sortarraysize = {CVAR_CLIENT | CVAR_SAVE, "r_transparent_sortarraysize", "4096", "number of distance-sorting layers"};
cvar_t r_celshading = {CVAR_CLIENT | CVAR_SAVE, "r_celshading", "0", "cartoon-style light shading (OpenGL 2.x only)"}; // FIXME remove OpenGL 2.x only once implemented for DX9
-cvar_t r_celoutlines = {CVAR_CLIENT | CVAR_SAVE, "r_celoutlines", "0", "cartoon-style outlines (requires r_shadow_deferred; OpenGL 2.x only)"}; // FIXME remove OpenGL 2.x only once implemented for DX9
+cvar_t r_celoutlines = {CVAR_CLIENT | CVAR_SAVE, "r_celoutlines", "0", "cartoon-style outlines (requires r_shadow_deferred)"};
cvar_t gl_fogenable = {CVAR_CLIENT, "gl_fogenable", "0", "nehahra fog enable (for Nehahra compatibility only)"};
cvar_t gl_fogdensity = {CVAR_CLIENT, "gl_fogdensity", "0.25", "nehahra fog density (recommend values below 0.1) (for Nehahra compatibility only)"};
cvar_t r_glsl_postprocess_uservec2_enable = {CVAR_CLIENT | CVAR_SAVE, "r_glsl_postprocess_uservec2_enable", "1", "enables postprocessing uservec2 usage, creates USERVEC1 define (only useful if default.glsl has been customized)"};
cvar_t r_glsl_postprocess_uservec3_enable = {CVAR_CLIENT | CVAR_SAVE, "r_glsl_postprocess_uservec3_enable", "1", "enables postprocessing uservec3 usage, creates USERVEC1 define (only useful if default.glsl has been customized)"};
cvar_t r_glsl_postprocess_uservec4_enable = {CVAR_CLIENT | CVAR_SAVE, "r_glsl_postprocess_uservec4_enable", "1", "enables postprocessing uservec4 usage, creates USERVEC1 define (only useful if default.glsl has been customized)"};
+cvar_t r_colorfringe = {CVAR_CLIENT | CVAR_SAVE, "r_colorfringe", "0", "Chromatic aberration. Values higher than 0.025 will noticeably distort the image"};
cvar_t r_water = {CVAR_CLIENT | CVAR_SAVE, "r_water", "0", "whether to use reflections and refraction on water surfaces (note: r_wateralpha must be set below 1)"};
cvar_t r_water_cameraentitiesonly = {CVAR_CLIENT | CVAR_SAVE, "r_water_cameraentitiesonly", "0", "whether to only show QC-defined reflections/refractions (typically used for camera- or portal-like effects)"};
cvar_t r_water_refractdistort = {CVAR_CLIENT | CVAR_SAVE, "r_water_refractdistort", "0.01", "how much water refractions shimmer"};
cvar_t r_water_reflectdistort = {CVAR_CLIENT | CVAR_SAVE, "r_water_reflectdistort", "0.01", "how much water reflections shimmer"};
cvar_t r_water_scissormode = {CVAR_CLIENT, "r_water_scissormode", "3", "scissor (1) or cull (2) or both (3) water renders"};
-cvar_t r_water_lowquality = {CVAR_CLIENT, "r_water_lowquality", "0", "special option to accelerate water rendering, 1 disables shadows and particles, 2 disables all dynamic lights"};
+cvar_t r_water_lowquality = {CVAR_CLIENT, "r_water_lowquality", "0", "special option to accelerate water rendering: 1 disables all dynamic lights, 2 disables particles too"};
cvar_t r_water_hideplayer = {CVAR_CLIENT | CVAR_SAVE, "r_water_hideplayer", "0", "if set to 1 then player will be hidden in refraction views, if set to 2 then player will also be hidden in reflection views, player is always visible in camera views"};
cvar_t r_lerpsprites = {CVAR_CLIENT | CVAR_SAVE, "r_lerpsprites", "0", "enables animation smoothing on sprites"};
{"combined", "glsl", builtinshaderstrings, "#define MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n", " lightdirectionmap_tangentspace"},
{"combined", "glsl", builtinshaderstrings, "#define MODE_LIGHTDIRECTIONMAP_FORCED_LIGHTMAP\n", " lightdirectionmap_forced_lightmap"},
{"combined", "glsl", builtinshaderstrings, "#define MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR\n", " lightdirectionmap_forced_vertexcolor"},
+ {"combined", "glsl", builtinshaderstrings, "#define MODE_LIGHTGRID\n", " lightgrid"},
{"combined", "glsl", builtinshaderstrings, "#define MODE_LIGHTDIRECTION\n", " lightdirection"},
{"combined", "glsl", builtinshaderstrings, "#define MODE_LIGHTSOURCE\n", " lightsource"},
{"combined", "glsl", builtinshaderstrings, "#define MODE_REFRACTION\n", " refraction"},
int tex_Texture_Shirt;
int tex_Texture_FogHeightTexture;
int tex_Texture_FogMask;
+ int tex_Texture_LightGrid;
int tex_Texture_Lightmap;
int tex_Texture_Deluxemap;
int tex_Texture_Attenuation;
int loc_Texture_Shirt;
int loc_Texture_FogHeightTexture;
int loc_Texture_FogMask;
+ int loc_Texture_LightGrid;
int loc_Texture_Lightmap;
int loc_Texture_Deluxemap;
int loc_Texture_Attenuation;
int loc_FogRangeRecip;
int loc_LightColor;
int loc_LightDir;
+ int loc_LightGridMatrix;
+ int loc_LightGridNormalMatrix;
int loc_LightPosition;
int loc_OffsetMapping_ScaleSteps;
int loc_OffsetMapping_LodDistance;
int loc_UserVec2;
int loc_UserVec3;
int loc_UserVec4;
+ int loc_ColorFringe;
int loc_ViewTintColor;
int loc_ViewToLight;
int loc_ModelToLight;
p->loc_Texture_Shirt = qglGetUniformLocation(p->program, "Texture_Shirt");
p->loc_Texture_FogHeightTexture = qglGetUniformLocation(p->program, "Texture_FogHeightTexture");
p->loc_Texture_FogMask = qglGetUniformLocation(p->program, "Texture_FogMask");
+ p->loc_Texture_LightGrid = qglGetUniformLocation(p->program, "Texture_LightGrid");
p->loc_Texture_Lightmap = qglGetUniformLocation(p->program, "Texture_Lightmap");
p->loc_Texture_Deluxemap = qglGetUniformLocation(p->program, "Texture_Deluxemap");
p->loc_Texture_Attenuation = qglGetUniformLocation(p->program, "Texture_Attenuation");
p->loc_FogPlaneViewDist = qglGetUniformLocation(p->program, "FogPlaneViewDist");
p->loc_FogRangeRecip = qglGetUniformLocation(p->program, "FogRangeRecip");
p->loc_LightColor = qglGetUniformLocation(p->program, "LightColor");
+ p->loc_LightGridMatrix = qglGetUniformLocation(p->program, "LightGridMatrix");
+ p->loc_LightGridNormalMatrix = qglGetUniformLocation(p->program, "LightGridNormalMatrix");
p->loc_LightDir = qglGetUniformLocation(p->program, "LightDir");
p->loc_LightPosition = qglGetUniformLocation(p->program, "LightPosition");
p->loc_OffsetMapping_ScaleSteps = qglGetUniformLocation(p->program, "OffsetMapping_ScaleSteps");
p->loc_UserVec2 = qglGetUniformLocation(p->program, "UserVec2");
p->loc_UserVec3 = qglGetUniformLocation(p->program, "UserVec3");
p->loc_UserVec4 = qglGetUniformLocation(p->program, "UserVec4");
+ p->loc_ColorFringe = qglGetUniformLocation(p->program, "ColorFringe");
p->loc_ViewTintColor = qglGetUniformLocation(p->program, "ViewTintColor");
p->loc_ViewToLight = qglGetUniformLocation(p->program, "ViewToLight");
p->loc_ModelToLight = qglGetUniformLocation(p->program, "ModelToLight");
p->tex_Texture_Shirt = -1;
p->tex_Texture_FogHeightTexture = -1;
p->tex_Texture_FogMask = -1;
+ p->tex_Texture_LightGrid = -1;
p->tex_Texture_Lightmap = -1;
p->tex_Texture_Deluxemap = -1;
p->tex_Texture_Attenuation = -1;
if (p->loc_Texture_Shirt >= 0) {p->tex_Texture_Shirt = sampler;qglUniform1i(p->loc_Texture_Shirt , sampler);sampler++;}
if (p->loc_Texture_FogHeightTexture>= 0) {p->tex_Texture_FogHeightTexture = sampler;qglUniform1i(p->loc_Texture_FogHeightTexture, sampler);sampler++;}
if (p->loc_Texture_FogMask >= 0) {p->tex_Texture_FogMask = sampler;qglUniform1i(p->loc_Texture_FogMask , sampler);sampler++;}
+ if (p->loc_Texture_LightGrid >= 0) {p->tex_Texture_LightGrid = sampler;qglUniform1i(p->loc_Texture_LightGrid , sampler);sampler++;}
if (p->loc_Texture_Lightmap >= 0) {p->tex_Texture_Lightmap = sampler;qglUniform1i(p->loc_Texture_Lightmap , sampler);sampler++;}
if (p->loc_Texture_Deluxemap >= 0) {p->tex_Texture_Deluxemap = sampler;qglUniform1i(p->loc_Texture_Deluxemap , sampler);sampler++;}
if (p->loc_Texture_Attenuation >= 0) {p->tex_Texture_Attenuation = sampler;qglUniform1i(p->loc_Texture_Attenuation , sampler);sampler++;}
Con_Printf("%s written\n", modeinfo[mode].filename);
}
else
- Con_Printf("failed to write to %s\n", modeinfo[mode].filename);
+ Con_Errorf("failed to write to %s\n", modeinfo[mode].filename);
}
}
}
if (vid.allowalphatocoverage)
GL_AlphaToCoverage(false);
}
+ else if (t->currentmaterialflags & MATERIALFLAG_LIGHTGRID)
+ {
+ if (r_glsl_offsetmapping.integer && ((R_TextureFlags(t->nmaptexture) & TEXF_ALPHA) || t->offsetbias != 0.0f))
+ {
+ switch(t->offsetmapping)
+ {
+ case OFFSETMAPPING_LINEAR: permutation |= SHADERPERMUTATION_OFFSETMAPPING;break;
+ case OFFSETMAPPING_RELIEF: permutation |= SHADERPERMUTATION_OFFSETMAPPING | SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING;break;
+ case OFFSETMAPPING_DEFAULT: permutation |= SHADERPERMUTATION_OFFSETMAPPING;if (r_glsl_offsetmapping_reliefmapping.integer) permutation |= SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING;break;
+ case OFFSETMAPPING_OFF: break;
+ }
+ }
+ if (t->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND)
+ permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND;
+ if (t->currentmaterialflags & MATERIALFLAG_ALPHAGEN_VERTEX)
+ permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX;
+ // directional model lighting
+ mode = SHADERMODE_LIGHTGRID;
+ if ((t->glowtexture || t->backgroundglowtexture) && r_hdr_glowintensity.value > 0 && !gl_lightmaps.integer)
+ permutation |= SHADERPERMUTATION_GLOW;
+ permutation |= SHADERPERMUTATION_DIFFUSE;
+ if (t->glosstexture || t->backgroundglosstexture)
+ permutation |= SHADERPERMUTATION_SPECULAR;
+ if (r_refdef.fogenabled)
+ permutation |= r_texture_fogheighttexture ? SHADERPERMUTATION_FOGHEIGHTTEXTURE : (r_refdef.fogplaneviewabove ? SHADERPERMUTATION_FOGOUTSIDE : SHADERPERMUTATION_FOGINSIDE);
+ if (t->colormapping)
+ permutation |= SHADERPERMUTATION_COLORMAPPING;
+ if (r_shadow_usingshadowmaportho && !(rsurface.ent_flags & RENDER_NOSELFSHADOW))
+ {
+ permutation |= SHADERPERMUTATION_SHADOWMAPORTHO;
+ permutation |= SHADERPERMUTATION_SHADOWMAP2D;
+
+ if (r_shadow_shadowmap2ddepthbuffer)
+ permutation |= SHADERPERMUTATION_DEPTHRGB;
+ }
+ if (t->currentmaterialflags & MATERIALFLAG_REFLECTION)
+ permutation |= SHADERPERMUTATION_REFLECTION;
+ if (r_shadow_usingdeferredprepass && !(t->currentmaterialflags & MATERIALFLAG_BLENDED))
+ permutation |= SHADERPERMUTATION_DEFERREDLIGHTMAP;
+ if (t->reflectmasktexture)
+ permutation |= SHADERPERMUTATION_REFLECTCUBE;
+ if (r_shadow_bouncegrid_state.texture && cl.csqc_vidvars.drawworld && !notrippy)
+ {
+ permutation |= SHADERPERMUTATION_BOUNCEGRID;
+ if (r_shadow_bouncegrid_state.directional)
+ permutation |= SHADERPERMUTATION_BOUNCEGRIDDIRECTIONAL;
+ }
+ GL_BlendFunc(t->currentblendfunc[0], t->currentblendfunc[1]);
+ blendfuncflags = R_BlendFuncFlags(t->currentblendfunc[0], t->currentblendfunc[1]);
+ // when using alphatocoverage, we don't need alphakill
+ if (vid.allowalphatocoverage)
+ {
+ if (r_transparent_alphatocoverage.integer)
+ {
+ GL_AlphaToCoverage((t->currentmaterialflags & MATERIALFLAG_ALPHATEST) != 0);
+ permutation &= ~SHADERPERMUTATION_ALPHAKILL;
+ }
+ else
+ GL_AlphaToCoverage(false);
+ }
+ }
else if (t->currentmaterialflags & MATERIALFLAG_MODELLIGHT)
{
if (r_glsl_offsetmapping.integer && ((R_TextureFlags(t->nmaptexture) & TEXF_ALPHA) || t->offsetbias != 0.0f))
if (r_shadow_bouncegrid_state.directional)
permutation |= SHADERPERMUTATION_BOUNCEGRIDDIRECTIONAL;
}
- GL_BlendFunc(t->currentlayers[0].blendfunc1, t->currentlayers[0].blendfunc2);
- blendfuncflags = R_BlendFuncFlags(t->currentlayers[0].blendfunc1, t->currentlayers[0].blendfunc2);
+ GL_BlendFunc(t->currentblendfunc[0], t->currentblendfunc[1]);
+ blendfuncflags = R_BlendFuncFlags(t->currentblendfunc[0], t->currentblendfunc[1]);
// when using alphatocoverage, we don't need alphakill
if (vid.allowalphatocoverage)
{
if (r_shadow_bouncegrid_state.directional)
permutation |= SHADERPERMUTATION_BOUNCEGRIDDIRECTIONAL;
}
- GL_BlendFunc(t->currentlayers[0].blendfunc1, t->currentlayers[0].blendfunc2);
- blendfuncflags = R_BlendFuncFlags(t->currentlayers[0].blendfunc1, t->currentlayers[0].blendfunc2);
+ GL_BlendFunc(t->currentblendfunc[0], t->currentblendfunc[1]);
+ blendfuncflags = R_BlendFuncFlags(t->currentblendfunc[0], t->currentblendfunc[1]);
// when using alphatocoverage, we don't need alphakill
if (vid.allowalphatocoverage)
{
{
if (r_glsl_permutation->loc_Color_Ambient >= 0) qglUniform3f(r_glsl_permutation->loc_Color_Ambient, t->render_modellight_ambient[0], t->render_modellight_ambient[1], t->render_modellight_ambient[2]);
}
+ else if (mode == SHADERMODE_LIGHTGRID)
+ {
+ if (r_glsl_permutation->loc_Color_Ambient >= 0) qglUniform3f(r_glsl_permutation->loc_Color_Ambient, t->render_lightmap_ambient[0], t->render_lightmap_ambient[1], t->render_lightmap_ambient[2]);
+ if (r_glsl_permutation->loc_Color_Diffuse >= 0) qglUniform3f(r_glsl_permutation->loc_Color_Diffuse, t->render_lightmap_diffuse[0], t->render_lightmap_diffuse[1], t->render_lightmap_diffuse[2]);
+ if (r_glsl_permutation->loc_Color_Specular >= 0) qglUniform3f(r_glsl_permutation->loc_Color_Specular, t->render_lightmap_specular[0], t->render_lightmap_specular[1], t->render_lightmap_specular[2]);
+ // other LightGrid uniforms handled below
+ }
else if (mode == SHADERMODE_LIGHTDIRECTION)
{
if (r_glsl_permutation->loc_Color_Ambient >= 0) qglUniform3f(r_glsl_permutation->loc_Color_Ambient, t->render_modellight_ambient[0], t->render_modellight_ambient[1], t->render_modellight_ambient[2]);
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, t->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);
+ if (r_glsl_permutation->loc_PixelToScreenTexCoord >= 0) qglUniform2f(r_glsl_permutation->loc_PixelToScreenTexCoord, 1.0f/r_fb.screentexturewidth, 1.0f/r_fb.screentextureheight);
if (r_glsl_permutation->loc_BounceGridMatrix >= 0) {Matrix4x4_Concat(&tempmatrix, &r_shadow_bouncegrid_state.matrix, &rsurface.matrix);Matrix4x4_ToArrayFloatGL(&tempmatrix, m16f);qglUniformMatrix4fv(r_glsl_permutation->loc_BounceGridMatrix, 1, false, m16f);}
if (r_glsl_permutation->loc_BounceGridIntensity >= 0) qglUniform1f(r_glsl_permutation->loc_BounceGridIntensity, r_shadow_bouncegrid_state.intensity*r_refdef.view.colorscale);
+ if (r_glsl_permutation->loc_LightGridMatrix >= 0 && r_refdef.scene.worldmodel)
+ {
+ float m9f[9];
+ Matrix4x4_Concat(&tempmatrix, &r_refdef.scene.worldmodel->brushq3.lightgridworldtotexturematrix, &rsurface.matrix);
+ Matrix4x4_ToArrayFloatGL(&tempmatrix, m16f);
+ qglUniformMatrix4fv(r_glsl_permutation->loc_LightGridMatrix, 1, false, m16f);
+ Matrix4x4_Normalize3(&tempmatrix, &rsurface.matrix);
+ Matrix4x4_ToArrayFloatGL(&tempmatrix, m16f);
+ m9f[0] = m16f[0];m9f[1] = m16f[1];m9f[2] = m16f[2];
+ m9f[3] = m16f[4];m9f[4] = m16f[5];m9f[5] = m16f[6];
+ m9f[6] = m16f[8];m9f[7] = m16f[9];m9f[8] = m16f[10];
+ qglUniformMatrix3fv(r_glsl_permutation->loc_LightGridNormalMatrix, 1, false, m9f);
+ }
if (r_glsl_permutation->tex_Texture_First >= 0) R_Mesh_TexBind(r_glsl_permutation->tex_Texture_First , r_texture_white );
if (r_glsl_permutation->tex_Texture_Second >= 0) R_Mesh_TexBind(r_glsl_permutation->tex_Texture_Second , r_texture_white );
}
}
if (r_glsl_permutation->tex_Texture_BounceGrid >= 0) R_Mesh_TexBind(r_glsl_permutation->tex_Texture_BounceGrid, r_shadow_bouncegrid_state.texture);
+ if (r_glsl_permutation->tex_Texture_LightGrid >= 0 && r_refdef.scene.worldmodel) R_Mesh_TexBind(r_glsl_permutation->tex_Texture_LightGrid, r_refdef.scene.worldmodel->brushq3.lightgridtexture);
CHECKGLERROR
break;
}
if (r_glsl_permutation->loc_ShadowMap_Parameters >= 0) qglUniform4f( r_glsl_permutation->loc_ShadowMap_Parameters , r_shadow_lightshadowmap_parameters[0], r_shadow_lightshadowmap_parameters[1], r_shadow_lightshadowmap_parameters[2], r_shadow_lightshadowmap_parameters[3]);
if (r_glsl_permutation->loc_SpecularPower >= 0) qglUniform1f( r_glsl_permutation->loc_SpecularPower , (r_shadow_gloss.integer == 2 ? r_shadow_gloss2exponent.value : r_shadow_glossexponent.value) * (r_shadow_glossexact.integer ? 0.25f : 1.0f) - 1.0f);
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);
+ if (r_glsl_permutation->loc_PixelToScreenTexCoord >= 0) qglUniform2f( r_glsl_permutation->loc_PixelToScreenTexCoord , 1.0f/r_fb.screentexturewidth, 1.0f/r_fb.screentextureheight);
if (r_glsl_permutation->tex_Texture_Attenuation >= 0) R_Mesh_TexBind(r_glsl_permutation->tex_Texture_Attenuation , r_shadow_attenuationgradienttexture );
if (r_glsl_permutation->tex_Texture_ScreenNormalMap >= 0) R_Mesh_TexBind(r_glsl_permutation->tex_Texture_ScreenNormalMap , r_shadow_prepassgeometrynormalmaptexture );
}
// _luma is supported only for tenebrae compatibility
+ // _blend and .blend are supported only for Q3 & QL compatibility, this hack can be removed if better Q3 shader support is implemented
// _glow is the preferred name
mymiplevel = savemiplevel;
- if (skinframe->glow == NULL && ((pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_glow", skinframe->basename), false, false, false, &mymiplevel)) || (pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_luma", skinframe->basename), false, false, false, &mymiplevel))))
+ if (skinframe->glow == NULL && ((pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_glow", skinframe->basename), false, false, false, &mymiplevel)) || (pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s.blend", skinframe->basename), false, false, false, &mymiplevel)) || (pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_blend", skinframe->basename), false, false, false, &mymiplevel)) || (pixels = loadimagepixelsbgra(va(vabuf, sizeof(vabuf), "%s_luma", skinframe->basename), false, false, false, &mymiplevel))))
{
skinframe->glow = R_LoadTexture2D (r_main_texturepool, va(vabuf, sizeof(vabuf), "%s_glow", skinframe->basename), image_width, image_height, pixels, vid.sRGB3D ? TEXTYPE_SRGB_BGRA : TEXTYPE_BGRA, textureflags & (gl_texturecompression_glow.integer && gl_texturecompression.integer ? ~0 : ~TEXF_COMPRESS), mymiplevel, NULL);
#ifndef USE_GLES2
#endif
}
+extern unsigned int r_shadow_occlusion_buf;
+
static void gl_main_shutdown(void)
{
R_RenderTarget_FreeUnused(true);
#endif
break;
}
-
+ r_shadow_occlusion_buf = 0;
r_numqueries = 0;
r_maxqueries = 0;
memset(r_queries, 0, sizeof(r_queries));
Cvar_RegisterVariable(&r_lerplightstyles);
Cvar_RegisterVariable(&r_waterscroll);
Cvar_RegisterVariable(&r_bloom);
+ Cvar_RegisterVariable(&r_colorfringe);
Cvar_RegisterVariable(&r_bloom_colorscale);
Cvar_RegisterVariable(&r_bloom_brighten);
Cvar_RegisterVariable(&r_bloom_blur);
qboolean R_CanSeeBox(int numsamples, vec_t eyejitter, vec_t entboxenlarge, vec_t entboxexpand, vec_t pad, vec3_t eye, vec3_t entboxmins, vec3_t entboxmaxs)
{
- int i;
+ long unsigned int i;
+ int j;
vec3_t eyemins, eyemaxs;
vec3_t boxmins, boxmaxs;
vec3_t padmins, padmaxs;
{
for (i = 0; i < sizeof(positions) / sizeof(positions[0]); i++)
{
+ trace_t trace;
VectorCopy(eye, start);
end[0] = boxmins[0] + (boxmaxs[0] - boxmins[0]) * positions[i][0];
end[1] = boxmins[1] + (boxmaxs[1] - boxmins[1]) * positions[i][1];
end[2] = boxmins[2] + (boxmaxs[2] - boxmins[2]) * positions[i][2];
//trace_t trace = CL_TraceLine(start, end, MOVE_NORMAL, NULL, SUPERCONTENTS_SOLID, SUPERCONTENTS_SKY, MATERIALFLAGMASK_TRANSLUCENT, 0.0f, true, false, NULL, true, true);
- trace_t trace = CL_Cache_TraceLineSurfaces(start, end, MOVE_NORMAL, SUPERCONTENTS_SOLID, 0, MATERIALFLAGMASK_TRANSLUCENT);
+ trace = CL_Cache_TraceLineSurfaces(start, end, MOVE_NORMAL, SUPERCONTENTS_SOLID, 0, MATERIALFLAGMASK_TRANSLUCENT);
// not picky - if the trace ended anywhere in the box we're good
if (BoxesOverlap(trace.endpos, trace.endpos, padmins, padmaxs))
return true;
return true;
// try various random positions
- for (i = 0; i < numsamples; i++)
+ for (j = 0; j < numsamples; j++)
{
VectorSet(start, lhrandom(eyemins[0], eyemaxs[0]), lhrandom(eyemins[1], eyemaxs[1]), lhrandom(eyemins[2], eyemaxs[2]));
VectorSet(end, lhrandom(boxmins[0], boxmaxs[0]), lhrandom(boxmins[1], boxmaxs[1]), lhrandom(boxmins[2], boxmaxs[2]));
float viewscalefpsadjusted = 1.0f;
-static void R_GetScaledViewSize(int width, int height, int *outwidth, int *outheight)
-{
- float scale = r_viewscale.value * sqrt(viewscalefpsadjusted);
- scale = bound(0.03125f, scale, 1.0f);
- *outwidth = (int)ceil(width * scale);
- *outheight = (int)ceil(height * scale);
-}
-
void R_SetupView(qboolean allowwaterclippingplane, int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight)
{
const float *customclipplane = NULL;
if (r->depthisrenderbuffer)
r->depthtexture = R_LoadTextureRenderBuffer(r_main_texturepool, va(vabuf, sizeof(vabuf), "renderbuffer%i_depth_type%i", i, (int)r->depthtextype), r->texturewidth, r->textureheight, r->depthtextype);
else
- r->depthtexture = R_LoadTexture2D(r_main_texturepool, va(vabuf, sizeof(vabuf), "rendertarget%i_depth_type%i", i, j, (int)r->depthtextype), r->texturewidth, r->textureheight, NULL, r->depthtextype, TEXF_RENDERTARGET | TEXF_FORCELINEAR | TEXF_CLAMP, -1, NULL);
+ r->depthtexture = R_LoadTexture2D(r_main_texturepool, va(vabuf, sizeof(vabuf), "rendertarget%i_depth_type%i", i, (int)r->depthtextype), r->texturewidth, r->textureheight, NULL, r->depthtextype, TEXF_RENDERTARGET | TEXF_FORCELINEAR | TEXF_CLAMP, -1, NULL);
}
r->fbo = R_Mesh_CreateFramebufferObject(r->depthtexture, r->colortexture[0], r->colortexture[1], r->colortexture[2], r->colortexture[3]);
}
return r;
}
-static void R_Water_StartFrame(void)
+static void R_Water_StartFrame(int viewwidth, int viewheight)
{
int waterwidth, waterheight;
- if (vid.width > (int)vid.maxtexturesize_2d || vid.height > (int)vid.maxtexturesize_2d)
+ if (viewwidth > (int)vid.maxtexturesize_2d || viewheight > (int)vid.maxtexturesize_2d)
return;
// set waterwidth and waterheight to the water resolution that will be
// used (often less than the screen resolution for faster rendering)
- waterwidth = (int)bound(1, r_refdef.view.width * r_water_resolutionmultiplier.value, r_refdef.view.width);
- waterheight = (int)bound(1, r_refdef.view.height * r_water_resolutionmultiplier.value, r_refdef.view.height);
- R_GetScaledViewSize(waterwidth, waterheight, &waterwidth, &waterheight);
+ waterwidth = (int)bound(16, viewwidth * r_water_resolutionmultiplier.value, viewwidth);
+ waterheight = (int)bound(16, viewheight * r_water_resolutionmultiplier.value, viewheight);
if (!r_water.integer || r_showsurfaces.integer)
waterwidth = waterheight = 0;
static void R_Bloom_StartFrame(void)
{
- int bloomtexturewidth, bloomtextureheight, screentexturewidth, screentextureheight;
- int viewwidth, viewheight;
+ int screentexturewidth, screentextureheight;
textype_t textype = TEXTYPE_COLORBUFFER;
+ double scale;
// clear the pointers to rendertargets from last frame as they're stale
r_fb.rt_screen = NULL;
adjust = (targetframetime - actualframetime) * r_viewscale_fpsscaling_multiply.value;
adjust = bound(-r_viewscale_fpsscaling_stepmax.value, adjust, r_viewscale_fpsscaling_stepmax.value);
if (r_viewscale_fpsscaling_stepsize.value > 0)
- adjust = (int)(adjust / r_viewscale_fpsscaling_stepsize.value) * r_viewscale_fpsscaling_stepsize.value;
+ {
+ if (adjust > 0)
+ adjust = floor(adjust / r_viewscale_fpsscaling_stepsize.value) * r_viewscale_fpsscaling_stepsize.value;
+ else
+ adjust = ceil(adjust / r_viewscale_fpsscaling_stepsize.value) * r_viewscale_fpsscaling_stepsize.value;
+ }
viewscalefpsadjusted += adjust;
viewscalefpsadjusted = bound(r_viewscale_fpsscaling_min.value, viewscalefpsadjusted, 1.0f);
}
else
viewscalefpsadjusted = 1.0f;
- R_GetScaledViewSize(r_refdef.view.width, r_refdef.view.height, &viewwidth, &viewheight);
+ scale = r_viewscale.value * sqrt(viewscalefpsadjusted);
+ if (vid.samples)
+ scale *= sqrt(vid.samples); // supersampling
+ scale = bound(0.03125f, scale, 4.0f);
+ screentexturewidth = (int)ceil(r_refdef.view.width * scale);
+ screentextureheight = (int)ceil(r_refdef.view.height * scale);
+ screentexturewidth = bound(1, screentexturewidth, (int)vid.maxtexturesize_2d);
+ screentextureheight = bound(1, screentextureheight, (int)vid.maxtexturesize_2d);
// set bloomwidth and bloomheight to the bloom resolution that will be
// used (often less than the screen resolution for faster rendering)
- r_fb.bloomwidth = bound(1, r_bloom_resolution.integer, vid.width);
- r_fb.bloomheight = r_fb.bloomwidth * vid.height / vid.width;
- r_fb.bloomheight = bound(1, r_fb.bloomheight, vid.height);
+ r_fb.bloomheight = bound(1, r_bloom_resolution.value * 0.75f, screentextureheight);
+ r_fb.bloomwidth = r_fb.bloomheight * screentexturewidth / screentextureheight;
+ r_fb.bloomwidth = bound(1, r_fb.bloomwidth, screentexturewidth);
r_fb.bloomwidth = bound(1, r_fb.bloomwidth, (int)vid.maxtexturesize_2d);
r_fb.bloomheight = bound(1, r_fb.bloomheight, (int)vid.maxtexturesize_2d);
- // calculate desired texture sizes
- screentexturewidth = viewwidth;
- screentextureheight = viewheight;
- bloomtexturewidth = r_fb.bloomwidth;
- bloomtextureheight = r_fb.bloomheight;
-
if ((r_bloom.integer || (!R_Stereo_Active() && (r_motionblur.value > 0 || r_damageblur.value > 0))) && ((r_bloom_resolution.integer < 4 || r_bloom_blur.value < 1 || r_bloom_blur.value >= 512) || r_refdef.view.width > (int)vid.maxtexturesize_2d || r_refdef.view.height > (int)vid.maxtexturesize_2d))
{
Cvar_SetValueQuick(&r_bloom, 0);
Cvar_SetValueQuick(&r_motionblur, 0);
Cvar_SetValueQuick(&r_damageblur, 0);
}
+ if (!r_bloom.integer)
+ r_fb.bloomwidth = r_fb.bloomheight = 0;
// allocate motionblur ghost texture if needed - this is the only persistent texture and is only useful on the main view
if (r_refdef.view.ismain && (r_fb.screentexturewidth != screentexturewidth || r_fb.screentextureheight != screentextureheight || r_fb.textype != textype))
}
}
- if (r_bloom.integer)
- {
- // bloom texture is a different resolution
- r_fb.bloomwidth = bound(1, r_bloom_resolution.integer, r_refdef.view.width);
- r_fb.bloomheight = r_fb.bloomwidth * r_refdef.view.height / r_refdef.view.width;
- r_fb.bloomheight = bound(1, r_fb.bloomheight, r_refdef.view.height);
- }
- else
- r_fb.bloomwidth = r_fb.bloomheight = 0;
-
r_fb.rt_screen = R_RenderTarget_Get(screentexturewidth, screentextureheight, TEXTYPE_DEPTHBUFFER24STENCIL8, true, textype, TEXTYPE_UNUSED, TEXTYPE_UNUSED, TEXTYPE_UNUSED);
r_refdef.view.clear = true;
if (r_glsl_permutation->loc_UserVec3 >= 0) qglUniform4f(r_glsl_permutation->loc_UserVec3 , uservecs[2][0], uservecs[2][1], uservecs[2][2], uservecs[2][3]);
if (r_glsl_permutation->loc_UserVec4 >= 0) qglUniform4f(r_glsl_permutation->loc_UserVec4 , uservecs[3][0], uservecs[3][1], uservecs[3][2], uservecs[3][3]);
if (r_glsl_permutation->loc_Saturation >= 0) qglUniform1f(r_glsl_permutation->loc_Saturation , r_glsl_saturation.value);
- if (r_glsl_permutation->loc_PixelToScreenTexCoord >= 0) qglUniform2f(r_glsl_permutation->loc_PixelToScreenTexCoord, 1.0f/vid.width, 1.0f/vid.height);
+ if (r_glsl_permutation->loc_PixelToScreenTexCoord >= 0) qglUniform2f(r_glsl_permutation->loc_PixelToScreenTexCoord, 1.0f/r_fb.screentexturewidth, 1.0f/r_fb.screentextureheight);
if (r_glsl_permutation->loc_BloomColorSubtract >= 0) qglUniform4f(r_glsl_permutation->loc_BloomColorSubtract , r_bloom_colorsubtract.value, r_bloom_colorsubtract.value, r_bloom_colorsubtract.value, 0.0f);
+ if (r_glsl_permutation->loc_ColorFringe >= 0) qglUniform1f(r_glsl_permutation->loc_ColorFringe, r_colorfringe.value );
break;
}
R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
viewcolortexture = r_fb.rt_screen->colortexture[0];
viewx = 0;
viewy = 0;
- viewwidth = width;
- viewheight = height;
+ viewwidth = r_fb.rt_screen->texturewidth;
+ viewheight = r_fb.rt_screen->textureheight;
}
- R_Water_StartFrame();
+ R_Water_StartFrame(viewwidth, viewheight);
CHECKGLERROR
if (r_timereport_active)
static void R_DrawLocs(void);
static void R_DrawEntityBBoxes(prvm_prog_t *prog);
static void R_DrawModelDecals(void);
-extern cvar_t cl_decals_newsystem;
extern qboolean r_shadow_usingdeferredprepass;
extern int r_shadow_shadowmapatlas_modelshadows_size;
void R_RenderScene(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight)
if (cl.csqc_vidvars.drawworld)
{
- if (cl_decals_newsystem.integer)
- {
- R_DrawModelDecals();
- if (r_timereport_active)
- R_TimeReport("modeldecals");
- }
- else
- {
- R_DrawDecals();
- if (r_timereport_active)
- R_TimeReport("decals");
- }
+ R_DrawModelDecals();
+ if (r_timereport_active)
+ R_TimeReport("modeldecals");
R_DrawParticles();
if (r_timereport_active)
if (edict->priv.server->free)
continue;
// exclude the following for now, as they don't live in world coordinate space and can't be solid:
- if (PRVM_serveredictedict(edict, tag_entity) != 0)
+ if (PRVM_gameedictedict(edict, tag_entity) != 0)
continue;
- if (PRVM_serveredictedict(edict, viewmodelforclient) != 0)
+ if (prog == SVVM_prog && PRVM_serveredictedict(edict, viewmodelforclient) != 0)
continue;
VectorLerp(edict->priv.server->areamins, 0.5f, edict->priv.server->areamaxs, center);
R_MeshQueue_AddTransparent(TRANSPARENTSORT_DISTANCE, center, R_DrawEntityBBoxes_Callback, (entity_render_t *)NULL, i, (rtlight_t *)prog);
}
}
-static void R_Texture_AddLayer(texture_t *t, qboolean depthmask, int blendfunc1, int blendfunc2, texturelayertype_t type, rtexture_t *texture, const matrix4x4_t *matrix, float r, float g, float b, float a)
-{
- texturelayer_t *layer;
- layer = t->currentlayers + t->currentnumlayers++;
- layer->type = type;
- layer->depthmask = depthmask;
- layer->blendfunc1 = blendfunc1;
- layer->blendfunc2 = blendfunc2;
- layer->texture = texture;
- layer->texmatrix = *matrix;
- layer->color[0] = r;
- layer->color[1] = g;
- layer->color[2] = b;
- layer->color[3] = a;
-}
-
static qboolean R_TestQ3WaveFunc(q3wavefunc_t func, const float *parms)
{
if(parms[0] == 0 && parms[1] == 0)
t->currentmaterialflags |= MATERIALFLAG_MODELLIGHT;
if (rsurface.entity->render_rtlight_disabled)
t->currentmaterialflags |= MATERIALFLAG_NORTLIGHT;
+ if (rsurface.entity->render_lightgrid)
+ t->currentmaterialflags |= MATERIALFLAG_LIGHTGRID;
if (t->currentmaterialflags & MATERIALFLAG_CUSTOMBLEND && !(R_BlendFuncFlags(t->customblendfunc[0], t->customblendfunc[1]) & BLENDFUNC_ALLOWS_COLORMOD))
{
// some CUSTOMBLEND blendfuncs are too weird, we have to ignore colormod and view colorscale
- t->currentmaterialflags = t->currentmaterialflags | MATERIALFLAG_NORTLIGHT;
+ t->currentmaterialflags = (t->currentmaterialflags | MATERIALFLAG_MODELLIGHT | MATERIALFLAG_NORTLIGHT) & ~MATERIALFLAG_LIGHTGRID;
for (q = 0; q < 3; q++)
{
t->render_glowmod[q] = rsurface.entity->glowmod[q];
else if ((t->currentmaterialflags & MATERIALFLAG_FULLBRIGHT) || !(rsurface.ent_flags & RENDER_LIGHT))
{
// fullbright is basically MATERIALFLAG_MODELLIGHT but with ambient locked to 1,1,1 and no shading
- t->currentmaterialflags = t->currentmaterialflags | MATERIALFLAG_NORTLIGHT | MATERIALFLAG_MODELLIGHT;
+ t->currentmaterialflags = (t->currentmaterialflags | MATERIALFLAG_NORTLIGHT | MATERIALFLAG_MODELLIGHT) & ~MATERIALFLAG_LIGHTGRID;
for (q = 0; q < 3; q++)
{
t->render_glowmod[q] = rsurface.entity->render_glowmod[q] * r_refdef.view.colorscale;
t->render_rtlight_specular[q] = 0;
}
}
+ else if (t->currentmaterialflags & MATERIALFLAG_LIGHTGRID)
+ {
+ t->currentmaterialflags &= ~MATERIALFLAG_MODELLIGHT;
+ 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_ambient[q] = 0;
+ t->render_modellight_diffuse[q] = 0;
+ t->render_modellight_specular[q] = 0;
+ t->render_lightmap_ambient[q] = rsurface.entity->render_lightmap_ambient[q] * r_refdef.view.colorscale;
+ t->render_lightmap_diffuse[q] = rsurface.entity->render_lightmap_diffuse[q] * 2 * r_refdef.view.colorscale;
+ t->render_lightmap_specular[q] = rsurface.entity->render_lightmap_specular[q] * 2 * r_refdef.view.colorscale;
+ t->render_rtlight_diffuse[q] = rsurface.entity->render_rtlight_diffuse[q] * r_refdef.view.colorscale;
+ t->render_rtlight_specular[q] = rsurface.entity->render_rtlight_specular[q] * r_refdef.view.colorscale;
+ }
+ }
else if ((rsurface.ent_flags & (RENDER_DYNAMICMODELLIGHT | RENDER_CUSTOMIZEDMODELLIGHT)) || rsurface.modeltexcoordlightmap2f == NULL)
{
// ambient + single direction light (modellight)
- t->currentmaterialflags |= MATERIALFLAG_MODELLIGHT;
+ t->currentmaterialflags = (t->currentmaterialflags | MATERIALFLAG_MODELLIGHT) & ~MATERIALFLAG_LIGHTGRID;
for (q = 0; q < 3; q++)
{
t->render_glowmod[q] = rsurface.entity->render_glowmod[q] * r_refdef.view.colorscale;
//
// FIXME: this is fine for effects but CSQC polygons should be subject
// to lighting.
- t->currentmaterialflags &= ~MATERIALFLAG_MODELLIGHT;
+ t->currentmaterialflags &= ~(MATERIALFLAG_MODELLIGHT | MATERIALFLAG_LIGHTGRID);
for (q = 0; q < 3; q++)
{
t->render_glowmod[q] = rsurface.entity->render_glowmod[q] * r_refdef.view.colorscale;
}
}
- t->currentnumlayers = 0;
- if (t->currentmaterialflags & MATERIALFLAG_WALL)
+ t->currentblendfunc[0] = GL_ONE;
+ t->currentblendfunc[1] = GL_ZERO;
+ if (t->currentmaterialflags & MATERIALFLAG_ADD)
{
- int blendfunc1, blendfunc2;
- qboolean depthmask;
- if (t->currentmaterialflags & MATERIALFLAG_ADD)
- {
- blendfunc1 = GL_SRC_ALPHA;
- blendfunc2 = GL_ONE;
- }
- else if (t->currentmaterialflags & MATERIALFLAG_ALPHA)
- {
- blendfunc1 = GL_SRC_ALPHA;
- blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
- }
- else if (t->currentmaterialflags & MATERIALFLAG_CUSTOMBLEND)
- {
- blendfunc1 = t->customblendfunc[0];
- blendfunc2 = t->customblendfunc[1];
- }
- else
- {
- blendfunc1 = GL_ONE;
- blendfunc2 = GL_ZERO;
- }
- depthmask = !(t->currentmaterialflags & MATERIALFLAG_BLENDED);
- if (t->currentmaterialflags & MATERIALFLAG_MODELLIGHT)
- {
- // basic lit geometry
- R_Texture_AddLayer(t, depthmask, blendfunc1, blendfunc2, TEXTURELAYERTYPE_LITTEXTURE, t->basetexture, &t->currenttexmatrix, 2, 2, 2, t->currentalpha);
- // add pants/shirt if needed
- if (VectorLength2(t->render_colormap_pants) >= (1.0f / 1048576.0f) && t->pantstexture)
- R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_LITTEXTURE, t->pantstexture, &t->currenttexmatrix, 2 * t->render_colormap_pants[0], 2 * t->render_colormap_pants[1], 2 * t->render_colormap_pants[2], t->currentalpha);
- if (VectorLength2(t->render_colormap_shirt) >= (1.0f / 1048576.0f) && t->shirttexture)
- R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_LITTEXTURE, t->shirttexture, &t->currenttexmatrix, 2 * t->render_colormap_shirt[0], 2 * t->render_colormap_shirt[1], 2 * t->render_colormap_shirt[2], t->currentalpha);
- }
- else
- {
- // basic lit geometry
- R_Texture_AddLayer(t, depthmask, blendfunc1, blendfunc2, TEXTURELAYERTYPE_LITTEXTURE, t->basetexture, &t->currenttexmatrix, t->render_lightmap_diffuse[0], t->render_lightmap_diffuse[1], t->render_lightmap_diffuse[2], t->currentalpha);
- // add pants/shirt if needed
- if (VectorLength2(t->render_colormap_pants) >= (1.0f / 1048576.0f) && t->pantstexture)
- R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_LITTEXTURE, t->pantstexture, &t->currenttexmatrix, t->render_colormap_pants[0] * t->render_lightmap_diffuse[0], t->render_colormap_pants[1] * t->render_lightmap_diffuse[1], t->render_colormap_pants[2] * t->render_lightmap_diffuse[2], t->currentalpha);
- if (VectorLength2(t->render_colormap_shirt) >= (1.0f / 1048576.0f) && t->shirttexture)
- R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_LITTEXTURE, t->shirttexture, &t->currenttexmatrix, t->render_colormap_shirt[0] * t->render_lightmap_diffuse[0], t->render_colormap_shirt[1] * t->render_lightmap_diffuse[1], t->render_colormap_shirt[2] * t->render_lightmap_diffuse[2], t->currentalpha);
- // now add ambient passes if needed
- if (VectorLength2(t->render_lightmap_ambient) >= (1.0f/1048576.0f))
- {
- R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_TEXTURE, t->basetexture, &t->currenttexmatrix, t->render_lightmap_ambient[0], t->render_lightmap_ambient[1], t->render_lightmap_ambient[2], t->currentalpha);
- if (VectorLength2(t->render_colormap_pants) >= (1.0f / 1048576.0f) && t->pantstexture)
- R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_TEXTURE, t->pantstexture, &t->currenttexmatrix, t->render_colormap_pants[0] * t->render_lightmap_ambient[0], t->render_colormap_pants[1] * t->render_lightmap_ambient[1], t->render_colormap_pants[2] * t->render_lightmap_ambient[2], t->currentalpha);
- if (VectorLength2(t->render_colormap_shirt) >= (1.0f / 1048576.0f) && t->shirttexture)
- R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_TEXTURE, t->shirttexture, &t->currenttexmatrix, t->render_colormap_shirt[0] * t->render_lightmap_ambient[0], t->render_colormap_shirt[1] * t->render_lightmap_ambient[1], t->render_colormap_shirt[2] * t->render_lightmap_ambient[2], t->currentalpha);
- }
- }
- if (t->glowtexture != NULL && !gl_lightmaps.integer)
- R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_TEXTURE, t->glowtexture, &t->currenttexmatrix, t->render_glowmod[0], t->render_glowmod[1], t->render_glowmod[2], t->currentalpha);
- if (r_refdef.fogenabled && !(t->currentmaterialflags & MATERIALFLAG_ADD))
- {
- // if this is opaque use alpha blend which will darken the earlier
- // passes cheaply.
- //
- // if this is an alpha blended material, all the earlier passes
- // were darkened by fog already, so we only need to add the fog
- // color ontop through the fog mask texture
- //
- // if this is an additive blended material, all the earlier passes
- // were darkened by fog already, and we should not add fog color
- // (because the background was not darkened, there is no fog color
- // that was lost behind it).
- R_Texture_AddLayer(t, false, GL_SRC_ALPHA, (t->currentmaterialflags & MATERIALFLAG_BLENDED) ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA, TEXTURELAYERTYPE_FOG, t->fogtexture, &t->currenttexmatrix, r_refdef.fogcolor[0], r_refdef.fogcolor[1], r_refdef.fogcolor[2], t->currentalpha);
- }
+ t->currentblendfunc[0] = GL_SRC_ALPHA;
+ t->currentblendfunc[1] = GL_ONE;
+ }
+ else if (t->currentmaterialflags & MATERIALFLAG_ALPHA)
+ {
+ t->currentblendfunc[0] = GL_SRC_ALPHA;
+ t->currentblendfunc[1] = GL_ONE_MINUS_SRC_ALPHA;
+ }
+ else if (t->currentmaterialflags & MATERIALFLAG_CUSTOMBLEND)
+ {
+ t->currentblendfunc[0] = t->customblendfunc[0];
+ t->currentblendfunc[1] = t->customblendfunc[1];
}
return t;
void RSurf_ActiveCustomEntity(const matrix4x4_t *matrix, const matrix4x4_t *inversematrix, int entflags, double shadertime, float r, float g, float b, float a, int numvertices, const float *vertex3f, const float *texcoord2f, const float *normal3f, const float *svector3f, const float *tvector3f, const float *color4f, int numtriangles, const int *element3i, const unsigned short *element3s, qboolean wantnormals, qboolean wanttangents)
{
rsurface.entity = r_refdef.scene.worldentity;
+ if (r != 1.0f || g != 1.0f || b != 1.0f || a != 1.0f) {
+ // HACK to provide a valid entity with modded colors to R_GetCurrentTexture.
+ // A better approach could be making this copy only once per frame.
+ static entity_render_t custom_entity;
+ int q;
+ custom_entity = *rsurface.entity;
+ for (q = 0; q < 3; ++q) {
+ float colormod = q == 0 ? r : q == 1 ? g : b;
+ custom_entity.render_fullbright[q] *= colormod;
+ custom_entity.render_modellight_ambient[q] *= colormod;
+ custom_entity.render_modellight_diffuse[q] *= colormod;
+ custom_entity.render_lightmap_ambient[q] *= colormod;
+ custom_entity.render_lightmap_diffuse[q] *= colormod;
+ custom_entity.render_rtlight_diffuse[q] *= colormod;
+ }
+ custom_entity.alpha *= a;
+ rsurface.entity = &custom_entity;
+ }
rsurface.skeleton = NULL;
rsurface.ent_skinnum = 0;
rsurface.ent_qwskin = -1;
static void R_DrawTextureSurfaceList_Sky(int texturenumsurfaces, const msurface_t **texturesurfacelist)
{
- int i, j;
+ int j;
+ const float *v;
+ float p[3], mins[3], maxs[3];
+ int scissor[4];
// transparent sky would be ridiculous
if (rsurface.texture->currentmaterialflags & MATERIALFLAGMASK_DEPTHSORTED)
return;
// add the vertices of the surfaces to a world bounding box so we can scissor the sky render later
if (r_sky_scissor.integer)
{
- RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ALLOWMULTIDRAW, texturenumsurfaces, texturesurfacelist);
- for (i = 0; i < texturenumsurfaces; i++)
+ RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_NOGAPS, texturenumsurfaces, texturesurfacelist);
+ for (j = 0, v = rsurface.batchvertex3f + 3 * rsurface.batchfirstvertex; j < rsurface.batchnumvertices; j++, v += 3)
{
- const msurface_t *surf = texturesurfacelist[i];
- const float *v;
- float p[3];
- float mins[3], maxs[3];
- int scissor[4];
- for (j = 0, v = rsurface.batchvertex3f + 3 * surf->num_firstvertex; j < surf->num_vertices; j++, v += 3)
+ Matrix4x4_Transform(&rsurface.matrix, v, p);
+ if (j > 0)
{
- Matrix4x4_Transform(&rsurface.matrix, v, p);
- if (j > 0)
- {
- if (mins[0] > p[0]) mins[0] = p[0];
- if (mins[1] > p[1]) mins[1] = p[1];
- if (mins[2] > p[2]) mins[2] = p[2];
- if (maxs[0] < p[0]) maxs[0] = p[0];
- if (maxs[1] < p[1]) maxs[1] = p[1];
- if (maxs[2] < p[2]) maxs[2] = p[2];
- }
- else
- {
- VectorCopy(p, mins);
- VectorCopy(p, maxs);
- }
+ if (mins[0] > p[0]) mins[0] = p[0];
+ if (mins[1] > p[1]) mins[1] = p[1];
+ if (mins[2] > p[2]) mins[2] = p[2];
+ if (maxs[0] < p[0]) maxs[0] = p[0];
+ if (maxs[1] < p[1]) maxs[1] = p[1];
+ if (maxs[2] < p[2]) maxs[2] = p[2];
+ }
+ else
+ {
+ VectorCopy(p, mins);
+ VectorCopy(p, maxs);
}
- if (!R_ScissorForBBox(mins, maxs, scissor))
+ }
+ if (!R_ScissorForBBox(mins, maxs, scissor))
+ {
+ if (skyscissor[2])
{
- if (skyscissor[2])
+ if (skyscissor[0] > scissor[0])
{
- if (skyscissor[0] > scissor[0])
- {
- skyscissor[2] += skyscissor[0] - scissor[0];
- skyscissor[0] = scissor[0];
- }
- if (skyscissor[1] > scissor[1])
- {
- skyscissor[3] += skyscissor[1] - scissor[1];
- skyscissor[1] = scissor[1];
- }
- if (skyscissor[0] + skyscissor[2] < scissor[0] + scissor[2])
- skyscissor[2] = scissor[0] + scissor[2] - skyscissor[0];
- if (skyscissor[1] + skyscissor[3] < scissor[1] + scissor[3])
- skyscissor[3] = scissor[1] + scissor[3] - skyscissor[1];
+ skyscissor[2] += skyscissor[0] - scissor[0];
+ skyscissor[0] = scissor[0];
}
- else
- Vector4Copy(scissor, skyscissor);
+ if (skyscissor[1] > scissor[1])
+ {
+ skyscissor[3] += skyscissor[1] - scissor[1];
+ skyscissor[1] = scissor[1];
+ }
+ if (skyscissor[0] + skyscissor[2] < scissor[0] + scissor[2])
+ skyscissor[2] = scissor[0] + scissor[2] - skyscissor[0];
+ if (skyscissor[1] + skyscissor[3] < scissor[1] + scissor[3])
+ skyscissor[3] = scissor[1] + scissor[3] - skyscissor[1];
}
+ else
+ Vector4Copy(scissor, skyscissor);
}
}
R_DrawTextureSurfaceList_DepthOnly(texturenumsurfaces, texturesurfacelist);
else if (prepass)
{
- if (!rsurface.texture->currentnumlayers)
+ if (!(rsurface.texture->currentmaterialflags & MATERIALFLAG_WALL))
return;
if (rsurface.texture->currentmaterialflags & MATERIALFLAGMASK_DEPTHSORTED)
R_ProcessTransparentTextureSurfaceList(texturenumsurfaces, texturesurfacelist);
}
else if ((rsurface.texture->currentmaterialflags & MATERIALFLAG_SKY) && (!r_showsurfaces.integer || r_showsurfaces.integer == 3))
R_DrawTextureSurfaceList_Sky(texturenumsurfaces, texturesurfacelist);
- else if (!rsurface.texture->currentnumlayers)
+ else if (!(rsurface.texture->currentmaterialflags & MATERIALFLAG_WALL))
return;
else if (((rsurface.texture->currentmaterialflags & MATERIALFLAGMASK_DEPTHSORTED) || (r_showsurfaces.integer == 3 && (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST))))
{
float worldmaxs[3];
entity_render_t *ent;
- if (!cl_decals_newsystem.integer)
- return;
-
worldmins[0] = worldorigin[0] - worldsize;
worldmins[1] = worldorigin[1] - worldsize;
worldmins[2] = worldorigin[2] - worldsize;
{
r_decalsystem_splatqueue_t *queue;
- if (!cl_decals_newsystem.integer || r_decalsystem_numqueued == MAX_DECALSYSTEM_QUEUE)
+ if (r_decalsystem_numqueued == MAX_DECALSYSTEM_QUEUE)
return;
queue = &r_decalsystem_queue[r_decalsystem_numqueued++];
r_refdef.stats[r_stat_totaldecals] += numdecals;
- if (r_showsurfaces.integer)
+ if (r_showsurfaces.integer || !r_drawdecals.integer)
return;
R_DrawModelDecals_Entity(r_refdef.scene.worldentity);
}
}
-extern cvar_t mod_collision_bih;
static void R_DrawDebugModel(void)
{
entity_render_t *ent = rsurface.entity;
{
RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_NOGAPS, 1, &surface);
GL_CullFace((rsurface.texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE) ? GL_NONE : r_refdef.view.cullface_back);
- if (!rsurface.texture->currentlayers->depthmask)
+ if ((rsurface.texture->currentmaterialflags & MATERIALFLAG_BLENDED))
GL_Color(c, 0, 0, 1.0f);
else if (ent == r_refdef.scene.worldentity)
GL_Color(c, c, c, 1.0f);
if ((rsurface.texture->currentmaterialflags & flagsmask) && surface->num_triangles)
{
RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ARRAY_NORMAL | BATCHNEED_ARRAY_VECTOR | BATCHNEED_NOGAPS, 1, &surface);
- if (!rsurface.texture->currentlayers->depthmask)
+ if ((rsurface.texture->currentmaterialflags & MATERIALFLAG_BLENDED))
GL_Color(r_refdef.view.colorscale, 0, 0, r_showtris.value);
else if (ent == r_refdef.scene.worldentity)
GL_Color(r_refdef.view.colorscale, r_refdef.view.colorscale, r_refdef.view.colorscale, r_showtris.value);
offsetx = 0.5f * width * vid_conwidth.value / vid.width;
offsety = 0;
}
- surf = Mod_Mesh_AddSurface(mod, Mod_Mesh_GetTexture(mod, "white", 0, 0, MATERIALFLAG_WALL | MATERIALFLAG_VERTEXCOLOR | MATERIALFLAG_ALPHAGEN_VERTEX), true);
+ surf = Mod_Mesh_AddSurface(mod, Mod_Mesh_GetTexture(mod, "white", 0, 0, MATERIALFLAG_WALL | MATERIALFLAG_VERTEXCOLOR | MATERIALFLAG_ALPHAGEN_VERTEX | MATERIALFLAG_ALPHA | MATERIALFLAG_BLENDED | MATERIALFLAG_NOSHADOW), true);
e0 = Mod_Mesh_IndexForVertex(mod, surf, x1 - offsetx, y1 - offsety, 10, 0, 0, -1, 0, 0, 0, 0, r1, g1, b1, alpha1);
e1 = Mod_Mesh_IndexForVertex(mod, surf, x2 - offsetx, y2 - offsety, 10, 0, 0, -1, 0, 0, 0, 0, r2, g2, b2, alpha2);
e2 = Mod_Mesh_IndexForVertex(mod, surf, x2 + offsetx, y2 + offsety, 10, 0, 0, -1, 0, 0, 0, 0, r2, g2, b2, alpha2);
void R_DrawCustomSurface(skinframe_t *skinframe, const matrix4x4_t *texmatrix, int materialflags, int firstvertex, int numvertices, int firsttriangle, int numtriangles, qboolean writedepth, qboolean prepass, qboolean ui)
{
- int q;
static texture_t texture;
- static msurface_t surface;
- const msurface_t *surfacelist = &surface;
// fake enough texture and surface state to render this geometry
texture.specularscalemod = 1;
texture.specularpowermod = 1;
texture.transparentsort = TRANSPARENTSORT_DISTANCE;
- // WHEN ADDING DEFAULTS HERE, REMEMBER TO PUT DEFAULTS IN ALL LOADERS
- // JUST GREP FOR "specularscalemod = 1".
- for (q = 0; q < 3; q++)
- {
- texture.render_glowmod[q] = r_refdef.view.colorscale * r_hdr_glowintensity.value;
- texture.render_modellight_lightdir[q] = q == 2;
- texture.render_modellight_ambient[q] = r_refdef.view.colorscale * r_refdef.scene.ambientintensity;
- texture.render_modellight_diffuse[q] = r_refdef.view.colorscale;
- texture.render_modellight_specular[q] = r_refdef.view.colorscale;
- texture.render_lightmap_ambient[q] = r_refdef.view.colorscale * r_refdef.scene.ambientintensity;
- texture.render_lightmap_diffuse[q] = r_refdef.view.colorscale * r_refdef.scene.lightmapintensity;
- texture.render_lightmap_specular[q] = r_refdef.view.colorscale;
- texture.render_rtlight_diffuse[q] = r_refdef.view.colorscale;
- texture.render_rtlight_specular[q] = r_refdef.view.colorscale;
- }
- texture.currentalpha = 1.0f;
-
- surface.texture = &texture;
- surface.num_triangles = numtriangles;
- surface.num_firsttriangle = firsttriangle;
- surface.num_vertices = numvertices;
- surface.num_firstvertex = firstvertex;
-
- // now render it
- rsurface.texture = R_GetCurrentTexture(surface.texture);
- rsurface.lightmaptexture = NULL;
- rsurface.deluxemaptexture = NULL;
- rsurface.uselightmaptexture = false;
- R_DrawModelTextureSurfaceList(1, &surfacelist, writedepth, prepass, ui);
+ R_DrawCustomSurface_Texture(&texture, texmatrix, materialflags, firstvertex, numvertices, firsttriangle, numtriangles, writedepth, prepass, ui);
}
void R_DrawCustomSurface_Texture(texture_t *texture, const matrix4x4_t *texmatrix, int materialflags, int firstvertex, int numvertices, int firsttriangle, int numtriangles, qboolean writedepth, qboolean prepass, qboolean ui)