mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-14 06:34:10 +00:00
Added r_showViewEnvprobes
This commit is contained in:
parent
804c16d0a4
commit
1a66dc50af
7 changed files with 208 additions and 3 deletions
|
@ -1698,6 +1698,82 @@ void idRenderBackend::DBG_ShowLights()
|
|||
}
|
||||
|
||||
// RB begin
|
||||
/*
|
||||
==============
|
||||
RB_ShowViewEnvprobes
|
||||
|
||||
Visualize all environemnt probes used in the current scene
|
||||
==============
|
||||
*/
|
||||
void idRenderBackend::DBG_ShowViewEnvprobes()
|
||||
{
|
||||
if( !r_showViewEnvprobes.GetInteger() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GL_State( GLS_DEFAULT | GLS_CULL_TWOSIDED );
|
||||
|
||||
renderProgManager.BindShader_Environment();
|
||||
|
||||
int count = 0;
|
||||
for( viewEnvprobe_t* vProbe = viewDef->viewEnvprobes; vProbe != NULL; vProbe = vProbe->next )
|
||||
{
|
||||
count++;
|
||||
|
||||
GL_State( GLS_DEPTHFUNC_ALWAYS | GLS_DEPTHMASK );
|
||||
GL_Color( 1.0f, 1.0f, 1.0f );
|
||||
|
||||
float modelMatrix[16];
|
||||
|
||||
idMat3 axis;
|
||||
axis.Identity();
|
||||
|
||||
R_AxisToModelMatrix( axis, vProbe->globalOrigin, modelMatrix );
|
||||
|
||||
idRenderMatrix modelRenderMatrix;
|
||||
idRenderMatrix::CreateFromOriginAxis( vProbe->globalOrigin, axis, modelRenderMatrix );
|
||||
|
||||
// calculate the matrix that transforms the unit cube to exactly cover the model in world space
|
||||
const float size = 16.0f;
|
||||
idBounds debugBounds( idVec3( -size ), idVec3( size ) );
|
||||
|
||||
idRenderMatrix inverseBaseModelProject;
|
||||
idRenderMatrix::OffsetScaleForBounds( modelRenderMatrix, debugBounds, inverseBaseModelProject );
|
||||
|
||||
idRenderMatrix invProjectMVPMatrix;
|
||||
idRenderMatrix::Multiply( viewDef->worldSpace.mvp, inverseBaseModelProject, invProjectMVPMatrix );
|
||||
RB_SetMVP( invProjectMVPMatrix );
|
||||
|
||||
idVec4 localViewOrigin( 1.0f );
|
||||
idVec4 globalViewOrigin;
|
||||
globalViewOrigin.x = viewDef->renderView.vieworg.x;
|
||||
globalViewOrigin.y = viewDef->renderView.vieworg.y;
|
||||
globalViewOrigin.z = viewDef->renderView.vieworg.z;
|
||||
globalViewOrigin.w = 1.0f;
|
||||
|
||||
//inverseBaseModelProject.TransformPoint( globalViewOrigin, localViewOrigin );
|
||||
R_GlobalPointToLocal( modelMatrix, viewDef->renderView.vieworg, localViewOrigin.ToVec3() );
|
||||
|
||||
renderProgManager.SetUniformValue( RENDERPARM_LOCALVIEWORIGIN, localViewOrigin.ToFloatPtr() ); // rpLocalViewOrigin
|
||||
|
||||
GL_SelectTexture( 0 );
|
||||
if( r_showViewEnvprobes.GetInteger() >= 2 )
|
||||
{
|
||||
globalImages->defaultUACIrradianceCube->Bind();
|
||||
}
|
||||
else
|
||||
{
|
||||
globalImages->defaultUACRadianceCube->Bind();
|
||||
}
|
||||
|
||||
//GL_SelectTexture( 1 );
|
||||
//globalImages->flatNormalMap->Bind();
|
||||
|
||||
DrawElementsWithCounters( &zeroOneCubeSurface );
|
||||
}
|
||||
}
|
||||
|
||||
void idRenderBackend::DBG_ShowShadowMapLODs()
|
||||
{
|
||||
if( !r_showShadowMapLODs.GetInteger() )
|
||||
|
@ -3068,6 +3144,7 @@ void idRenderBackend::DBG_RenderDebugTools( drawSurf_t** drawSurfs, int numDrawS
|
|||
DBG_ShowViewEntitys( viewDef->viewEntitys );
|
||||
DBG_ShowLights();
|
||||
// RB begin
|
||||
DBG_ShowViewEnvprobes();
|
||||
DBG_ShowShadowMapLODs();
|
||||
DBG_ShowShadowMaps();
|
||||
// RB end
|
||||
|
|
|
@ -655,6 +655,7 @@ void idRenderBackend::PrepareStageTexturing( const shaderStage_t* pStage, const
|
|||
// per-pixel reflection mapping with bump mapping
|
||||
GL_SelectTexture( 1 );
|
||||
bumpStage->texture.image->Bind();
|
||||
|
||||
GL_SelectTexture( 0 );
|
||||
|
||||
RENDERLOG_PRINTF( "TexGen: TG_REFLECT_CUBE: Bumpy Environment\n" );
|
||||
|
|
|
@ -425,6 +425,7 @@ private:
|
|||
void DBG_ShowDominantTris( drawSurf_t** drawSurfs, int numDrawSurfs );
|
||||
void DBG_ShowEdges( drawSurf_t** drawSurfs, int numDrawSurfs );
|
||||
void DBG_ShowLights();
|
||||
void DBG_ShowViewEnvprobes(); // RB
|
||||
void DBG_ShowShadowMapLODs(); // RB
|
||||
void DBG_ShowPortals();
|
||||
void DBG_ShowDebugText();
|
||||
|
|
|
@ -270,10 +270,12 @@ public:
|
|||
bool archived; // for demo writing
|
||||
|
||||
// derived information
|
||||
idPlane lightProject[4]; // old style light projection where Z and W are flipped and projected lights lightProject[3] is divided by ( zNear + zFar )
|
||||
//idPlane lightProject[4]; // old style light projection where Z and W are flipped and projected lights lightProject[3] is divided by ( zNear + zFar )
|
||||
idRenderMatrix baseLightProject; // global xyz1 to projected light strq
|
||||
idRenderMatrix inverseBaseLightProject;// transforms the zero-to-one cube to exactly cover the light in world space
|
||||
|
||||
idBounds globalProbeBounds;
|
||||
|
||||
areaReference_t* references; // each area the light is present in will have a lightRef
|
||||
//idInteraction* firstInteraction; // doubly linked list
|
||||
//idInteraction* lastInteraction;
|
||||
|
@ -1143,6 +1145,7 @@ extern idCVar r_useHierarchicalDepthBuffer;
|
|||
|
||||
extern idCVar r_usePBR;
|
||||
extern idCVar r_pbrDebug;
|
||||
extern idCVar r_showViewEnvprobes;
|
||||
|
||||
extern idCVar r_exposure;
|
||||
// RB end
|
||||
|
|
|
@ -299,6 +299,7 @@ idCVar r_useHierarchicalDepthBuffer( "r_useHierarchicalDepthBuffer", "1", CVAR_R
|
|||
|
||||
idCVar r_usePBR( "r_usePBR", "1", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_BOOL, "use PBR and Image Based Lighting instead of old Quake 4 style ambient lighting" );
|
||||
idCVar r_pbrDebug( "r_pbrDebug", "0", CVAR_RENDERER | CVAR_INTEGER, "show which materials have PBR support (green = PBR, red = oldschool D3)" );
|
||||
idCVar r_showViewEnvprobes( "r_showViewEnvprobes", "0", CVAR_RENDERER | CVAR_INTEGER, "1 = displays the bounding boxes of all view environment probes, 2 = show irradiance" );
|
||||
|
||||
idCVar r_exposure( "r_exposure", "0.5", CVAR_ARCHIVE | CVAR_RENDERER | CVAR_FLOAT, "HDR exposure or LDR brightness [0.0 .. 1.0]", 0.0f, 1.0f );
|
||||
// RB end
|
||||
|
@ -2475,6 +2476,7 @@ void idRenderSystemLocal::Init()
|
|||
if( zeroOneCubeTriangles == NULL )
|
||||
{
|
||||
zeroOneCubeTriangles = R_MakeZeroOneCubeTris();
|
||||
R_DeriveTangents( zeroOneCubeTriangles ); // RB: we need normals for debugging reflections
|
||||
}
|
||||
// make sure the tr.testImageTriangles data is current in the vertex / index cache
|
||||
if( testImageTriangles == NULL )
|
||||
|
|
|
@ -758,10 +758,126 @@ ENVPROBE DEFS
|
|||
=================================================================================
|
||||
*/
|
||||
|
||||
void R_DeriveEnvprobeData( RenderEnvprobeLocal* probe )
|
||||
{
|
||||
// TODO get images
|
||||
|
||||
|
||||
/*
|
||||
light->falloffImage = light->lightShader->LightFalloffImage();
|
||||
|
||||
if( light->falloffImage == NULL )
|
||||
{
|
||||
// use the falloff from the default shader of the correct type
|
||||
const idMaterial* defaultShader;
|
||||
|
||||
if( light->parms.pointLight )
|
||||
{
|
||||
defaultShader = tr.defaultPointLight;
|
||||
|
||||
// Touch the default shader. to make sure it's decl has been parsed ( it might have been purged ).
|
||||
declManager->Touch( static_cast< const idDecl*>( defaultShader ) );
|
||||
|
||||
light->falloffImage = defaultShader->LightFalloffImage();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// projected lights by default don't diminish with distance
|
||||
defaultShader = tr.defaultProjectedLight;
|
||||
|
||||
// Touch the light shader. to make sure it's decl has been parsed ( it might have been purged ).
|
||||
declManager->Touch( static_cast< const idDecl*>( defaultShader ) );
|
||||
|
||||
light->falloffImage = defaultShader->LightFalloffImage();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// ------------------------------------
|
||||
// compute the light projection matrix
|
||||
// ------------------------------------
|
||||
|
||||
idRenderMatrix localProject;
|
||||
float zScale = 1.0f;
|
||||
float radius = 300.0f; // TODO
|
||||
|
||||
// An environemt probe uses a box projection like a point light.
|
||||
// This projects into the 0.0 - 1.0 texture range instead of -1.0 to 1.0 clip space range.
|
||||
localProject.Zero();
|
||||
localProject[0][0] = 0.5f / radius;
|
||||
localProject[1][1] = 0.5f / radius;
|
||||
localProject[2][2] = 0.5f / radius;
|
||||
localProject[0][3] = 0.5f;
|
||||
localProject[1][3] = 0.5f;
|
||||
localProject[2][3] = 0.5f;
|
||||
localProject[3][3] = 1.0f; // identity perspective
|
||||
|
||||
// set the old style light projection where Z and W are flipped and
|
||||
// for projected lights lightProject[3] is divided by ( zNear + zFar )
|
||||
/*
|
||||
light->lightProject[0][0] = localProject[0][0];
|
||||
light->lightProject[0][1] = localProject[0][1];
|
||||
light->lightProject[0][2] = localProject[0][2];
|
||||
light->lightProject[0][3] = localProject[0][3];
|
||||
|
||||
light->lightProject[1][0] = localProject[1][0];
|
||||
light->lightProject[1][1] = localProject[1][1];
|
||||
light->lightProject[1][2] = localProject[1][2];
|
||||
light->lightProject[1][3] = localProject[1][3];
|
||||
|
||||
light->lightProject[2][0] = localProject[3][0];
|
||||
light->lightProject[2][1] = localProject[3][1];
|
||||
light->lightProject[2][2] = localProject[3][2];
|
||||
light->lightProject[2][3] = localProject[3][3];
|
||||
|
||||
light->lightProject[3][0] = localProject[2][0] * zScale;
|
||||
light->lightProject[3][1] = localProject[2][1] * zScale;
|
||||
light->lightProject[3][2] = localProject[2][2] * zScale;
|
||||
light->lightProject[3][3] = localProject[2][3] * zScale;
|
||||
|
||||
// transform the lightProject
|
||||
float lightTransform[16];
|
||||
R_AxisToModelMatrix( light->parms.axis, light->parms.origin, lightTransform );
|
||||
for( int i = 0; i < 4; i++ )
|
||||
{
|
||||
idPlane temp = light->lightProject[i];
|
||||
R_LocalPlaneToGlobal( lightTransform, temp, light->lightProject[i] );
|
||||
}
|
||||
*/
|
||||
|
||||
// Rotate and translate the light projection by the light matrix.
|
||||
// 99% of lights remain axis aligned in world space.
|
||||
idMat3 axis;
|
||||
axis.Identity();
|
||||
|
||||
idRenderMatrix lightMatrix;
|
||||
idRenderMatrix::CreateFromOriginAxis( probe->parms.origin, axis, lightMatrix );
|
||||
|
||||
idRenderMatrix inverseLightMatrix;
|
||||
if( !idRenderMatrix::Inverse( lightMatrix, inverseLightMatrix ) )
|
||||
{
|
||||
idLib::Warning( "lightMatrix invert failed" );
|
||||
}
|
||||
|
||||
// 'baseLightProject' goes from global space -> light local space -> light projective space
|
||||
idRenderMatrix::Multiply( localProject, inverseLightMatrix, probe->baseLightProject );
|
||||
|
||||
// Invert the light projection so we can deform zero-to-one cubes into
|
||||
// the light model and calculate global bounds.
|
||||
if( !idRenderMatrix::Inverse( probe->baseLightProject, probe->inverseBaseLightProject ) )
|
||||
{
|
||||
idLib::Warning( "baseLightProject invert failed" );
|
||||
}
|
||||
|
||||
// calculate the global light bounds by inverse projecting the zero to one cube with the 'inverseBaseLightProject'
|
||||
idRenderMatrix::ProjectedBounds( probe->globalProbeBounds, probe->inverseBaseLightProject, bounds_zeroOneCube, false );
|
||||
}
|
||||
|
||||
void R_CreateEnvprobeRefs( RenderEnvprobeLocal* probe )
|
||||
{
|
||||
// TODO ? derive envprobe data
|
||||
//R_DeriveEnvprobeData( probe );
|
||||
// derive envprobe data
|
||||
R_DeriveEnvprobeData( probe );
|
||||
|
||||
// determine the areaNum for the envprobe origin, which may let us
|
||||
// cull the envprobe if it is behind a closed door
|
||||
|
|
|
@ -57,6 +57,11 @@ viewEnvprobe_t* R_SetEnvprobeDefViewEnvprobe( RenderEnvprobeLocal* probe )
|
|||
// and the scissor will be reduced in R_AddSingleEnvprobe based on the screen space projection
|
||||
vProbe->scissorRect.Clear();
|
||||
|
||||
// copy data used by backend
|
||||
// RB: this would normaly go into R_AddSingleEnvprobe
|
||||
vProbe->globalOrigin = probe->parms.origin;
|
||||
vProbe->inverseBaseLightProject = probe->inverseBaseLightProject;
|
||||
|
||||
// link the view light
|
||||
vProbe->next = tr.viewDef->viewEnvprobes;
|
||||
tr.viewDef->viewEnvprobes = vProbe;
|
||||
|
|
Loading…
Reference in a new issue