mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-13 22:22:05 +00:00
Fixed reflections in bumpyenvironment2
This commit is contained in:
parent
249397bcb8
commit
e8c226e08a
4 changed files with 156 additions and 52 deletions
|
@ -1840,8 +1840,8 @@ void idRenderBackend::GetCurrentBindingLayout( int type )
|
|||
auto& bindings = desc[1].bindings;
|
||||
bindings[0].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID();
|
||||
bindings[1].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID();
|
||||
bindings[1].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 2 )->GetTextureID();
|
||||
bindings[1].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 3 )->GetTextureID();
|
||||
bindings[2].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 2 )->GetTextureID();
|
||||
bindings[3].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 3 )->GetTextureID();
|
||||
}
|
||||
|
||||
if( R_UsePixelatedLook() )
|
||||
|
|
|
@ -537,6 +537,110 @@ static void R_FindClosestEnvironmentProbes()
|
|||
tr.viewDef->irradianceImage = nearest->irradianceImage;
|
||||
}
|
||||
|
||||
// form a triangle of the 3 closest probes
|
||||
idVec3 verts[3];
|
||||
for( int i = 0; i < 3; i++ )
|
||||
{
|
||||
verts[i] = viewEnvprobes[0]->parms.origin;
|
||||
}
|
||||
|
||||
for( int i = 0; i < viewEnvprobes.Num() && i < 3; i++ )
|
||||
{
|
||||
RenderEnvprobeLocal* vProbe = viewEnvprobes[i];
|
||||
|
||||
verts[i] = vProbe->parms.origin;
|
||||
}
|
||||
|
||||
idVec3 closest = R_ClosestPointPointTriangle( testOrigin, verts[0], verts[1], verts[2] );
|
||||
idVec3 bary;
|
||||
|
||||
// find the barycentric coordinates
|
||||
float denom = idWinding::TriangleArea( verts[0], verts[1], verts[2] );
|
||||
if( denom == 0 )
|
||||
{
|
||||
// triangle is line
|
||||
float t;
|
||||
|
||||
R_ClosestPointOnLineSegment( testOrigin, verts[0], verts[1], t );
|
||||
|
||||
bary.Set( 1.0f - t, t, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
float a, b, c;
|
||||
|
||||
a = idWinding::TriangleArea( closest, verts[1], verts[2] ) / denom;
|
||||
b = idWinding::TriangleArea( closest, verts[2], verts[0] ) / denom;
|
||||
c = idWinding::TriangleArea( closest, verts[0], verts[1] ) / denom;
|
||||
|
||||
bary.Set( a, b, c );
|
||||
}
|
||||
|
||||
tr.viewDef->radianceImageBlends.Set( bary.x, bary.y, bary.z, 0.0f );
|
||||
|
||||
for( int i = 0; i < viewEnvprobes.Num() && i < 3; i++ )
|
||||
{
|
||||
if( !viewEnvprobes[i]->radianceImage->IsDefaulted() )
|
||||
{
|
||||
tr.viewDef->radianceImages[i] = viewEnvprobes[i]->radianceImage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// this one tries to interpolate between probes over time
|
||||
static void R_FindClosestEnvironmentProbes2()
|
||||
{
|
||||
// set safe defaults
|
||||
tr.viewDef->globalProbeBounds.Clear();
|
||||
|
||||
tr.viewDef->irradianceImage = globalImages->defaultUACIrradianceCube;
|
||||
tr.viewDef->radianceImageBlends.Set( 1, 0, 0, 0 );
|
||||
for( int i = 0; i < 3; i++ )
|
||||
{
|
||||
tr.viewDef->radianceImages[i] = globalImages->defaultUACRadianceCube;
|
||||
}
|
||||
|
||||
// early out
|
||||
if( tr.viewDef->areaNum == -1 || tr.viewDef->isSubview )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
idList<RenderEnvprobeLocal*, TAG_RENDER_ENVPROBE> viewEnvprobes;
|
||||
for( int i = 0; i < tr.primaryWorld->envprobeDefs.Num(); i++ )
|
||||
{
|
||||
RenderEnvprobeLocal* vProbe = tr.primaryWorld->envprobeDefs[i];
|
||||
if( vProbe )
|
||||
{
|
||||
// check for being closed off behind a door
|
||||
if( r_useLightAreaCulling.GetBool() && vProbe->areaNum != -1 && !tr.viewDef->connectedAreas[ vProbe->areaNum ] )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
viewEnvprobes.AddUnique( vProbe );
|
||||
}
|
||||
}
|
||||
|
||||
if( viewEnvprobes.Num() == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
idVec3 testOrigin = tr.viewDef->renderView.vieworg;
|
||||
|
||||
// sort by distance
|
||||
// RB: each Doom 3 level has ~50 - 150 probes so this should be ok for each frame
|
||||
viewEnvprobes.SortWithTemplate( idSort_CompareEnvprobe( testOrigin ) );
|
||||
|
||||
RenderEnvprobeLocal* nearest = viewEnvprobes[0];
|
||||
tr.viewDef->globalProbeBounds = nearest->globalProbeBounds;
|
||||
|
||||
if( nearest->irradianceImage->IsLoaded() && !nearest->irradianceImage->IsDefaulted() )
|
||||
{
|
||||
tr.viewDef->irradianceImage = nearest->irradianceImage;
|
||||
}
|
||||
|
||||
static float oldBarycentricWeights[3] = {0};
|
||||
static int oldIndexes[3] = {0};
|
||||
static int timeInterpolateStart = 0;
|
||||
|
|
|
@ -47,6 +47,7 @@ struct PS_IN
|
|||
float3 texcoord2 : TEXCOORD2_centroid;
|
||||
float3 texcoord3 : TEXCOORD3_centroid;
|
||||
float3 texcoord4 : TEXCOORD4_centroid;
|
||||
float4 texcoord5 : TEXCOORD5_centroid;
|
||||
float4 color : COLOR0;
|
||||
};
|
||||
|
||||
|
@ -77,10 +78,11 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
globalNormal.y = dot3( localNormal, fragment.texcoord3 );
|
||||
globalNormal.z = dot3( localNormal, fragment.texcoord4 );
|
||||
|
||||
float3 globalEye = normalize( fragment.texcoord1 );
|
||||
float3 globalPosition = fragment.texcoord5.xyz;
|
||||
|
||||
float3 reflectionVector = globalNormal * dot3( globalEye, globalNormal );
|
||||
reflectionVector = ( reflectionVector * 2.0f ) - globalEye;
|
||||
float3 globalView = normalize( globalPosition - rpGlobalEyePos.xyz );
|
||||
|
||||
float3 reflectionVector = reflect( globalView, globalNormal );
|
||||
|
||||
#if 0
|
||||
// parallax box correction using portal area bounds
|
||||
|
|
|
@ -51,22 +51,23 @@ struct VS_OUT
|
|||
float3 texcoord2 : TEXCOORD2_centroid;
|
||||
float3 texcoord3 : TEXCOORD3_centroid;
|
||||
float3 texcoord4 : TEXCOORD4_centroid;
|
||||
float4 texcoord5 : TEXCOORD5_centroid;
|
||||
float4 color : COLOR0;
|
||||
};
|
||||
// *INDENT-ON*
|
||||
|
||||
void main( VS_IN vertex, out VS_OUT result )
|
||||
{
|
||||
#if USE_GPU_SKINNING
|
||||
float4 vNormal = vertex.normal * 2.0 - 1.0;
|
||||
float4 vTangent = vertex.tangent * 2.0 - 1.0;
|
||||
float3 vBinormal = cross( vNormal.xyz, vTangent.xyz ) * vTangent.w;
|
||||
float3 vBitangent = cross( vNormal.xyz, vTangent.xyz ) * vTangent.w;
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// 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 )
|
||||
//--------------------------------------------------------------
|
||||
#if USE_GPU_SKINNING
|
||||
//--------------------------------------------------------------
|
||||
// GPU transformation of the normal / tangent / 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;
|
||||
|
@ -105,11 +106,11 @@ void main( VS_IN vertex, out VS_OUT result )
|
|||
tangent.z = dot3( matZ, vTangent );
|
||||
tangent = normalize( tangent );
|
||||
|
||||
float3 binormal;
|
||||
binormal.x = dot3( matX, vBinormal );
|
||||
binormal.y = dot3( matY, vBinormal );
|
||||
binormal.z = dot3( matZ, vBinormal );
|
||||
binormal = normalize( binormal );
|
||||
float3 bitangent;
|
||||
bitangent.x = dot3( matX, vBitangent );
|
||||
bitangent.y = dot3( matY, vBitangent );
|
||||
bitangent.z = dot3( matZ, vBitangent );
|
||||
bitangent = normalize( bitangent );
|
||||
|
||||
float4 modelPosition;
|
||||
modelPosition.x = dot4( matX, vertex.position );
|
||||
|
@ -117,13 +118,36 @@ void main( VS_IN vertex, out VS_OUT result )
|
|||
modelPosition.z = dot4( matZ, vertex.position );
|
||||
modelPosition.w = 1.0;
|
||||
|
||||
#else
|
||||
float4 modelPosition = vertex.position;
|
||||
float3 normal = vNormal.xyz;
|
||||
float3 tangent = vTangent.xyz;
|
||||
float3 bitangent = vBitangent.xyz;
|
||||
#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.position.xyz = psxVertexJitter( result.position );
|
||||
|
||||
result.texcoord0 = vertex.texcoord.xy;
|
||||
|
||||
// PSX affine texture mapping
|
||||
#if 0
|
||||
if( rpPSXDistortions.z > 0.0 )
|
||||
{
|
||||
float distance = length( rpLocalViewOrigin - modelPosition );
|
||||
float warp = psxAffineWarp( distance );
|
||||
|
||||
result.texcoord0.z = warp;
|
||||
result.texcoord0.xy *= warp;
|
||||
result.texcoord1.xy *= warp;
|
||||
result.texcoord2.xy *= warp;
|
||||
}
|
||||
#endif
|
||||
|
||||
float4 toEye = rpLocalViewOrigin - modelPosition;
|
||||
|
||||
result.texcoord1.x = dot3( toEye, rpModelMatrixX );
|
||||
|
@ -134,46 +158,20 @@ void main( VS_IN vertex, out VS_OUT result )
|
|||
result.texcoord3.x = dot3( tangent, rpModelMatrixY );
|
||||
result.texcoord4.x = dot3( tangent, rpModelMatrixZ );
|
||||
|
||||
result.texcoord2.y = dot3( binormal, rpModelMatrixX );
|
||||
result.texcoord3.y = dot3( binormal, rpModelMatrixY );
|
||||
result.texcoord4.y = dot3( binormal, rpModelMatrixZ );
|
||||
|
||||
result.texcoord2.z = dot3( normal, rpModelMatrixX );
|
||||
result.texcoord3.z = dot3( normal, rpModelMatrixY );
|
||||
result.texcoord4.z = dot3( normal, rpModelMatrixZ );
|
||||
#else
|
||||
float4 normal = vertex.normal * 2.0 - 1.0;
|
||||
float4 tangent = vertex.tangent * 2.0 - 1.0;
|
||||
float3 binormal = cross( normal.xyz, tangent.xyz ) * tangent.w;
|
||||
|
||||
result.position.x = dot4( vertex.position, rpMVPmatrixX );
|
||||
result.position.y = dot4( vertex.position, rpMVPmatrixY );
|
||||
result.position.z = dot4( vertex.position, rpMVPmatrixZ );
|
||||
result.position.w = dot4( vertex.position, rpMVPmatrixW );
|
||||
|
||||
result.texcoord0 = vertex.texcoord.xy;
|
||||
|
||||
float4 toEye = rpLocalViewOrigin - vertex.position;
|
||||
|
||||
result.texcoord1.x = dot3( toEye, rpModelMatrixX );
|
||||
result.texcoord1.y = dot3( toEye, rpModelMatrixY );
|
||||
result.texcoord1.z = dot3( toEye, rpModelMatrixZ );
|
||||
|
||||
result.texcoord2.x = dot3( tangent, rpModelMatrixX );
|
||||
result.texcoord3.x = dot3( tangent, rpModelMatrixY );
|
||||
result.texcoord4.x = dot3( tangent, rpModelMatrixZ );
|
||||
|
||||
result.texcoord2.y = dot3( binormal, rpModelMatrixX );
|
||||
result.texcoord3.y = dot3( binormal, rpModelMatrixY );
|
||||
result.texcoord4.y = dot3( binormal, rpModelMatrixZ );
|
||||
result.texcoord2.y = dot3( bitangent, rpModelMatrixX );
|
||||
result.texcoord3.y = dot3( bitangent, rpModelMatrixY );
|
||||
result.texcoord4.y = dot3( bitangent, rpModelMatrixZ );
|
||||
|
||||
result.texcoord2.z = dot3( normal, rpModelMatrixX );
|
||||
result.texcoord3.z = dot3( normal, rpModelMatrixY );
|
||||
result.texcoord4.z = dot3( normal, rpModelMatrixZ );
|
||||
|
||||
#endif
|
||||
|
||||
result.position.xyz = psxVertexJitter( result.position );
|
||||
float4 worldPosition;
|
||||
worldPosition.x = dot4( modelPosition, rpModelMatrixX );
|
||||
worldPosition.y = dot4( modelPosition, rpModelMatrixY );
|
||||
worldPosition.z = dot4( modelPosition, rpModelMatrixZ );
|
||||
worldPosition.w = dot4( modelPosition, rpModelMatrixW );
|
||||
result.texcoord5 = worldPosition;
|
||||
|
||||
result.color = rpColor;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue