29 #include "../idlib/precompiled.h"
34 static const float CHECK_BOUNDS_EPSILON = 1.0f;
117 lightDir = localLightOrigin - v->
xyz;
171 for (
int i = 0;
i < numVerts;
i++ ) {
173 temp[
i*2+0].
xyz[0] = v[0];
174 temp[
i*2+1].
xyz[0] = v[0];
175 temp[
i*2+0].
xyz[1] = v[1];
176 temp[
i*2+1].
xyz[1] = v[1];
177 temp[
i*2+0].
xyz[2] = v[2];
178 temp[
i*2+1].
xyz[2] = v[2];
179 temp[
i*2+0].
xyz[3] = 1.0f;
180 temp[
i*2+1].
xyz[3] = 0.0f;
204 for ( i = 0; i < numVerts; i++ ) {
205 texCoords[
i][0] = verts[
i].
xyz[0] - localViewOrigin[0];
206 texCoords[
i][1] = verts[
i].
xyz[1] - localViewOrigin[1];
207 texCoords[
i][2] = verts[
i].
xyz[2] - localViewOrigin[2];
228 wobbleDegrees = wobbleDegrees *
idMath::PI / 180;
229 wobbleSpeed = wobbleSpeed * 2 *
idMath::PI / 60;
230 rotateSpeed = rotateSpeed * 2 *
idMath::PI / 60;
235 float s = sin( a ) * sin( wobbleDegrees );
236 float c = cos( a ) * sin( wobbleDegrees );
237 float z = cos( wobbleDegrees );
245 axis[1][0] = -sin( a * 2 ) * sin( wobbleDegrees );
246 axis[1][2] = -s * sin( wobbleDegrees );
247 axis[1][1] = sqrt( 1.0
f - ( axis[1][0] * axis[1][0] + axis[1][2] * axis[1][2] ) );
250 axis[1] -= ( axis[2] * axis[1] ) * axis[2];
254 axis[0].Cross( axis[1], axis[2] );
260 transform[0] = axis[0][0] * c + axis[1][0] *
s;
261 transform[4] = axis[0][1] * c + axis[1][1] *
s;
262 transform[8] = axis[0][2] * c + axis[1][2] *
s;
264 transform[1] = axis[1][0] * c - axis[0][0] *
s;
265 transform[5] = axis[1][1] * c - axis[0][1] *
s;
266 transform[9] = axis[1][2] * c - axis[0][2] *
s;
268 transform[2] = axis[2][0];
269 transform[6] = axis[2][1];
270 transform[10] = axis[2][2];
272 transform[3] = transform[7] = transform[11] = 0.0f;
273 transform[12] = transform[13] = transform[14] = 0.0f;
282 for ( i = 0; i < numVerts; i++ ) {
285 v[0] = verts[
i].
xyz[0] - localViewOrigin[0];
286 v[1] = verts[
i].
xyz[1] - localViewOrigin[1];
287 v[2] = verts[
i].
xyz[2] - localViewOrigin[2];
302 static void R_SpecularTexGen(
drawSurf_t *surf,
const idVec3 &globalLightOrigin,
const idVec3 &viewOrg ) {
323 bool *used = (
bool *)_alloca16( tri->
numVerts *
sizeof( used[0] ) );
324 memset( used, 0, tri->
numVerts *
sizeof( used[0] ) );
339 idVec3 lightDir = localLightOrigin - v->
xyz;
340 idVec3 viewDir = localViewOrigin - v->
xyz;
343 lightDir[0] *= ilength;
344 lightDir[1] *= ilength;
345 lightDir[2] *= ilength;
348 viewDir[0] *= ilength;
349 viewDir[1] *= ilength;
350 viewDir[2] *= ilength;
354 texCoords[
i][0] = lightDir * v->
tangents[0];
355 texCoords[
i][1] = lightDir * v->
tangents[1];
356 texCoords[
i][2] = lightDir * v->
normal;
417 static const float INSIDE_LIGHT_FRUSTUM_SLOP = 32;
423 for ( i = 0 ; i < 6 ; i++ ) {
425 if ( d > INSIDE_LIGHT_FRUSTUM_SLOP ) {
440 static bool R_PointInFrustum(
idVec3 &
p,
idPlane *planes,
int numPlanes ) {
441 for (
int i = 0 ; i < numPlanes ; i++ ) {
479 if ( d < INSIDE_LIGHT_FRUSTUM_SLOP ) {
610 if ( inter !=
NULL ) {
627 float modelMatrix[16];
669 drawSurf->
space = space;
673 if ( viewInsideShadow ) {
674 drawSurf->
dsFlags |= DSF_VIEW_INSIDE_SHADOW;
721 for ( i = 0 ; i < 6 ; i++ ) {
740 for ( j = 0; j < 5; j++ ) {
753 if ( clip[3] <= 0.01
f ) {
764 }
else if ( windowX < tr.viewDef->scissor.x1 ) {
769 }
else if ( windowY < tr.viewDef->scissor.y1 ) {
813 for (
int i = 0 ; i < tri->
numVerts ; i++ ) {
818 if ( clip[3] <= 1 ) {
837 }
else if ( windowX < tr.viewDef->scissor.x1 ) {
842 }
else if ( windowY < tr.viewDef->scissor.y1 ) {
887 if ( !lightShader ) {
888 common->
Error(
"R_AddLightSurfaces: NULL lightShader" );
916 for ( lightStageNum = 0 ; lightStageNum < lightShader->
GetNumStages() ; lightStageNum++ ) {
927 if ( lightRegs[ registers[0] ] < 0.001
f ) {
928 lightRegs[ registers[0] ] = 0.0f;
930 if ( lightRegs[ registers[1] ] < 0.001
f ) {
931 lightRegs[ registers[1] ] = 0.0f;
933 if ( lightRegs[ registers[2] ] < 0.001
f ) {
934 lightRegs[ registers[2] ] = 0.0f;
943 if ( lightRegs[ registers[0] ] > 0.0
f ||
944 lightRegs[ registers[1] ] > 0.0
f ||
945 lightRegs[ registers[2] ] > 0.0
f ) {
987 for (
int i = 0 ; i < 3 ; i++ ) {
1077 common->
Error(
"R_IssueEntityDefCallback: dynamic entity callback didn't set model" );
1081 if ( oldBounds[0][0] > def->
referenceBounds[0][0] + CHECK_BOUNDS_EPSILON ||
1082 oldBounds[0][1] > def->
referenceBounds[0][1] + CHECK_BOUNDS_EPSILON ||
1083 oldBounds[0][2] > def->
referenceBounds[0][2] + CHECK_BOUNDS_EPSILON ||
1084 oldBounds[1][0] < def->
referenceBounds[1][0] - CHECK_BOUNDS_EPSILON ||
1085 oldBounds[1][1] < def->
referenceBounds[1][1] - CHECK_BOUNDS_EPSILON ||
1086 oldBounds[1][2] < def->
referenceBounds[1][2] - CHECK_BOUNDS_EPSILON ) {
1105 bool callbackUpdate;
1111 callbackUpdate =
false;
1117 common->
Error(
"R_EntityDefDynamicModel: NULL model" );
1154 common->
Printf(
"entity %i dynamic model exceeded reference bounds\n", def->
index );
1186 const float *shaderParms;
1187 static float refRegs[MAX_EXPRESSION_REGISTERS];
1191 drawSurf->
geo = tri;
1192 drawSurf->
space = space;
1240 memcpy( generatedShaderParms, renderEntity->
shaderParms,
sizeof( generatedShaderParms ) );
1245 shaderParms = generatedShaderParms;
1274 switch( shader->
Texgen() ) {
1291 gui = renderEntity->
gui[ guiNum ];
1293 if ( gui ==
NULL ) {
1335 static void R_AddAmbientDrawsurfs(
viewEntity_t *vEntity ) {
1352 for ( i = 0 ; i < total ; i++ ) {
1382 for ( j = 0 ; j < tri->
numVerts ; j++ ) {
1383 for ( k = 0 ; k < 3 ; k++ ) {
1384 if ( tri->
verts[j].
xyz[k] > tri->
bounds[1][k] + CHECK_BOUNDS_EPSILON
1385 || tri->
verts[j].
xyz[k] < tri->
bounds[0][k] - CHECK_BOUNDS_EPSILON ) {
1431 decal->AddDecalDrawSurf( vEntity );
1522 R_AddAmbientDrawsurfs( vEntity );
1602 const_cast<drawSurf_t *
>(surf)->scissorRect.Intersect( surfRect );
1609 const_cast<drawSurf_t *
>(surf)->scissorRect.Intersect( surfRect );
static void RemoveOverlaySurfacesFromModel(idRenderModel *baseModel)
idRenderWorldLocal * world
const idMaterial * lightShader
idRenderModel * dynamicModel
idCVar r_useEntityScissors("r_useEntityScissors","0", CVAR_RENDERER|CVAR_BOOL,"1 = use custom scissor rectangle for each entity")
idCVar r_skipOverlays("r_skipOverlays","0", CVAR_RENDERER|CVAR_BOOL,"skip overlay surfaces")
const srfTriangles_t * geo
virtual idRenderModel * InstantiateDynamicModel(const struct renderEntity_s *ent, const struct viewDef_s *view, idRenderModel *cachedModel)=0
idCVar r_useShadowCulling("r_useShadowCulling","1", CVAR_RENDERER|CVAR_BOOL,"try to cull shadows from partially visible lights")
void R_CreatePrivateShadowCache(srfTriangles_t *tri)
void R_AddModelSurfaces(void)
idScreenRect R_ScreenRectFromViewFrustumBounds(const idBounds &bounds)
bool viewSeesGlobalLightOrigin
const float GetSort(void) const
bool generateAllInteractionsCalled
struct viewEntity_s * viewEntity
idCVar r_useIndexBuffers("r_useIndexBuffers","0", CVAR_RENDERER|CVAR_ARCHIVE|CVAR_INTEGER,"use ARB_vertex_buffer_object for indexes", 0, 1, idCmdSystem::ArgCompletion_Integer< 0, 1 >)
void R_AddDrawSurf(const srfTriangles_t *tri, const viewEntity_t *space, const renderEntity_t *renderEntity, const idMaterial *shader, const idScreenRect &scissor)
idCVar r_showEntityScissors("r_showEntityScissors","0", CVAR_RENDERER|CVAR_BOOL,"show entity scissor rectangles")
bool ReceivesLighting(void) const
float GetFloat(void) const
const int GetNumStages(void) const
void R_SkyboxTexGen(drawSurf_t *surf, const idVec3 &viewOrg)
const float * ConstantRegisters() const
const float * ToFloatPtr(void) const
idRenderModel * R_EntityDefDynamicModel(idRenderEntityLocal *def)
float Distance(const idVec3 &v) const
bool R_GlobalShaderOverride(const idMaterial **shader)
virtual void VPCALL CreateTextureSpaceLightVectors(idVec3 *lightVectors, const idVec3 &lightOrigin, const idDrawVert *verts, const int numVerts, const int *indexes, const int numIndexes)=0
const idMaterial * referenceShader
idCVar r_skipSpecular("r_skipSpecular","0", CVAR_RENDERER|CVAR_BOOL|CVAR_CHEAT|CVAR_ARCHIVE,"use black for specular1")
idCVar r_checkBounds("r_checkBounds","0", CVAR_RENDERER|CVAR_BOOL,"compare all surface bounds with precalculated ones")
const idMaterial * shader
void R_RemoveUnecessaryViewLights(void)
int GetEntityGui(void) const
int suppressShadowInViewID
const struct drawSurf_s * localShadows
void Union(const idScreenRect &rect)
const char * GetName(void) const
idCVar r_useShadowSurfaceScissor("r_useShadowSurfaceScissor","1", CVAR_RENDERER|CVAR_BOOL,"scissor shadows by the scissor rect of the interaction surfaces")
const struct drawSurf_s * globalInteractions
virtual const char * Name() const =0
idRenderLightLocal * lightDef
bool IsBlendLight() const
void R_DeriveTangents(srfTriangles_t *tri, bool allocFacePlanes=true)
idRenderLightLocal * lightDef
idCVar r_singleSurface("r_singleSurface","-1", CVAR_RENDERER|CVAR_INTEGER,"suppress all but one surface on each entity")
const struct viewEntity_s * space
struct vertCache_s * ambientCache
viewLight_t * R_SetLightDefViewLight(idRenderLightLocal *light)
static idInteraction * AllocAndLink(idRenderEntityLocal *edef, idRenderLightLocal *ldef)
deferredEntityCallback_t callback
const idMaterial * material
float projectionMatrix[16]
idCVar r_useClippedLightScissors("r_useClippedLightScissors","1", CVAR_RENDERER|CVAR_INTEGER,"0 = full screen when near clipped, 1 = exact when near clipped, 2 = exact always", 0, 2, idCmdSystem::ArgCompletion_Integer< 0, 2 >)
void EvaluateRegisters(float *regs, const float entityParms[MAX_ENTITY_SHADER_PARMS], const struct viewDef_s *view, idSoundEmitter *soundEmitter=NULL) const
const idMaterial * customShader
void * R_ClearedFrameAlloc(int bytes)
bool ProjectionBounds(const idBounds &bounds, idBounds &projectionBounds) const
shadowFrustum_t shadowFrustums[6]
idCVar r_skipSuppress("r_skipSuppress","0", CVAR_RENDERER|CVAR_BOOL,"ignore the per-view suppressions")
bool R_CullLocalBox(const idBounds &bounds, const float modelMatrix[16], int numPlanes, const idPlane *planes)
const int MAX_ENTITY_SHADER_PARMS
const idMaterial * lightShader
struct srfTriangles_s * ambientSurface
virtual dynamicModel_t IsDynamicModel() const =0
int suppressLightInViewID
float shaderParms[MAX_ENTITY_SHADER_PARMS]
backEndName_t backEndRenderer
bool LightCastsShadows() const
struct viewLight_s * next
int suppressShadowInLightID
struct viewLight_s * viewLights
idUserInterface * GlobalGui(void) const
bool noDynamicInteractions
virtual void VPCALL CreateSpecularTextureCoords(idVec4 *texCoords, const idVec3 &lightOrigin, const idVec3 &viewOrigin, const idDrawVert *verts, const int numVerts, const int *indexes, const int numIndexes)=0
idInteraction ** interactionTable
bool backEndRendererHasVertexPrograms
int dynamicModelFrameCount
int viewSeesShadowPlaneBits
GLuint GLuint GLsizei count
void AddPoint(float x, float y)
int GetNumPoints(void) const
idRenderModelDecal * decals
void R_CreateVertexProgramShadowCache(srfTriangles_t *tri)
GLubyte GLubyte GLubyte GLubyte w
struct viewEntity_s * next
const shaderStage_t * GetStage(const int index) const
idScreenRect R_ClippedLightScissorRectangle(viewLight_t *vLight)
areaReference_t * references
idCVar r_lightSourceRadius("r_lightSourceRadius","0", CVAR_RENDERER|CVAR_FLOAT,"for soft-shadow sampling")
bool R_IssueEntityDefCallback(idRenderEntityLocal *def)
bool R_PreciseCullSurface(const drawSurf_t *drawSurf, idBounds &ndcBounds)
srfTriangles_t * geometry
const idDeclSkin * customSkin
struct vertCache_s * dynamicTexCoords
const idMaterial * R_RemapShaderBySkin(const idMaterial *shader, const idDeclSkin *skin, const idMaterial *customShader)
int GetInteger(void) const
struct areaReference_s * ownerNext
const int MAX_RENDERENTITY_GUI
virtual const modelSurface_t * Surface(int surfaceNum) const =0
void Intersect(const idScreenRect &rect)
void AddActiveInteraction(void)
idCVar r_useLightScissors("r_useLightScissors","1", CVAR_RENDERER|CVAR_BOOL,"1 = use custom scissor rectangle for each light")
idCVar r_showLightScissors("r_showLightScissors","0", CVAR_RENDERER|CVAR_BOOL,"show light scissor rectangles")
struct vertCache_s * lightingCache
void Touch(vertCache_t *buffer)
const struct drawSurf_s * translucentInteractions
shadowCache_t * shadowVertexes
void R_LinkLightSurf(const drawSurf_t **link, const srfTriangles_t *tri, const viewEntity_t *space, const idRenderLightLocal *light, const idMaterial *shader, const idScreenRect &scissor, bool viewInsideShadow)
void R_TransformClipToDevice(const idPlane &clip, const viewDef_t *view, idVec3 &normalized)
idRenderEntityLocal * entityDef
struct vertCache_s * shadowCache
GLubyte GLubyte GLubyte a
virtual void Printf(const char *fmt,...) id_attribute((format(printf
idCVar r_useInteractionTable("r_useInteractionTable","1", CVAR_RENDERER|CVAR_BOOL,"create a full entityDefs * lightDefs table to make finding interactions faster")
virtual idBounds Bounds(const struct renderEntity_s *ent=NULL) const =0
vertCache_t * AllocFrameTemp(void *data, int bytes)
const int * GetTexGenRegisters(void) const
idRenderModel * cachedDynamicModel
void R_TransformModelToClip(const idVec3 &src, const float *modelMatrix, const float *projectionMatrix, idPlane &eye, idPlane &dst)
const float * shaderRegisters
srfTriangles_t * frustumTris
idScreenRect R_CalcEntityScissorRectangle(viewEntity_t *vEntity)
void myGlMultMatrix(const float *a, const float *b, float *out)
void R_GlobalPointToLocal(const float modelMatrix[16], const idVec3 &in, idVec3 &out)
GLdouble GLdouble GLdouble r
idRenderModel * prelightModel
const int GetNumRegisters() const
void CreateLightDefInteractions(idRenderLightLocal *ldef)
struct viewEntity_s * viewEntitys
void R_RenderGuiSurf(idUserInterface *gui, drawSurf_t *drawSurf)
void R_AddLightSurfaces(void)
const struct drawSurf_s * globalShadows
const int INITIAL_DRAWSURFS
int interactionTableWidth
const struct drawSurf_s * localInteractions
void Alloc(void *data, int bytes, vertCache_t **buffer, bool indexBuffer=false)
idScreenRect R_CalcLightScissorRectangle(viewLight_t *vLight)
idInteraction * entityNext
const struct drawSurf_s * nextOnLight
bool R_CreateAmbientCache(srfTriangles_t *tri, bool needsLighting)
idRenderModelDecal * Next(void) const
idRenderModelOverlay * overlay
float modelViewMatrix[16]
idWinding * frustumWindings[6]
struct portalArea_s * area
class idSoundEmitter * referenceSound
idRenderEntityLocal * entity
class idUserInterface * gui[MAX_RENDERENTITY_GUI]
areaReference_t entityRefs
void * R_FrameAlloc(int bytes)
idVertexCache vertexCache
void AddOverlaySurfacesToModel(idRenderModel *baseModel)
viewEntity_t * R_SetEntityDefViewEntity(idRenderEntityLocal *def)
struct areaReference_s * areaNext
GLuint GLenum GLenum transform
void R_WobbleskyTexGen(drawSurf_t *surf, const idVec3 &viewOrg)
virtual int GetTimeGroupTime(int timeGroup)=0
idInteraction * firstInteraction
idRenderWorldLocal * renderWorld
struct vertCache_s * indexCache
const srfTriangles_t * frustumTris
void R_LocalPointToGlobal(const float modelMatrix[16], const idVec3 &in, idVec3 &out)
idSoundEmitter * referenceSound
virtual void Error(const char *fmt,...) id_attribute((format(printf
idCVar r_useOptimizedShadows("r_useOptimizedShadows","1", CVAR_RENDERER|CVAR_BOOL,"use the dmap generated static shadow volumes")
void R_AxisToModelMatrix(const idMat3 &axis, const idVec3 &origin, float modelMatrix[16])
bool ClipInPlace(const idPlane &plane, const float epsilon=ON_EPSILON, const bool keepOn=false)
struct lightingCache_s lightingCache_t
void R_ShowColoredScreenRect(const idScreenRect &rect, int colorIndex)
float shaderParms[MAX_ENTITY_SHADER_PARMS]
virtual void SelectTimeGroup(int timeGroup)=0
const float * shaderRegisters
void R_ClearEntityDefDynamicModel(idRenderEntityLocal *def)
virtual float DepthHack() const =0
static float RSqrt(float x)
struct viewLight_s * viewLight
bool R_CreateLightingCache(const idRenderEntityLocal *ent, const idRenderLightLocal *light, srfTriangles_t *tri)
virtual int VPCALL CreateVertexProgramShadowCache(idVec4 *vertexCache, const idDrawVert *verts, const int numVerts)=0
idSIMDProcessor * SIMDProcessor
virtual int NumSurfaces() const =0