Browse Source

materialsystem: fix s_NormalizationCubemap generation for ToGL

sanitize 1.12
nillerusr 3 years ago
parent
commit
432a6b2297
  1. 3
      engine/vprof_engine.cpp
  2. 12
      materialsystem/stdshaders/flashlight_ps2x.fxc
  3. 48
      materialsystem/texturemanager.cpp

3
engine/vprof_engine.cpp

@ -1117,8 +1117,6 @@ void WriteRemoteVProfGroupData( VProfListenInfo_t &info ) @@ -1117,8 +1117,6 @@ void WriteRemoteVProfGroupData( VProfListenInfo_t &info )
const char *pName = g_pVProfileForDisplay->GetBudgetGroupName( nIndex );
buf.PutString( pName );
}
g_ServerRemoteAccess.SendVProfData( info.m_nListenerId, true, buf.Base(), buf.TellMaxPut() );
}
static ConVar rpt_vprof_time( "rpt_vprof_time","0.25", FCVAR_HIDDEN | FCVAR_DONTRECORD, "" );
@ -1167,7 +1165,6 @@ void WriteRemoteVProfData() @@ -1167,7 +1165,6 @@ void WriteRemoteVProfData()
Assert( nIndex >= 0 );
pSentTimes[ nIndex ] = pTimes[j];
}
g_ServerRemoteAccess.SendVProfData( s_VProfListeners[i].m_nListenerId, false, pSentTimes, nSentSize );
}
}

12
materialsystem/stdshaders/flashlight_ps2x.fxc

@ -201,16 +201,22 @@ float4 main( PS_INPUT i ) : COLOR @@ -201,16 +201,22 @@ float4 main( PS_INPUT i ) : COLOR
#if NORMALMAP == 0
float3 worldPosToLightVector = texCUBE( NormalizingCubemapSampler, i.worldPosToLightVector ) * 2.0f - 1.0f;
float nDotL = 0.577350f;
float nDotL = dot( worldPosToLightVector, vNormal.xyz );
#endif
#if NORMALMAP == 1
// flashlightfixme: wrap this!
float nDotL = 0.577350f;
float3 tangentPosToLightVector = texCUBE( NormalizingCubemapSampler, i.tangentPosToLightVector ) * 2.0f - 1.0f;
float nDotL = dot( tangentPosToLightVector, vNormal.xyz );
#endif
#if NORMALMAP == 2
float nDotL = 0.577350f;
float3 tangentPosToLightVector = normalize( i.tangentPosToLightVector );
float nDotL =
vNormal.x*dot( tangentPosToLightVector, bumpBasis[0]) +
vNormal.y*dot( tangentPosToLightVector, bumpBasis[1]) +
vNormal.z*dot( tangentPosToLightVector, bumpBasis[2]);
#endif
float3 outColor;

48
materialsystem/texturemanager.cpp

