else if (permutation & SHADERPERMUTATION_MODE_LIGHTDIRECTION)
{
if (r_glsl_permutation->loc_AmbientColor >= 0)
- qglUniform3fARB(r_glsl_permutation->loc_AmbientColor, rsurface_entity->modellight_ambient[0] * ambientscale, rsurface_entity->modellight_ambient[1] * ambientscale, rsurface_entity->modellight_ambient[2] * ambientscale);
+ qglUniform3fARB(r_glsl_permutation->loc_AmbientColor, rsurface_modellight_ambient[0] * ambientscale, rsurface_modellight_ambient[1] * ambientscale, rsurface_modellight_ambient[2] * ambientscale);
if (r_glsl_permutation->loc_DiffuseColor >= 0)
- qglUniform3fARB(r_glsl_permutation->loc_DiffuseColor, rsurface_entity->modellight_diffuse[0] * diffusescale, rsurface_entity->modellight_diffuse[1] * diffusescale, rsurface_entity->modellight_diffuse[2] * diffusescale);
+ qglUniform3fARB(r_glsl_permutation->loc_DiffuseColor, rsurface_modellight_diffuse[0] * diffusescale, rsurface_modellight_diffuse[1] * diffusescale, rsurface_modellight_diffuse[2] * diffusescale);
if (r_glsl_permutation->loc_SpecularColor >= 0)
- qglUniform3fARB(r_glsl_permutation->loc_SpecularColor, rsurface_entity->modellight_diffuse[0] * specularscale, rsurface_entity->modellight_diffuse[1] * specularscale, rsurface_entity->modellight_diffuse[2] * specularscale);
+ qglUniform3fARB(r_glsl_permutation->loc_SpecularColor, rsurface_modellight_diffuse[0] * specularscale, rsurface_modellight_diffuse[1] * specularscale, rsurface_modellight_diffuse[2] * specularscale);
if (r_glsl_permutation->loc_LightDir >= 0)
- qglUniform3fARB(r_glsl_permutation->loc_LightDir, rsurface_entity->modellight_lightdir[0], rsurface_entity->modellight_lightdir[1], rsurface_entity->modellight_lightdir[2]);
+ qglUniform3fARB(r_glsl_permutation->loc_LightDir, rsurface_modellight_lightdir[0], rsurface_modellight_lightdir[1], rsurface_modellight_lightdir[2]);
}
else
{
if (r_glsl_permutation->loc_Color_Pants >= 0)
{
if (rsurface_texture->currentskinframe->pants)
- qglUniform3fARB(r_glsl_permutation->loc_Color_Pants, rsurface_entity->colormap_pantscolor[0], rsurface_entity->colormap_pantscolor[1], rsurface_entity->colormap_pantscolor[2]);
+ qglUniform3fARB(r_glsl_permutation->loc_Color_Pants, rsurface_colormap_pantscolor[0], rsurface_colormap_pantscolor[1], rsurface_colormap_pantscolor[2]);
else
qglUniform3fARB(r_glsl_permutation->loc_Color_Pants, 0, 0, 0);
}
if (r_glsl_permutation->loc_Color_Shirt >= 0)
{
if (rsurface_texture->currentskinframe->shirt)
- qglUniform3fARB(r_glsl_permutation->loc_Color_Shirt, rsurface_entity->colormap_shirtcolor[0], rsurface_entity->colormap_shirtcolor[1], rsurface_entity->colormap_shirtcolor[2]);
+ qglUniform3fARB(r_glsl_permutation->loc_Color_Shirt, rsurface_colormap_shirtcolor[0], rsurface_colormap_shirtcolor[1], rsurface_colormap_shirtcolor[2]);
else
qglUniform3fARB(r_glsl_permutation->loc_Color_Shirt, 0, 0, 0);
}
float *rsurface_lightmapcolor4f;
int rsurface_lightmapcolor4f_bufferobject;
size_t rsurface_lightmapcolor4f_bufferoffset;
+matrix4x4_t rsurface_matrix;
+matrix4x4_t rsurface_inversematrix;
+frameblend_t rsurface_frameblend[4];
+vec3_t rsurface_modellight_ambient;
+vec3_t rsurface_modellight_diffuse;
+vec3_t rsurface_modellight_lightdir;
+vec3_t rsurface_colormap_pantscolor;
+vec3_t rsurface_colormap_shirtcolor;
vec3_t rsurface_modelorg;
qboolean rsurface_generatedvertex;
-const entity_render_t *rsurface_entity;
const model_t *rsurface_model;
texture_t *rsurface_texture;
qboolean rsurface_uselightmaptexture;
void RSurf_ActiveWorldEntity(void)
{
RSurf_CleanUp();
- rsurface_entity = r_refdef.worldentity;
rsurface_model = r_refdef.worldmodel;
if (rsurface_array_size < rsurface_model->surfmesh.num_vertices)
R_Mesh_ResizeArrays(rsurface_model->surfmesh.num_vertices);
+ rsurface_matrix = identitymatrix;
+ rsurface_inversematrix = identitymatrix;
R_Mesh_Matrix(&identitymatrix);
VectorCopy(r_view.origin, rsurface_modelorg);
+ VectorSet(rsurface_modellight_ambient, 0, 0, 0);
+ VectorSet(rsurface_modellight_diffuse, 0, 0, 0);
+ VectorSet(rsurface_modellight_lightdir, 0, 0, 1);
+ VectorSet(rsurface_colormap_pantscolor, 0, 0, 0);
+ VectorSet(rsurface_colormap_shirtcolor, 0, 0, 0);
+ rsurface_frameblend[0].frame = 0;
+ rsurface_frameblend[0].lerp = 1;
+ rsurface_frameblend[1].frame = 0;
+ rsurface_frameblend[1].lerp = 0;
+ rsurface_frameblend[2].frame = 0;
+ rsurface_frameblend[2].lerp = 0;
+ rsurface_frameblend[3].frame = 0;
+ rsurface_frameblend[3].lerp = 0;
rsurface_modelvertex3f = rsurface_model->surfmesh.data_vertex3f;
rsurface_modelvertex3f_bufferobject = rsurface_model->surfmesh.vbo;
rsurface_modelvertex3f_bufferoffset = rsurface_model->surfmesh.vbooffset_vertex3f;
void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, qboolean wanttangents)
{
RSurf_CleanUp();
- rsurface_entity = ent;
rsurface_model = ent->model;
if (rsurface_array_size < rsurface_model->surfmesh.num_vertices)
R_Mesh_ResizeArrays(rsurface_model->surfmesh.num_vertices);
- R_Mesh_Matrix(&ent->matrix);
- Matrix4x4_Transform(&ent->inversematrix, r_view.origin, rsurface_modelorg);
- if (rsurface_model->surfmesh.isanimated && (rsurface_entity->frameblend[0].lerp != 1 || rsurface_entity->frameblend[0].frame != 0))
+ rsurface_matrix = ent->matrix;
+ rsurface_inversematrix = ent->inversematrix;
+ R_Mesh_Matrix(&rsurface_matrix);
+ Matrix4x4_Transform(&rsurface_inversematrix, r_view.origin, rsurface_modelorg);
+ VectorCopy(ent->modellight_ambient, rsurface_modellight_ambient);
+ VectorCopy(ent->modellight_diffuse, rsurface_modellight_diffuse);
+ VectorCopy(ent->modellight_lightdir, rsurface_modellight_lightdir);
+ VectorCopy(ent->colormap_pantscolor, rsurface_colormap_pantscolor);
+ VectorCopy(ent->colormap_shirtcolor, rsurface_colormap_shirtcolor);
+ rsurface_frameblend[0] = ent->frameblend[0];
+ rsurface_frameblend[1] = ent->frameblend[1];
+ rsurface_frameblend[2] = ent->frameblend[2];
+ rsurface_frameblend[3] = ent->frameblend[3];
+ if (rsurface_model->surfmesh.isanimated && (rsurface_frameblend[0].lerp != 1 || rsurface_frameblend[0].frame != 0))
{
if (wanttangents)
{
rsurface_modelsvector3f = rsurface_array_modelsvector3f;
rsurface_modeltvector3f = rsurface_array_modeltvector3f;
rsurface_modelnormal3f = rsurface_array_modelnormal3f;
- Mod_Alias_GetMesh_Vertices(rsurface_model, rsurface_entity->frameblend, rsurface_array_modelvertex3f, rsurface_array_modelnormal3f, rsurface_array_modelsvector3f, rsurface_array_modeltvector3f);
+ Mod_Alias_GetMesh_Vertices(rsurface_model, rsurface_frameblend, rsurface_array_modelvertex3f, rsurface_array_modelnormal3f, rsurface_array_modelsvector3f, rsurface_array_modeltvector3f);
}
else if (wantnormals)
{
rsurface_modelsvector3f = NULL;
rsurface_modeltvector3f = NULL;
rsurface_modelnormal3f = rsurface_array_modelnormal3f;
- Mod_Alias_GetMesh_Vertices(rsurface_model, rsurface_entity->frameblend, rsurface_array_modelvertex3f, rsurface_array_modelnormal3f, NULL, NULL);
+ Mod_Alias_GetMesh_Vertices(rsurface_model, rsurface_frameblend, rsurface_array_modelvertex3f, rsurface_array_modelnormal3f, NULL, NULL);
}
else
{
rsurface_modelsvector3f = NULL;
rsurface_modeltvector3f = NULL;
rsurface_modelnormal3f = NULL;
- Mod_Alias_GetMesh_Vertices(rsurface_model, rsurface_entity->frameblend, rsurface_array_modelvertex3f, NULL, NULL, NULL);
+ Mod_Alias_GetMesh_Vertices(rsurface_model, rsurface_frameblend, rsurface_array_modelvertex3f, NULL, NULL, NULL);
}
rsurface_modelvertex3f_bufferobject = 0;
rsurface_modelvertex3f_bufferoffset = 0;
{
int texturesurfaceindex;
float center[3], forward[3], right[3], up[3], v[3], newforward[3], newright[3], newup[3];
- Matrix4x4_Transform3x3(&rsurface_entity->inversematrix, r_view.forward, newforward);
- Matrix4x4_Transform3x3(&rsurface_entity->inversematrix, r_view.right, newright);
- Matrix4x4_Transform3x3(&rsurface_entity->inversematrix, r_view.up, newup);
+ Matrix4x4_Transform3x3(&rsurface_inversematrix, r_view.forward, newforward);
+ Matrix4x4_Transform3x3(&rsurface_inversematrix, r_view.right, newright);
+ Matrix4x4_Transform3x3(&rsurface_inversematrix, r_view.up, newup);
VectorNormalize(newforward);
VectorNormalize(newright);
VectorNormalize(newup);
vec3_t lightdir;
// TODO: optimize
// model lighting
- VectorCopy(rsurface_entity->modellight_lightdir, lightdir);
- ambientcolor[0] = rsurface_entity->modellight_ambient[0] * r * 0.5f;
- ambientcolor[1] = rsurface_entity->modellight_ambient[1] * g * 0.5f;
- ambientcolor[2] = rsurface_entity->modellight_ambient[2] * b * 0.5f;
- diffusecolor[0] = rsurface_entity->modellight_diffuse[0] * r * 0.5f;
- diffusecolor[1] = rsurface_entity->modellight_diffuse[1] * g * 0.5f;
- diffusecolor[2] = rsurface_entity->modellight_diffuse[2] * b * 0.5f;
+ VectorCopy(rsurface_modellight_lightdir, lightdir);
+ ambientcolor[0] = rsurface_modellight_ambient[0] * r * 0.5f;
+ ambientcolor[1] = rsurface_modellight_ambient[1] * g * 0.5f;
+ ambientcolor[2] = rsurface_modellight_ambient[2] * b * 0.5f;
+ diffusecolor[0] = rsurface_modellight_diffuse[0] * r * 0.5f;
+ diffusecolor[1] = rsurface_modellight_diffuse[1] * g * 0.5f;
+ diffusecolor[2] = rsurface_modellight_diffuse[2] * b * 0.5f;
if (VectorLength2(diffusecolor) > 0)
{
// generate color arrays for the surfaces in this list
skyrendernow = false;
R_Sky();
// restore entity matrix
- R_Mesh_Matrix(&rsurface_entity->matrix);
+ R_Mesh_Matrix(&rsurface_matrix);
}
GL_DepthRange(0, (rsurface_texture->currentmaterialflags & MATERIALFLAG_SHORTDEPTHRANGE) ? 0.0625 : 1);
GL_DepthTest(!(rsurface_texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST));
R_Mesh_TexCoordPointer(3, 3, rsurface_normal3f, rsurface_normal3f_bufferobject, rsurface_normal3f_bufferoffset);
R_Mesh_TexCoordPointer(4, 2, rsurface_model->surfmesh.data_texcoordlightmap2f, rsurface_model->surfmesh.vbo, rsurface_model->surfmesh.vbooffset_texcoordlightmap2f);
+ GL_Color(rsurface_texture->currentlayers[0].color[0], rsurface_texture->currentlayers[0].color[1], rsurface_texture->currentlayers[0].color[2], rsurface_texture->currentlayers[0].color[3]);
if (rsurface_texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT)
{
R_Mesh_TexBind(7, R_GetTexture(r_texture_white));
GL_CullFace((rsurface_texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE) ? GL_NONE : GL_FRONT); // quake is backwards, this culls back faces
GL_BlendFunc(rsurface_texture->currentlayers[0].blendfunc1, rsurface_texture->currentlayers[0].blendfunc2);
GL_DepthMask(writedepth && !(rsurface_texture->currentmaterialflags & MATERIALFLAG_BLENDED));
- GL_Color(rsurface_entity->colormod[0], rsurface_entity->colormod[1], rsurface_entity->colormod[2], rsurface_texture->currentalpha);
GL_AlphaTest((rsurface_texture->currentmaterialflags & MATERIALFLAG_ALPHATEST) != 0);
// FIXME: identify models using a better check than rsurface_model->brush.shadowmesh
rsurface_lightmode = ((rsurface_texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT) || rsurface_model->brush.shadowmesh) ? 0 : 2;
RSurf_CleanUp();
}
-void R_QueueSurfaceList(int numsurfaces, msurface_t **surfacelist, int flagsmask, qboolean writedepth, qboolean depthonly)
+void R_QueueSurfaceList(entity_render_t *ent, int numsurfaces, msurface_t **surfacelist, int flagsmask, qboolean writedepth, qboolean depthonly)
{
int i, j;
vec3_t tempcenter, center;
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_entity->matrix, tempcenter, center);
- R_MeshQueue_AddTransparent(rsurface_texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST ? r_view.origin : center, R_DrawSurface_TransparentCallback, rsurface_entity, surface - rsurface_model->data_surfaces, r_shadow_rtlight);
+ Matrix4x4_Transform(&rsurface_matrix, tempcenter, center);
+ R_MeshQueue_AddTransparent(rsurface_texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST ? r_view.origin : center, R_DrawSurface_TransparentCallback, ent, surface - rsurface_model->data_surfaces, r_shadow_rtlight);
}
else
{
counttriangles += surface->num_triangles;
if (numsurfacelist >= maxsurfacelist)
{
- R_QueueSurfaceList(numsurfacelist, surfacelist, flagsmask, writedepth, depthonly);
+ R_QueueSurfaceList(r_refdef.worldentity, numsurfacelist, surfacelist, flagsmask, writedepth, depthonly);
numsurfacelist = 0;
}
}
}
}
if (numsurfacelist)
- R_QueueSurfaceList(numsurfacelist, surfacelist, flagsmask, writedepth, depthonly);
+ R_QueueSurfaceList(r_refdef.worldentity, numsurfacelist, surfacelist, flagsmask, writedepth, depthonly);
r_refdef.stats.entities_triangles += counttriangles;
RSurf_CleanUp();
counttriangles += surface->num_triangles;
if (numsurfacelist >= maxsurfacelist)
{
- R_QueueSurfaceList(numsurfacelist, surfacelist, flagsmask, writedepth, depthonly);
+ R_QueueSurfaceList(ent, numsurfacelist, surfacelist, flagsmask, writedepth, depthonly);
numsurfacelist = 0;
}
}
}
if (numsurfacelist)
- R_QueueSurfaceList(numsurfacelist, surfacelist, flagsmask, writedepth, depthonly);
+ R_QueueSurfaceList(ent, numsurfacelist, surfacelist, flagsmask, writedepth, depthonly);
r_refdef.stats.entities_triangles += counttriangles;
RSurf_CleanUp();
static void R_Shadow_RenderLighting_Light_Vertex(int firstvertex, int numvertices, int numtriangles, const int *element3i, int element3i_bufferobject, size_t element3i_bufferoffset, const vec3_t lightcolorbase, const vec3_t lightcolorpants, const vec3_t lightcolorshirt, rtexture_t *basetexture, rtexture_t *pantstexture, rtexture_t *shirttexture, rtexture_t *normalmaptexture, rtexture_t *glosstexture, float ambientscale, float diffusescale, float specularscale, qboolean dopants, qboolean doshirt)
{
// OpenGL 1.1 path (anything)
- model_t *model = rsurface_entity->model;
+ const model_t *model = rsurface_model;
float ambientcolorbase[3], diffusecolorbase[3];
float ambientcolorpants[3], diffusecolorpants[3];
float ambientcolorshirt[3], diffusecolorshirt[3];
float ambientscale, diffusescale, specularscale;
vec3_t lightcolorbase, lightcolorpants, lightcolorshirt;
// calculate colors to render this texture with
- lightcolorbase[0] = r_shadow_rtlight->currentcolor[0] * rsurface_entity->colormod[0] * rsurface_texture->currentalpha;
- lightcolorbase[1] = r_shadow_rtlight->currentcolor[1] * rsurface_entity->colormod[1] * rsurface_texture->currentalpha;
- lightcolorbase[2] = r_shadow_rtlight->currentcolor[2] * rsurface_entity->colormod[2] * rsurface_texture->currentalpha;
+ lightcolorbase[0] = r_shadow_rtlight->currentcolor[0] * rsurface_texture->currentlayers[0].color[0] * rsurface_texture->currentlayers[0].color[3];
+ lightcolorbase[1] = r_shadow_rtlight->currentcolor[1] * rsurface_texture->currentlayers[0].color[1] * rsurface_texture->currentlayers[0].color[3];
+ lightcolorbase[2] = r_shadow_rtlight->currentcolor[2] * rsurface_texture->currentlayers[0].color[2] * rsurface_texture->currentlayers[0].color[3];
ambientscale = r_shadow_rtlight->ambientscale;
diffusescale = r_shadow_rtlight->diffusescale;
specularscale = r_shadow_rtlight->specularscale * rsurface_texture->specularscale;
GL_CullFace((rsurface_texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE) ? GL_NONE : GL_FRONT); // quake is backwards, this culls back faces
if (rsurface_texture->colormapping)
{
- qboolean dopants = rsurface_texture->currentskinframe->pants != NULL && VectorLength2(rsurface_entity->colormap_pantscolor) >= (1.0f / 1048576.0f);
- qboolean doshirt = rsurface_texture->currentskinframe->shirt != NULL && VectorLength2(rsurface_entity->colormap_shirtcolor) >= (1.0f / 1048576.0f);
+ qboolean dopants = rsurface_texture->currentskinframe->pants != NULL && VectorLength2(rsurface_colormap_pantscolor) >= (1.0f / 1048576.0f);
+ qboolean doshirt = rsurface_texture->currentskinframe->shirt != NULL && VectorLength2(rsurface_colormap_shirtcolor) >= (1.0f / 1048576.0f);
if (dopants)
{
- lightcolorpants[0] = lightcolorbase[0] * rsurface_entity->colormap_pantscolor[0];
- lightcolorpants[1] = lightcolorbase[1] * rsurface_entity->colormap_pantscolor[1];
- lightcolorpants[2] = lightcolorbase[2] * rsurface_entity->colormap_pantscolor[2];
+ lightcolorpants[0] = lightcolorbase[0] * rsurface_colormap_pantscolor[0];
+ lightcolorpants[1] = lightcolorbase[1] * rsurface_colormap_pantscolor[1];
+ lightcolorpants[2] = lightcolorbase[2] * rsurface_colormap_pantscolor[2];
}
else
VectorClear(lightcolorpants);
if (doshirt)
{
- lightcolorshirt[0] = lightcolorbase[0] * rsurface_entity->colormap_shirtcolor[0];
- lightcolorshirt[1] = lightcolorbase[1] * rsurface_entity->colormap_shirtcolor[1];
- lightcolorshirt[2] = lightcolorbase[2] * rsurface_entity->colormap_shirtcolor[2];
+ lightcolorshirt[0] = lightcolorbase[0] * rsurface_colormap_shirtcolor[0];
+ lightcolorshirt[1] = lightcolorbase[1] * rsurface_colormap_shirtcolor[1];
+ lightcolorshirt[2] = lightcolorbase[2] * rsurface_colormap_shirtcolor[2];
}
else
VectorClear(lightcolorshirt);