/*
================
EmitSurface
================
*/
void idGuiModel::EmitSurface( guiModelSurface_t *surf, float modelMatrix[16], float modelViewMatrix[16], bool depthHack ) {
	srfTriangles_t	*tri;
	if( surf->numVerts == 0 ) {
		return;		// nothing in the surface
	}
	// copy verts and indexes
	tri = ( srfTriangles_t * )R_ClearedFrameAlloc( sizeof( *tri ) );
	tri->numIndexes = surf->numIndexes;
	tri->numVerts = surf->numVerts;
	tri->indexes = ( glIndex_t * )R_FrameAlloc( tri->numIndexes * sizeof( tri->indexes[0] ) );
	memcpy( tri->indexes, &indexes[surf->firstIndex], tri->numIndexes * sizeof( tri->indexes[0] ) );
	// we might be able to avoid copying these and just let them reference the list vars
	// but some things, like deforms and recursive
	// guis, need to access the verts in cpu space, not just through the vertex range
	tri->verts = ( idDrawVert * )R_FrameAlloc( tri->numVerts * sizeof( tri->verts[0] ) );
	memcpy( tri->verts, &verts[surf->firstVert], tri->numVerts * sizeof( tri->verts[0] ) );
	// move the verts to the vertex cache
	tri->ambientCache = vertexCache.AllocFrameTemp( tri->verts, tri->numVerts * sizeof( tri->verts[0] ) );
	// if we are out of vertex cache, don't create the surface
	if( !tri->ambientCache ) {
		return;
	}
	renderEntity_t renderEntity;
	memset( &renderEntity, 0, sizeof( renderEntity ) );
	memcpy( renderEntity.shaderParms, surf->color, sizeof( surf->color ) );
	viewEntity_t *guiSpace = ( viewEntity_t * )R_ClearedFrameAlloc( sizeof( *guiSpace ) );
	memcpy( guiSpace->modelMatrix, modelMatrix, sizeof( guiSpace->modelMatrix ) );
	memcpy( guiSpace->modelViewMatrix, modelViewMatrix, sizeof( guiSpace->modelViewMatrix ) );
	guiSpace->weaponDepthHack = depthHack;
	// add the surface, which might recursively create another gui
	R_AddDrawSurf( tri, guiSpace, &renderEntity, surf->material, tr.viewDef->scissor );
}
Exemple #2
0
/*
AddDecalSurface()
    adds a decal surface to the scene
*/
void R_AddDecalSurface(decal_t *decal)
{
	int dlightMap;

	srfDecal_t   *srf;
	srfGeneric_t *gen;

	/* early outs */
	if (decal->shader == NULL || decal->parent->viewCount != tr.viewCount || r_firstSceneDecal + tr.refdef.numDecals >= MAX_DECALS)
	{
		return;
	}

	/* get decal surface */
	srf = &tr.refdef.decals[tr.refdef.numDecals];
	tr.refdef.numDecals++;

	/* set it up */
	srf->surfaceType = SF_DECAL;
	srf->numVerts    = decal->numVerts;
	Com_Memcpy(srf->verts, decal->verts, srf->numVerts * sizeof(*srf->verts));

	/* fade colors */
	if (decal->fadeStartTime < tr.refdef.time && decal->fadeStartTime < decal->fadeEndTime)
	{
		int   i;
		float fade = (float) (decal->fadeEndTime - tr.refdef.time) /
		             (float) (decal->fadeEndTime - decal->fadeStartTime);

		for (i = 0; i < decal->numVerts; i++)
		{
			decal->verts[i].modulate[0] *= fade;
			decal->verts[i].modulate[1] *= fade;
			decal->verts[i].modulate[2] *= fade;
			decal->verts[i].modulate[3] *= fade;
		}
	}

	/* dynamic lights? */
	if (decal->parent != NULL)
	{
		gen       = (srfGeneric_t *) decal->parent->data;
		dlightMap = (gen->dlightBits != 0);
	}
	else
	{
		dlightMap = 0;
	}

	/* add surface to scene */
	R_AddDrawSurf((void *) srf, decal->shader, decal->fogIndex, 0, dlightMap);
	tr.pc.c_decalSurfaces++;

	/* free temporary decal */
	if (decal->fadeEndTime <= tr.refdef.time)
	{
		decal->shader = NULL;
	}
}
Exemple #3
0
/*
AddDecalSurface()
adds a decal surface to the scene
*/
void R_AddDecalSurface(decal_t *decal)
{
	int        i;     //, dlightMap;
	float      fade;
	srfDecal_t *srf;
	//srfGeneric_t   *gen;

	// early outs
	if (decal->shader == NULL || decal->parent->viewCount != tr.viewCountNoReset || tr.refdef.numDecals >= MAX_DECALS)
	{
		return;
	}

	// get decal surface
	srf = &tr.refdef.decals[tr.refdef.numDecals];
	tr.refdef.numDecals++;

	// set it up
	srf->surfaceType = SF_DECAL;
	srf->numVerts    = decal->numVerts;
	Com_Memcpy(srf->verts, decal->verts, srf->numVerts * sizeof(*srf->verts));

	// fade colors
	if (decal->fadeStartTime < tr.refdef.time && decal->fadeStartTime < decal->fadeEndTime)
	{
		fade = (float)(decal->fadeEndTime - tr.refdef.time) / (float)(decal->fadeEndTime - decal->fadeStartTime);
		for (i = 0; i < decal->numVerts; i++)
		{
			decal->verts[i].modulate[0] *= fade;
			decal->verts[i].modulate[1] *= fade;
			decal->verts[i].modulate[2] *= fade;
			decal->verts[i].modulate[3] *= fade;
		}
	}

	// dynamic lights?
	/*
	if(decal->parent != NULL)
	{
	    gen = (srfGeneric_t *) decal->parent->data;
	    dlightMap = (gen->dlightBits[tr.smpFrame] != 0);
	}
	else
	{
	    dlightMap = 0;
	}
	*/

	// add surface to scene
	//R_AddDrawSurf((void *)srf, decal->shader, decal->fogIndex, 0, dlightMap);
	R_AddDrawSurf((surfaceType_t *)srf, decal->shader, -1, decal->fogIndex);
	tr.pc.c_decalSurfaces++;

	// free temporary decal
	if (decal->fadeEndTime <= tr.refdef.time)
	{
		decal->shader = NULL;
	}
}
Exemple #4
0
/*
=====================
idRenderModelDecal::AddDecalDrawSurf
=====================
*/
void idRenderModelDecal::AddDecalDrawSurf( viewEntity_t *space ) {
	int i, j, maxTime;
	float f;
	decalInfo_t	decalInfo;
	
	if ( tri.numIndexes == 0 ) {
		return;
	}

	// fade down all the verts with time
	decalInfo = material->GetDecalInfo();
	maxTime = decalInfo.stayTime + decalInfo.fadeTime;

	// set vertex colors and remove faded triangles
	for ( i = 0 ; i < tri.numIndexes ; i += 3 ) {
		int	deltaTime = tr.viewDef->renderView.time - indexStartTime[i];

		if ( deltaTime > maxTime ) {
			continue;
		}

		if ( deltaTime <= decalInfo.stayTime ) {
			continue;
		}

		deltaTime -= decalInfo.stayTime;
		f = (float)deltaTime / decalInfo.fadeTime;

		for ( j = 0; j < 3; j++ ) {
			int	ind = tri.indexes[i+j];

			for ( int k = 0; k < 4; k++ ) {
				float fcolor = decalInfo.start[k] + ( decalInfo.end[k] - decalInfo.start[k] ) * f;
				int icolor = idMath::FtoiFast( fcolor * vertDepthFade[ind] * 255.0f );
				if ( icolor < 0 ) {
					icolor = 0;
				} else if ( icolor > 255 ) {
					icolor = 255;
				}
				tri.verts[ind].color[k] = icolor;
			}
		}
	}

	// copy the tri and indexes to temp heap memory,
	// because if we are running multi-threaded, we wouldn't
	// be able to reorganize the index list
	srfTriangles_t *newTri = (srfTriangles_t *)R_FrameAlloc( sizeof( *newTri ) );
	*newTri = tri;

	// copy the current vertexes to temp vertex cache
	newTri->ambientCache = vertexCache.AllocFrameTemp( tri.verts, tri.numVerts * sizeof( idDrawVert ) );

	// create the drawsurf
	R_AddDrawSurf( newTri, space, &space->entityDef->parms, material, space->scissorRect );
}
Exemple #5
0
void R_AddPolygonSurfaces()
{
    tr.currentEntityNum = ENTITYNUM_WORLD;
    tr.shiftedEntityNum = tr.currentEntityNum << QSORT_ENTITYNUM_SHIFT;

    const srfPoly_t* poly = tr.refdef.polys;
    for (int i = 0; i < tr.refdef.numPolys; ++i, ++poly) {
        R_AddDrawSurf( (const surfaceType_t*)poly, R_GetShaderByHandle( poly->hShader ), poly->fogIndex );
    }
}
Exemple #6
0
/*
=====================
R_AddPolygonSurfaces

Adds all the scene's polys into this view's drawsurf list
=====================
*/
void R_AddPolygonSurfaces( void ) {
	int			i;
	shader_t	*sh;
	srfPoly_t	*poly;

	tr.currentEntityNum = ENTITYNUM_WORLD;
	tr.shiftedEntityNum = tr.currentEntityNum << QSORT_ENTITYNUM_SHIFT;

	for ( i = 0, poly = tr.refdef.polys; i < tr.refdef.numPolys ; i++, poly++ ) {
		sh = R_GetShaderByHandle( poly->hShader );
		R_AddDrawSurf( ( surfaceType_t * )poly, sh, poly->fogIndex, qfalse ); // ***GREGS_VC9_PORT_MOD*** -- changed typecast; was void *
	}
}
Exemple #7
0
/*
=====================
R_AddPolygonSurfaces

Adds all the scene's polys into this view's drawsurf list
=====================
*/
void R_AddPolygonSurfaces( void ) {
	int			i;
	shader_t	*sh;
	srfPoly_t	*poly;

	tr.currentEntityNum = REFENTITYNUM_WORLD;
	tr.shiftedEntityNum = tr.currentEntityNum << QSORT_REFENTITYNUM_SHIFT;

	for ( i = 0, poly = tr.refdef.polys; i < tr.refdef.numPolys ; i++, poly++ ) {
		sh = R_GetShaderByHandle( poly->hShader );
		R_AddDrawSurf( ( void * )poly, sh, poly->fogIndex, qfalse );
	}
}
/*
=====================
R_AddPolygonSurfaces

Adds all the scene's polys into this view's drawsurf list
=====================
*/
void R_AddPolygonSurfaces( void ) {
	int			i;
	shader_t	*sh;
	srfPoly_t	*poly;

	tr.currentEntityNum = ENTITYNUM_WORLD;
	tr.shiftedEntityNum = tr.currentEntityNum << QSORT_ENTITYNUM_SHIFT;

	for ( i = 0, poly = tr.refdef.polys; i < tr.refdef.numPolys ; i++, poly++ ) {
		sh = R_GetShaderByHandle( poly->hShader );
		R_AddDrawSurf( reinterpret_cast<surfaceType_t*>(poly), sh, poly->fogIndex, false );
	}
}
Exemple #9
0
/*
=====================
R_AddPolygonSurfaces

Adds all the scene's polys into this view's drawsurf list
=====================
*/
void R_AddPolygonBufferSurfaces() {
    int i;
    shader_t* sh;
    srfPolyBuffer_t* polybuffer;

    tr.currentEntity = &tr.worldEntity;

    for (i = 0, polybuffer = tr.refdef.polybuffers; i < tr.refdef.numPolybuffers;
         i++, polybuffer++) {
        sh = R_GetShaderByHandle(polybuffer->pPolyBuffer->shader);

        R_AddDrawSurf((surfaceType_t*) polybuffer, sh, -1, polybuffer->fogIndex);
    }
}
Exemple #10
0
/*
=====================
R_AddPolygonSurfaces

Adds all the scene's polys into this view's drawsurf list
=====================
*/
void R_AddPolygonBufferSurfaces( void ) {
	int i;
	shader_t        *sh;
	srfPolyBuffer_t *polybuffer;

	tr.currentEntityNum = ENTITYNUM_WORLD;
	tr.shiftedEntityNum = tr.currentEntityNum << QSORT_REFENTITYNUM_SHIFT;

	for ( i = 0, polybuffer = tr.refdef.polybuffers; i < tr.refdef.numPolyBuffers ; i++, polybuffer++ ) {
		sh = R_GetShaderByHandle( polybuffer->pPolyBuffer->shader );

		R_AddDrawSurf( ( void * )polybuffer, sh, R_PolyBufferFogNum( polybuffer ), qfalse );
	}
}
Exemple #11
0
/*
=====================
R_AddPolygonSurfaces

Adds all the scene's polys into this view's drawsurf list
=====================
*/
void R_AddPolygonSurfaces( void ) {
	int			i;
	shader_t	*sh;
	srfPoly_t	*poly;
	int		fogMask;

	tr.currentEntityNum = REFENTITYNUM_WORLD;
	tr.shiftedEntityNum = tr.currentEntityNum << QSORT_REFENTITYNUM_SHIFT;
	fogMask = -((tr.refdef.rdflags & RDF_NOFOG) == 0);

	for ( i = 0, poly = tr.refdef.polys; i < tr.refdef.numPolys ; i++, poly++ ) {
		sh = R_GetShaderByHandle( poly->hShader );
		R_AddDrawSurf( ( void * )poly, sh, poly->fogIndex & fogMask, qfalse, qfalse, 0 /*cubeMap*/  );
	}
}
Exemple #12
0
/*
=====================
R_AddPolygonSurfaces

Adds all the scene's polys into this view's drawsurf list
=====================
*/
void R_AddPolygonSurfaces() {
    int i;
    shader_t* sh;
    srfPoly_t* poly;

    if (!r_drawpolies->integer) {
        return;
    }

    tr.currentEntity = &tr.worldEntity;

    for (i = 0, poly = tr.refdef.polys; i < tr.refdef.numPolys; i++, poly++) {
        sh = R_GetShaderByHandle(poly->hShader);
        R_AddDrawSurf((surfaceType_t*) poly, sh, -1, poly->fogIndex);
    }
}
Exemple #13
0
/*
==============
R_AddAnimSurfaces
==============
*/
void R_AddAnimSurfaces( trRefEntity_t *ent ) {
	md4Header_t		*header;
	md4Surface_t	*surface;
	md4LOD_t		*lod;
	shader_t		*shader;
	int				i;

	header = tr.currentModel->md4;
	lod = (md4LOD_t *)( (byte *)header + header->ofsLODs );

	surface = (md4Surface_t *)( (byte *)lod + lod->ofsSurfaces );
	for ( i = 0 ; i < lod->numSurfaces ; i++ ) {
		shader = R_GetShaderByHandle( surface->shaderIndex );
		R_AddDrawSurf( (void *)surface, shader, 0 /*fogNum*/, qfalse );
		surface = (md4Surface_t *)( (byte *)surface + surface->ofsEnd );
	}
}
Exemple #14
0
//	adds a decal surface to the scene
static void R_AddDecalSurface( mbrush46_decal_t* decal ) {
	//	early outs
	if ( decal->shader == NULL || decal->parent->viewCount != tr.viewCount || tr.refdef.numDecals >= MAX_DECALS ) {
		return;
	}

	//	get decal surface
	idSurfaceDecal* srf = &tr.refdef.decals[ tr.refdef.numDecals ];
	tr.refdef.numDecals++;

	//	set it up
	srf->surf.numVerts = decal->numVerts;
	Com_Memcpy( srf->surf.verts, decal->verts, srf->surf.numVerts * sizeof ( *srf->surf.verts ) );

	//	fade colors
	if ( decal->fadeStartTime < tr.refdef.time && decal->fadeStartTime < decal->fadeEndTime ) {
		float fade = ( float )( decal->fadeEndTime - tr.refdef.time ) /
					 ( float )( decal->fadeEndTime - decal->fadeStartTime );
		for ( int i = 0; i < decal->numVerts; i++ ) {
			decal->verts[ i ].modulate[ 0 ] *= fade;
			decal->verts[ i ].modulate[ 1 ] *= fade;
			decal->verts[ i ].modulate[ 2 ] *= fade;
			decal->verts[ i ].modulate[ 3 ] *= fade;
		}
	}

	//	dynamic lights?
	int dlightMap;
	if ( decal->parent != NULL ) {
		dlightMap = decal->parent->dlightBits[ tr.smpFrame ] != 0;
	} else {
		dlightMap = 0;
	}

	//	add surface to scene
	R_AddDrawSurf( srf, decal->shader, decal->fogIndex, dlightMap, 0, 0, 0 );
	tr.pc.c_decalSurfaces++;

	//	free temporary decal
	if ( decal->fadeEndTime <= tr.refdef.time ) {
		decal->shader = NULL;
	}
}
/*
=====================
R_AddPolygonSurfaces

Adds all the scene's polys into this view's drawsurf list
=====================
*/
void R_AddPolygonSurfaces( void ) {
	int			i;
	shader_t	*sh;
	srfPoly_t	*poly;

	tr.currentEntityNum = ENTITYNUM_WORLD;
	tr.shiftedEntityNum = tr.currentEntityNum << QSORT_ENTITYNUM_SHIFT;

	for ( i = 0, poly = tr.refdef.polys; i < tr.refdef.numPolys ; i++, poly++ ) {
		sh = R_GetShaderByHandle( poly->hShader );
//sortSL{
		// a hack to get the SprayLogo-"Level" into the Engine
		// without changing the vm-interface-functions
		if(poly->verts->st[0]>=10.0f)
			poly->lvl = ((int)poly->verts->st[0]/10);
		else
			poly->lvl = 0;
//sortSL}
		R_AddDrawSurf( ( void * )poly, sh, poly->fogIndex, qfalse );
	}
}
Exemple #16
0
// much stuff in there is just copied from R_AddMd3Surfaces in tr_mesh.c
void R_MDRAddAnimSurfaces( trRefEntity_t *ent ) {
	mdrHeader_t		*header;
	mdrSurface_t	*surface;
	mdrLOD_t		*lod;
	shader_t		*shader;
	skin_t		*skin;
	int				i, j;
	int				lodnum = 0;
	int				fogNum = 0;
	int				cull;
	qboolean	personalModel;

	header = (mdrHeader_t *) tr.currentModel->modelData;
	
	personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal;
	
	if ( ent->e.renderfx & RF_WRAP_FRAMES )
	{
		ent->e.frame %= header->numFrames;
		ent->e.oldframe %= header->numFrames;
	}	
	
	//
	// Validate the frames so there is no chance of a crash.
	// This will write directly into the entity structure, so
	// when the surfaces are rendered, they don't need to be
	// range checked again.
	//
	if ((ent->e.frame >= header->numFrames) 
		|| (ent->e.frame < 0)
		|| (ent->e.oldframe >= header->numFrames)
		|| (ent->e.oldframe < 0) )
	{
		ri->Printf( PRINT_DEVELOPER, "R_MDRAddAnimSurfaces: no such frame %d to %d for '%s'\n",
			   ent->e.oldframe, ent->e.frame, tr.currentModel->name );
		ent->e.frame = 0;
		ent->e.oldframe = 0;
	}

	//
	// cull the entire model if merged bounding box of both frames
	// is outside the view frustum.
	//
	cull = R_MDRCullModel (header, ent);
	if ( cull == CULL_OUT ) {
		return;
	}	

	// figure out the current LOD of the model we're rendering, and set the lod pointer respectively.
	lodnum = R_ComputeLOD(ent);
	// check whether this model has as that many LODs at all. If not, try the closest thing we got.
	if(header->numLODs <= 0)
		return;
	if(header->numLODs <= lodnum)
		lodnum = header->numLODs - 1;

	lod = (mdrLOD_t *)( (byte *)header + header->ofsLODs);
	for(i = 0; i < lodnum; i++)
	{
		lod = (mdrLOD_t *) ((byte *) lod + lod->ofsEnd);
	}
	
	// set up lighting
	if ( !personalModel || r_shadows->integer > 1 )
	{
		R_SetupEntityLighting( &tr.refdef, ent );
	}

	// fogNum?
	fogNum = R_MDRComputeFogNum( header, ent );

	surface = (mdrSurface_t *)( (byte *)lod + lod->ofsSurfaces );

	for ( i = 0 ; i < lod->numSurfaces ; i++ )
	{
		
		if(ent->e.customShader)
			shader = R_GetShaderByHandle(ent->e.customShader);
		else if(ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins)
		{
			skin = R_GetSkinByHandle(ent->e.customSkin);
			shader = tr.defaultShader;
			
			for(j = 0; j < skin->numSurfaces; j++)
			{
				if (!strcmp(skin->surfaces[j]->name, surface->name))
				{
					shader = skin->surfaces[j]->shader;
					break;
				}
			}
		}
		else if(surface->shaderIndex > 0)
			shader = R_GetShaderByHandle( surface->shaderIndex );
		else
			shader = tr.defaultShader;

		// we will add shadows even if the main object isn't visible in the view

		// stencil shadows can't do personal models unless I polyhedron clip
		if ( !personalModel
		        && r_shadows->integer == 2
			&& fogNum == 0
			&& !(ent->e.renderfx & ( RF_NOSHADOW | RF_DEPTHHACK ) )
			&& shader->sort == SS_OPAQUE )
		{
			R_AddDrawSurf( (void *)surface, tr.shadowShader, 0, qfalse );
		}

		// projection shadows work fine with personal models
		if ( r_shadows->integer == 3
			&& fogNum == 0
			&& (ent->e.renderfx & RF_SHADOW_PLANE )
			&& shader->sort == SS_OPAQUE )
		{
			R_AddDrawSurf( (void *)surface, tr.projectionShadowShader, 0, qfalse );
		}

		if (!personalModel)
			R_AddDrawSurf( (void *)surface, shader, fogNum, qfalse );

		surface = (mdrSurface_t *)( (byte *)surface + surface->ofsEnd );
	}
}
Exemple #17
0
/*
=================
R_AddIQMSurfaces

Add all surfaces of this model
=================
*/
void R_AddIQMSurfaces( trRefEntity_t *ent ) {
	iqmData_t		*data;
	iqmData_t		*skeleton;
	iqmData_t		*oldSkeleton;
	srfIQModel_t		*surface;
	int			i, j;
	qboolean		personalModel;
	int			cull;
	int			fogNum;
	int         cubemapIndex;
	shader_t		*shader;
	skin_t			*skin;
	skinSurface_t	*skinSurf;

	data = tr.currentModel->modelData;
	surface = data->surfaces;

	if ( !data->num_surfaces || !data->num_triangles || !data->num_vertexes ) {
		ri.Printf( PRINT_WARNING, "WARNING: Tried to render IQM '%s' with no surfaces\n", tr.currentModel->name );
		return;
	}

	skeleton = R_GetIQMModelDataByHandle( ent->e.frameModel, data );
	oldSkeleton = R_GetIQMModelDataByHandle( ent->e.oldframeModel, data );

	// don't add mirror only objects if not in a mirror/portal
	personalModel = (ent->e.renderfx & RF_ONLY_MIRROR) && !tr.viewParms.isPortal;

	if ( ent->e.renderfx & RF_WRAP_FRAMES ) {
		ent->e.frame %= skeleton->num_frames;
		ent->e.oldframe %= oldSkeleton->num_frames;
	}

	//
	// Validate the frames so there is no chance of a crash.
	// This will write directly into the entity structure, so
	// when the surfaces are rendered, they don't need to be
	// range checked again.
	//
	if ( (ent->e.frame >= skeleton->num_frames) 
	     || (ent->e.frame < 0)
	     || (ent->e.oldframe >= oldSkeleton->num_frames)
	     || (ent->e.oldframe < 0) ) {
		ri.Printf( PRINT_DEVELOPER, "R_AddIQMSurfaces: no such frame %d to %d for '%s'\n",
			   ent->e.oldframe, ent->e.frame,
			   tr.currentModel->name );
		ent->e.frame = 0;
		ent->e.oldframe = 0;
	}

	//
	// cull the entire model if merged bounding box of both frames
	// is outside the view frustum.
	//
	cull = R_CullIQM ( skeleton, oldSkeleton, ent );
	if ( cull == CULL_OUT ) {
		return;
	}

	//
	// set up lighting now that we know we aren't culled
	//
	if ( !personalModel || r_shadows->integer > 1 ) {
		R_SetupEntityLighting( &tr.refdef, ent );
	}

	//
	// see if we are in a fog volume
	//
	fogNum = R_ComputeIQMFogNum( skeleton, ent );

	cubemapIndex = R_CubemapForPoint(ent->e.origin);

	for ( i = 0 ; i < data->num_surfaces ; i++ ) {
		if(ent->e.customShader)
			shader = R_GetShaderByHandle( ent->e.customShader );
		else if(ent->e.customSkin > 0 && ent->e.customSkin <= tr.refdef.numSkins)
		{
			skin = &tr.refdef.skins[ent->e.customSkin - 1];
			shader = tr.defaultShader;

			for(j = 0 ; j < skin->numSurfaces ; j++)
			{
				skinSurf = &tr.skinSurfaces[ skin->surfaces[ j ] ];

				if (!strcmp(skinSurf->name, surface->name))
				{
					shader = skinSurf->shader;
					break;
				}
			}

			if (shader == tr.nodrawShader) {
				surface++;
				continue;
			}
		} else {
			shader = surface->shader;
		}

		// we will add shadows even if the main object isn't visible in the view

		// stencil shadows can't do personal models unless I polyhedron clip
		if ( !personalModel
			&& r_shadows->integer == 2 
			&& fogNum == 0
			&& !(ent->e.renderfx & ( RF_NOSHADOW | RF_DEPTHHACK ) ) 
			&& shader->sort == SS_OPAQUE ) {
			R_AddDrawSurf( (void *)surface, tr.shadowShader, 0, 0, 0, 0 );
		}

		// projection shadows work fine with personal models
		if ( r_shadows->integer == 3
			&& fogNum == 0
			&& (ent->e.renderfx & RF_SHADOW_PLANE )
			&& shader->sort == SS_OPAQUE ) {
			R_AddDrawSurf( (void *)surface, tr.projectionShadowShader, 0, 0, 0, 0 );
		}

		if( !personalModel ) {
			R_AddEntDrawSurf( ent, (void *)surface, shader, fogNum, 0, 0, cubemapIndex );
		}

		surface++;
	}
}
Exemple #18
0
/*
=================
R_AddMD3Surfaces

=================
*/
void R_AddMD3Surfaces( trRefEntity_t *ent ) {
	int i;
	mdvModel_t	*model = NULL;
	mdvSurface_t	*surface = NULL;
	shader_t        *shader = NULL;
	int cull;
	int lod;
	int fogNum;
	int cubemapIndex;
	qboolean personalModel;

	// don't add third_person objects if not in a portal
	personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !(tr.viewParms.isPortal 
	                 || (tr.viewParms.flags & (VPF_SHADOWMAP | VPF_DEPTHSHADOW)));

	if ( ent->e.renderfx & RF_WRAP_FRAMES ) {
		ent->e.frame %= tr.currentModel->mdv[0]->numFrames;
		ent->e.oldframe %= tr.currentModel->mdv[0]->numFrames;
	}

	//
	// Validate the frames so there is no chance of a crash.
	// This will write directly into the entity structure, so
	// when the surfaces are rendered, they don't need to be
	// range checked again.
	//
	if ( (ent->e.frame >= tr.currentModel->mdv[0]->numFrames)
		|| ( ent->e.frame < 0 )
		|| (ent->e.oldframe >= tr.currentModel->mdv[0]->numFrames)
		|| ( ent->e.oldframe < 0 ) ) {
		ri.Printf( PRINT_DEVELOPER, "R_AddMD3Surfaces: no such frame %d to %d for '%s'\n",
				   ent->e.oldframe, ent->e.frame,
				   tr.currentModel->name );
		ent->e.frame = 0;
		ent->e.oldframe = 0;
	}

	//
	// compute LOD
	//
	lod = R_ComputeLOD( ent );

	model = tr.currentModel->mdv[lod];

	//
	// cull the entire model if merged bounding box of both frames
	// is outside the view frustum.
	//
	cull = R_CullModel ( model, ent );
	if ( cull == CULL_OUT ) {
		return;
	}

	//
	// set up lighting now that we know we aren't culled
	//
	if ( !personalModel || r_shadows->integer > 1 ) {
		R_SetupEntityLighting( &tr.refdef, ent );
	}

	//
	// see if we are in a fog volume
	//
	fogNum = R_ComputeFogNum( model, ent );

	cubemapIndex = R_CubemapForPoint(ent->e.origin);

	//
	// draw all surfaces
	//
	surface = model->surfaces;
	for ( i = 0 ; i < model->numSurfaces ; i++ ) {
		int j;

//----(SA)	blink will change to be an overlay rather than replacing the head texture.
//		think of it like batman's mask.  the polygons that have eye texture are duplicated
//		and the 'lids' rendered with polygonoffset shader parm over the top of the open eyes.  this gives
//		minimal overdraw/alpha blending/texture use without breaking the model and causing seams
		if ( !Q_stricmp( surface->name, "h_blink" ) ) {
			if ( !( ent->e.renderfx & RF_BLINK ) ) {
				//surface = ( md3Surface_t * )( (byte *)surface + surface->ofsEnd );
				//surface++;
				continue;
			}
		}
//----(SA)	end

		if ( ent->e.customShader ) {
			shader = R_GetShaderByHandle( ent->e.customShader );
		} else if ( ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins ) {
			skin_t *skin;

			skin = R_GetSkinByHandle( ent->e.customSkin );

			// match the surface name to something in the skin file
			shader = tr.defaultShader;
			for ( j = 0 ; j < skin->numSurfaces ; j++ ) {
				// the names have both been lowercased
				if ( !strcmp( skin->surfaces[j]->name, surface->name ) ) {
					shader = skin->surfaces[j]->shader;
					break;
				}
			}

			if ( shader == tr.defaultShader ) {
				ri.Printf( PRINT_DEVELOPER, "WARNING: no shader for surface %s in skin %s\n", surface->name, skin->name );
			} else if ( shader->defaultShader )     {
				ri.Printf( PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name );
			}
		//} else if ( surface->numShaders <= 0 ) {
			//shader = tr.defaultShader;
		} else {
			//md3Shader = ( md3Shader_t * )( (byte *)surface + surface->ofsShaders );
			//md3Shader += ent->e.skinNum % surface->numShaders;
			shader = tr.shaders[ surface->shaderIndexes[ ent->e.skinNum % surface->numShaderIndexes ] ];
		}


		// don't add third_person objects if not viewing through a portal
		if ( !personalModel ) {
// GR - tessellate according to model capabilities
			srfVaoMdvMesh_t *vaoSurface = &model->vaoSurfaces[i];
			R_AddDrawSurf( (void *)vaoSurface, shader, fogNum, qfalse, qfalse, cubemapIndex, tr.currentModel->ATI_tess );
		}

		surface++;
	}

}
Exemple #19
0
/*==============================================================
  R_AddMyGhoulSurfaces
    This is where the system tosses MOD_GLM, surfaces are added here
==============================================================*/
void R_AddMyGhoulSurfaces( trRefEntity_t *ent ) {
	//model_t *animModel;
	//glaHeader_t *gla;
	glmHeader_t		*header;
//	model_t *model_anims;
	glmHeader_t *anims = 0;
	//glmSurface_t *surf;
	glmSurface_t *surface;
	glmSurfHierarchy_t *surfh;
	//mg_animstate_t *as = NULL;
	int animated = 0;
	glmLOD_t		*lod;
	glmLODSurfOffset_t	*lod_surf_ofs;
	shader_t		*shader;
	int				i;
	//int				cull;
	//int				lod;
	int				fogNum = 0;
	qboolean		personalModel;
	int newQuatDeal = 0;

	//mygBQArr_t *oldframe;
	//mygBQArr_t *newframe;
	//mygBQArr_t *resframe;
	//mygBoneArr_t *pose;
	//vec3_t	trans;
	//int bonewatch = 1;

	// don't add third_person objects if not in a portal
	personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal;

	if( personalModel )
	{
		//ent->needZFail = qtrue;
	}

	header = tr.currentModel->modelData;
	if( header->animIndex != 0 )
	{
#if 0
		model_anims = R_GetModelByHandle( header->animIndex );

		if( model_anims->type == MOD_GLA )
		{
			anims = model_anims->gla;
			as = RE_AS_Fetch( ent->e.frame );
		}

		if( as->index == 0 )
		{
			anims = 0;
			animated = 0;
		}
		else
		{
			if( as->index != 0 )
			{
				animated = 1;
			}
		}
#endif
	}
	else
	{
		animated = 0;
	}
	
//	printf( "(GLM) myghoul model is " );
//	if(personalModel) printf( "personal model, " );
//	if(animated) printf( "animated." );

#if 0
	if( animated )
	{
		AnimStateAnimsPop( as, anims );
		MG_InheritQuats( anims, (mgQuat_t*)as->resframe->quat, 0 );
		if( !newQuatDeal ) MG_MatsPopulate( anims, (mgQuat_t*)as->resframe->quat, as->pose );
	}
#endif

	// compute LOD
	//lod = R_ComputeLOD( ent );
	// cull the entire model if merged bounding box of both frames
	// is outside the view frustum.
	/*cull = R_CullModel ( header, ent );
	if ( cull == CULL_OUT ) {
		return;
	}*/
	// set up lighting now that we know we aren't culled
	if ( !personalModel || r_shadows->integer > 1 ) {
		R_SetupEntityLighting( &tr.refdef, ent );
	}

	// see if we are in a fog volume
	//fogNum = R_ComputeFogNum( header, ent );

	//ri.Printf( PRINT_DEVELOPER, "(I) Adding this MG Model\n" );
	lod = (glmLOD_t *)( (byte *)header + header->ofsLODs );
	lod_surf_ofs = ( glmLODSurfOffset_t *) ((byte *)lod + 4 );
	surfh = (glmSurfHierarchy_t *) ( (byte *)header + header->ofsSurfHierarchy );
	surface = (glmSurface_t *)( (byte *)lod_surf_ofs + lod_surf_ofs->offsets[0] );
	for ( i = 0 ; i < header->numSurfaces ; i++ ) {
		if( surfh->name[0] != '*' && strcmp( "stupidtriangle_off", surfh->name ) )
		{
			if ( ent->e.customShader ) {
				shader = R_GetShaderByHandle( ent->e.customShader );
			} else if ( ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins ) {
				skin_t *skin;
				int		j;

				skin = R_GetSkinByHandle( ent->e.customSkin );
				// match the surface name to something in the skin file
				shader = tr.defaultShader;
				for ( j = 0 ; j < skin->numSurfaces ; j++ ) {
					// the names have both been lowercased
					if ( !strcmp( skin->surfaces[j]->name, surfh->name ) ) {
						shader = skin->surfaces[j]->shader;
						break;
					}
				}
				if (shader == tr.defaultShader) {
					//ri.Printf( PRINT_DEVELOPER, "WARNING: no shader for surface %s in skin %s\n", surfh->name, skin->name);
				}
				else if (shader->defaultShader) {
					//ri.Printf( PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name);
				}
			} else {
				shader = R_GetShaderByHandle( surfh->shaderIndex );
			}
			// we will add shadows even if the main object isn't visible in the view

			// stencil shadows can't do personal models unless I polyhedron clip
			if ( !personalModel ) {
				R_AddDrawSurf( (void *)surface, shader, 0, qfalse );
			}

			if ( !personalModel
				&& r_shadows->integer == 2
				&& fogNum == 0
				&& !(ent->e.renderfx & ( RF_NOSHADOW | RF_DEPTHHACK ) )
				&& shader->sort == SS_OPAQUE ) {
				R_AddDrawSurf( (void *)surface, tr.shadowShader, 0, qfalse );
			}

			if ( r_shadows->integer == 4
				&& fogNum == 0
				&& !(ent->e.renderfx & ( RF_NOSHADOW | RF_DEPTHHACK ) )
				&& shader->sort == SS_OPAQUE ) {
				R_AddDrawSurf( (void *)surface, tr.shadowShader, 0, qfalse );
			}

			// projection shadows work fine with personal models
			if ( r_shadows->integer == 3
				&& fogNum == 0
				&& (ent->e.renderfx & RF_SHADOW_PLANE )
				&& shader->sort == SS_OPAQUE ) {
				R_AddDrawSurf( (void *)surface, tr.projectionShadowShader, 0, qfalse );
			}
		}

		surface = (glmSurface_t *)( (byte *)surface + surface->ofsEnd );
		surfh = (glmSurfHierarchy_t *) ( (byte *)&surfh->childIndexes[surfh->numChildren] );
	}
}
Exemple #20
0
/*
==============
R_AddMD5Surfaces
==============
*/
void R_AddMD5Surfaces( trRefEntity_t *ent )
{
	md5Model_t   *model;
	md5Surface_t *surface;
	shader_t     *shader;
	int          i;
	qboolean     personalModel;
	int          fogNum;

	model = tr.currentModel->model.md5;

	// don't add third_person objects if not in a portal
	personalModel = ( ent->e.renderfx & RF_THIRD_PERSON ) && !tr.viewParms.isPortal;

	// cull the entire model if merged bounding box of both frames
	// is outside the view frustum
	if ( R_CullMD5( ent ) == CULL_OUT )
	{
		return;
	}

	// set up lighting now that we know we aren't culled
	if ( !personalModel || r_shadows->integer > SHADOWING_BLOB )
	{
		R_SetupEntityLighting( &tr.refdef, ent );
	}

	// see if we are in a fog volume

	fogNum = 0; //R_FogWorldBox(ent->worldBounds);

	// finally add surfaces
	for ( i = 0, surface = model->surfaces; i < model->numSurfaces; i++, surface++ )
	{
		if ( ent->e.customShader )
		{
			shader = R_GetShaderByHandle( ent->e.customShader );
		}
		else if ( ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins )
		{
			skin_t *skin;

			skin = R_GetSkinByHandle( ent->e.customSkin );

			// match the surface name to something in the skin file
			shader = tr.defaultShader;

			// FIXME: replace MD3_MAX_SURFACES for skin_t::surfaces
			if ( i >= 0 && i < skin->numSurfaces && skin->surfaces[ i ] )
			{
				shader = skin->surfaces[ i ]->shader;
			}

			if ( shader == tr.defaultShader )
			{
				ri.Printf( PRINT_DEVELOPER, "WARNING: no shader for surface %i in skin %s\n", i, skin->name );
			}
			else if ( shader->defaultShader )
			{
				ri.Printf( PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name );
			}
		}
		else
		{
			shader = R_GetShaderByHandle( surface->shaderIndex );

			if ( ent->e.altShaderIndex > 0 && ent->e.altShaderIndex < MAX_ALTSHADERS &&
			     shader->altShader[ ent->e.altShaderIndex ].index )
			{
				shader = R_GetShaderByHandle( shader->altShader[ ent->e.altShaderIndex ].index );
			}
		}

		// we will add shadows even if the main object isn't visible in the view

		// don't add third_person objects if not viewing through a portal
		if ( !personalModel )
		{
			R_AddDrawSurf( ( surfaceType_t * ) surface, shader, fogNum, 0, 0 );
		}
	}
}
Exemple #21
0
/*
==============
R_AddAnimSurfaces
==============
*/
void R_AddAnimSurfaces(trRefEntity_t *ent)
{
	mdsHeader_t  *header = tr.currentModel->model.mds;
	mdsSurface_t *surface;
	shader_t     *shader = 0;
	int          i, fogNum, cull;
	qboolean     personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal; // don't add third_person objects if not in a portal

	// cull the entire model if merged bounding box of both frames
	// is outside the view frustum.
	cull = R_CullModel(header, ent);
	if (cull == CULL_OUT)
	{
		return;
	}

	// set up lighting now that we know we aren't culled
	if (!personalModel || r_shadows->integer > 1)
	{
		R_SetupEntityLighting(&tr.refdef, ent);
	}

	// see if we are in a fog volume
	fogNum = R_ComputeFogNum(header, ent);

	surface = ( mdsSurface_t * )((byte *)header + header->ofsSurfaces);
	for (i = 0 ; i < header->numSurfaces ; i++)
	{

		if (ent->e.customShader)
		{
			shader = R_GetShaderByHandle(ent->e.customShader);
		}
		else if (ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins)
		{
			skin_t *skin;
			int    hash;
			int    j;

			skin = R_GetSkinByHandle(ent->e.customSkin);

			// match the surface name to something in the skin file
			shader = tr.defaultShader;

			if (ent->e.renderfx & RF_BLINK)
			{
				char *s = va("%s_b", surface->name);   // append '_b' for 'blink'
				hash = Com_HashKey(s, strlen(s));
				for (j = 0 ; j < skin->numSurfaces ; j++)
				{
					if (hash != skin->surfaces[j]->hash)
					{
						continue;
					}
					if (!strcmp(skin->surfaces[j]->name, s))
					{
						shader = skin->surfaces[j]->shader;
						break;
					}
				}
			}

			if (shader == tr.defaultShader)        // blink reference in skin was not found
			{
				hash = Com_HashKey(surface->name, sizeof(surface->name));
				for (j = 0 ; j < skin->numSurfaces ; j++)
				{
					// the names have both been lowercased
					if (hash != skin->surfaces[j]->hash)
					{
						continue;
					}
					if (!strcmp(skin->surfaces[j]->name, surface->name))
					{
						shader = skin->surfaces[j]->shader;
						break;
					}
				}
			}

			if (shader == tr.defaultShader)
			{
				Ren_Developer("WARNING: no shader for surface %s in skin %s\n", surface->name, skin->name);
			}
			else if (shader->defaultShader)
			{
				Ren_Developer("WARNING: shader %s in skin %s not found\n", shader->name, skin->name);
			}
		}
		else
		{
			shader = R_GetShaderByHandle(surface->shaderIndex);
		}

		// don't add third_person objects if not viewing through a portal
		if (!personalModel)
		{
			R_AddDrawSurf((void *)surface, shader, fogNum, 0, 0);
		}

		surface = ( mdsSurface_t * )((byte *)surface + surface->ofsEnd);
	}
}
Exemple #22
0
/*
=================
R_AddMD3Surfaces

=================
*/
void R_AddMD3Surfaces(trRefEntity_t *ent) {
	int i;
	mdvModel_t		*model = NULL;
	mdvSurface_t	*surface = NULL;
	shader_t        *shader = NULL;
	int cull;
	int lod;
	int fogNum;
	int cubemapIndex;
	qboolean personalModel;

	// don't add third_person objects if not in a portal
	personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !(tr.viewParms.isPortal 
	 || (tr.viewParms.flags & (VPF_SHADOWMAP | VPF_DEPTHSHADOW)));

	if (ent->e.renderfx & RF_WRAP_FRAMES) {
		ent->e.frame %= tr.currentModel->mdv[0]->numFrames;
		ent->e.oldframe %= tr.currentModel->mdv[0]->numFrames;
	}

	//
	// Validate the frames so there is no chance of a crash.
	// This will write directly into the entity structure, so
	// when the surfaces are rendered, they don't need to be
	// range checked again.
	//
	if ((ent->e.frame >= tr.currentModel->mdv[0]->numFrames)
		|| (ent->e.frame < 0)
		|| (ent->e.oldframe >= tr.currentModel->mdv[0]->numFrames)
		|| (ent->e.oldframe < 0)) {
		ri.Printf(PRINT_DEVELOPER, "R_AddMD3Surfaces: no such frame %d to %d for '%s'\n",
				   ent->e.oldframe, ent->e.frame,
				   tr.currentModel->name);
		ent->e.frame = 0;
		ent->e.oldframe = 0;
	}

	//
	// compute LOD
	//
	lod = R_ComputeLOD(ent);

	model = tr.currentModel->mdv[lod];

	//
	// cull the entire model if merged bounding box of both frames
	// is outside the view frustum.
	//
	cull = R_CullModel (model, ent);
	if (cull == CULL_OUT) {
		return;
	}

	//
	// set up lighting now that we know we aren't culled
	//
	if (!personalModel || r_shadows->integer > 1) {
		R_SetupEntityLighting(&tr.refdef, ent);
	}

	//
	// see if we are in a fog volume
	//
	fogNum = R_ComputeFogNum(model, ent);

	cubemapIndex = R_CubemapForPoint(ent->e.origin);

	//
	// draw all surfaces
	//
	surface = model->surfaces;
	for (i = 0 ; i < model->numSurfaces ; i++) {

		if (ent->e.customShader) {
			shader = R_GetShaderByHandle(ent->e.customShader);
		} else if (ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins) {
			skin_t *skin;
			int j;

			skin = R_GetSkinByHandle(ent->e.customSkin);

			// match the surface name to something in the skin file
			shader = tr.defaultShader;

//----(SA)	added blink
			if (ent->e.renderfx & RF_BLINK) {
				const char *s = va("%s_b", surface->name);   // append '_b' for 'blink'
				for (j = 0 ; j < skin->numSurfaces ; j++) {
					if (!strcmp(skin->surfaces[j]->name, s)) {
						shader = skin->surfaces[j]->shader;
						break;
					}
				}
			}

			if (shader == tr.defaultShader) {    // blink reference in skin was not found
				for (j = 0 ; j < skin->numSurfaces ; j++) {
					// the names have both been lowercased

					if (!strcmp(skin->surfaces[j]->name, surface->name)) {
						shader = skin->surfaces[j]->shader;
						break;
					}
				}
			}
//----(SA)	end

			if (shader == tr.defaultShader) {
				ri.Printf(PRINT_DEVELOPER, "WARNING: no shader for surface %s in skin %s\n", surface->name, skin->name);
			} else if (shader->defaultShader)     {
				ri.Printf(PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name);
			}
		//} else if (surface->numShaders <= 0) {
			//shader = tr.defaultShader;
		} else {
			//md3Shader = (md3Shader_t *) ((byte *)surface + surface->ofsShaders);
			//md3Shader += ent->e.skinNum % surface->numShaders;
			//shader = tr.shaders[ md3Shader->shaderIndex ];
			shader = tr.shaders[ surface->shaderIndexes[ ent->e.skinNum % surface->numShaderIndexes ] ];
		}


		// for testing polygon shadows (on /all/ models)
		if (r_shadows->integer == 4) {
			R_AddDrawSurf((void *)surface, tr.projectionShadowShader, 0, qfalse, qfalse, 0);
		}


		// don't add third_person objects if not viewing through a portal
		if(!personalModel)
		{
			srfVaoMdvMesh_t *vaoSurface = &model->vaoSurfaces[i];

			R_AddDrawSurf((void *)vaoSurface, shader, fogNum, qfalse, qfalse, cubemapIndex);
		}

		surface++;
	}

}
Exemple #23
0
/*
=================
R_AddMDCSurfaces

=================
*/
void R_AddMDCSurfaces( trRefEntity_t *ent ) {
	int i;
	mdcHeader_t     *header = 0;
	mdcSurface_t    *surface = 0;
	md3Shader_t     *md3Shader = 0;
	shader_t        *shader = 0;
	int cull;
	int lod;
	int fogNum;
	qboolean personalModel;

	// don't add third_person objects if not in a portal
	personalModel = ( ent->e.renderfx & RF_THIRD_PERSON ) && !tr.viewParms.isPortal;

	if ( ent->e.renderfx & RF_WRAP_FRAMES ) {
		ent->e.frame %= tr.currentModel->mdc[0]->numFrames;
		ent->e.oldframe %= tr.currentModel->mdc[0]->numFrames;
	}

	//
	// Validate the frames so there is no chance of a crash.
	// This will write directly into the entity structure, so
	// when the surfaces are rendered, they don't need to be
	// range checked again.
	//
	if ( ( ent->e.frame >= tr.currentModel->mdc[0]->numFrames )
		 || ( ent->e.frame < 0 )
		 || ( ent->e.oldframe >= tr.currentModel->mdc[0]->numFrames )
		 || ( ent->e.oldframe < 0 ) ) {
		ri.Printf( PRINT_DEVELOPER, "R_AddMDCSurfaces: no such frame %d to %d for '%s'\n",
				   ent->e.oldframe, ent->e.frame,
				   tr.currentModel->name );
		ent->e.frame = 0;
		ent->e.oldframe = 0;
	}

	//
	// compute LOD
	//
	lod = R_ComputeLOD( ent );

	header = tr.currentModel->mdc[lod];

	//
	// cull the entire model if merged bounding box of both frames
	// is outside the view frustum.
	//
	cull = R_CullModel( header, ent );
	if ( cull == CULL_OUT ) {
		return;
	}

	//
	// set up lighting now that we know we aren't culled
	//
	if ( !personalModel || r_shadows->integer > 1 ) {
		R_SetupEntityLighting( &tr.refdef, ent );
	}

	//
	// see if we are in a fog volume
	//
	fogNum = R_ComputeFogNum( header, ent );

	//
	// draw all surfaces
	//
	surface = ( mdcSurface_t * )( (byte *)header + header->ofsSurfaces );
	for ( i = 0 ; i < header->numSurfaces ; i++ ) {
		int j;

//----(SA)	blink will change to be an overlay rather than replacing the head texture.
//		think of it like batman's mask.  the polygons that have eye texture are duplicated
//		and the 'lids' rendered with polygonoffset over the top of the open eyes.  this gives
//		minimal overdraw/alpha blending/texture use without breaking the model and causing seams
		if ( !Q_stricmp( surface->name, "h_blink" ) ) {
			if ( !( ent->e.renderfx & RF_BLINK ) ) {
				surface = ( mdcSurface_t * )( (byte *)surface + surface->ofsEnd );
				continue;
			}
		}
//----(SA)	end

		if ( ent->e.customShader ) {
			shader = R_GetShaderByHandle( ent->e.customShader );
		} else if ( ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins ) {
			skin_t *skin;

			skin = R_GetSkinByHandle( ent->e.customSkin );

			// match the surface name to something in the skin file
			shader = tr.defaultShader;
			for ( j = 0 ; j < skin->numSurfaces ; j++ ) {
				// the names have both been lowercased
				if ( !strcmp( skin->surfaces[j]->name, surface->name ) ) {
					shader = skin->surfaces[j]->shader;
					break;
				}
			}
		} else if ( surface->numShaders <= 0 ) {
			shader = tr.defaultShader;
		} else {
			md3Shader = ( md3Shader_t * )( (byte *)surface + surface->ofsShaders );
			md3Shader += ent->e.skinNum % surface->numShaders;
			shader = tr.shaders[ md3Shader->shaderIndex ];
		}


		// we will add shadows even if the main object isn't visible in the view

		// stencil shadows can't do personal models unless I polyhedron clip
		if ( !personalModel
			 && r_shadows->integer == 2
			 && fogNum == 0
			 && !( ent->e.renderfx & ( RF_NOSHADOW | RF_DEPTHHACK ) )
			 && shader->sort == SS_OPAQUE ) {
// GR - tessellate according to model capabilities
			R_AddDrawSurf( (void *)surface, tr.shadowShader, 0, qfalse, tr.currentModel->ATI_tess );
		}

//----(SA)

		// projection shadows work fine with personal models
//		if ( r_shadows->integer == 3
//			&& fogNum == 0
//			&& (ent->e.renderfx & RF_SHADOW_PLANE )
//			&& shader->sort == SS_OPAQUE ) {
//			R_AddDrawSurf( (void *)surface, tr.projectionShadowShader, 0, qfalse );
//		}

//----(SA)	for testing polygon shadows (on /all/ models)
//		if ( r_shadows->integer == 4)
//			R_AddDrawSurf( (void *)surface, tr.projectionShadowShader, 0, qfalse );

//----(SA)	done testing

		// don't add third_person objects if not viewing through a portal
		if ( !personalModel ) {
// GR - tessellate according to model capabilities
			R_AddDrawSurf( (void *)surface, shader, fogNum, qfalse, tr.currentModel->ATI_tess );
		}

		surface = ( mdcSurface_t * )( (byte *)surface + surface->ofsEnd );
	}

}
/*
=================
R_AddIQMSurfaces

Add all surfaces of this model
=================
*/
void R_AddIQMSurfaces( trRefEntity_t *ent ) {
	IQModel_t		*IQModel;
	srfIQModel_t		*surface;
	int                     i, j;
	bool                personalModel;
	int                     fogNum;
	shader_t                *shader;
	skin_t                  *skin;

	IQModel = tr.currentModel->iqm;
	surface = IQModel->surfaces;

	// don't add third_person objects if not in a portal
	personalModel = (ent->e.renderfx & RF_THIRD_PERSON) &&
	  tr.viewParms.portalLevel == 0;

	//
	// cull the entire model if merged bounding box of both frames
	// is outside the view frustum.
	//
	R_CullIQM( ent );

	if ( ent->cull == cullResult_t::CULL_OUT )
	{
		return;
	}

	//
	// set up lighting now that we know we aren't culled
	//
	if ( !personalModel || r_shadows->integer > Util::ordinal(shadowingMode_t::SHADOWING_BLOB) ) {
		R_SetupEntityLighting( &tr.refdef, ent, nullptr );
	}

	//
	// see if we are in a fog volume
	//
	fogNum = R_FogWorldBox( ent->worldBounds );

	for ( i = 0 ; i < IQModel->num_surfaces ; i++ ) {
		if(ent->e.customShader)
			shader = R_GetShaderByHandle( ent->e.customShader );
		else if(ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins)
		{
			skin = R_GetSkinByHandle(ent->e.customSkin);
			shader = tr.defaultShader;

			if (surface->name && *surface->name) {
				for(j = 0; j < skin->numSurfaces; j++)
				{
					if (!strcmp(skin->surfaces[j]->name, surface->name))
					{
						shader = skin->surfaces[j]->shader;
						break;
					}
				}
			}

			if ( shader == tr.defaultShader && i >= 0 && i < skin->numSurfaces && skin->surfaces[ i ] )
			{
				shader = skin->surfaces[ i ]->shader;
			}
		} else {

			shader = surface->shader;

			if ( ent->e.altShaderIndex > 0 && ent->e.altShaderIndex < MAX_ALTSHADERS &&
				shader->altShader[ ent->e.altShaderIndex ].index )
			{
				shader = R_GetShaderByHandle( shader->altShader[ ent->e.altShaderIndex ].index );
			}
		}

		// we will add shadows even if the main object isn't visible in the view

		if( !personalModel ) {
			R_AddDrawSurf( ( surfaceType_t *)surface, shader, -1, fogNum );
		}

		surface++;
	}
}
Exemple #25
0
/*
=================
R_AddIQMSurfaces

Add all surfaces of this model
=================
*/
void R_AddIQMSurfaces(trRefEntity_t* ent) {
    iqmData_t*       data;
    srfIQModel_t*        surface;
    int         i, j;
    qboolean        personalModel;
    int         cull;
    int         fogNum;
    shader_t*        shader;
    skin_t*          skin;

    data = tr.currentModel->modelData;
    surface = data->surfaces;

    // don't add third_person objects if not in a portal
    personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal;

    if (ent->e.renderfx & RF_WRAP_FRAMES) {
        ent->e.frame %= data->num_frames;
        ent->e.oldframe %= data->num_frames;
    }

    //
    // Validate the frames so there is no chance of a crash.
    // This will write directly into the entity structure, so
    // when the surfaces are rendered, they don't need to be
    // range checked again.
    //
    if ((ent->e.frame >= data->num_frames)
            || (ent->e.frame < 0)
            || (ent->e.oldframe >= data->num_frames)
            || (ent->e.oldframe < 0)) {
        ri.Printf(PRINT_DEVELOPER, "R_AddIQMSurfaces: no such frame %d to %d for '%s'\n",
                  ent->e.oldframe, ent->e.frame,
                  tr.currentModel->name);
        ent->e.frame = 0;
        ent->e.oldframe = 0;
    }

    //
    // cull the entire model if merged bounding box of both frames
    // is outside the view frustum.
    //
    cull = R_CullIQM(data, ent);
    if (cull == CULL_OUT) {
        return;
    }

    //
    // set up lighting now that we know we aren't culled
    //
    if (!personalModel || r_shadows->integer > 1) {
        R_SetupEntityLighting(&tr.refdef, ent);
    }

    //
    // see if we are in a fog volume
    //
    fogNum = R_ComputeIQMFogNum(data, ent);

    for (i = 0 ; i < data->num_surfaces ; i++) {
        if (ent->e.customShader)
            shader = R_GetShaderByHandle(ent->e.customShader);
        else if (ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins) {
            skin = R_GetSkinByHandle(ent->e.customSkin);
            shader = tr.defaultShader;

            for (j = 0; j < skin->numSurfaces; j++) {
                if (!strcmp(skin->surfaces[j]->name, surface->name)) {
                    shader = skin->surfaces[j]->shader;
                    break;
                }
            }
        } else {
            shader = surface->shader;
        }

        // we will add shadows even if the main object isn't visible in the view

        // stencil shadows can't do personal models unless I polyhedron clip
        if (!personalModel
                && r_shadows->integer == 2
                && fogNum == 0
                && !(ent->e.renderfx & (RF_NOSHADOW | RF_DEPTHHACK))
                && shader->sort == SS_OPAQUE) {
            R_AddDrawSurf((void*)surface, tr.shadowShader, 0, 0);
        }

        // projection shadows work fine with personal models
        if (r_shadows->integer == 3
                && fogNum == 0
                && (ent->e.renderfx & RF_SHADOW_PLANE)
                && shader->sort == SS_OPAQUE) {
            R_AddDrawSurf((void*)surface, tr.projectionShadowShader, 0, 0);
        }

        if (!personalModel) {
            R_AddDrawSurf((void*)surface, shader, fogNum, 0);
        }

        surface++;
    }
}
Exemple #26
0
/*
=================
R_AddMD3Surfaces

=================
*/
void R_AddMD3Surfaces( trRefEntity_t *ent ) {
	int				i;
	md3Header_t		*header = 0;
	md3Surface_t	*surface = 0;
	md3Shader_t		*md3Shader = 0;
	shader_t		*shader = 0;
	shader_t		*main_shader = 0;
	int				cull;
	int				lod;
	int				fogNum;
	qboolean		personalModel;

	// don't add third_person objects if not in a portal
	personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal;

	if ( ent->e.renderfx & RF_CAP_FRAMES) {
		if (ent->e.frame > tr.currentModel->md3[0]->numFrames-1)
			ent->e.frame = tr.currentModel->md3[0]->numFrames-1;
		if (ent->e.oldframe > tr.currentModel->md3[0]->numFrames-1)
			ent->e.oldframe = tr.currentModel->md3[0]->numFrames-1;
	}
	else if ( ent->e.renderfx & RF_WRAP_FRAMES ) {
		ent->e.frame %= tr.currentModel->md3[0]->numFrames;
		ent->e.oldframe %= tr.currentModel->md3[0]->numFrames;
	}

	//
	// Validate the frames so there is no chance of a crash.
	// This will write directly into the entity structure, so
	// when the surfaces are rendered, they don't need to be
	// range checked again.
	//
	if ( (ent->e.frame >= tr.currentModel->md3[0]->numFrames) 
		|| (ent->e.frame < 0)
		|| (ent->e.oldframe >= tr.currentModel->md3[0]->numFrames)
		|| (ent->e.oldframe < 0) ) 
	{
			VID_Printf (PRINT_ALL, "R_AddMD3Surfaces: no such frame %d to %d for '%s'\n",
				ent->e.oldframe, ent->e.frame,
				tr.currentModel->name );
			ent->e.frame = 0;
			ent->e.oldframe = 0;
	}

	//
	// compute LOD
	//
	lod = R_ComputeLOD( ent );

	header = tr.currentModel->md3[lod];

	//
	// cull the entire model if merged bounding box of both frames
	// is outside the view frustum.
	//
	cull = R_CullModel ( header, ent );
	if ( cull == CULL_OUT ) {
		return;
	}

	//
	// set up lighting now that we know we aren't culled
	//
#ifdef VV_LIGHTING
	if ( !personalModel ) {
		VVLightMan.R_SetupEntityLighting( &tr.refdef, ent );
#else
	if ( !personalModel || r_shadows->integer > 1 ) {
		R_SetupEntityLighting( &tr.refdef, ent );
#endif
	}

	//
	// see if we are in a fog volume
	//
	fogNum = R_ComputeFogNum( header, ent );

	//
	// draw all surfaces
	//
	main_shader = R_GetShaderByHandle( ent->e.customShader );

	surface = (md3Surface_t *)( (byte *)header + header->ofsSurfaces );
	for ( i = 0 ; i < header->numSurfaces ; i++ ) {

		if ( ent->e.customShader ) {// a little more efficient
			shader = main_shader;
		} else if ( ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins ) {
			skin_t *skin;
			int		j;

			skin = R_GetSkinByHandle( ent->e.customSkin );

			// match the surface name to something in the skin file
			shader = tr.defaultShader;
			for ( j = 0 ; j < skin->numSurfaces ; j++ ) {
				// the names have both been lowercased
				if ( !strcmp( skin->surfaces[j]->name, surface->name ) ) {
					shader = skin->surfaces[j]->shader;
					break;
				}
			}
		} else if ( surface->numShaders <= 0 ) {
			shader = tr.defaultShader;
		} else {
			md3Shader = (md3Shader_t *) ( (byte *)surface + surface->ofsShaders );
			md3Shader += ent->e.skinNum % surface->numShaders;
			shader = tr.shaders[ md3Shader->shaderIndex ];
		}


		// we will add shadows even if the main object isn't visible in the view

		// stencil shadows can't do personal models unless I polyhedron clip
		if ( !personalModel
			&& r_shadows->integer == 2 
#ifndef VV_LIGHTING
			&& fogNum == 0
#endif
			&& (ent->e.renderfx & RF_SHADOW_PLANE )
			&& !(ent->e.renderfx & ( RF_NOSHADOW | RF_DEPTHHACK ) ) 
			&& shader->sort == SS_OPAQUE ) {
			R_AddDrawSurf( (surfaceType_t *)surface, tr.shadowShader, 0, qfalse );
		}

		// projection shadows work fine with personal models
		if ( r_shadows->integer == 3
			&& fogNum == 0
			&& (ent->e.renderfx & RF_SHADOW_PLANE )
			&& shader->sort == SS_OPAQUE ) {
			R_AddDrawSurf( (surfaceType_t *)surface, tr.projectionShadowShader, 0, qfalse );
		}

		// don't add third_person objects if not viewing through a portal
		if ( !personalModel ) {
#ifdef VV_LIGHTING
			int dlightBits = ( ent->dlightBits != 0 );
			R_AddDrawSurf( (surfaceType_t *)surface, shader, fogNum, dlightBits );
#else
			R_AddDrawSurf( (surfaceType_t *)surface, shader, fogNum, qfalse );
#endif
		}

		surface = (md3Surface_t *)( (byte *)surface + surface->ofsEnd );
	}

}
/*
==============
R_AddMD5Surfaces
==============
*/
void R_AddMD5Surfaces(trRefEntity_t * ent)
{
	md5Model_t     *model;
	md5Surface_t   *surface;
	shader_t       *shader;
	int             i;
	qboolean        personalModel;
	int				fogNum;

	model = tr.currentModel->md5;

	// don't add third_person objects if not in a portal
	personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal;

	// cull the entire model if merged bounding box of both frames
	// is outside the view frustum
	R_CullMD5(ent);
	if(ent->cull == CULL_OUT)
	{
		return;
	}

	// set up world bounds for light intersection tests
	R_SetupEntityWorldBounds(ent);

	// set up lighting now that we know we aren't culled
	if(!personalModel || r_shadows->integer > SHADOWING_BLOB)
	{
		R_SetupEntityLighting(&tr.refdef, ent, NULL);
	}

	// see if we are in a fog volume
	fogNum = R_FogWorldBox(ent->worldBounds);

	if(!r_vboModels->integer || !model->numVBOSurfaces ||
	   (!glConfig2.vboVertexSkinningAvailable && ent->e.skeleton.type == SK_ABSOLUTE))
	{
		// finally add surfaces
		for(i = 0, surface = model->surfaces; i < model->numSurfaces; i++, surface++)
		{
			if(ent->e.customShader)
			{
				shader = R_GetShaderByHandle(ent->e.customShader);
			}
			else if(ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins)
			{
				skin_t         *skin;

				skin = R_GetSkinByHandle(ent->e.customSkin);

				// match the surface name to something in the skin file
				shader = tr.defaultShader;

				// FIXME: replace MD3_MAX_SURFACES for skin_t::surfaces
				if(i >= 0 && i < skin->numSurfaces && skin->surfaces[i])
				{
					shader = skin->surfaces[i]->shader;
				}
				if(shader == tr.defaultShader)
				{
					ri.Printf(PRINT_DEVELOPER, "WARNING: no shader for surface %i in skin %s\n", i, skin->name);
				}
				else if(shader->defaultShader)
				{
					ri.Printf(PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name);
				}
			}
			else
			{
				shader = R_GetShaderByHandle(surface->shaderIndex);
			}

			// we will add shadows even if the main object isn't visible in the view

			// don't add third_person objects if not viewing through a portal
			if(!personalModel)
			{
				R_AddDrawSurf((void *)surface, shader, -1, fogNum);
			}
		}
	}
	else
	{
		int             i;
		srfVBOMD5Mesh_t *vboSurface;
		shader_t       *shader;

		for(i = 0; i < model->numVBOSurfaces; i++)
		{
			vboSurface = model->vboSurfaces[i];

			if(ent->e.customShader)
			{
				shader = R_GetShaderByHandle(ent->e.customShader);
			}
			else if(ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins)
			{
				skin_t         *skin;

				skin = R_GetSkinByHandle(ent->e.customSkin);

				// match the surface name to something in the skin file
				shader = tr.defaultShader;

				// FIXME: replace MD3_MAX_SURFACES for skin_t::surfaces
				//if(i >= 0 && i < skin->numSurfaces && skin->surfaces[i])
				if(vboSurface->skinIndex >= 0 && vboSurface->skinIndex < skin->numSurfaces && skin->surfaces[vboSurface->skinIndex])
				{
					shader = skin->surfaces[vboSurface->skinIndex]->shader;
				}

				if(shader == tr.defaultShader)
				{
					ri.Printf(PRINT_DEVELOPER, "WARNING: no shader for surface %i in skin %s\n", i, skin->name);
				}
				else if(shader->defaultShader)
				{
					ri.Printf(PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name);
				}
			}
			else
			{
				shader = vboSurface->shader;
			}

			// don't add third_person objects if not viewing through a portal
			if(!personalModel)
			{
				R_AddDrawSurf((void *)vboSurface, shader, -1, fogNum);
			}
		}
	}
}
Exemple #28
0
/*
===============
R_AddAmbientDrawsurfs

Adds surfaces for the given viewEntity
Walks through the viewEntitys list and creates drawSurf_t for each surface of
each viewEntity that has a non-empty scissorRect
===============
*/
static void R_AddAmbientDrawsurfs( viewEntity_t *vEntity )
{
	int						i, total;
	idRenderEntityLocal		*def;
	srfTriangles_t			*tri;
	idRenderModel			*model;
	const idMaterial		*shader;
	
	def = vEntity->entityDef;
	
	if( def->dynamicModel )
	{
		model = def->dynamicModel;
	}
	else
	{
		model = def->parms.hModel;
	}
	
	// add all the surfaces
	total = model->NumSurfaces();
	
	for( i = 0; i < total; i++ )
	{
		const modelSurface_t	*surf = model->Surface( i );
		
		// for debugging, only show a single surface at a time
		if( r_singleSurface.GetInteger() >= 0 && i != r_singleSurface.GetInteger() )
		{
			continue;
		}
		tri = surf->geometry;
		
		if( !tri )
		{
			continue;
		}
		
		if( !tri->numIndexes )
		{
			continue;
		}
		shader = surf->shader;
		shader = R_RemapShaderBySkin( shader, def->parms.customSkin, def->parms.customShader );
		
		R_GlobalShaderOverride( &shader );
		
		if( !shader )
		{
			continue;
		}
		
		if( !shader->IsDrawn() )
		{
			continue;
		}
		
		// debugging tool to make sure we are have the correct pre-calculated bounds
		if( r_checkBounds.GetBool() )
		{
			int j, k;
			
			for( j = 0; j < tri->numVerts; j++ )
			{
				for( k = 0; k < 3; k++ )
				{
					if( tri->verts[j].xyz[k] > tri->bounds[1][k] + CHECK_BOUNDS_EPSILON || tri->verts[j].xyz[k] < tri->bounds[0][k] - CHECK_BOUNDS_EPSILON )
					{
						common->Printf( "bad tri->bounds on %s:%s\n", def->parms.hModel->Name(), shader->GetName() );
						break;
					}
					
					if( tri->verts[j].xyz[k] > def->referenceBounds[1][k] + CHECK_BOUNDS_EPSILON || tri->verts[j].xyz[k] < def->referenceBounds[0][k] - CHECK_BOUNDS_EPSILON )
					{
						common->Printf( "bad referenceBounds on %s:%s\n", def->parms.hModel->Name(), shader->GetName() );
						break;
					}
				}
				
				if( k != 3 )
				{
					break;
				}
			}
		}
		
		if( !R_CullLocalBox( tri->bounds, vEntity->modelMatrix, 5, tr.viewDef->frustum ) )
		{
			def->visibleCount = tr.viewCount;
			
			// make sure we have an ambient cache
			if( !R_CreateAmbientCache( tri, shader->ReceivesLighting() ) )
			{
				// don't add anything if the vertex cache was too full to give us an ambient cache
				return;
			}
			
			// touch it so it won't get purged
			vertexCache.Touch( tri->ambientCache );
			
			if( !tri->indexCache )
			{
				vertexCache.Alloc( tri->indexes, tri->numIndexes * sizeof( tri->indexes[0] ), &tri->indexCache, true );
			}
			
			if( tri->indexCache )
			{
				vertexCache.Touch( tri->indexCache );
			}
			
			// add the surface for drawing
			R_AddDrawSurf( tri, vEntity, &vEntity->entityDef->parms, shader, vEntity->scissorRect );
			
			// ambientViewCount is used to allow light interactions to be rejected
			// if the ambient surface isn't visible at all
			tri->ambientViewCount = tr.viewCount;
		}
	}
	
	// add the lightweight decal surfaces
	for( idRenderModelDecal *decal = def->decals; decal; decal = decal->Next() )
	{
		decal->AddDecalDrawSurf( vEntity );
	}
}
Exemple #29
0
/*
=================
R_AddMD3Surfaces

=================
*/
void R_AddMD3Surfaces(trRefEntity_t * ent)
{
	int             i;
	md3Header_t    *header = 0;
	md3Surface_t   *surface = 0;
	md3Shader_t    *md3Shader = 0;
	shader_t       *shader = 0;
	int             cull;
	int             lod;
	int             fogNum;
	bool        personalModel;

	// don't add third_person objects if not in a portal
	personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal;

	if(ent->e.renderfx & RF_WRAP_FRAMES)
	{
		ent->e.frame %= tr.currentModel->model.md3[0]->numFrames;
		ent->e.oldframe %= tr.currentModel->model.md3[0]->numFrames;
	}

	//
	// compute LOD
	//
	if(ent->e.renderfx & RF_FORCENOLOD)
	{
		lod = 0;
	}
	else
	{
		lod = R_ComputeLOD(ent);
	}

	//
	// Validate the frames so there is no chance of a crash.
	// This will write directly into the entity structure, so
	// when the surfaces are rendered, they don't need to be
	// range checked again.
	//
	if((ent->e.frame >= tr.currentModel->model.md3[lod]->numFrames)
	   || (ent->e.frame < 0) || (ent->e.oldframe >= tr.currentModel->model.md3[lod]->numFrames) || (ent->e.oldframe < 0))
	{
		ri.Printf(PRINT_DEVELOPER, "R_AddMD3Surfaces: no such frame %d to %d for '%s' (%d)\n",
				  ent->e.oldframe, ent->e.frame, tr.currentModel->name, tr.currentModel->model.md3[lod]->numFrames);
		ent->e.frame = 0;
		ent->e.oldframe = 0;
	}

	header = tr.currentModel->model.md3[lod];

	//
	// cull the entire model if merged bounding box of both frames
	// is outside the view frustum.
	//
	cull = R_CullModel(header, ent);
	if(cull == CULL_OUT)
	{
		return;
	}

	//
	// set up lighting now that we know we aren't culled
	//
	if(!personalModel || r_shadows->integer > 1)
	{
		R_SetupEntityLighting(&tr.refdef, ent);
	}

	//
	// see if we are in a fog volume
	//
	fogNum = R_ComputeFogNum(header, ent);

	//
	// draw all surfaces
	//
	surface = (md3Surface_t *) ((byte *) header + header->ofsSurfaces);
	for(i = 0; i < header->numSurfaces; i++)
	{

		if(ent->e.customShader)
		{
			shader = R_GetShaderByHandle(ent->e.customShader);
		}
		else if(ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins)
		{
			skin_t         *skin;
			int             hash;
			int             j;

			skin = R_GetSkinByHandle(ent->e.customSkin);

			// match the surface name to something in the skin file
			shader = tr.defaultShader;

//----(SA)  added blink
			if(ent->e.renderfx & RF_BLINK)
			{
				char           *s = va("%s_b", surface->name);	// append '_b' for 'blink'

				hash = Com_HashKey(s, strlen(s));
				for(j = 0; j < skin->numSurfaces; j++)
				{
					if(hash != skin->surfaces[j]->hash)
					{
						continue;
					}
					if(!strcmp(skin->surfaces[j]->name, s))
					{
						shader = skin->surfaces[j]->shader;
						break;
					}
				}
			}

			if(shader == tr.defaultShader)
			{					// blink reference in skin was not found
				hash = Com_HashKey(surface->name, sizeof(surface->name));
				for(j = 0; j < skin->numSurfaces; j++)
				{
					// the names have both been lowercased
					if(hash != skin->surfaces[j]->hash)
					{
						continue;
					}
					if(!strcmp(skin->surfaces[j]->name, surface->name))
					{
						shader = skin->surfaces[j]->shader;
						break;
					}
				}
			}
//----(SA)  end

			if(shader == tr.defaultShader)
			{
				ri.Printf(PRINT_DEVELOPER, "WARNING: no shader for surface %s in skin %s\n", surface->name, skin->name);
			}
			else if(shader->defaultShader)
			{
				ri.Printf(PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name);
			}
		}
		else if(surface->numShaders <= 0)
		{
			shader = tr.defaultShader;
		}
		else
		{
			md3Shader = (md3Shader_t *) ((byte *) surface + surface->ofsShaders);
			md3Shader += ent->e.skinNum % surface->numShaders;
			shader = tr.shaders[md3Shader->shaderIndex];
		}


		// we will add shadows even if the main object isn't visible in the view

		// stencil shadows can't do personal models unless I polyhedron clip
		if(!personalModel
		   && r_shadows->integer == 2
		   && fogNum == 0 && !(ent->e.renderfx & (RF_NOSHADOW | RF_DEPTHHACK)) && shader->sort == SS_OPAQUE)
		{
			R_AddDrawSurf((surfaceType_t *)surface, tr.shadowShader, 0, 0, 0);
		}

		// projection shadows work fine with personal models
		if(r_shadows->integer == 3 && fogNum == 0 && (ent->e.renderfx & RF_SHADOW_PLANE) && shader->sort == SS_OPAQUE)
		{
			R_AddDrawSurf((surfaceType_t *)surface, tr.projectionShadowShader, 0, 0, 0);
		}


		// for testing polygon shadows (on /all/ models)
		if(r_shadows->integer == 4)
		{
			R_AddDrawSurf((surfaceType_t *)surface, tr.projectionShadowShader, 0, 0, 0);
		}


		// don't add third_person objects if not viewing through a portal
		if(!personalModel)
		{
			R_AddDrawSurf((surfaceType_t *)surface, shader, fogNum, 0, 0);
		}

		surface = (md3Surface_t *) ((byte *) surface + surface->ofsEnd);
	}
}
Exemple #30
0
/*
==============
R_AddAnimSurfaces
==============
*/
void R_AddAnimSurfaces( trRefEntity_t *ent ) {
	mdsHeader_t     *header;
	mdsSurface_t    *surface;
	shader_t        *shader = 0;
	int i, fogNum, cull;
	qboolean personalModel;

	// don't add third_person objects if not in a portal
	personalModel = ( ent->e.renderfx & RF_THIRD_PERSON ) && !tr.viewParms.isPortal;

	header = tr.currentModel->mds;

	//
	// cull the entire model if merged bounding box of both frames
	// is outside the view frustum.
	//
	cull = R_CullModel( header, ent );
	if ( cull == CULL_OUT ) {
		return;
	}

	//
	// set up lighting now that we know we aren't culled
	//
	if ( !personalModel || r_shadows->integer > 1 ) {
		R_SetupEntityLighting( &tr.refdef, ent );
	}

	//
	// see if we are in a fog volume
	//
	fogNum = R_ComputeFogNum( header, ent );

	surface = ( mdsSurface_t * )( (byte *)header + header->ofsSurfaces );
	for ( i = 0 ; i < header->numSurfaces ; i++ ) {
		int j;

//----(SA)	blink will change to be an overlay rather than replacing the head texture.
//		think of it like batman's mask.  the polygons that have eye texture are duplicated
//		and the 'lids' rendered with polygonoffset over the top of the open eyes.  this gives
//		minimal overdraw/alpha blending/texture use without breaking the model and causing seams
		if ( !Q_stricmp( surface->name, "h_blink" ) ) {
			if ( !( ent->e.renderfx & RF_BLINK ) ) {
				surface = ( mdsSurface_t * )( (byte *)surface + surface->ofsEnd );
				continue;
			}
		}
//----(SA)	end


		if ( ent->e.customShader ) {
			shader = R_GetShaderByHandle( ent->e.customShader );
		} else if ( ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins ) {
			skin_t *skin;

			skin = R_GetSkinByHandle( ent->e.customSkin );

			// match the surface name to something in the skin file
			shader = tr.defaultShader;
			for ( j = 0 ; j < skin->numSurfaces ; j++ ) {
				// the names have both been lowercased
				if ( !strcmp( skin->surfaces[j]->name, surface->name ) ) {
					shader = skin->surfaces[j]->shader;
					break;
				}
			}

			if ( shader == tr.defaultShader ) {
				ri.Printf( PRINT_DEVELOPER, "WARNING: no shader for surface %s in skin %s\n", surface->name, skin->name );
			} else if ( shader->defaultShader ) {
				ri.Printf( PRINT_DEVELOPER, "WARNING: shader %s in skin %s not found\n", shader->name, skin->name );
			}
		} else {
			shader = R_GetShaderByHandle( surface->shaderIndex );
		}

		// don't add third_person objects if not viewing through a portal
		if ( !personalModel ) {
			// GR - always tessellate these objects
			R_AddDrawSurf( (void *)surface, shader, fogNum, qfalse, ATI_TESS_TRUFORM );
		}

		surface = ( mdsSurface_t * )( (byte *)surface + surface->ofsEnd );
	}
}