Ejemplo n.º 1
0
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CDispChain::AddTo( IDispInfo *pDispInfo )
{
#if 0
	//
	// only add a surface once
	//
	// NOTE: search is linear for now, look into this during opt. phase
	//
	for( IDispInfo *pCmpDispInfo = m_pHead; pCmpDispInfo; pCmpDispInfo = pCmpDispInfo->GetNextInChain() )
	{
		if( pCmpDispInfo == pDispInfo )
			return;
	}
#endif

	//
	// add unique surface to the chain
	//
	if( m_bForRayCasts )
	{
		pDispInfo->SetNextInRayCastChain( m_pHead );
	}
	else
	{
		pDispInfo->SetNextInRenderChain( m_pHead );
	}
	m_pHead = pDispInfo;
}
Ejemplo n.º 2
0
// returns surfID
static SurfaceHandle_t R_LightVecDisplacementChain( LightVecState_t& state, bool bUseLightStyles, Vector& c )
{
	// test the ray against displacements
	SurfaceHandle_t surfID = SURFACE_HANDLE_INVALID;

	for ( int i = 0; i < state.m_LightTestDisps.Count(); i++ )
	{
	
		float dist;
		Vector2D luv, tuv;
		IDispInfo *pDispInfo = state.m_LightTestDisps[i];
		if (pDispInfo->TestRay( state.m_Ray, 0.0f, state.m_HitFrac, dist, &luv, &tuv ))
		{
			// It hit it, and at a point closer than the previously computed
			// nearest intersection point
			state.m_HitFrac = dist;
			surfID = pDispInfo->GetParent();
			ComputeLightmapColor( surfID, (int)luv.x, (int)luv.y, bUseLightStyles, c );

			if (state.m_pLightmapS && state.m_pLightmapT)
			{
				ComputeLightmapCoordsAtIntersection( SurfaceLighting(surfID), (int)luv.x, (int)luv.y, state.m_pLightmapS, state.m_pLightmapT );
			}

			if (state.m_pTextureS && state.m_pTextureT)
			{
				*state.m_pTextureS = tuv.x;
				*state.m_pTextureT = tuv.y;
			}
		}
	}

	return surfID;
}
Ejemplo n.º 3
0
// returns surfID
static int R_LightVecDisplacementChain( LightVecState_t& state, bool bUseLightStyles, Vector& c )
{
	// test the ray against displacements
	int surfID = -1;

	IDispInfo *pDispInfo = state.m_LightTestChain.GetHead();
	for( ; pDispInfo; pDispInfo = pDispInfo->GetNextInRayCastChain() )
	{
		float dist;
		Vector2D luv, tuv;
		if (pDispInfo->TestRay( state.m_Ray, 0.0f, state.m_HitFrac, dist, &luv, &tuv ))
		{
			// It hit it, and at a point closer than the previously computed
			// nearest intersection point
			state.m_HitFrac = dist;
			surfID = pDispInfo->GetParent();

			ComputeLightmapColor( surfID, (int)luv.x, (int)luv.y, bUseLightStyles, c );

			if (state.m_pLightmapS && state.m_pLightmapT)
			{
				ComputeLightmapCoordsAtIntersection( SurfaceLighting(surfID), (int)luv.x, (int)luv.y, state.m_pLightmapS, state.m_pLightmapT );
			}

			if (state.m_pTextureS && state.m_pTextureT)
			{
				*state.m_pTextureS = tuv.x;
				*state.m_pTextureT = tuv.y;
			}
		}
	}

	return surfID;
}
Ejemplo n.º 4
0
int R_MarkLightsLeaf( dlight_t *light, int bit, mleaf_t *pLeaf )
{
	int countMarked = 0;
	for ( int i = 0; i < pLeaf->dispCount; i++ )
	{
		IDispInfo *pDispInfo = MLeaf_Disaplcement( pLeaf, i );

		SurfaceHandle_t parentSurfID = pDispInfo->GetParent();
		if ( parentSurfID )
		{
			// Don't redo all this work if we already hit this surface and decided it's lit by this light.
			msurfacelighting_t *pLighting = SurfaceLighting( parentSurfID );
			if( !R_IsDLightAlreadyMarked( pLighting, bit) )
			{
				// Do a different test for displacement surfaces.
				Vector bmin, bmax;
				MSurf_DispInfo( parentSurfID )->GetBoundingBox( bmin, bmax );
				if ( IsBoxIntersectingSphere(bmin, bmax, light->origin, light->GetRadius()) )
				{
					R_MarkSurfaceDLight( parentSurfID, pLighting, bit );
					countMarked++;
				}
			}
		}
	}

	SurfaceHandle_t *pHandle = &host_state.worldbrush->marksurfaces[pLeaf->firstmarksurface];
	for ( int i = 0; i < pLeaf->nummarksurfaces; i++ )
	{
		SurfaceHandle_t surfID = pHandle[i];
		ASSERT_SURF_VALID( surfID );
		
		// only process leaf surfaces
		if ( MSurf_Flags( surfID ) & SURFDRAW_NODE )
			continue;

		// Don't redo all this work if we already hit this surface and decided it's lit by this light.
		msurfacelighting_t *pLighting = SurfaceLighting( surfID );
		if(R_IsDLightAlreadyMarked(pLighting, bit))
			continue;

		float dist = DotProduct( light->origin, MSurf_Plane( surfID ).normal) - MSurf_Plane( surfID ).dist;
		
		if ( dist > light->GetRadius() || dist < -light->GetRadius() )
			continue;

		countMarked += R_TryLightMarkSurface( light, pLighting, surfID, bit );
	}
	return countMarked;
}
Ejemplo n.º 5
0
void R_MarkLightsLeaf( dlight_t *light, int bit, mleaf_t *pLeaf )
{
	for( CDispIterator it=pLeaf->GetDispIterator(); it.IsValid(); )
	{
		CDispLeafLink *pCur = it.Inc();

		// get current displacement surface info
		IDispInfo *pDispInfo = static_cast<IDispInfo*>( pCur->m_pDispInfo );

		int parentSurfID = pDispInfo->GetParent();
		if ( parentSurfID )
		{
			// Don't redo all this work if we already hit this surface and decided it's lit by this light.
			msurfacelighting_t *pLighting = SurfaceLighting( parentSurfID );
			if( !R_IsDLightAlreadyMarked( pLighting, bit) )
			{
				// Do a different test for displacement surfaces.
				Vector bmin, bmax;
				MSurf_DispInfo( parentSurfID )->GetBoundingBox( bmin, bmax );
				if ( SphereToAABBIntersection( light->origin, light->radius, bmin, bmax ) )
				{
					R_MarkSurfaceDLight( pLighting, bit ); 
				}
			}
		}
	}

	for ( int i = 0; i < pLeaf->nummarksurfaces; i++ )
	{
		int surfID = host_state.worldmodel->brush.marksurfaces[pLeaf->firstmarksurface + i];
		ASSERT_SURF_VALID( surfID );
		
		// only process leaf surfaces
		if ( MSurf_Flags( surfID ) & SURFDRAW_NODE )
			continue;

		// Don't redo all this work if we already hit this surface and decided it's lit by this light.
		msurfacelighting_t *pLighting = SurfaceLighting( surfID );
		if(R_IsDLightAlreadyMarked(pLighting, bit))
			continue;

		float dist = DotProduct( light->origin, MSurf_Plane( surfID ).normal) - MSurf_Plane( surfID ).dist;
		
		if ( dist > light->radius || dist < -light->radius )
			continue;

		R_TryLightMarkSurface( light, pLighting, surfID, bit );
	}
}
Ejemplo n.º 6
0
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CDispChain::RenderWireframeInLightmapPage( void )
{
#ifdef USE_CONVARS
	if( !r_DrawDisp.GetInt() )
		return;
#endif

    //
    // render wireframe in lightmap page for the given displacement
    //
	for( IDispInfo *pDispInfo = m_pHead; pDispInfo; pDispInfo = pDispInfo->GetNextInRenderChain() )
	{
		pDispInfo->RenderWireframeInLightmapPage();

		g_EngineStats.IncrementCountedStat( ENGINE_STATS_NUM_DISP_SURFACES, 1 );	
	}
}
Ejemplo n.º 7
0
static void AddDisplacementsInLeafToTestList( mleaf_t* pLeaf, LightVecState_t& state )
{
	// add displacement surfaces
	for ( int i = 0; i < pLeaf->dispCount; i++ )
	{
		// NOTE: We're not using the displacement's touched method here 
		// because we're just using the parent surface's visframe in the
		// surface add methods below
		IDispInfo *pDispInfo = MLeaf_Disaplcement( pLeaf, i );
		SurfaceHandle_t parentSurfID = pDispInfo->GetParent();

		// already processed this frame? Then don't do it again!
		if (MSurf_VisFrame( parentSurfID ) != r_surfacevisframe)
		{
			MSurf_VisFrame( parentSurfID ) = r_surfacevisframe;
			state.m_LightTestDisps.AddToTail( pDispInfo );
		}
	}
}
Ejemplo n.º 8
0
static void AddDisplacementsInLeafToTestList( mleaf_t* pLeaf, LightVecState_t& state )
{
	// add displacement surfaces
	for( CDispIterator it=pLeaf->GetDispIterator(); it.IsValid(); )
	{
		CDispLeafLink *pCur = it.Inc();

		// NOTE: We're not using the displacement's touched method here 
		// because we're just using the parent surface's visframe in the
		// surface add methods below
		IDispInfo* pDispInfo = static_cast<IDispInfo*>( pCur->m_pDispInfo );
		int parentSurfID = pDispInfo->GetParent();

		// already processed this frame? Then don't do it again!
		if (MSurf_VisFrame( parentSurfID ) != r_surfacevisframe)
		{
			MSurf_VisFrame( parentSurfID ) = r_surfacevisframe;
			state.m_LightTestChain.AddTo( pDispInfo );
		}
	}
}