mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-03-15 07:00:58 +00:00
Hierarchical depth buffer for SSAO works
This commit is contained in:
parent
d9f9db3b37
commit
e8826caae8
10 changed files with 289 additions and 122 deletions
|
@ -149,11 +149,8 @@ float3 reconstructNonUnitCSFaceNormal( float3 C )
|
|||
float3 getPosition( float2 ssP, sampler2D cszBuffer )
|
||||
{
|
||||
#if 1
|
||||
// derive clip space from the depth buffer and screen position
|
||||
float windowZ = tex2D( cszBuffer, ssP ).x;
|
||||
float3 ndc = float3( ssP * 2.0 - 1.0, windowZ * 2.0 - 1.0 );
|
||||
//float clipW = -rpProjectionMatrixZ.w / ( -rpProjectionMatrixZ.z - ndc.z );
|
||||
//float4 P = float4( ndc * clipW, clipW );
|
||||
float4 P = float4( ndc, 1.0 );
|
||||
#else
|
||||
float4 P;
|
||||
|
@ -170,26 +167,24 @@ float3 getPosition( float2 ssP, sampler2D cszBuffer )
|
|||
csP.y = dot4( P, rpProjectionMatrixY );
|
||||
csP.z = dot4( P, rpProjectionMatrixZ );
|
||||
csP.w = dot4( P, rpProjectionMatrixW );
|
||||
|
||||
csP.xyz /= csP.w;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
return csP.xyz;
|
||||
#else
|
||||
// transform to world space if using world space normals
|
||||
float4 wP;
|
||||
wP.x = dot4( csP, rpModelMatrixX );
|
||||
wP.y = dot4( csP, rpModelMatrixY );
|
||||
wP.z = dot4( csP, rpModelMatrixZ );
|
||||
wP.w = dot4( csP, rpModelMatrixW );
|
||||
//wP.xyz /= wP.w;
|
||||
wP.xyz /= wP.w;
|
||||
return wP.xyz;
|
||||
#endif
|
||||
|
||||
return csP.xyz;
|
||||
}
|
||||
|
||||
/** Read the camera-space position of the point at screen-space pixel ssP + unitOffset * ssR. Assumes length(unitOffset) == 1.
|
||||
Use cszBufferScale if reading from the peeled depth buffer, which has been scaled by (1 / invCszBufferScale) from the original */
|
||||
float3 getOffsetPosition( ivec2 issC, vec2 unitOffset, float ssR, sampler2D cszBuffer, float invCszBufferScale )
|
||||
float3 getOffsetPosition( int2 issC, float2 unitOffset, float ssR, sampler2D cszBuffer, float invCszBufferScale )
|
||||
{
|
||||
// Derivation:
|
||||
// mipLevel = floor(log(ssR / MAX_OFFSET));
|
||||
|
@ -199,32 +194,35 @@ float3 getOffsetPosition( ivec2 issC, vec2 unitOffset, float ssR, sampler2D cszB
|
|||
int mipLevel = clamp( int( floor( log2( ssR ) ) ) - LOG_MAX_OFFSET, 0, MAX_MIP_LEVEL );
|
||||
#endif
|
||||
|
||||
ivec2 ssP = ivec2( ssR * unitOffset ) + issC;
|
||||
int2 ssP = int2( ssR * unitOffset ) + issC;
|
||||
|
||||
float4 P;
|
||||
|
||||
// We need to divide by 2^mipLevel to read the appropriately scaled coordinate from a MIP-map.
|
||||
// Manually clamp to the texture size because texelFetch bypasses the texture unit
|
||||
ivec2 mipP = clamp( ssP >> mipLevel, ivec2( 0 ), textureSize( CS_Z_buffer, mipLevel ) - ivec2( 1 ) );
|
||||
int2 mipP = clamp( ssP >> mipLevel, int2( 0 ), textureSize( CS_Z_buffer, mipLevel ) - int2( 1 ) );
|
||||
|
||||
float2 ossC = float2( ssP ) * rpScreenCorrectionFactor.xy;
|
||||
|
||||
#if 1
|
||||
// RB: this is the key for fast ambient occlusion - use a hierarchical depth buffer
|
||||
// for more information see McGuire12SAO.pdf - Scalable Ambient Obscurance
|
||||
// http://graphics.cs.williams.edu/papers/SAOHPG12/
|
||||
float windowZ = texelFetch( cszBuffer, mipP, mipLevel ).r;
|
||||
#else
|
||||
float windowZ = texture( cszBuffer, ossC, 0.0 ).r;
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
float3 ndc = float3( ossC * 2.0 - 1.0, windowZ * 2.0 - 1.0 );
|
||||
//float clipW = -rpProjectionMatrixZ.w / ( -rpProjectionMatrixZ.z - ndc.z );
|
||||
//P = float4( ndc * clipW, clipW );
|
||||
P = float4( ndc, 1.0 );
|
||||
|
||||
//return P.xyz;
|
||||
#else
|
||||
|
||||
//P.z = texture( cszBuffer, mipP, 0.0 ).r;
|
||||
//P.z = texture( cszBuffer, mipP, mipLevel ).r;
|
||||
|
||||
// Offset to pixel center
|
||||
//P = reconstructCSPosition( ( vec2( ssP ) + vec2( 0.5 ) ) * invCszBufferScale, P.z, projInfo );
|
||||
//P = reconstructCSPosition( ( float2( ssP ) + float2( 0.5 ) ) * invCszBufferScale, P.z, projInfo );
|
||||
P.xy = ossC; //+ float2( 0.5 ) ) * invCszBufferScale;
|
||||
P.w = 1.0;
|
||||
#endif
|
||||
|
@ -236,19 +234,18 @@ float3 getOffsetPosition( ivec2 issC, vec2 unitOffset, float ssR, sampler2D cszB
|
|||
csP.z = dot4( P, rpProjectionMatrixZ );
|
||||
csP.w = dot4( P, rpProjectionMatrixW );
|
||||
csP.xyz /= csP.w;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
return csP.xyz;
|
||||
#else
|
||||
// transform to world space if using world space normals
|
||||
float4 wP;
|
||||
wP.x = dot4( csP, rpModelMatrixX );
|
||||
wP.y = dot4( csP, rpModelMatrixY );
|
||||
wP.z = dot4( csP, rpModelMatrixZ );
|
||||
wP.w = dot4( csP, rpModelMatrixW );
|
||||
//wP.xyz /= wP.w;
|
||||
wP.xyz /= wP.w;
|
||||
return wP.xyz;
|
||||
#endif
|
||||
|
||||
return csP.xyz;
|
||||
}
|
||||
|
||||
float fallOffFunction( float vv, float vn, float epsilon )
|
||||
|
@ -290,7 +287,7 @@ float aoValueFromPositionsAndNormal( float3 C, float3 n_C, float3 Q )
|
|||
const float epsilon = 0.001;
|
||||
|
||||
// Without the angular adjustment term, surfaces seen head on have less AO
|
||||
return fallOffFunction( vv, vn, epsilon );// * lerp( 1.0, max( 0.0, 1.5 * n_C.z ), 0.35 );
|
||||
return fallOffFunction( vv, vn, epsilon ) * lerp( 1.0, max( 0.0, 1.5 * n_C.z ), 0.35 );
|
||||
}
|
||||
|
||||
|
||||
|
@ -305,7 +302,7 @@ float aoValueFromPositionsAndNormal( float3 C, float3 n_C, float3 Q )
|
|||
|
||||
When sampling from the peeled depth buffer, make sure ssDiskRadius has been premultiplied by cszBufferScale
|
||||
*/
|
||||
float sampleAO( ivec2 issC, in float3 C, in float3 n_C, in float ssDiskRadius, in int tapIndex, in float randomPatternRotationAngle, in sampler2D cszBuffer, in float invCszBufferScale )
|
||||
float sampleAO( int2 issC, in float3 C, in float3 n_C, in float ssDiskRadius, in int tapIndex, in float randomPatternRotationAngle, in sampler2D cszBuffer, in float invCszBufferScale )
|
||||
{
|
||||
// Offset on the unit disk, spun for this pixel
|
||||
float ssR;
|
||||
|
@ -343,15 +340,9 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
}
|
||||
#endif
|
||||
|
||||
//float3 normal = tex2D( samp0, fragment.texcoord0 ).rgb * 2.0 - 1.0;
|
||||
//if( length( normal ) < 0.9 )
|
||||
//{
|
||||
//discard;
|
||||
//}
|
||||
|
||||
// Pixel being shaded
|
||||
float2 ssC = fragment.texcoord0;
|
||||
ivec2 issC = ivec2( ssC.x * rpScreenCorrectionFactor.z, ssC.y * rpScreenCorrectionFactor.w );
|
||||
int2 issC = int2( ssC.x * rpScreenCorrectionFactor.z, ssC.y * rpScreenCorrectionFactor.w );
|
||||
|
||||
// World space point being shaded
|
||||
vec3 C = getPosition( ssC, CS_Z_buffer );
|
||||
|
@ -363,12 +354,8 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
visibility = 0.0;
|
||||
|
||||
#if 1
|
||||
//vec3 n_C = texelFetch( normal_buffer, ivec2( gl_FragCoord.xy ), 0 ).xyz;
|
||||
//n_C = normalize( n_C * normal_readMultiplyFirst.xyz + normal_readAddSecond.xyz );
|
||||
|
||||
float3 n_C = tex2D( samp0, fragment.texcoord0 ).rgb * 2.0 - 1.0;
|
||||
n_C = normalize( n_C );
|
||||
//n_C = -n_C;
|
||||
vec3 n_C = texelFetch( samp0, int2( gl_FragCoord.xy ), 0 ).xyz * 2.0 - 1.0;
|
||||
//float3 n_C = tex2D( samp0, fragment.texcoord0 ).rgb * 2.0 - 1.0;
|
||||
|
||||
if( length( n_C ) < 0.1 )
|
||||
{
|
||||
|
@ -376,6 +363,9 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
return;
|
||||
}
|
||||
|
||||
n_C = normalize( n_C );
|
||||
//n_C = -n_C;
|
||||
|
||||
#else
|
||||
// Reconstruct normals from positions.
|
||||
float3 n_C = reconstructNonUnitCSFaceNormal( C );
|
||||
|
@ -451,10 +441,4 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
//result.color = float4( n_C, 1.0 );
|
||||
//result.color = texture( samp0, fragment.texcoord0 ).rgba;
|
||||
#endif
|
||||
// derive clip space from the depth buffer and screen position
|
||||
// float windowZ = tex2D( samp1, fragment.texcoord0 ).x;
|
||||
// float3 ndc = float3( fragment.texcoord0 * 2.0 - 1.0, windowZ * 2.0 - 1.0 );
|
||||
// float clipW = -rpProjectionMatrixZ.w / ( -rpProjectionMatrixZ.z - ndc.z );
|
||||
|
||||
// float4 clip = float4( ndc * clipW, clipW );
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ struct PS_OUT
|
|||
//#endif
|
||||
|
||||
/** (1, 0) or (0, 1)*/
|
||||
//uniform ivec2 axis;
|
||||
//uniform int2 axis;
|
||||
|
||||
|
||||
#define aoResult result.color.VALUE_COMPONENTS
|
||||
|
@ -135,13 +135,13 @@ float3 reconstructCSPosition( float2 S, float z )
|
|||
|
||||
/** Used for preventing AO computation on the sky (at infinite depth) and defining the CS Z to bilateral depth key scaling.
|
||||
This need not match the real far plane but should not be much more than it.*/
|
||||
const float FAR_PLANE_Z = -4000.0;
|
||||
const float FAR_PLANE_Z = -16000.0;
|
||||
|
||||
float3 positionFromKey( float key, ivec2 ssC )
|
||||
float3 positionFromKey( float key, int2 ssC )
|
||||
{
|
||||
float z = key * FAR_PLANE_Z;
|
||||
//float3 C = reconstructCSPosition( vec2( ssC )/* + vec2( 0.5 )*/, z, pInfo );
|
||||
float3 C = reconstructCSPosition( vec2( ssC ), z );
|
||||
//float3 C = reconstructCSPosition( float2( ssC )/* + float2( 0.5 )*/, z, pInfo );
|
||||
float3 C = reconstructCSPosition( float2( ssC ), z );
|
||||
return C;
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ uniform float4 normal_readMultiplyFirst;
|
|||
uniform float4 normal_readAddSecond;
|
||||
#endif
|
||||
|
||||
float calculateBilateralWeight( float key, float tapKey, ivec2 tapLoc, float3 n_C, float3 C )
|
||||
float calculateBilateralWeight( float key, float tapKey, int2 tapLoc, float3 n_C, float3 C )
|
||||
{
|
||||
// range domain (the "bilateral" weight). As depth difference increases, decrease weight.
|
||||
float depthWeight = max( 0.0, 1.0 - ( EDGE_SHARPNESS * 2000.0 ) * abs( tapKey - key ) );
|
||||
|
@ -239,7 +239,7 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
// # endif
|
||||
//# endif
|
||||
|
||||
ivec2 ssC = ivec2( gl_FragCoord.xy );
|
||||
int2 ssC = int2( gl_FragCoord.xy );
|
||||
|
||||
float4 temp = texelFetch( source, ssC, 0 );
|
||||
|
||||
|
@ -287,7 +287,7 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
// so the IF statement has no runtime cost
|
||||
if( r != 0 )
|
||||
{
|
||||
ivec2 tapLoc = ssC + ivec2( rpJitterTexScale.xy ) * ( r * SCALE );
|
||||
int2 tapLoc = ssC + int2( rpJitterTexScale.xy ) * ( r * SCALE );
|
||||
temp = texelFetch( source, tapLoc, 0 );
|
||||
float tapKey = unpackKey( temp.KEY_COMPONENTS );
|
||||
VALUE_TYPE value = temp.VALUE_COMPONENTS;
|
||||
|
@ -307,7 +307,7 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
float lastBilateralWeight = 9999.0;
|
||||
for( int r = -1; r >= -R; --r )
|
||||
{
|
||||
ivec2 tapLoc = ssC + ivec2( rpJitterTexScale.xy ) * ( r * SCALE );
|
||||
int2 tapLoc = ssC + int2( rpJitterTexScale.xy ) * ( r * SCALE );
|
||||
temp = texelFetch( source, tapLoc, 0 );
|
||||
float tapKey = unpackKey( temp.KEY_COMPONENTS );
|
||||
VALUE_TYPE value = temp.VALUE_COMPONENTS;
|
||||
|
@ -327,7 +327,7 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
lastBilateralWeight = 9999.0;
|
||||
for( int r = 1; r <= R; ++r )
|
||||
{
|
||||
ivec2 tapLoc = ssC + ivec2( rpJitterTexScale.xy ) * ( r * SCALE );
|
||||
int2 tapLoc = ssC + int2( rpJitterTexScale.xy ) * ( r * SCALE );
|
||||
temp = texelFetch( source, tapLoc, 0 );
|
||||
float tapKey = unpackKey( temp.KEY_COMPONENTS );
|
||||
VALUE_TYPE value = temp.VALUE_COMPONENTS;
|
||||
|
|
|
@ -31,6 +31,8 @@ struct PS_OUT
|
|||
};
|
||||
// *INDENT-ON*
|
||||
|
||||
//#extension GL_EXT_gpu_shader4 : enable
|
||||
|
||||
//#expect USE_PEELED_DEPTH_BUFFER "binary"
|
||||
|
||||
#if 0 //( USE_PEELED_DEPTH_BUFFER != 0 )
|
||||
|
@ -39,23 +41,39 @@ struct PS_OUT
|
|||
#define mask r
|
||||
#endif
|
||||
|
||||
float reconstructCSZ( float d )
|
||||
{
|
||||
//return clipInfo[0] / (clipInfo[1] * d + clipInfo[2]);
|
||||
|
||||
// infinite far perspective matrix
|
||||
return 3.0 / ( -1.0 * d + 1.0 );
|
||||
}
|
||||
|
||||
void main( PS_IN fragment, out PS_OUT result )
|
||||
{
|
||||
#if defined(BRIGHTPASS)
|
||||
float2 ssC = fragment.texcoord0;
|
||||
float depth = tex2D( samp0, ssC ).r;
|
||||
//depth = reconstructCSZ( depth );
|
||||
result.color.mask = depth;
|
||||
#else
|
||||
//int2 ssP = int2( gl_FragCoord.xy );
|
||||
int2 ssP = int2( fragment.texcoord0 * rpScreenCorrectionFactor.zw );
|
||||
|
||||
//int previousMIPNumber
|
||||
int previousMIPNumber = int( rpJitterTexScale.x );
|
||||
|
||||
// Rotated grid subsampling to avoid XY directional bias or Z precision bias while downsampling.
|
||||
// On DX9, the bit-and can be implemented with floating-point modulo
|
||||
//result.color.mask = texelFetch2D( texture, clamp( ssP * 2 + int2( ssP.y & 1, ssP.x & 1 ), int2( 0 ), textureSize( texture, previousMIPNumber ) - int2( 1 ) ), previousMIPNumber ).mask;
|
||||
//result.color.mask = texture( samp0, clamp( ssP * 2 + int2( ssP.y & 1, ssP.x & 1 ), int2( 0 ), textureSize( samp0, previousMIPNumber ) - int2( 1 ) ) * rpScreenCorrectionFactor.xy, previousMIPNumber ).mask;
|
||||
result.color.mask = texelFetch( samp0, clamp( ssP * 2 + int2( ssP.y & 1, ssP.x & 1 ), int2( 0 ), textureSize( samp0, previousMIPNumber ) - int2( 1 ) ), previousMIPNumber ).mask;
|
||||
//result.color.mask = texelFetch2D( samp0, int3( ssP * 2 + int2( ( ssP.y & 1 ) ^ 1, ( ssP.x & 1 ) ^ 1 ), 0 ) );
|
||||
|
||||
// result.color.mask = texelFetch( samp0, ssP, 0 ).r;
|
||||
|
||||
//float2 ssC = float2( ssP * 2 + int2( ( ssP.y & 1 ) ^ 1, ( ssP.x & 1 ) ^ 1 ) ) * rpScreenCorrectionFactor.xy;
|
||||
//float2 ssC = float2( ssP ) * rpScreenCorrectionFactor.xy;
|
||||
float2 ssC = fragment.texcoord0;
|
||||
float depth = tex2D( samp0, ssC ).r;
|
||||
result.color.mask = depth;
|
||||
//float2 ssC = fragment.texcoord0;
|
||||
//float depth = tex2D( samp0, ssC ).r;
|
||||
//result.color.mask = depth;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ return
|
|||
"AmbientOcclusion_AO.vertex",
|
||||
"AmbientOcclusion_blur.pixel",
|
||||
"AmbientOcclusion_blur.vertex",
|
||||
"AmbientOcclusion_minify.pixel",
|
||||
"AmbientOcclusion_minify.vertex",
|
||||
"bink.pixel",
|
||||
"bink.vertex",
|
||||
"bink_gui.pixel",
|
||||
|
|
|
@ -62,7 +62,7 @@ void main( PS_IN fragment, out PS_OUT result )
|
|||
localNormal.z = sqrt( 1.0f - dot3( localNormal, localNormal ) );
|
||||
|
||||
float3 globalNormal;
|
||||
#if 0
|
||||
#if 1
|
||||
globalNormal.x = dot3( localNormal, fragment.texcoord2 );
|
||||
globalNormal.y = dot3( localNormal, fragment.texcoord3 );
|
||||
globalNormal.z = dot3( localNormal, fragment.texcoord4 );
|
||||
|
|
|
@ -41,4 +41,6 @@ struct PS_OUT {
|
|||
|
||||
void main( PS_IN fragment, out PS_OUT result ) {
|
||||
result.color = tex2D( samp0, fragment.texcoord0 ) * rpColor;
|
||||
//result.color = textureLod( samp0, fragment.texcoord0, 2.0 ) * rpColor;
|
||||
//result.color = float4( 0.0, 1.0, 0.0, 1.0 ) * rpColor;
|
||||
}
|
|
@ -153,6 +153,7 @@ void idRenderProgManager::Init()
|
|||
{ BUILTIN_AMBIENT_OCCLUSION_BLUR, "AmbientOcclusion_blur", "", 0, false },
|
||||
{ BUILTIN_AMBIENT_OCCLUSION_BLUR_AND_OUTPUT, "AmbientOcclusion_blur", "_write", BIT( BRIGHTPASS ), false },
|
||||
{ BUILTIN_AMBIENT_OCCLUSION_MINIFY, "AmbientOcclusion_minify", "", 0, false },
|
||||
{ BUILTIN_AMBIENT_OCCLUSION_RECONSTRUCT_CSZ, "AmbientOcclusion_minify", "_mip0", BIT( BRIGHTPASS ), false },
|
||||
// RB end
|
||||
{ BUILTIN_STEREO_DEGHOST, "stereoDeGhost.vfp", 0, false },
|
||||
{ BUILTIN_STEREO_WARP, "stereoWarp.vfp", 0, false },
|
||||
|
|
|
@ -478,6 +478,11 @@ public:
|
|||
BindShader_Builtin( BUILTIN_AMBIENT_OCCLUSION_MINIFY );
|
||||
}
|
||||
|
||||
void BindShader_AmbientOcclusionReconstructCSZ()
|
||||
{
|
||||
BindShader_Builtin( BUILTIN_AMBIENT_OCCLUSION_RECONSTRUCT_CSZ );
|
||||
}
|
||||
|
||||
#if 0
|
||||
void BindShader_ZCullReconstruct()
|
||||
{
|
||||
|
@ -606,6 +611,7 @@ protected:
|
|||
BUILTIN_AMBIENT_OCCLUSION_BLUR,
|
||||
BUILTIN_AMBIENT_OCCLUSION_BLUR_AND_OUTPUT,
|
||||
BUILTIN_AMBIENT_OCCLUSION_MINIFY,
|
||||
BUILTIN_AMBIENT_OCCLUSION_RECONSTRUCT_CSZ,
|
||||
// RB end
|
||||
BUILTIN_STEREO_DEGHOST,
|
||||
BUILTIN_STEREO_WARP,
|
||||
|
|
|
@ -2074,7 +2074,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"const float intensity = 0.3;\n"
|
||||
"const float intensityDivR6 = intensity / ( radius* radius* radius* radius* radius* radius );\n"
|
||||
"\n"
|
||||
"const float projScale = 300.0;// * METERS_TO_DOOM;\n"
|
||||
"const float projScale = 500.0;// * METERS_TO_DOOM;\n"
|
||||
"\n"
|
||||
"//#expect NUM_SAMPLES \"Integer number of samples to take at each pixels\"\n"
|
||||
"//#expect NUM_SPIRAL_TURNS \"Integer number of turns around the circle that the spiral pattern makes. The G3D::AmbientOcclusion class provides a discrepancy-minimizing value of NUM_SPIRAL_TURNS for eac value of NUM_SAMPLES.\"\n"
|
||||
|
@ -2149,11 +2149,8 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"float3 getPosition( float2 ssP, sampler2D cszBuffer )\n"
|
||||
"{\n"
|
||||
"#if 1\n"
|
||||
" // derive clip space from the depth buffer and screen position\n"
|
||||
" float windowZ = tex2D( cszBuffer, ssP ).x;\n"
|
||||
" float3 ndc = float3( ssP * 2.0 - 1.0, windowZ * 2.0 - 1.0 );\n"
|
||||
" //float clipW = -rpProjectionMatrixZ.w / ( -rpProjectionMatrixZ.z - ndc.z );\n"
|
||||
" //float4 P = float4( ndc * clipW, clipW );\n"
|
||||
" float4 P = float4( ndc, 1.0 );\n"
|
||||
"#else\n"
|
||||
" float4 P;\n"
|
||||
|
@ -2170,26 +2167,24 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" csP.y = dot4( P, rpProjectionMatrixY );\n"
|
||||
" csP.z = dot4( P, rpProjectionMatrixZ );\n"
|
||||
" csP.w = dot4( P, rpProjectionMatrixW );\n"
|
||||
" \n"
|
||||
" csP.xyz /= csP.w;\n"
|
||||
"#endif\n"
|
||||
" \n"
|
||||
"#if 0\n"
|
||||
" return csP.xyz;\n"
|
||||
"#else\n"
|
||||
" // transform to world space if using world space normals\n"
|
||||
" float4 wP;\n"
|
||||
" wP.x = dot4( csP, rpModelMatrixX );\n"
|
||||
" wP.y = dot4( csP, rpModelMatrixY );\n"
|
||||
" wP.z = dot4( csP, rpModelMatrixZ );\n"
|
||||
" wP.w = dot4( csP, rpModelMatrixW );\n"
|
||||
" //wP.xyz /= wP.w;\n"
|
||||
" wP.xyz /= wP.w;\n"
|
||||
" return wP.xyz;\n"
|
||||
"#endif\n"
|
||||
" \n"
|
||||
" return csP.xyz;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"/** Read the camera-space position of the point at screen-space pixel ssP + unitOffset * ssR. Assumes length(unitOffset) == 1.\n"
|
||||
" Use cszBufferScale if reading from the peeled depth buffer, which has been scaled by (1 / invCszBufferScale) from the original */\n"
|
||||
"float3 getOffsetPosition( ivec2 issC, vec2 unitOffset, float ssR, sampler2D cszBuffer, float invCszBufferScale )\n"
|
||||
"float3 getOffsetPosition( int2 issC, float2 unitOffset, float ssR, sampler2D cszBuffer, float invCszBufferScale )\n"
|
||||
"{\n"
|
||||
" // Derivation:\n"
|
||||
" // mipLevel = floor(log(ssR / MAX_OFFSET));\n"
|
||||
|
@ -2199,32 +2194,35 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" int mipLevel = clamp( int( floor( log2( ssR ) ) ) - LOG_MAX_OFFSET, 0, MAX_MIP_LEVEL );\n"
|
||||
"#endif\n"
|
||||
" \n"
|
||||
" ivec2 ssP = ivec2( ssR * unitOffset ) + issC;\n"
|
||||
" int2 ssP = int2( ssR * unitOffset ) + issC;\n"
|
||||
" \n"
|
||||
" float4 P;\n"
|
||||
" \n"
|
||||
" // We need to divide by 2^mipLevel to read the appropriately scaled coordinate from a MIP-map.\n"
|
||||
" // Manually clamp to the texture size because texelFetch bypasses the texture unit\n"
|
||||
" ivec2 mipP = clamp( ssP >> mipLevel, ivec2( 0 ), textureSize( CS_Z_buffer, mipLevel ) - ivec2( 1 ) );\n"
|
||||
" int2 mipP = clamp( ssP >> mipLevel, int2( 0 ), textureSize( CS_Z_buffer, mipLevel ) - int2( 1 ) );\n"
|
||||
" \n"
|
||||
" float2 ossC = float2( ssP ) * rpScreenCorrectionFactor.xy;\n"
|
||||
" \n"
|
||||
"#if 1\n"
|
||||
" // RB: this is the key for fast ambient occlusion - use a hierarchical depth buffer\n"
|
||||
" // for more information see McGuire12SAO.pdf - Scalable Ambient Obscurance\n"
|
||||
" // http://graphics.cs.williams.edu/papers/SAOHPG12/\n"
|
||||
" float windowZ = texelFetch( cszBuffer, mipP, mipLevel ).r;\n"
|
||||
"#else\n"
|
||||
" float windowZ = texture( cszBuffer, ossC, 0.0 ).r;\n"
|
||||
"#endif\n"
|
||||
" \n"
|
||||
"#if 1\n"
|
||||
" float3 ndc = float3( ossC * 2.0 - 1.0, windowZ * 2.0 - 1.0 );\n"
|
||||
" //float clipW = -rpProjectionMatrixZ.w / ( -rpProjectionMatrixZ.z - ndc.z );\n"
|
||||
" //P = float4( ndc * clipW, clipW );\n"
|
||||
" P = float4( ndc, 1.0 );\n"
|
||||
" \n"
|
||||
" //return P.xyz;\n"
|
||||
"#else\n"
|
||||
" \n"
|
||||
" //P.z = texture( cszBuffer, mipP, 0.0 ).r;\n"
|
||||
" //P.z = texture( cszBuffer, mipP, mipLevel ).r;\n"
|
||||
" \n"
|
||||
" // Offset to pixel center\n"
|
||||
" //P = reconstructCSPosition( ( vec2( ssP ) + vec2( 0.5 ) ) * invCszBufferScale, P.z, projInfo );\n"
|
||||
" //P = reconstructCSPosition( ( float2( ssP ) + float2( 0.5 ) ) * invCszBufferScale, P.z, projInfo );\n"
|
||||
" P.xy = ossC; //+ float2( 0.5 ) ) * invCszBufferScale;\n"
|
||||
" P.w = 1.0;\n"
|
||||
"#endif\n"
|
||||
|
@ -2236,19 +2234,18 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" csP.z = dot4( P, rpProjectionMatrixZ );\n"
|
||||
" csP.w = dot4( P, rpProjectionMatrixW );\n"
|
||||
" csP.xyz /= csP.w;\n"
|
||||
"#endif\n"
|
||||
" \n"
|
||||
"#if 0\n"
|
||||
" return csP.xyz;\n"
|
||||
"#else\n"
|
||||
" // transform to world space if using world space normals\n"
|
||||
" float4 wP;\n"
|
||||
" wP.x = dot4( csP, rpModelMatrixX );\n"
|
||||
" wP.y = dot4( csP, rpModelMatrixY );\n"
|
||||
" wP.z = dot4( csP, rpModelMatrixZ );\n"
|
||||
" wP.w = dot4( csP, rpModelMatrixW );\n"
|
||||
" //wP.xyz /= wP.w;\n"
|
||||
" wP.xyz /= wP.w;\n"
|
||||
" return wP.xyz;\n"
|
||||
"#endif\n"
|
||||
" \n"
|
||||
" return csP.xyz;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float fallOffFunction( float vv, float vn, float epsilon )\n"
|
||||
|
@ -2290,7 +2287,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" const float epsilon = 0.001;\n"
|
||||
" \n"
|
||||
" // Without the angular adjustment term, surfaces seen head on have less AO\n"
|
||||
" return fallOffFunction( vv, vn, epsilon );// * lerp( 1.0, max( 0.0, 1.5 * n_C.z ), 0.35 );\n"
|
||||
" return fallOffFunction( vv, vn, epsilon ) * lerp( 1.0, max( 0.0, 1.5 * n_C.z ), 0.35 );\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"\n"
|
||||
|
@ -2305,7 +2302,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"\n"
|
||||
" When sampling from the peeled depth buffer, make sure ssDiskRadius has been premultiplied by cszBufferScale\n"
|
||||
"*/\n"
|
||||
"float sampleAO( ivec2 issC, in float3 C, in float3 n_C, in float ssDiskRadius, in int tapIndex, in float randomPatternRotationAngle, in sampler2D cszBuffer, in float invCszBufferScale )\n"
|
||||
"float sampleAO( int2 issC, in float3 C, in float3 n_C, in float ssDiskRadius, in int tapIndex, in float randomPatternRotationAngle, in sampler2D cszBuffer, in float invCszBufferScale )\n"
|
||||
"{\n"
|
||||
" // Offset on the unit disk, spun for this pixel\n"
|
||||
" float ssR;\n"
|
||||
|
@ -2337,21 +2334,15 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" result.color = float4( 1.0, 0.0, 0.0, 1.0 );\n"
|
||||
" \n"
|
||||
"#if 0\n"
|
||||
" if( fragment.texcoord0.x < 0.25 )\n"
|
||||
" if( fragment.texcoord0.x < 0.5 )\n"
|
||||
" {\n"
|
||||
" discard;\n"
|
||||
" }\n"
|
||||
"#endif\n"
|
||||
" \n"
|
||||
" //float3 normal = tex2D( samp0, fragment.texcoord0 ).rgb * 2.0 - 1.0;\n"
|
||||
" //if( length( normal ) < 0.9 )\n"
|
||||
" //{\n"
|
||||
" //discard;\n"
|
||||
" //}\n"
|
||||
" \n"
|
||||
" // Pixel being shaded\n"
|
||||
" float2 ssC = fragment.texcoord0;\n"
|
||||
" ivec2 issC = ivec2( ssC.x * rpScreenCorrectionFactor.z, ssC.y * rpScreenCorrectionFactor.w );\n"
|
||||
" int2 issC = int2( ssC.x * rpScreenCorrectionFactor.z, ssC.y * rpScreenCorrectionFactor.w );\n"
|
||||
" \n"
|
||||
" // World space point being shaded\n"
|
||||
" vec3 C = getPosition( ssC, CS_Z_buffer );\n"
|
||||
|
@ -2362,13 +2353,9 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" \n"
|
||||
" visibility = 0.0;\n"
|
||||
" \n"
|
||||
"#if 0\n"
|
||||
" //vec3 n_C = texelFetch( normal_buffer, ivec2( gl_FragCoord.xy ), 0 ).xyz;\n"
|
||||
" //n_C = normalize( n_C * normal_readMultiplyFirst.xyz + normal_readAddSecond.xyz );\n"
|
||||
" \n"
|
||||
" float3 n_C = tex2D( samp0, fragment.texcoord0 ).rgb * 2.0 - 1.0;\n"
|
||||
" n_C = normalize( n_C );\n"
|
||||
" //n_C = -n_C;\n"
|
||||
"#if 1\n"
|
||||
" vec3 n_C = texelFetch( samp0, int2( gl_FragCoord.xy ), 0 ).xyz * 2.0 - 1.0;\n"
|
||||
" //float3 n_C = tex2D( samp0, fragment.texcoord0 ).rgb * 2.0 - 1.0;\n"
|
||||
" \n"
|
||||
" if( length( n_C ) < 0.1 )\n"
|
||||
" {\n"
|
||||
|
@ -2376,6 +2363,9 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" return;\n"
|
||||
" }\n"
|
||||
" \n"
|
||||
" n_C = normalize( n_C );\n"
|
||||
" //n_C = -n_C;\n"
|
||||
" \n"
|
||||
"#else\n"
|
||||
" // Reconstruct normals from positions.\n"
|
||||
" float3 n_C = reconstructNonUnitCSFaceNormal( C );\n"
|
||||
|
@ -2451,12 +2441,6 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" //result.color = float4( n_C, 1.0 );\n"
|
||||
" //result.color = texture( samp0, fragment.texcoord0 ).rgba;\n"
|
||||
"#endif\n"
|
||||
" // derive clip space from the depth buffer and screen position\n"
|
||||
" // float windowZ = tex2D( samp1, fragment.texcoord0 ).x;\n"
|
||||
" // float3 ndc = float3( fragment.texcoord0 * 2.0 - 1.0, windowZ * 2.0 - 1.0 );\n"
|
||||
" // float clipW = -rpProjectionMatrixZ.w / ( -rpProjectionMatrixZ.z - ndc.z );\n"
|
||||
" \n"
|
||||
" // float4 clip = float4( ndc * clipW, clipW );\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
|
||||
|
@ -2609,7 +2593,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"//#endif\n"
|
||||
"\n"
|
||||
"/** (1, 0) or (0, 1)*/\n"
|
||||
"//uniform ivec2 axis;\n"
|
||||
"//uniform int2 axis;\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"#define aoResult result.color.VALUE_COMPONENTS\n"
|
||||
|
@ -2653,13 +2637,13 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"\n"
|
||||
"/** Used for preventing AO computation on the sky (at infinite depth) and defining the CS Z to bilateral depth key scaling.\n"
|
||||
" This need not match the real far plane but should not be much more than it.*/\n"
|
||||
"const float FAR_PLANE_Z = -4000.0;\n"
|
||||
"const float FAR_PLANE_Z = -16000.0;\n"
|
||||
"\n"
|
||||
"float3 positionFromKey( float key, ivec2 ssC )\n"
|
||||
"float3 positionFromKey( float key, int2 ssC )\n"
|
||||
"{\n"
|
||||
" float z = key * FAR_PLANE_Z;\n"
|
||||
" //float3 C = reconstructCSPosition( vec2( ssC )/* + vec2( 0.5 )*/, z, pInfo );\n"
|
||||
" float3 C = reconstructCSPosition( vec2( ssC ), z );\n"
|
||||
" //float3 C = reconstructCSPosition( float2( ssC )/* + float2( 0.5 )*/, z, pInfo );\n"
|
||||
" float3 C = reconstructCSPosition( float2( ssC ), z );\n"
|
||||
" return C;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
|
@ -2670,7 +2654,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"uniform float4 normal_readAddSecond;\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"float calculateBilateralWeight( float key, float tapKey, ivec2 tapLoc, float3 n_C, float3 C )\n"
|
||||
"float calculateBilateralWeight( float key, float tapKey, int2 tapLoc, float3 n_C, float3 C )\n"
|
||||
"{\n"
|
||||
" // range domain (the \"bilateral\" weight). As depth difference increases, decrease weight.\n"
|
||||
" float depthWeight = max( 0.0, 1.0 - ( EDGE_SHARPNESS * 2000.0 ) * abs( tapKey - key ) );\n"
|
||||
|
@ -2757,7 +2741,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"// # endif\n"
|
||||
"//# endif\n"
|
||||
"\n"
|
||||
" ivec2 ssC = ivec2( gl_FragCoord.xy );\n"
|
||||
" int2 ssC = int2( gl_FragCoord.xy );\n"
|
||||
" \n"
|
||||
" float4 temp = texelFetch( source, ssC, 0 );\n"
|
||||
" \n"
|
||||
|
@ -2805,7 +2789,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" // so the IF statement has no runtime cost\n"
|
||||
" if( r != 0 )\n"
|
||||
" {\n"
|
||||
" ivec2 tapLoc = ssC + ivec2( rpJitterTexScale.xy ) * ( r * SCALE );\n"
|
||||
" int2 tapLoc = ssC + int2( rpJitterTexScale.xy ) * ( r * SCALE );\n"
|
||||
" temp = texelFetch( source, tapLoc, 0 );\n"
|
||||
" float tapKey = unpackKey( temp.KEY_COMPONENTS );\n"
|
||||
" VALUE_TYPE value = temp.VALUE_COMPONENTS;\n"
|
||||
|
@ -2825,7 +2809,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" float lastBilateralWeight = 9999.0;\n"
|
||||
" for( int r = -1; r >= -R; --r )\n"
|
||||
" {\n"
|
||||
" ivec2 tapLoc = ssC + ivec2( rpJitterTexScale.xy ) * ( r * SCALE );\n"
|
||||
" int2 tapLoc = ssC + int2( rpJitterTexScale.xy ) * ( r * SCALE );\n"
|
||||
" temp = texelFetch( source, tapLoc, 0 );\n"
|
||||
" float tapKey = unpackKey( temp.KEY_COMPONENTS );\n"
|
||||
" VALUE_TYPE value = temp.VALUE_COMPONENTS;\n"
|
||||
|
@ -2845,7 +2829,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" lastBilateralWeight = 9999.0;\n"
|
||||
" for( int r = 1; r <= R; ++r )\n"
|
||||
" {\n"
|
||||
" ivec2 tapLoc = ssC + ivec2( rpJitterTexScale.xy ) * ( r * SCALE );\n"
|
||||
" int2 tapLoc = ssC + int2( rpJitterTexScale.xy ) * ( r * SCALE );\n"
|
||||
" temp = texelFetch( source, tapLoc, 0 );\n"
|
||||
" float tapKey = unpackKey( temp.KEY_COMPONENTS );\n"
|
||||
" VALUE_TYPE value = temp.VALUE_COMPONENTS;\n"
|
||||
|
@ -2926,6 +2910,143 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
|
||||
},
|
||||
|
||||
{
|
||||
"renderprogs/AmbientOcclusion_minify.pixel",
|
||||
"/**\n"
|
||||
" \file AmbientOcclusion_minify.pix\n"
|
||||
" \author Morgan McGuire and Michael Mara, NVIDIA Research\n"
|
||||
"\n"
|
||||
" Open Source under the \"BSD\" license: http://www.opensource.org/licenses/bsd-license.php\n"
|
||||
"\n"
|
||||
" Copyright (c) 2011-2012, NVIDIA\n"
|
||||
" Copyright (c) 2016 Robert Beckebans ( id Tech 4.x integration )\n"
|
||||
" All rights reserved.\n"
|
||||
"\n"
|
||||
" Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n"
|
||||
"\n"
|
||||
" Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n"
|
||||
" Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n"
|
||||
" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
|
||||
"\n"
|
||||
" */\n"
|
||||
"#include \"renderprogs/global.inc\"\n"
|
||||
"\n"
|
||||
"// *INDENT-OFF*\n"
|
||||
"uniform sampler2D samp0 : register( s0 ); // zbuffer\n"
|
||||
" \n"
|
||||
"struct PS_IN\n"
|
||||
"{\n"
|
||||
" float2 texcoord0 : TEXCOORD0_centroid;\n"
|
||||
"};\n"
|
||||
" \n"
|
||||
"struct PS_OUT \n"
|
||||
"{\n"
|
||||
" float4 color : COLOR;\n"
|
||||
"};\n"
|
||||
"// *INDENT-ON*\n"
|
||||
"\n"
|
||||
"//#extension GL_EXT_gpu_shader4 : enable\n"
|
||||
"\n"
|
||||
"//#expect USE_PEELED_DEPTH_BUFFER \"binary\"\n"
|
||||
"\n"
|
||||
"#if 0 //( USE_PEELED_DEPTH_BUFFER != 0 )\n"
|
||||
"#define mask rg\n"
|
||||
"#else\n"
|
||||
"#define mask r\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"float reconstructCSZ( float d )\n"
|
||||
"{\n"
|
||||
" //return clipInfo[0] / (clipInfo[1] * d + clipInfo[2]);\n"
|
||||
" \n"
|
||||
" // infinite far perspective matrix\n"
|
||||
" return 3.0 / ( -1.0 * d + 1.0 );\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"void main( PS_IN fragment, out PS_OUT result )\n"
|
||||
"{\n"
|
||||
"#if defined(BRIGHTPASS)\n"
|
||||
" float2 ssC = fragment.texcoord0;\n"
|
||||
" float depth = tex2D( samp0, ssC ).r;\n"
|
||||
" //depth = reconstructCSZ( depth );\n"
|
||||
" result.color.mask = depth;\n"
|
||||
"#else\n"
|
||||
" //int2 ssP = int2( gl_FragCoord.xy );\n"
|
||||
" int2 ssP = int2( fragment.texcoord0 * rpScreenCorrectionFactor.zw );\n"
|
||||
" \n"
|
||||
" int previousMIPNumber = int( rpJitterTexScale.x );\n"
|
||||
" \n"
|
||||
" // Rotated grid subsampling to avoid XY directional bias or Z precision bias while downsampling.\n"
|
||||
" // On DX9, the bit-and can be implemented with floating-point modulo\n"
|
||||
" //result.color.mask = texture( samp0, clamp( ssP * 2 + int2( ssP.y & 1, ssP.x & 1 ), int2( 0 ), textureSize( samp0, previousMIPNumber ) - int2( 1 ) ) * rpScreenCorrectionFactor.xy, previousMIPNumber ).mask;\n"
|
||||
" result.color.mask = texelFetch( samp0, clamp( ssP * 2 + int2( ssP.y & 1, ssP.x & 1 ), int2( 0 ), textureSize( samp0, previousMIPNumber ) - int2( 1 ) ), previousMIPNumber ).mask;\n"
|
||||
" //result.color.mask = texelFetch2D( samp0, int3( ssP * 2 + int2( ( ssP.y & 1 ) ^ 1, ( ssP.x & 1 ) ^ 1 ), 0 ) );\n"
|
||||
" \n"
|
||||
" // result.color.mask = texelFetch( samp0, ssP, 0 ).r;\n"
|
||||
" \n"
|
||||
" //float2 ssC = float2( ssP * 2 + int2( ( ssP.y & 1 ) ^ 1, ( ssP.x & 1 ) ^ 1 ) ) * rpScreenCorrectionFactor.xy;\n"
|
||||
" //float2 ssC = float2( ssP ) * rpScreenCorrectionFactor.xy;\n"
|
||||
" //float2 ssC = fragment.texcoord0;\n"
|
||||
" //float depth = tex2D( samp0, ssC ).r;\n"
|
||||
" //result.color.mask = depth;\n"
|
||||
"#endif\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
|
||||
},
|
||||
|
||||
{
|
||||
"renderprogs/AmbientOcclusion_minify.vertex",
|
||||
"/*\n"
|
||||
"===========================================================================\n"
|
||||
"\n"
|
||||
"Doom 3 BFG Edition GPL Source Code\n"
|
||||
"Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. \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\"\n"
|
||||
"\n"
|
||||
"struct VS_IN \n"
|
||||
"{\n"
|
||||
" float4 position : POSITION;\n"
|
||||
" float2 texcoord : TEXCOORD0;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct VS_OUT\n"
|
||||
"{\n"
|
||||
" float4 position : POSITION;\n"
|
||||
" float2 texcoord0 : TEXCOORD0;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void main( VS_IN vertex, out VS_OUT result )\n"
|
||||
"{\n"
|
||||
" result.position = vertex.position;\n"
|
||||
" result.texcoord0 = vertex.texcoord;\n"
|
||||
"}\n"
|
||||
|
||||
},
|
||||
|
||||
{
|
||||
"renderprogs/bink.pixel",
|
||||
"/*\n"
|
||||
|
@ -5764,7 +5885,7 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
" localNormal.z = sqrt( 1.0f - dot3( localNormal, localNormal ) );\n"
|
||||
"\n"
|
||||
" float3 globalNormal;\n"
|
||||
"#if 0\n"
|
||||
"#if 1\n"
|
||||
" globalNormal.x = dot3( localNormal, fragment.texcoord2 );\n"
|
||||
" globalNormal.y = dot3( localNormal, fragment.texcoord3 );\n"
|
||||
" globalNormal.z = dot3( localNormal, fragment.texcoord4 );\n"
|
||||
|
@ -10136,6 +10257,8 @@ static const cgShaderDef_t cg_renderprogs[] =
|
|||
"\n"
|
||||
"void main( PS_IN fragment, out PS_OUT result ) {\n"
|
||||
" result.color = tex2D( samp0, fragment.texcoord0 ) * rpColor;\n"
|
||||
" //result.color = textureLod( samp0, fragment.texcoord0, 2.0 ) * rpColor;\n"
|
||||
" //result.color = float4( 0.0, 1.0, 0.0, 1.0 ) * rpColor;\n"
|
||||
"}\n"
|
||||
|
||||
},
|
||||
|
|
|
@ -1752,9 +1752,13 @@ AMBIENT PASS RENDERING
|
|||
RB_AmbientPass
|
||||
==================
|
||||
*/
|
||||
static void RB_AmbientPass( const drawSurf_t* const* drawSurfs, int numDrawSurfs )
|
||||
static void RB_AmbientPass( const drawSurf_t* const* drawSurfs, int numDrawSurfs, bool fillGbuffer )
|
||||
{
|
||||
if( ( r_forceAmbient.GetFloat() <= 0 || r_skipAmbient.GetBool() ) && !r_useSSGI.GetBool() )
|
||||
if( fillGbuffer && !r_useSSGI.GetBool() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if( r_forceAmbient.GetFloat() <= 0 || r_skipAmbient.GetBool() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -1842,7 +1846,7 @@ static void RB_AmbientPass( const drawSurf_t* const* drawSurfs, int numDrawSurfs
|
|||
//else
|
||||
{
|
||||
#if 1
|
||||
if( r_useSSGI.GetBool() )
|
||||
if( r_useSSGI.GetBool() && fillGbuffer )
|
||||
{
|
||||
// fill geometry buffer with normal/roughness information
|
||||
if( drawSurf->jointCache )
|
||||
|
@ -2104,7 +2108,7 @@ static void RB_AmbientPass( const drawSurf_t* const* drawSurfs, int numDrawSurfs
|
|||
renderLog.CloseMainBlock();
|
||||
|
||||
#if 1
|
||||
if( r_useSSGI.GetBool() )
|
||||
if( r_useSSGI.GetBool() && fillGbuffer )
|
||||
{
|
||||
GL_SelectTexture( 0 );
|
||||
globalImages->currentNormalsImage->Bind();
|
||||
|
@ -4616,7 +4620,7 @@ void RB_SSAO()
|
|||
glClearColor( 0, 0, 0, 1 );
|
||||
|
||||
GL_SelectTexture( 0 );
|
||||
globalImages->currentDepthImage->Bind();
|
||||
//globalImages->currentDepthImage->Bind();
|
||||
|
||||
for( int i = 0; i < MAX_HIERARCHICAL_ZBUFFERS; i++ )
|
||||
{
|
||||
|
@ -4630,6 +4634,26 @@ void RB_SSAO()
|
|||
|
||||
glClear( GL_COLOR_BUFFER_BIT );
|
||||
|
||||
if( i == 0 )
|
||||
{
|
||||
renderProgManager.BindShader_AmbientOcclusionReconstructCSZ();
|
||||
|
||||
globalImages->currentDepthImage->Bind();
|
||||
}
|
||||
else
|
||||
{
|
||||
renderProgManager.BindShader_AmbientOcclusionMinify();
|
||||
|
||||
GL_SelectTexture( 0 );
|
||||
globalImages->hierarchicalZbufferImage->Bind();
|
||||
}
|
||||
|
||||
float jitterTexScale[4];
|
||||
jitterTexScale[0] = i - 1;
|
||||
jitterTexScale[1] = 0;
|
||||
jitterTexScale[2] = 0;
|
||||
jitterTexScale[3] = 0;
|
||||
SetFragmentParm( RENDERPARM_JITTERTEXSCALE, jitterTexScale ); // rpJitterTexScale
|
||||
#if 1
|
||||
float screenCorrectionParm[4];
|
||||
screenCorrectionParm[0] = 1.0f / width;
|
||||
|
@ -4908,10 +4932,17 @@ void RB_DrawViewInternal( const viewDef_t* viewDef, const int stereoEye )
|
|||
//-------------------------------------------------
|
||||
RB_FillDepthBufferFast( drawSurfs, numDrawSurfs );
|
||||
|
||||
//-------------------------------------------------
|
||||
// FIXME, OPTIMIZE: merge this with FillDepthBufferFast like in a light prepass deferred renderer
|
||||
//
|
||||
// fill the geometric buffer with normals and roughness
|
||||
//-------------------------------------------------
|
||||
RB_AmbientPass( drawSurfs, numDrawSurfs, true );
|
||||
|
||||
//-------------------------------------------------
|
||||
// fill the depth buffer and the color buffer with precomputed Q3A style lighting
|
||||
//-------------------------------------------------
|
||||
RB_AmbientPass( drawSurfs, numDrawSurfs );
|
||||
RB_AmbientPass( drawSurfs, numDrawSurfs, false );
|
||||
|
||||
//-------------------------------------------------
|
||||
// main light renderer
|
||||
|
|
Loading…
Reference in a new issue