Added HACK to look for PBR maps with the suffix _rmao

This commit is contained in:
Robert Beckebans 2020-04-13 17:31:07 +02:00
parent d03c4cc398
commit 56a2ec0dfc
8 changed files with 62 additions and 14 deletions

View file

@ -102,7 +102,7 @@ void main( PS_IN fragment, out PS_OUT result ) {
#if 1 //defined(USE_PBR)
#if 1 //defined(USE_METALNESS)
#if defined(USE_PBR)
const half metallic = specMapSRGB.g;
const half roughness = specMapSRGB.r;
const half glossiness = 1.0 - roughness;
@ -118,6 +118,9 @@ void main( PS_IN fragment, out PS_OUT result ) {
half3 diffuseColor = baseColor * ( 1.0 - metallic );
half3 specularColor = lerp( dielectricColor, baseColor, metallic );
diffuseColor = half3( 0.0, 0.0, 0.0 );
specularColor = half3( 0.0, 1.0, 0.0 );
#else
// HACK calculate roughness from D3 gloss maps
float Y = dot( LUMINANCE_SRGB.rgb, specMapSRGB.rgb );
@ -130,6 +133,8 @@ void main( PS_IN fragment, out PS_OUT result ) {
half3 diffuseColor = diffuseMap;
half3 specularColor = specMap.rgb;
diffuseColor = half3( 0.0, 0.0, 0.0 );
specularColor = half3( 1.0, 0.0, 0.0 );
#endif
float3 diffuseLight = ( texCUBE( samp7, globalNormal ).rgb ) * diffuseColor * ( rpDiffuseModifier.xyz ) * 3.5f;

View file

@ -632,7 +632,9 @@ IMAGEFILES
====================================================================
*/
void R_LoadImage( const char* name, byte** pic, int* width, int* height, ID_TIME_T* timestamp, bool makePowerOf2 );
// RB: added texture usage for PBR _rmao[d] HACK
void R_LoadImage( const char* name, byte** pic, int* width, int* height, ID_TIME_T* timestamp, bool makePowerOf2, textureUsage_t* usage );
// pic is in top to bottom raster format
bool R_LoadCubeImages( const char* cname, cubeFiles_t extensions, byte* pic[6], int* size, ID_TIME_T* timestamp );

View file

@ -654,7 +654,7 @@ void R_CombineCubeImages_f( const idCmdArgs& args )
sprintf( filename, "%s%i%04i.tga", baseName.c_str(), orderRemap[side], frameNum );
idLib::Printf( "reading %s\n", filename );
R_LoadImage( filename, &pics[side], &width, &height, NULL, true );
R_LoadImage( filename, &pics[side], &width, &height, NULL, true, NULL );
if( !pics[side] )
{

View file

@ -892,7 +892,7 @@ If pic is NULL, the image won't actually be loaded, it will just find the
timestamp.
=================
*/
void R_LoadImage( const char* cname, byte** pic, int* width, int* height, ID_TIME_T* timestamp, bool makePowerOf2 )
void R_LoadImage( const char* cname, byte** pic, int* width, int* height, ID_TIME_T* timestamp, bool makePowerOf2, textureUsage_t* usage )
{
idStr name = cname;
@ -925,9 +925,32 @@ void R_LoadImage( const char* cname, byte** pic, int* width, int* height, ID_TIM
name.ExtractFileExtension( ext );
idStr origName = name;
// RB begin
// RB begin
// PBR HACK - look for the same file name that provides a _rmao[d] suffix and prefer it
// if it is available, otherwise
bool pbrImageLookup = false;
if( usage && *usage == TD_SPECULAR )
{
name.StripFileExtension();
if( name.StripTrailingOnce( "_s" ) )
{
name += "_rmao";
}
ext = "png";
name.DefaultFileExtension( ".png" );
pbrImageLookup = true;
}
retry:
// try
if( !ext.IsEmpty() )
{
// try only the image with the specified extension: default .tga
int i;
for( i = 0; i < numImageLoaders; i++ )
{
@ -940,9 +963,9 @@ void R_LoadImage( const char* cname, byte** pic, int* width, int* height, ID_TIM
if( i < numImageLoaders )
{
if( pic && *pic == NULL )
if( ( pic && *pic == NULL ) || ( timestamp && *timestamp == FILE_NOT_FOUND_TIMESTAMP ) )
{
// image with the specified extension was not found so try all formats
// image with the specified extension was not found so try all extensions
for( i = 0; i < numImageLoaders; i++ )
{
name.SetFileExtension( imageLoaders[i].ext );
@ -950,14 +973,32 @@ void R_LoadImage( const char* cname, byte** pic, int* width, int* height, ID_TIM
if( pic && *pic != NULL )
{
//common->Warning("image %s failed to load, using %s instead", origName.c_str(), name.c_str());
//idLib::Warning( "image %s failed to load, using %s instead", origName.c_str(), name.c_str());
break;
}
}
}
}
if( pbrImageLookup )
{
if( ( pic && *pic == NULL ) || ( timestamp && *timestamp == FILE_NOT_FOUND_TIMESTAMP ) )
{
name = origName;
name.ExtractFileExtension( ext );
pbrImageLookup = false;
goto retry;
}
if( pic && *pic != NULL )
{
idLib::Printf( "PBR hack: using '%s' instead of '%s'", name.c_str(), origName.c_str() );
*usage = TD_SPECULAR_PBR_RMAO;
}
}
}
// RB end
// RB end
if( ( width && *width < 1 ) || ( height && *height < 1 ) )
{

View file

@ -683,7 +683,7 @@ static bool R_ParseImageProgram_r( idLexer& src, byte** pic, int* width, int* he
}
// load it as an image
R_LoadImage( token.c_str(), pic, width, height, &timestamp, true );
R_LoadImage( token.c_str(), pic, width, height, &timestamp, true, usage );
if( timestamp == -1 )
{

View file

@ -1495,7 +1495,7 @@ void R_MakeAmbientMap_f( const idCmdArgs& args )
common->Printf( "loading %s\n", fullname.c_str() );
const bool captureToImage = false;
common->UpdateScreen( captureToImage );
R_LoadImage( fullname, &buffers[i], &width, &height, NULL, true );
R_LoadImage( fullname, &buffers[i], &width, &height, NULL, true, NULL );
if( !buffers[i] )
{
common->Printf( "failed.\n" );
@ -1609,7 +1609,7 @@ void R_TransformCubemap( const char* orgDirection[6], const char* orgDir, const
common->Printf( "loading %s\n", fullname.c_str() );
const bool captureToImage = false;
common->UpdateScreen( captureToImage );
R_LoadImage( fullname, &buffers[i], &width, &height, NULL, true );
R_LoadImage( fullname, &buffers[i], &width, &height, NULL, true, NULL );
//check if the buffer is troublesome
if( !buffers[i] )

View file

@ -914,7 +914,7 @@ bool idSWF::LoadJSON( const char* filename )
byte* imageData = NULL;
int width, height;
ID_TIME_T timestamp;
R_LoadImage( imageName.c_str(), &imageData, &width, &height, &timestamp, false );
R_LoadImage( imageName.c_str(), &imageData, &width, &height, &timestamp, false, NULL );
if( imageData != NULL )
{
LoadImage( i, imageData, width, height );

View file

@ -1006,7 +1006,7 @@ void idGameBustOutWindow::LoadBoardFiles()
name += ( i + 1 );
name += ".tga";
R_LoadImage( name, &pic, &w, &h, &time, false );
R_LoadImage( name, &pic, &w, &h, &time, false, NULL );
if( pic != NULL )
{