From 0f8ee906da7999c0900d0796db3c5022244b6b2d Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Sat, 28 Mar 2020 17:56:12 +0100 Subject: [PATCH] Experimental changes to test PBR texture set --- base/renderprogs/ambient_lighting_IBL.ps.hlsl | 36 ++++++++++------ base/renderprogs/interaction.ps.hlsl | 4 +- base/renderprogs/interactionSM.ps.hlsl | 6 +-- neo/renderer/Image_load.cpp | 41 ++++++------------- 4 files changed, 40 insertions(+), 47 deletions(-) diff --git a/base/renderprogs/ambient_lighting_IBL.ps.hlsl b/base/renderprogs/ambient_lighting_IBL.ps.hlsl index ccd8a849..bb351bfd 100644 --- a/base/renderprogs/ambient_lighting_IBL.ps.hlsl +++ b/base/renderprogs/ambient_lighting_IBL.ps.hlsl @@ -3,7 +3,7 @@ Doom 3 BFG Edition GPL Source Code Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. -Copyright (C) 2013-2019 Robert Beckebans +Copyright (C) 2013-2020 Robert Beckebans This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). @@ -60,7 +60,8 @@ void main( PS_IN fragment, out PS_OUT result ) { // half4 lightFalloff = idtex2Dproj( samp1, fragment.texcoord2 ); // half4 lightProj = idtex2Dproj( samp2, fragment.texcoord3 ); half4 YCoCG = tex2D( samp2, fragment.texcoord1.xy ); - half4 specMap = tex2D( samp1, fragment.texcoord2.xy ); + half4 specMapSRGB = tex2D( samp1, fragment.texcoord2.xy ); + half4 specMap = sRGBAToLinearRGBA( specMapSRGB ); //half3 lightVector = normalize( fragment.texcoord0.xyz ); half3 diffuseMap = sRGBToLinearRGB( ConvertYCoCgToRGB( YCoCG ) ); @@ -99,10 +100,11 @@ void main( PS_IN fragment, out PS_OUT result ) { float3 reflectionVector = globalNormal * dot3( globalEye, globalNormal ); reflectionVector = ( reflectionVector * 2.0f ) - globalEye; -#if defined(USE_PBR) +#if 1 //defined(USE_PBR) - const half metallic = specMap.g; - const half roughness = specMap.r; +#if 1 //defined(USE_METALNESS) + const half metallic = specMapSRGB.g; + const half roughness = specMapSRGB.r; const half glossiness = 1.0 - roughness; // the vast majority of real-world materials (anything not metal or gems) have F(0°) @@ -116,11 +118,21 @@ void main( PS_IN fragment, out PS_OUT result ) { half3 diffuseColor = baseColor * ( 1.0 - metallic ); half3 specularColor = lerp( dielectricColor, baseColor, metallic ); +#else + // HACK calculate roughness from D3 gloss maps + float Y = dot( LUMINANCE_SRGB.rgb, specMapSRGB.rgb ); - //diffuseColor = half3( 1.0 ); - float3 diffuseLight = ( texCUBE( samp7, globalNormal ).rgb ) * diffuseColor * ( rpDiffuseModifier.xyz ) * 1.5f; + //const float glossiness = clamp( 1.0 - specMapSRGB.r, 0.0, 0.98 ); + const float glossiness = clamp( pow( Y, 1.0 / 2.0 ), 0.0, 0.98 ); - //specularColor = half3( 0.0 ); + const float roughness = 1.0 - glossiness; + + half3 diffuseColor = diffuseMap; + half3 specularColor = specMap.rgb; + +#endif + + float3 diffuseLight = ( texCUBE( samp7, globalNormal ).rgb ) * diffuseColor * ( rpDiffuseModifier.xyz ) * 3.5f; float mip = clamp( ( roughness * 7.0 ) + 3.0, 0.0, 10.0 ); float3 envColor = ( textureLod( samp8, reflectionVector, mip ).rgb ) * ( rpSpecularModifier.xyz ) * 1.0f; @@ -129,11 +141,9 @@ void main( PS_IN fragment, out PS_OUT result ) { #else - half4 specMapSRGB = specMap; - specMap = sRGBAToLinearRGBA( specMap ); - - //float3 diffuseLight = sRGBToLinearRGB( texCUBE( samp7, globalNormal ).rgb ) * diffuseMap.rgb * ( rpDiffuseModifier.xyz ) * 3.5f; - float3 diffuseLight = ( texCUBE( samp7, globalNormal ).rgb ) * diffuseMap.rgb * ( rpDiffuseModifier.xyz ) * 3.5f; + // non PBR path + + float3 diffuseLight = ( texCUBE( samp7, globalNormal ).rgb ) * diffuseMap.rgb * ( rpDiffuseModifier.xyz ) * 3.5f; //float3 diffuseLight = diffuseMap.rgb * ( rpDiffuseModifier.xyz ) * 1.5f; // HACK calculate roughness from D3 gloss maps diff --git a/base/renderprogs/interaction.ps.hlsl b/base/renderprogs/interaction.ps.hlsl index d38b12db..ca7fc348 100644 --- a/base/renderprogs/interaction.ps.hlsl +++ b/base/renderprogs/interaction.ps.hlsl @@ -98,7 +98,7 @@ void main( PS_IN fragment, out PS_OUT result ) #if 1 //defined(USE_PBR) -#if 0 //defined(USE_METALNESS) +#if 1 //defined(USE_METALNESS) const half metallic = specMapSRGB.g; const half roughness = specMapSRGB.r; const half glossiness = 1.0 - roughness; @@ -139,7 +139,7 @@ void main( PS_IN fragment, out PS_OUT result ) half ldotH = clamp( dot3( lightVector, halfAngleVector ), 0.0, 1.0 ); // compensate r_lightScale 3 * 2 - half3 reflectColor = specMap.rgb * rpSpecularModifier.rgb * 1.0;// * 0.5; + half3 reflectColor = specularColor * rpSpecularModifier.rgb * 1.0;// * 0.5; // cheap approximation by ARM with only one division // http://community.arm.com/servlet/JiveServlet/download/96891546-19496/siggraph2015-mmg-renaldas-slides.pdf diff --git a/base/renderprogs/interactionSM.ps.hlsl b/base/renderprogs/interactionSM.ps.hlsl index 8888ceac..b3b031a6 100644 --- a/base/renderprogs/interactionSM.ps.hlsl +++ b/base/renderprogs/interactionSM.ps.hlsl @@ -3,7 +3,7 @@ Doom 3 BFG Edition GPL Source Code Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. -Copyright (C) 2013-2014 Robert Beckebans +Copyright (C) 2013-2020 Robert Beckebans This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). @@ -280,7 +280,7 @@ void main( PS_IN fragment, out PS_OUT result ) #if 1 //defined(USE_PBR) -#if 0 //defined(USE_METALNESS) +#if 1 //defined(USE_METALNESS) const half metallic = specMapSRGB.g; const half roughness = specMapSRGB.r; const half glossiness = 1.0 - roughness; @@ -321,7 +321,7 @@ void main( PS_IN fragment, out PS_OUT result ) half ldotH = clamp( dot3( lightVector, halfAngleVector ), 0.0, 1.0 ); // compensate r_lightScale 3 * 2 - half3 reflectColor = specMap.rgb * rpSpecularModifier.rgb * 1.0;// * 0.5; + half3 reflectColor = specularColor * rpSpecularModifier.rgb * 1.0;// * 0.5; // cheap approximation by ARM with only one division // http://community.arm.com/servlet/JiveServlet/download/96891546-19496/siggraph2015-mmg-renaldas-slides.pdf diff --git a/neo/renderer/Image_load.cpp b/neo/renderer/Image_load.cpp index de9648a9..33dfd3c8 100644 --- a/neo/renderer/Image_load.cpp +++ b/neo/renderer/Image_load.cpp @@ -241,35 +241,6 @@ void idImage::AllocImage( const idImageOpts& imgOpts, textureFilter_t tf, textur } /* - - - // foresthale 2014-05-30: give a nice progress display when binarizing - commonLocal.LoadPacifierBinarizeFilename( GetName() , "generated image" ); - if( opts.numLevels > 1 ) - { - commonLocal.LoadPacifierBinarizeProgressTotal( opts.width * opts.height * 4 / 3 ); - } - else - { - commonLocal.LoadPacifierBinarizeProgressTotal( opts.width * opts.height ); - } - - commonLocal.LoadPacifierBinarizeEnd(); - - - // foresthale 2014-05-30: give a nice progress display when binarizing - commonLocal.LoadPacifierBinarizeFilename( GetName(), "generated cube image" ); - if( opts.numLevels > 1 ) - { - commonLocal.LoadPacifierBinarizeProgressTotal( opts.width * opts.width * 6 * 4 / 3 ); - } - else - { - commonLocal.LoadPacifierBinarizeProgressTotal( opts.width * opts.width * 6 ); - } - - commonLocal.LoadPacifierBinarizeEnd(); - =============== GetGeneratedName @@ -314,6 +285,12 @@ void idImage::ActuallyLoadImage( bool fromBackEnd ) return; } + // RB: the following does not load the source images from disk because pic is NULL + // but it tries to get the timestamp to see if we have a newer file than the one in the compressed .bimage + + // TODO also check for alternative names like .png suffices or _rmao.png or even _rmaod.png files + // to support the PBR code path + if( com_productionMode.GetInteger() != 0 ) { sourceFileTime = FILE_NOT_FOUND_TIMESTAMP; @@ -349,6 +326,7 @@ void idImage::ActuallyLoadImage( bool fromBackEnd ) idStrStatic< MAX_OSPATH > generatedName = GetName(); GetGeneratedName( generatedName, usage, cubeFiles ); + // RB: try to load the .bimage and skip if sourceFileTime is newer idBinaryImage im( generatedName ); binaryFileTime = im.LoadFromGeneratedFile( sourceFileTime ); @@ -417,6 +395,8 @@ void idImage::ActuallyLoadImage( bool fromBackEnd ) } else { + // RB: try to read the source image from disk + idStr binarizeReason = "binarize: unknown reason"; if( binaryFileTime == FILE_NOT_FOUND_TIMESTAMP ) { @@ -540,11 +520,14 @@ void idImage::ActuallyLoadImage( bool fromBackEnd ) commonLocal.LoadPacifierBinarizeProgressTotal( opts.width * opts.width * 6 ); } + // RB: convert to compressed DXT or whatever choosen target format im.Load2DFromMemory( opts.width, opts.height, pic, opts.numLevels, opts.format, opts.colorFormat, opts.gammaMips ); commonLocal.LoadPacifierBinarizeEnd(); Mem_Free( pic ); } + + // RB: write the compressed .bimage which contains the optimized GPU format binaryFileTime = im.WriteGeneratedFile( sourceFileTime ); }