mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-14 06:34:10 +00:00
Added lightgrid debug shader
This commit is contained in:
parent
6ad03afca6
commit
884658d6dd
10 changed files with 552 additions and 28 deletions
|
@ -15,6 +15,8 @@ return
|
|||
"builtin/debug/shadowDebug_skinned.vs.hlsl",
|
||||
"builtin/debug/octahedron.ps.hlsl",
|
||||
"builtin/debug/octahedron.vs.hlsl",
|
||||
"builtin/debug/lightgrid.ps.hlsl",
|
||||
"builtin/debug/lightgrid.vs.hlsl",
|
||||
|
||||
"builtin/fog/blendLight.ps.hlsl",
|
||||
"builtin/fog/blendLight.vs.hlsl",
|
||||
|
|
110
base/renderprogs/builtin/debug/lightgrid.ps.hlsl
Normal file
110
base/renderprogs/builtin/debug/lightgrid.ps.hlsl
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
Copyright (C) 2021 Robert Beckebans
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||
|
||||
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
#include "renderprogs/global.inc.hlsl"
|
||||
|
||||
|
||||
// *INDENT-OFF*
|
||||
uniform sampler2D samp0 : register(s0); // texture 0 is octahedron cube map atlas
|
||||
|
||||
struct PS_IN {
|
||||
float4 position : VPOS;
|
||||
float3 texcoord0 : TEXCOORD0_centroid;
|
||||
float3 texcoord1 : TEXCOORD1_centroid;
|
||||
float4 color : COLOR0;
|
||||
};
|
||||
|
||||
struct PS_OUT {
|
||||
float4 color : COLOR;
|
||||
};
|
||||
// *INDENT-ON*
|
||||
|
||||
|
||||
float3 lightGridOrigin = float3( -192.0, -128.0, 0 );
|
||||
float3 lightGridSize = float3( 64.0, 64.0, 128.0 );
|
||||
int3 lightGridBounds = int3( 7, 7, 3 );
|
||||
|
||||
int3 GetBaseGridCoord( float3 origin )
|
||||
{
|
||||
int3 pos;
|
||||
|
||||
float3 lightOrigin = origin - lightGridOrigin;
|
||||
for( int i = 0; i < 3; i++ )
|
||||
{
|
||||
float v;
|
||||
|
||||
v = lightOrigin[i] * ( 1.0f / lightGridSize[i] );
|
||||
pos[i] = int( floor( v ) );
|
||||
|
||||
if( pos[i] < 0 )
|
||||
{
|
||||
pos[i] = 0;
|
||||
}
|
||||
else if( pos[i] >= lightGridBounds[i] - 1 )
|
||||
{
|
||||
pos[i] = lightGridBounds[i] - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void main( PS_IN fragment, out PS_OUT result )
|
||||
{
|
||||
const int LIGHTGRID_IRRADIANCE_SIZE = 32;
|
||||
|
||||
float3 globalPosition = fragment.texcoord0.xyz;
|
||||
float3 globalNormal = normalize( fragment.texcoord1 );
|
||||
|
||||
float2 normalizedOctCoord = octEncode( globalNormal );
|
||||
float2 normalizedOctCoordZeroOne = ( normalizedOctCoord + float2( 1.0 ) ) * 0.5;
|
||||
|
||||
float invXY = ( 1.0 / ( lightGridBounds[0] * lightGridBounds[1] ) );
|
||||
float invZ = ( 1.0 / lightGridBounds[2] );
|
||||
|
||||
normalizedOctCoordZeroOne.x *= invXY;
|
||||
normalizedOctCoordZeroOne.y *= invZ;
|
||||
|
||||
int3 gridStep;
|
||||
|
||||
gridStep[0] = 1;
|
||||
gridStep[1] = lightGridBounds[0];
|
||||
gridStep[2] = lightGridBounds[0] * lightGridBounds[1];
|
||||
|
||||
int3 gridCoord = GetBaseGridCoord( globalPosition );
|
||||
|
||||
normalizedOctCoordZeroOne.x += ( gridCoord[0] * gridStep[0] + gridCoord[1] * gridStep[1] ) * invXY;
|
||||
normalizedOctCoordZeroOne.y += ( gridCoord[2] * invZ );
|
||||
|
||||
float4 envMap = tex2D( samp0, normalizedOctCoordZeroOne );
|
||||
|
||||
result.color = float4( envMap.xyz, 1.0f ) * 1.0 * fragment.color;
|
||||
}
|
126
base/renderprogs/builtin/debug/lightgrid.vs.hlsl
Normal file
126
base/renderprogs/builtin/debug/lightgrid.vs.hlsl
Normal file
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
Copyright (C) 2021 Robert Beckebans
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
||||
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
||||
|
||||
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
#include "renderprogs/global.inc.hlsl"
|
||||
|
||||
|
||||
uniform matrices_ubo { float4 matrices[408]; };
|
||||
|
||||
// *INDENT-OFF*
|
||||
struct VS_IN {
|
||||
float4 position : POSITION;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
float4 normal : NORMAL;
|
||||
float4 tangent : TANGENT;
|
||||
float4 color : COLOR0;
|
||||
float4 color2 : COLOR1;
|
||||
};
|
||||
|
||||
struct VS_OUT {
|
||||
float4 position : POSITION;
|
||||
float3 texcoord0 : TEXCOORD0;
|
||||
float3 texcoord1 : TEXCOORD1;
|
||||
float4 color : COLOR0;
|
||||
};
|
||||
// *INDENT-ON*
|
||||
|
||||
void main( VS_IN vertex, out VS_OUT result )
|
||||
{
|
||||
float4 vNormal = vertex.normal * 2.0 - 1.0;
|
||||
|
||||
#if defined( USE_GPU_SKINNING )
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// GPU transformation of the normal / binormal / bitangent
|
||||
//
|
||||
// multiplying with 255.1 give us the same result and is faster than floor( w * 255 + 0.5 )
|
||||
//--------------------------------------------------------------
|
||||
const float w0 = vertex.color2.x;
|
||||
const float w1 = vertex.color2.y;
|
||||
const float w2 = vertex.color2.z;
|
||||
const float w3 = vertex.color2.w;
|
||||
|
||||
float4 matX, matY, matZ; // must be float4 for vec4
|
||||
int joint = int( vertex.color.x * 255.1 * 3.0 );
|
||||
matX = matrices[int( joint + 0 )] * w0;
|
||||
matY = matrices[int( joint + 1 )] * w0;
|
||||
matZ = matrices[int( joint + 2 )] * w0;
|
||||
|
||||
joint = int( vertex.color.y * 255.1 * 3.0 );
|
||||
matX += matrices[int( joint + 0 )] * w1;
|
||||
matY += matrices[int( joint + 1 )] * w1;
|
||||
matZ += matrices[int( joint + 2 )] * w1;
|
||||
|
||||
joint = int( vertex.color.z * 255.1 * 3.0 );
|
||||
matX += matrices[int( joint + 0 )] * w2;
|
||||
matY += matrices[int( joint + 1 )] * w2;
|
||||
matZ += matrices[int( joint + 2 )] * w2;
|
||||
|
||||
joint = int( vertex.color.w * 255.1 * 3.0 );
|
||||
matX += matrices[int( joint + 0 )] * w3;
|
||||
matY += matrices[int( joint + 1 )] * w3;
|
||||
matZ += matrices[int( joint + 2 )] * w3;
|
||||
|
||||
float3 normal;
|
||||
normal.x = dot3( matX, vNormal );
|
||||
normal.y = dot3( matY, vNormal );
|
||||
normal.z = dot3( matZ, vNormal );
|
||||
normal = normalize( normal );
|
||||
|
||||
float4 modelPosition;
|
||||
modelPosition.x = dot4( matX, vertex.position );
|
||||
modelPosition.y = dot4( matY, vertex.position );
|
||||
modelPosition.z = dot4( matZ, vertex.position );
|
||||
modelPosition.w = 1.0;
|
||||
|
||||
#else
|
||||
|
||||
float4 modelPosition = vertex.position;
|
||||
float4 normal = vNormal;
|
||||
|
||||
#endif
|
||||
|
||||
result.position.x = dot4( modelPosition, rpMVPmatrixX );
|
||||
result.position.y = dot4( modelPosition, rpMVPmatrixY );
|
||||
result.position.z = dot4( modelPosition, rpMVPmatrixZ );
|
||||
result.position.w = dot4( modelPosition, rpMVPmatrixW );
|
||||
|
||||
result.texcoord1.x = dot3( normal, rpModelMatrixX );
|
||||
result.texcoord1.y = dot3( normal, rpModelMatrixY );
|
||||
result.texcoord1.z = dot3( normal, rpModelMatrixZ );
|
||||
|
||||
float4 worldPosition;
|
||||
worldPosition.x = dot4( modelPosition, rpModelMatrixX );
|
||||
worldPosition.y = dot4( modelPosition, rpModelMatrixY );
|
||||
worldPosition.z = dot4( modelPosition, rpModelMatrixZ );
|
||||
worldPosition.w = dot4( modelPosition, rpModelMatrixW );
|
||||
result.texcoord0 = worldPosition.xyz;
|
||||
|
||||
result.color = sRGBAToLinearRGBA( rpColor );
|
||||
}
|
|
@ -1719,7 +1719,7 @@ void idRenderBackend::DBG_ShowViewEnvprobes()
|
|||
{
|
||||
count++;
|
||||
|
||||
renderProgManager.BindShader_Octahedron();
|
||||
renderProgManager.BindShader_DebugOctahedron();
|
||||
|
||||
GL_State( GLS_DEPTHFUNC_ALWAYS | GLS_DEPTHMASK );
|
||||
GL_Color( 1.0f, 1.0f, 1.0f );
|
||||
|
@ -1815,6 +1815,10 @@ void idRenderBackend::DBG_ShowLightGrid()
|
|||
const int numColors = 7;
|
||||
static idVec4 colors[numColors] = { colorBlack, colorBlue, colorCyan, colorGreen, colorYellow, colorRed, colorWhite };
|
||||
|
||||
// use rpGlobalLightOrigin for camera center
|
||||
idVec4 globalViewOrigin( viewDef->renderView.vieworg.x, viewDef->renderView.vieworg.y, viewDef->renderView.vieworg.z, 1.0f );
|
||||
renderProgManager.SetUniformValue( RENDERPARM_GLOBALLIGHTORIGIN, globalViewOrigin.ToFloatPtr() );
|
||||
|
||||
for( int i = 0; i < area->lightGrid.lightGridPoints.Num(); i++ )
|
||||
{
|
||||
lightGridPoint_t* gridPoint = &area->lightGrid.lightGridPoints[i];
|
||||
|
@ -1829,13 +1833,16 @@ void idRenderBackend::DBG_ShowLightGrid()
|
|||
continue;
|
||||
}
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
if( i > 53 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
// move center into the cube so we can void using negative results with GetBaseGridCoord
|
||||
idVec3 gridPointOrigin = gridPoint->origin + idVec3( 4, 4, 4 );
|
||||
|
||||
idVec4 localViewOrigin( 1.0f );
|
||||
idVec4 globalViewOrigin;
|
||||
globalViewOrigin.x = viewDef->renderView.vieworg.x;
|
||||
|
@ -1844,12 +1851,21 @@ void idRenderBackend::DBG_ShowLightGrid()
|
|||
globalViewOrigin.w = 1.0f;
|
||||
|
||||
float modelMatrix[16];
|
||||
R_AxisToModelMatrix( axis, gridPoint->origin, modelMatrix );
|
||||
R_AxisToModelMatrix( axis, gridPointOrigin, modelMatrix );
|
||||
|
||||
R_GlobalPointToLocal( modelMatrix, viewDef->renderView.vieworg, localViewOrigin.ToVec3() );
|
||||
|
||||
renderProgManager.SetUniformValue( RENDERPARM_LOCALVIEWORIGIN, localViewOrigin.ToFloatPtr() ); // rpLocalViewOrigin
|
||||
|
||||
// RB: if we want to get the normals in world space so we need the model -> world matrix
|
||||
idRenderMatrix modelMatrix2;
|
||||
idRenderMatrix::Transpose( *( idRenderMatrix* )modelMatrix, modelMatrix2 );
|
||||
|
||||
renderProgManager.SetUniformValue( RENDERPARM_MODELMATRIX_X, &modelMatrix2[0][0] );
|
||||
renderProgManager.SetUniformValue( RENDERPARM_MODELMATRIX_Y, &modelMatrix2[1][0] );
|
||||
renderProgManager.SetUniformValue( RENDERPARM_MODELMATRIX_Z, &modelMatrix2[2][0] );
|
||||
renderProgManager.SetUniformValue( RENDERPARM_MODELMATRIX_W, &modelMatrix2[3][0] );
|
||||
|
||||
|
||||
#if 0
|
||||
renderProgManager.BindShader_Color();
|
||||
|
@ -1862,10 +1878,10 @@ void idRenderBackend::DBG_ShowLightGrid()
|
|||
//idVec4 color = colors[ i % numColors ];
|
||||
GL_Color( color );
|
||||
#else
|
||||
renderProgManager.BindShader_Octahedron();
|
||||
renderProgManager.BindShader_DebugLightGrid();
|
||||
|
||||
GL_SelectTexture( 0 );
|
||||
gridPoint->irradianceImage->Bind();
|
||||
area->lightGrid.irradianceImage->Bind();
|
||||
#endif
|
||||
|
||||
idRenderMatrix modelRenderMatrix;
|
||||
|
@ -1883,6 +1899,7 @@ void idRenderBackend::DBG_ShowLightGrid()
|
|||
RB_SetMVP( invProjectMVPMatrix );
|
||||
|
||||
DrawElementsWithCounters( &zeroOneSphereSurface );
|
||||
//DrawElementsWithCounters( &zeroOneCubeSurface );
|
||||
}
|
||||
|
||||
if( r_showLightGrid.GetInteger() == 2 )
|
||||
|
|
|
@ -154,8 +154,12 @@ void idRenderProgManager::Init()
|
|||
{ BUILTIN_PBR_INTERACTION_SHADOW_MAPPING_PARALLEL, "builtin/lighting/interactionSM", "_parallel_PBR", BIT( LIGHT_PARALLEL ) | BIT( USE_PBR ), false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT },
|
||||
{ BUILTIN_PBR_INTERACTION_SHADOW_MAPPING_PARALLEL_SKINNED, "builtin/lighting/interactionSM", "_parallel_skinned_PBR", BIT( USE_GPU_SKINNING ) | BIT( LIGHT_PARALLEL ) | BIT( USE_PBR ), true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT },
|
||||
|
||||
{ BUILTIN_OCTAHEDRON, "builtin/debug/octahedron", "", 0, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT },
|
||||
{ BUILTIN_OCTAHEDRON_SKINNED, "builtin/debug/octahedron", "_skinned", BIT( USE_GPU_SKINNING ), true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT },
|
||||
// debug stuff
|
||||
{ BUILTIN_DEBUG_LIGHTGRID, "builtin/debug/lightgrid", "", 0, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT },
|
||||
{ BUILTIN_DEBUG_LIGHTGRID_SKINNED, "builtin/debug/lightgrid", "_skinned", BIT( USE_GPU_SKINNING ), true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT },
|
||||
|
||||
{ BUILTIN_DEBUG_OCTAHEDRON, "builtin/debug/octahedron", "", 0, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT },
|
||||
{ BUILTIN_DEBUG_OCTAHEDRON_SKINNED, "builtin/debug/octahedron", "_skinned", BIT( USE_GPU_SKINNING ), true, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT },
|
||||
// RB end
|
||||
|
||||
{ BUILTIN_ENVIRONMENT, "builtin/legacy/environment", "", 0, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT },
|
||||
|
@ -272,7 +276,8 @@ void idRenderProgManager::Init()
|
|||
renderProgs[builtinShaders[BUILTIN_SHADOW_DEBUG_SKINNED]].usesJoints = true;
|
||||
renderProgs[builtinShaders[BUILTIN_FOG_SKINNED]].usesJoints = true;
|
||||
// RB begin
|
||||
renderProgs[builtinShaders[BUILTIN_OCTAHEDRON_SKINNED]].usesJoints = true;
|
||||
renderProgs[builtinShaders[BUILTIN_DEBUG_LIGHTGRID_SKINNED]].usesJoints = true;
|
||||
renderProgs[builtinShaders[BUILTIN_DEBUG_OCTAHEDRON_SKINNED]].usesJoints = true;
|
||||
renderProgs[builtinShaders[BUILTIN_AMBIENT_LIGHTING_SKINNED]].usesJoints = true;
|
||||
renderProgs[builtinShaders[BUILTIN_AMBIENT_LIGHTING_IBL_SKINNED]].usesJoints = true;
|
||||
renderProgs[builtinShaders[BUILTIN_AMBIENT_LIGHTING_IBL_PBR_SKINNED]].usesJoints = true;
|
||||
|
|
|
@ -451,14 +451,24 @@ public:
|
|||
BindShader_Builtin( BUILTIN_PBR_INTERACTION_SHADOW_MAPPING_PARALLEL_SKINNED );
|
||||
}
|
||||
|
||||
void BindShader_Octahedron()
|
||||
void BindShader_DebugLightGrid()
|
||||
{
|
||||
BindShader_Builtin( BUILTIN_OCTAHEDRON );
|
||||
BindShader_Builtin( BUILTIN_DEBUG_LIGHTGRID );
|
||||
}
|
||||
|
||||
void BindShader_OctahedronSkinned()
|
||||
void BindShader_DebugLightGridSkinned()
|
||||
{
|
||||
BindShader_Builtin( BUILTIN_OCTAHEDRON_SKINNED );
|
||||
BindShader_Builtin( BUILTIN_DEBUG_LIGHTGRID_SKINNED );
|
||||
}
|
||||
|
||||
void BindShader_DebugOctahedron()
|
||||
{
|
||||
BindShader_Builtin( BUILTIN_DEBUG_OCTAHEDRON );
|
||||
}
|
||||
|
||||
void BindShader_DebugOctahedronSkinned()
|
||||
{
|
||||
BindShader_Builtin( BUILTIN_DEBUG_OCTAHEDRON_SKINNED );
|
||||
}
|
||||
// RB end
|
||||
|
||||
|
@ -767,8 +777,11 @@ private:
|
|||
BUILTIN_PBR_INTERACTION_SHADOW_MAPPING_PARALLEL,
|
||||
BUILTIN_PBR_INTERACTION_SHADOW_MAPPING_PARALLEL_SKINNED,
|
||||
|
||||
BUILTIN_OCTAHEDRON,
|
||||
BUILTIN_OCTAHEDRON_SKINNED,
|
||||
BUILTIN_DEBUG_LIGHTGRID,
|
||||
BUILTIN_DEBUG_LIGHTGRID_SKINNED,
|
||||
|
||||
BUILTIN_DEBUG_OCTAHEDRON,
|
||||
BUILTIN_DEBUG_OCTAHEDRON_SKINNED,
|
||||
// RB end
|
||||
BUILTIN_ENVIRONMENT,
|
||||
BUILTIN_ENVIRONMENT_SKINNED,
|
||||
|
|
|
@ -2761,6 +2761,254 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
|
||||
},
|
||||
|
||||
{
|
||||
"renderprogs/builtin/debug/lightgrid.ps.hlsl",
|
||||
"/*\n"
|
||||
"===========================================================================\n"
|
||||
"\n"
|
||||
"Doom 3 BFG Edition GPL Source Code\n"
|
||||
"Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.\n"
|
||||
"Copyright (C) 2021 Robert Beckebans\n"
|
||||
"\n"
|
||||
"This file is part of the Doom 3 BFG Edition GPL Source Code (\"Doom 3 BFG Edition Source Code\").\n"
|
||||
"\n"
|
||||
"Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify\n"
|
||||
"it under the terms of the GNU General Public License as published by\n"
|
||||
"the Free Software Foundation, either version 3 of the License, or\n"
|
||||
"(at your option) any later version.\n"
|
||||
"\n"
|
||||
"Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,\n"
|
||||
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
|
||||
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
|
||||
"GNU General Public License for more details.\n"
|
||||
"\n"
|
||||
"You should have received a copy of the GNU General Public License\n"
|
||||
"along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.\n"
|
||||
"\n"
|
||||
"In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.\n"
|
||||
"\n"
|
||||
"If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.\n"
|
||||
"\n"
|
||||
"===========================================================================\n"
|
||||
"*/\n"
|
||||
"\n"
|
||||
"#include \"renderprogs/global.inc.hlsl\"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"// *INDENT-OFF*\n"
|
||||
"uniform sampler2D samp0 : register(s0); // texture 0 is octahedron cube map atlas\n"
|
||||
"\n"
|
||||
"struct PS_IN {\n"
|
||||
" float4 position : VPOS;\n"
|
||||
" float3 texcoord0 : TEXCOORD0_centroid;\n"
|
||||
" float3 texcoord1 : TEXCOORD1_centroid;\n"
|
||||
" float4 color : COLOR0;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct PS_OUT {\n"
|
||||
" float4 color : COLOR;\n"
|
||||
"};\n"
|
||||
"// *INDENT-ON*\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"float3 lightGridOrigin = float3( -192.0, -128.0, 0 );\n"
|
||||
"float3 lightGridSize = float3( 64.0, 64.0, 128.0 );\n"
|
||||
"int3 lightGridBounds = int3( 7, 7, 3 );\n"
|
||||
"\n"
|
||||
"int3 GetBaseGridCoord( float3 origin )\n"
|
||||
"{\n"
|
||||
" int3 pos;\n"
|
||||
"\n"
|
||||
" float3 lightOrigin = origin - lightGridOrigin;\n"
|
||||
" for( int i = 0; i < 3; i++ )\n"
|
||||
" {\n"
|
||||
" float v;\n"
|
||||
"\n"
|
||||
" v = lightOrigin[i] * ( 1.0f / lightGridSize[i] );\n"
|
||||
" pos[i] = int( floor( v ) );\n"
|
||||
"\n"
|
||||
" if( pos[i] < 0 )\n"
|
||||
" {\n"
|
||||
" pos[i] = 0;\n"
|
||||
" }\n"
|
||||
" else if( pos[i] >= lightGridBounds[i] - 1 )\n"
|
||||
" {\n"
|
||||
" pos[i] = lightGridBounds[i] - 1;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" return pos;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"void main( PS_IN fragment, out PS_OUT result )\n"
|
||||
"{\n"
|
||||
" const int LIGHTGRID_IRRADIANCE_SIZE = 32;\n"
|
||||
"\n"
|
||||
" float3 globalPosition = fragment.texcoord0.xyz;\n"
|
||||
" float3 globalNormal = normalize( fragment.texcoord1 );\n"
|
||||
"\n"
|
||||
" float2 normalizedOctCoord = octEncode( globalNormal );\n"
|
||||
" float2 normalizedOctCoordZeroOne = ( normalizedOctCoord + float2( 1.0 ) ) * 0.5;\n"
|
||||
"\n"
|
||||
" float invXY = ( 1.0 / ( lightGridBounds[0] * lightGridBounds[1] ) );\n"
|
||||
" float invZ = ( 1.0 / lightGridBounds[2] );\n"
|
||||
"\n"
|
||||
" normalizedOctCoordZeroOne.x *= invXY;\n"
|
||||
" normalizedOctCoordZeroOne.y *= invZ;\n"
|
||||
"\n"
|
||||
" int3 gridStep;\n"
|
||||
"\n"
|
||||
" gridStep[0] = 1;\n"
|
||||
" gridStep[1] = lightGridBounds[0];\n"
|
||||
" gridStep[2] = lightGridBounds[0] * lightGridBounds[1];\n"
|
||||
"\n"
|
||||
" int3 gridCoord = GetBaseGridCoord( globalPosition );\n"
|
||||
"\n"
|
||||
" normalizedOctCoordZeroOne.x += ( gridCoord[0] * gridStep[0] + gridCoord[1] * gridStep[1] ) * invXY;\n"
|
||||
" normalizedOctCoordZeroOne.y += ( gridCoord[2] * invZ );\n"
|
||||
"\n"
|
||||
" float4 envMap = tex2D( samp0, normalizedOctCoordZeroOne );\n"
|
||||
"\n"
|
||||
" result.color = float4( envMap.xyz, 1.0f ) * 1.0 * fragment.color;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
|
||||
},
|
||||
|
||||
{
|
||||
"renderprogs/builtin/debug/lightgrid.vs.hlsl",
|
||||
"/*\n"
|
||||
"===========================================================================\n"
|
||||
"\n"
|
||||
"Doom 3 BFG Edition GPL Source Code\n"
|
||||
"Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.\n"
|
||||
"Copyright (C) 2021 Robert Beckebans\n"
|
||||
"\n"
|
||||
"This file is part of the Doom 3 BFG Edition GPL Source Code (\"Doom 3 BFG Edition Source Code\").\n"
|
||||
"\n"
|
||||
"Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify\n"
|
||||
"it under the terms of the GNU General Public License as published by\n"
|
||||
"the Free Software Foundation, either version 3 of the License, or\n"
|
||||
"(at your option) any later version.\n"
|
||||
"\n"
|
||||
"Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,\n"
|
||||
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
|
||||
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
|
||||
"GNU General Public License for more details.\n"
|
||||
"\n"
|
||||
"You should have received a copy of the GNU General Public License\n"
|
||||
"along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.\n"
|
||||
"\n"
|
||||
"In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.\n"
|
||||
"\n"
|
||||
"If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.\n"
|
||||
"\n"
|
||||
"===========================================================================\n"
|
||||
"*/\n"
|
||||
"\n"
|
||||
"#include \"renderprogs/global.inc.hlsl\"\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"uniform matrices_ubo { float4 matrices[408]; };\n"
|
||||
"\n"
|
||||
"// *INDENT-OFF*\n"
|
||||
"struct VS_IN {\n"
|
||||
" float4 position : POSITION;\n"
|
||||
" float2 texcoord : TEXCOORD0;\n"
|
||||
" float4 normal : NORMAL;\n"
|
||||
" float4 tangent : TANGENT;\n"
|
||||
" float4 color : COLOR0;\n"
|
||||
" float4 color2 : COLOR1;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct VS_OUT {\n"
|
||||
" float4 position : POSITION;\n"
|
||||
" float3 texcoord0 : TEXCOORD0;\n"
|
||||
" float3 texcoord1 : TEXCOORD1;\n"
|
||||
" float4 color : COLOR0;\n"
|
||||
"};\n"
|
||||
"// *INDENT-ON*\n"
|
||||
"\n"
|
||||
"void main( VS_IN vertex, out VS_OUT result )\n"
|
||||
"{\n"
|
||||
" float4 vNormal = vertex.normal * 2.0 - 1.0;\n"
|
||||
"\n"
|
||||
"#if defined( USE_GPU_SKINNING )\n"
|
||||
"\n"
|
||||
" //--------------------------------------------------------------\n"
|
||||
" // GPU transformation of the normal / binormal / bitangent\n"
|
||||
" //\n"
|
||||
" // multiplying with 255.1 give us the same result and is faster than floor( w * 255 + 0.5 )\n"
|
||||
" //--------------------------------------------------------------\n"
|
||||
" const float w0 = vertex.color2.x;\n"
|
||||
" const float w1 = vertex.color2.y;\n"
|
||||
" const float w2 = vertex.color2.z;\n"
|
||||
" const float w3 = vertex.color2.w;\n"
|
||||
"\n"
|
||||
" float4 matX, matY, matZ; // must be float4 for vec4\n"
|
||||
" int joint = int( vertex.color.x * 255.1 * 3.0 );\n"
|
||||
" matX = matrices[int( joint + 0 )] * w0;\n"
|
||||
" matY = matrices[int( joint + 1 )] * w0;\n"
|
||||
" matZ = matrices[int( joint + 2 )] * w0;\n"
|
||||
"\n"
|
||||
" joint = int( vertex.color.y * 255.1 * 3.0 );\n"
|
||||
" matX += matrices[int( joint + 0 )] * w1;\n"
|
||||
" matY += matrices[int( joint + 1 )] * w1;\n"
|
||||
" matZ += matrices[int( joint + 2 )] * w1;\n"
|
||||
"\n"
|
||||
" joint = int( vertex.color.z * 255.1 * 3.0 );\n"
|
||||
" matX += matrices[int( joint + 0 )] * w2;\n"
|
||||
" matY += matrices[int( joint + 1 )] * w2;\n"
|
||||
" matZ += matrices[int( joint + 2 )] * w2;\n"
|
||||
"\n"
|
||||
" joint = int( vertex.color.w * 255.1 * 3.0 );\n"
|
||||
" matX += matrices[int( joint + 0 )] * w3;\n"
|
||||
" matY += matrices[int( joint + 1 )] * w3;\n"
|
||||
" matZ += matrices[int( joint + 2 )] * w3;\n"
|
||||
"\n"
|
||||
" float3 normal;\n"
|
||||
" normal.x = dot3( matX, vNormal );\n"
|
||||
" normal.y = dot3( matY, vNormal );\n"
|
||||
" normal.z = dot3( matZ, vNormal );\n"
|
||||
" normal = normalize( normal );\n"
|
||||
"\n"
|
||||
" float4 modelPosition;\n"
|
||||
" modelPosition.x = dot4( matX, vertex.position );\n"
|
||||
" modelPosition.y = dot4( matY, vertex.position );\n"
|
||||
" modelPosition.z = dot4( matZ, vertex.position );\n"
|
||||
" modelPosition.w = 1.0;\n"
|
||||
"\n"
|
||||
"#else\n"
|
||||
"\n"
|
||||
" float4 modelPosition = vertex.position;\n"
|
||||
" float4 normal = vNormal;\n"
|
||||
"\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
" result.position.x = dot4( modelPosition, rpMVPmatrixX );\n"
|
||||
" result.position.y = dot4( modelPosition, rpMVPmatrixY );\n"
|
||||
" result.position.z = dot4( modelPosition, rpMVPmatrixZ );\n"
|
||||
" result.position.w = dot4( modelPosition, rpMVPmatrixW );\n"
|
||||
"\n"
|
||||
" result.texcoord1.x = dot3( normal, rpModelMatrixX );\n"
|
||||
" result.texcoord1.y = dot3( normal, rpModelMatrixY );\n"
|
||||
" result.texcoord1.z = dot3( normal, rpModelMatrixZ );\n"
|
||||
"\n"
|
||||
" float4 worldPosition;\n"
|
||||
" worldPosition.x = dot4( modelPosition, rpModelMatrixX );\n"
|
||||
" worldPosition.y = dot4( modelPosition, rpModelMatrixY );\n"
|
||||
" worldPosition.z = dot4( modelPosition, rpModelMatrixZ );\n"
|
||||
" worldPosition.w = dot4( modelPosition, rpModelMatrixW );\n"
|
||||
" result.texcoord0 = worldPosition.xyz;\n"
|
||||
"\n"
|
||||
" result.color = sRGBAToLinearRGBA( rpColor );\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
|
||||
},
|
||||
|
||||
{
|
||||
"renderprogs/builtin/fog/blendLight.ps.hlsl",
|
||||
"/*\n"
|
||||
|
|
|
@ -1937,7 +1937,7 @@ static srfTriangles_t* R_MakeZeroOneSphereTris()
|
|||
|
||||
verts[ numVerts ].SetTexCoord( s * S, r * R );
|
||||
verts[ numVerts ].xyz = idVec3( x, y, z ) * radius;
|
||||
verts[ numVerts ].SetNormal( -x, -y, -z );
|
||||
verts[ numVerts ].SetNormal( x, y, z );
|
||||
verts[ numVerts ].SetColor( 0xffffffff );
|
||||
numVerts++;
|
||||
|
||||
|
|
|
@ -35,6 +35,17 @@ If you have questions concerning this license or the applicable additional terms
|
|||
static const int MAX_LIGHTGRID_ATLAS_SIZE = 4096;
|
||||
static const int MAX_AREA_LIGHTGRID_POINTS = ( MAX_LIGHTGRID_ATLAS_SIZE / LIGHTGRID_IRRADIANCE_SIZE ) * ( MAX_LIGHTGRID_ATLAS_SIZE / LIGHTGRID_IRRADIANCE_SIZE );
|
||||
|
||||
LightGrid::LightGrid()
|
||||
{
|
||||
lightGridSize.Set( 64, 64, 128 );
|
||||
//lightGridPoints.Clear();
|
||||
|
||||
area = -1;
|
||||
validGridPoints = 0;
|
||||
|
||||
irradianceImage = NULL;
|
||||
}
|
||||
|
||||
void LightGrid::SetupLightGrid( const idBounds& bounds, const char* mapName, const idRenderWorld* world, int _area )
|
||||
{
|
||||
//idLib::Printf( "----- SetupLightGrid -----\n" );
|
||||
|
@ -86,15 +97,8 @@ void LightGrid::SetupLightGrid( const idBounds& bounds, const char* mapName, con
|
|||
|
||||
idStr fullname;
|
||||
|
||||
for( int i = 0; i < lightGridPoints.Num(); i++ )
|
||||
{
|
||||
lightGridPoint_t* gridPoint = &lightGridPoints[i];
|
||||
|
||||
gridPoint->irradianceImage = NULL;
|
||||
|
||||
fullname.Format( "env/%s/area%i_lightgridpoint%i_amb", basename.c_str(), area, i );
|
||||
gridPoint->irradianceImage = globalImages->ImageFromFile( fullname, TF_LINEAR, TR_CLAMP, TD_R11G11B10F, CF_2D );
|
||||
}
|
||||
fullname.Format( "env/%s/area%i_lightgrid_amb", basename.c_str(), area );
|
||||
irradianceImage = globalImages->ImageFromFile( fullname, TF_NEAREST, TR_CLAMP, TD_R11G11B10F, CF_2D );
|
||||
#else
|
||||
for( int i = 0; i < lightGridPoints.Num(); i++ )
|
||||
{
|
||||
|
|
|
@ -67,9 +67,6 @@ struct lightGridPoint_t
|
|||
bool valid; // is not in solid area
|
||||
|
||||
SphericalHarmonicsT<float, 4> SH4;
|
||||
|
||||
// TODO REMOVE just for testing
|
||||
idImage* irradianceImage;
|
||||
};
|
||||
|
||||
class LightGrid
|
||||
|
@ -84,7 +81,9 @@ public:
|
|||
idList<lightGridPoint_t> lightGridPoints;
|
||||
int validGridPoints;
|
||||
|
||||
//LightGrid();
|
||||
idImage* irradianceImage;
|
||||
|
||||
LightGrid();
|
||||
|
||||
// setup light grid for given world bounds
|
||||
void SetupLightGrid( const idBounds& bounds, const char* baseName, const idRenderWorld* world, int _area );
|
||||
|
|
Loading…
Reference in a new issue