Modified source engine (2017) developed by valve and leaked in 2020. Not for commercial purporses
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
4.2 KiB

//===== Copyright <EFBFBD> 1996-2005, Valve Corporation, All rights reserved. ======//
5 years ago
//
// Purpose: Responsible for drawing the scene
//
//===========================================================================//
#include "cbase.h"
#include "materialsystem/IMaterialSystem.h"
#include "materialsystem/IMaterialVar.h"
5 years ago
#include "materialsystem/imaterialsystemhardwareconfig.h"
#include "rendertexture.h"
#include "view_scene.h"
#include "viewrender.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Convars related to controlling rendering
//-----------------------------------------------------------------------------
ConVar r_updaterefracttexture( "r_updaterefracttexture", "1", FCVAR_CHEAT );
ConVar r_depthoverlay( "r_depthoverlay", "0", FCVAR_CHEAT, "Replaces opaque objects with their grayscaled depth values. r_showz_power scales the output." );
int g_viewscene_refractUpdateFrame = 0;
bool g_bAllowMultipleRefractUpdatesPerScenePerFrame = false;
#if defined( _X360 )
class CAllowMultipleRefractsLogic : public CAutoGameSystem
{
public:
void LevelInitPreEntity()
{
// EP1 core room needs many refract updates per frame to avoid looking broken (ep1_citadel_03)
// Same with Kleiner's lab (d1_trainstation_05)
g_bAllowMultipleRefractUpdatesPerScenePerFrame = FStrEq( MapName(), "ep1_citadel_03" ) || FStrEq( MapName(), "d1_trainstation_05" );
}
};
static CAllowMultipleRefractsLogic s_AllowMultipleRefractsLogic;
#endif
void ViewTransform( const Vector &worldSpace, Vector &viewSpace )
{
const VMatrix &viewMatrix = engine->WorldToViewMatrix();
Vector3DMultiplyPosition( viewMatrix, worldSpace, viewSpace );
}
//-----------------------------------------------------------------------------
// Purpose: UNDONE: Clean this up some, handle off-screen vertices
// Input : *point -
// *screen -
// Output : int
5 years ago
//-----------------------------------------------------------------------------
int ScreenTransform( const Vector& point, Vector& screen )
5 years ago
{
// UNDONE: Clean this up some, handle off-screen vertices
float w;
const VMatrix &worldToScreen = engine->WorldToScreenMatrix();
5 years ago
screen.x = worldToScreen[0][0] * point[0] + worldToScreen[0][1] * point[1] + worldToScreen[0][2] * point[2] + worldToScreen[0][3];
screen.y = worldToScreen[1][0] * point[0] + worldToScreen[1][1] * point[1] + worldToScreen[1][2] * point[2] + worldToScreen[1][3];
// z = worldToScreen[2][0] * point[0] + worldToScreen[2][1] * point[1] + worldToScreen[2][2] * point[2] + worldToScreen[2][3];
w = worldToScreen[3][0] * point[0] + worldToScreen[3][1] * point[1] + worldToScreen[3][2] * point[2] + worldToScreen[3][3];
5 years ago
// Just so we have something valid here
screen.z = 0.0f;
bool behind;
if( w < 0.001f )
{
behind = true;
screen.x *= 100000;
screen.y *= 100000;
}
else
{
behind = false;
float invw = 1.0f / w;
screen.x *= invw;
screen.y *= invw;
}
return behind;
}
void UpdateFullScreenDepthTexture( void )
{
if ( g_pMaterialSystemHardwareConfig->GetDXSupportLevel() <= 90 )
5 years ago
return;
ITexture *pDepthTex = GetFullFrameDepthTexture();
CMatRenderContextPtr pRenderContext( materials );
Rect_t viewportRect;
pRenderContext->GetViewport( viewportRect.x, viewportRect.y, viewportRect.width, viewportRect.height );
if ( IsX360() )
5 years ago
{
pRenderContext->CopyRenderTargetToTextureEx( pDepthTex, -1, &viewportRect, &viewportRect );
5 years ago
}
else
{
pRenderContext->CopyRenderTargetToTextureEx( pDepthTex, 0, NULL, NULL );
}
pRenderContext->SetFullScreenDepthTextureValidityFlag( true );
if ( r_depthoverlay.GetBool() )
5 years ago
{
IMaterial *pMaterial = materials->FindMaterial( "debug/showz", TEXTURE_GROUP_OTHER, true );
IMaterialVar *BaseTextureVar = pMaterial->FindVar( "$basetexture", NULL, false );
IMaterialVar *pDepthInAlpha = NULL;
if( IsPC() )
{
pDepthInAlpha = pMaterial->FindVar( "$ALPHADEPTH", NULL, false );
pDepthInAlpha->SetIntValue( 1 );
}
BaseTextureVar->SetTextureValue( pDepthTex );
pRenderContext->OverrideDepthEnable( true, false ); //don't write to depth, or else we'll never see translucents
pRenderContext->DrawScreenSpaceQuad( pMaterial );
pRenderContext->OverrideDepthEnable( false, true );
}
}