@ -250,9 +250,6 @@ static void CreateSolidTexture( ITextureInternal *pTexture, color32 color ) @@ -250,9 +250,6 @@ static void CreateSolidTexture( ITextureInternal *pTexture, color32 color )
class CNormalizationCubemap : public ITextureRegenerator
{
public:
// TODO(nillerusr): broken here with togl /= (maybe here)
virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pSubRect )
{
// Normalization cubemap doesn't make sense on low-end hardware
@ -280,7 +277,39 @@ public: @@ -280,7 +277,39 @@ public:
{
float u = x * flInvWidth - 1.0f;
float oow = 1.0f / sqrt( 1.0f + u*u + v*v );
#ifdef DX_TO_GL_ABSTRACTION
float flX = (255.0f * 0.5 * (u*oow + 1.0f) + 0.5f);
float flY = (255.0f * 0.5 * (v*oow + 1.0f) + 0.5f);
float flZ = (255.0f * 0.5 * (oow + 1.0f) + 0.5f);
flX /= 256.0f;
flY /= 256.0f;
flZ /= 256.0f;
switch (iFace)
{
case CUBEMAP_FACE_RIGHT:
pixelWriter.WritePixelF( flZ, 1.f - flY, 1.f - flX, 1.f );
break;
case CUBEMAP_FACE_LEFT:
pixelWriter.WritePixelF( 1.f - flZ, 1.f - flY, flX, 1.f );
break;
case CUBEMAP_FACE_BACK:
pixelWriter.WritePixelF( flX, flZ, flY, 1.f );
break;
case CUBEMAP_FACE_FRONT:
pixelWriter.WritePixelF( flX, 1.f - flZ, 1.f - flY, 1.f );
break;
case CUBEMAP_FACE_UP:
pixelWriter.WritePixelF( flX, 1.f - flY, flZ, 1.f );
break;
case CUBEMAP_FACE_DOWN:
pixelWriter.WritePixelF( 1.f - flX, 1.f - flY, 1.f - flZ, 1.f );
break;
default:
break;
}
#else
int ix = (int)(255.0f * 0.5f * (u*oow + 1.0f) + 0.5f);
ix = clamp( ix, 0, 255 );
int iy = (int)(255.0f * 0.5f * (v*oow + 1.0f) + 0.5f);
@ -311,6 +340,7 @@ public: @@ -311,6 +340,7 @@ public:
default:
break;
}
#endif
}
}
}
@ -1501,13 +1531,16 @@ void CTextureManager::Init( int nFlags ) @@ -1501,13 +1531,16 @@ void CTextureManager::Init( int nFlags )
color.a = 0;
CreateSolidTexture( m_pGreyAlphaZeroTexture, color );
int nTextureFlags = TEXTUREFLAGS_ENVMAP | TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_NOLOD | TEXTUREFLAGS_SINGLECOPY | TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT | TEXTUREFLAGS_CLAMPU;
if ( HardwareConfig()->GetMaxDXSupportLevel() >= 80 )
{
ImageFormat fmt = IsOpenGL() ? IMAGE_FORMAT_RGBA16161616F : IMAGE_FORMAT_BGRX8888;
// Create a normalization cubemap
m_pNormalizationCubemap = CreateProceduralTexture( "normalize", TEXTURE_GROUP_CUBE_MAP,
NORMALIZATION_CUBEMAP_SIZE, NORMALIZATION_CUBEMAP_SIZE, 1, IMAGE_FORMAT_BGRX8888,
TEXTUREFLAGS_ENVMAP | TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_SINGLECOPY |
TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT | TEXTUREFLAGS_CLAMPU );
NORMALIZATION_CUBEMAP_SIZE, NORMALIZATION_CUBEMAP_SIZE, 1, fmt,
nTextureFlags );
CreateNormalizationCubemap( m_pNormalizationCubemap );
}
@ -1516,7 +1549,6 @@ void CTextureManager::Init( int nFlags ) @@ -1516,7 +1549,6 @@ void CTextureManager::Init( int nFlags )
// In GL, we have poor format support, so we ask for signed float
ImageFormat fmt = IsOpenGL() ? IMAGE_FORMAT_RGBA16161616F : IMAGE_FORMAT_UVWQ8888;
int nTextureFlags = TEXTUREFLAGS_ENVMAP | TEXTUREFLAGS_NOMIP | TEXTUREFLAGS_NOLOD | TEXTUREFLAGS_SINGLECOPY | TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT | TEXTUREFLAGS_CLAMPU;
#ifdef OSX
// JasonM - ridiculous hack around R500 lameness...we never use this texture on OSX anyways (right?)
@ -1528,7 +1560,7 @@ void CTextureManager::Init( int nFlags ) @@ -1528,7 +1560,7 @@ void CTextureManager::Init( int nFlags )
m_pSignedNormalizationCubemap = CreateProceduralTexture( "normalizesigned", TEXTURE_GROUP_CUBE_MAP,
NORMALIZATION_CUBEMAP_SIZE, NORMALIZATION_CUBEMAP_SIZE, 1, fmt, nTextureFlags );
CreateSignedNormalizationCubemap( m_pSignedNormalizationCubemap );
m_pIdentityLightWarp = FindOrLoadTexture( "dev/IdentityLightWarp", TEXTURE_GROUP_OTHER );
m_pIdentityLightWarp->IncrementReferenceCount();
}

Loading…
Cancel
Save