mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-24 22:05:40 +00:00
Update GFXTextureManager and GBitmap
GBitmap Changes: Added all other formats to gbitmap that we support gbitmap now supports cubemaps added converters for all these other formats added stb_image_resize for extrudemips so we can extrude mipmaps for all other formats GFXTextureManager Can now directly make cubemaps and texture arrays based on the GFXTextureProfile API implementations for all functions that cubemaps and arrays needed
This commit is contained in:
parent
975fc924cc
commit
3aef90a6bc
66 changed files with 4235 additions and 2590 deletions
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
namespace IBLUtilities
|
||||
{
|
||||
void GenerateIrradianceMap(GFXTextureTargetRef renderTarget, GFXCubemapHandle cubemap, GFXCubemapHandle &cubemapOut)
|
||||
void GenerateIrradianceMap(GFXTextureTargetRef renderTarget, GFXTexHandle cubemap, GFXTexHandle &cubemapOut)
|
||||
{
|
||||
GFXTransformSaver saver;
|
||||
|
||||
|
|
@ -65,11 +65,11 @@ namespace IBLUtilities
|
|||
GFX->setShaderConstBuffer(irrConsts);
|
||||
GFX->setStateBlock(irrStateBlock);
|
||||
GFX->setVertexBuffer(NULL);
|
||||
GFX->setCubeTexture(0, cubemap);
|
||||
GFX->setTexture(0, cubemap);
|
||||
|
||||
for (U32 i = 0; i < 6; i++)
|
||||
{
|
||||
renderTarget->attachTexture(GFXTextureTarget::Color0, cubemapOut, i);
|
||||
renderTarget->attachTexture(GFXTextureTarget::Color0, cubemapOut, 0,0, i);
|
||||
irrConsts->setSafe(irrFaceSC, (S32)i);
|
||||
GFX->setActiveRenderTarget(renderTarget);
|
||||
GFX->clear(GFXClearTarget, LinearColorF::BLACK, 1.0f, 0);
|
||||
|
|
@ -80,7 +80,7 @@ namespace IBLUtilities
|
|||
GFX->popActiveRenderTarget();
|
||||
}
|
||||
|
||||
void GenerateAndSaveIrradianceMap(String outputPath, S32 resolution, GFXCubemapHandle cubemap, GFXCubemapHandle &cubemapOut)
|
||||
void GenerateAndSaveIrradianceMap(String outputPath, S32 resolution, GFXTexHandle cubemap, GFXTexHandle &cubemapOut)
|
||||
{
|
||||
if (outputPath.isEmpty())
|
||||
{
|
||||
|
|
@ -101,7 +101,7 @@ namespace IBLUtilities
|
|||
}
|
||||
}
|
||||
|
||||
void SaveCubeMap(String outputPath, GFXCubemapHandle &cubemap)
|
||||
void SaveCubeMap(String outputPath, GFXTexHandle &cubemap)
|
||||
{
|
||||
if (outputPath.isEmpty())
|
||||
{
|
||||
|
|
@ -118,7 +118,7 @@ namespace IBLUtilities
|
|||
}
|
||||
}
|
||||
|
||||
void GeneratePrefilterMap(GFXTextureTargetRef renderTarget, GFXCubemapHandle cubemap, U32 mipLevels, GFXCubemapHandle &cubemapOut)
|
||||
void GeneratePrefilterMap(GFXTextureTargetRef renderTarget, GFXTexHandle cubemap, U32 mipLevels, GFXTexHandle &cubemapOut)
|
||||
{
|
||||
GFXTransformSaver saver;
|
||||
|
||||
|
|
@ -153,9 +153,9 @@ namespace IBLUtilities
|
|||
GFX->pushActiveRenderTarget();
|
||||
GFX->setShader(prefilterShader);
|
||||
GFX->setShaderConstBuffer(prefilterConsts);
|
||||
GFX->setCubeTexture(0, cubemap);
|
||||
GFX->setTexture(0, cubemap);
|
||||
|
||||
U32 prefilterSize = cubemapOut->getSize();
|
||||
U32 prefilterSize = cubemapOut->getWidth();
|
||||
|
||||
U32 resolutionSize = prefilterSize;
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ namespace IBLUtilities
|
|||
prefilterConsts->setSafe(prefilterRoughnessSC, roughness);
|
||||
prefilterConsts->setSafe(prefilterMipSizeSC, mipSize);
|
||||
U32 size = prefilterSize * mPow(0.5f, mip);
|
||||
renderTarget->attachTexture(GFXTextureTarget::Color0, cubemapOut, face);
|
||||
renderTarget->attachTexture(GFXTextureTarget::Color0, cubemapOut, 0,0 ,face);
|
||||
GFX->setActiveRenderTarget(renderTarget, false);//we set the viewport ourselves
|
||||
GFX->setViewport(RectI(0, 0, size, size));
|
||||
GFX->clear(GFXClearTarget, LinearColorF::BLACK, 1.0f, 0);
|
||||
|
|
@ -183,7 +183,7 @@ namespace IBLUtilities
|
|||
GFX->popActiveRenderTarget();
|
||||
}
|
||||
|
||||
void GenerateAndSavePrefilterMap(String outputPath, S32 resolution, GFXCubemapHandle cubemap, U32 mipLevels, GFXCubemapHandle &cubemapOut)
|
||||
void GenerateAndSavePrefilterMap(String outputPath, S32 resolution, GFXTexHandle cubemap, U32 mipLevels, GFXTexHandle &cubemapOut)
|
||||
{
|
||||
if (outputPath.isEmpty())
|
||||
{
|
||||
|
|
@ -504,7 +504,7 @@ namespace IBLUtilities
|
|||
//SH Calculations
|
||||
// From http://sunandblackcat.com/tipFullView.php?l=eng&topicid=32&topic=Spherical-Harmonics-From-Cube-Texture
|
||||
// With shader decode logic from https://github.com/nicknikolov/cubemap-sh
|
||||
void calculateSHTerms(GFXCubemapHandle cubemap, LinearColorF SHTerms[9], F32 SHConstants[5])
|
||||
void calculateSHTerms(GFXTexHandle cubemap, LinearColorF SHTerms[9], F32 SHConstants[5])
|
||||
{
|
||||
if (!cubemap)
|
||||
return;
|
||||
|
|
@ -525,7 +525,7 @@ namespace IBLUtilities
|
|||
VectorF(0.0f, 0.0f, -1.0f),
|
||||
};
|
||||
|
||||
U32 cubemapResolution = cubemap->getSize();
|
||||
U32 cubemapResolution = cubemap->getWidth();
|
||||
|
||||
GBitmap* cubeFaceBitmaps[6];
|
||||
|
||||
|
|
|
|||
|
|
@ -38,13 +38,13 @@
|
|||
|
||||
namespace IBLUtilities
|
||||
{
|
||||
void GenerateIrradianceMap(GFXTextureTargetRef renderTarget, GFXCubemapHandle cubemap, GFXCubemapHandle &cubemapOut);
|
||||
void GenerateAndSaveIrradianceMap(String outputPath, S32 resolution, GFXCubemapHandle cubemap, GFXCubemapHandle &cubemapOut);
|
||||
void GenerateIrradianceMap(GFXTextureTargetRef renderTarget, GFXTexHandle cubemap, GFXTexHandle& cubemapOut);
|
||||
void GenerateAndSaveIrradianceMap(String outputPath, S32 resolution, GFXTexHandle cubemap, GFXTexHandle& cubemapOut);
|
||||
|
||||
void GeneratePrefilterMap(GFXTextureTargetRef renderTarget, GFXCubemapHandle cubemap, U32 mipLevels, GFXCubemapHandle &cubemapOut);
|
||||
void GenerateAndSavePrefilterMap(String outputPath, S32 resolution, GFXCubemapHandle cubemap, U32 mipLevels, GFXCubemapHandle &cubemapOut);
|
||||
void GeneratePrefilterMap(GFXTextureTargetRef renderTarget, GFXTexHandle cubemap, U32 mipLevels, GFXTexHandle &cubemapOut);
|
||||
void GenerateAndSavePrefilterMap(String outputPath, S32 resolution, GFXTexHandle cubemap, U32 mipLevels, GFXTexHandle &cubemapOut);
|
||||
|
||||
void SaveCubeMap(String outputPath, GFXCubemapHandle &cubemap);
|
||||
void SaveCubeMap(String outputPath, GFXTexHandle &cubemap);
|
||||
|
||||
void bakeReflection(String outputPath, S32 resolution);
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ namespace IBLUtilities
|
|||
//SH Calculations
|
||||
// From http://sunandblackcat.com/tipFullView.php?l=eng&topicid=32&topic=Spherical-Harmonics-From-Cube-Texture
|
||||
// With shader decode logic from https://github.com/nicknikolov/cubemap-sh
|
||||
void calculateSHTerms(GFXCubemapHandle cubemap, LinearColorF SHTerms[9], F32 SHConstants[5]);
|
||||
void calculateSHTerms(GFXTexHandle cubemap, LinearColorF SHTerms[9], F32 SHConstants[5]);
|
||||
|
||||
F32 texelSolidAngle(F32 aU, F32 aV, U32 width, U32 height);
|
||||
|
||||
|
|
|
|||
|
|
@ -86,6 +86,13 @@ ImplementEnumType(ReflectionModeEnum,
|
|||
//{ ReflectionProbe::DynamicCubemap, "Dynamic Cubemap", "Uses a cubemap baked from the probe's current position, updated at a set rate" },
|
||||
EndImplementEnumType;
|
||||
|
||||
void ReflectionProbe::ProbeInfo::clear()
|
||||
{
|
||||
mPrefilterCubemap.free();
|
||||
mIrradianceCubemap.free();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Object setup and teardown
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -146,11 +153,18 @@ ReflectionProbe::~ReflectionProbe()
|
|||
if (mReflectionModeType == StaticCubemap && mStaticCubemap)
|
||||
mStaticCubemap->deleteObject();
|
||||
|
||||
if (mIrridianceMap)
|
||||
mIrridianceMap->deleteObject();
|
||||
mProbeInfo.clear();
|
||||
|
||||
if (mIrridianceMap) {
|
||||
if (mIrridianceMap->isProperlyAdded() && !mIrridianceMap->isRemoved())
|
||||
mIrridianceMap->deleteObject();
|
||||
}
|
||||
|
||||
if (mPrefilterMap)
|
||||
mPrefilterMap->deleteObject();
|
||||
{
|
||||
if (mPrefilterMap->isProperlyAdded() && !mPrefilterMap->isRemoved())
|
||||
mPrefilterMap->deleteObject();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -603,7 +617,7 @@ void ReflectionProbe::processBakedCubemap()
|
|||
return;
|
||||
|
||||
String irrPath = getIrradianceMapPath();
|
||||
if (Platform::isFile(irrPath))
|
||||
if ((mIrridianceMap == nullptr || mIrridianceMap->mCubemap.isNull()) && Platform::isFile(irrPath))
|
||||
{
|
||||
mIrridianceMap->setCubemapFile(FileName(irrPath));
|
||||
mIrridianceMap->updateFaces();
|
||||
|
|
@ -616,7 +630,7 @@ void ReflectionProbe::processBakedCubemap()
|
|||
}
|
||||
|
||||
String prefilPath = getPrefilterMapPath();
|
||||
if (Platform::isFile(prefilPath))
|
||||
if ((mPrefilterMap == nullptr || mPrefilterMap->mCubemap.isNull()) && Platform::isFile(prefilPath))
|
||||
{
|
||||
mPrefilterMap->setCubemapFile(FileName(prefilPath));
|
||||
mPrefilterMap->updateFaces();
|
||||
|
|
@ -631,7 +645,7 @@ void ReflectionProbe::processBakedCubemap()
|
|||
mProbeInfo.mPrefilterCubemap = mPrefilterMap->mCubemap;
|
||||
mProbeInfo.mIrradianceCubemap = mIrridianceMap->mCubemap;
|
||||
|
||||
if (mEnabled && mProbeInfo.mPrefilterCubemap->isInitialized() && mProbeInfo.mIrradianceCubemap->isInitialized())
|
||||
if (mEnabled && !mProbeInfo.mPrefilterCubemap.isNull() && !mProbeInfo.mIrradianceCubemap.isNull())
|
||||
{
|
||||
//mProbeInfo.mIsEnabled = true;
|
||||
|
||||
|
|
@ -698,7 +712,7 @@ void ReflectionProbe::processStaticCubemap()
|
|||
return;
|
||||
}
|
||||
|
||||
if (mStaticCubemap->mCubemap == nullptr)
|
||||
if (mStaticCubemap->mCubemap.isNull())
|
||||
{
|
||||
mStaticCubemap->createMap();
|
||||
mStaticCubemap->updateFaces();
|
||||
|
|
@ -706,13 +720,13 @@ void ReflectionProbe::processStaticCubemap()
|
|||
|
||||
if (mUseHDRCaptures)
|
||||
{
|
||||
mIrridianceMap->mCubemap->initDynamic(mPrefilterSize, GFXFormatR16G16B16A16F);
|
||||
mPrefilterMap->mCubemap->initDynamic(mPrefilterSize, GFXFormatR16G16B16A16F);
|
||||
mIrridianceMap->mCubemap.set(mPrefilterSize, mPrefilterSize, GFXFormatR16G16B16A16F, &GFXCubemapRenderTargetProfile, "ReflectionProbe::mIrridianceMap_HDR");
|
||||
mPrefilterMap->mCubemap.set(mPrefilterSize, mPrefilterSize, GFXFormatR16G16B16A16F, &GFXCubemapRenderTargetProfile, "ReflectionProbe::mPrefilterMap_HDR");
|
||||
}
|
||||
else
|
||||
{
|
||||
mIrridianceMap->mCubemap->initDynamic(mPrefilterSize, GFXFormatR8G8B8A8);
|
||||
mPrefilterMap->mCubemap->initDynamic(mPrefilterSize, GFXFormatR8G8B8A8);
|
||||
mIrridianceMap->mCubemap.set(mPrefilterSize, mPrefilterSize, GFXFormatR8G8B8A8, &GFXCubemapRenderTargetProfile, "ReflectionProbe::mIrridianceMap");
|
||||
mPrefilterMap->mCubemap.set(mPrefilterSize, mPrefilterSize, GFXFormatR8G8B8A8, &GFXCubemapRenderTargetProfile, "ReflectionProbe::mPrefilterMap");
|
||||
}
|
||||
|
||||
GFXTextureTargetRef renderTarget = GFX->allocRenderToTextureTarget(false);
|
||||
|
|
@ -730,7 +744,7 @@ void ReflectionProbe::processStaticCubemap()
|
|||
mProbeInfo.mIrradianceCubemap = mIrridianceMap->mCubemap;
|
||||
}
|
||||
|
||||
if (mEnabled && mProbeInfo.mPrefilterCubemap->isInitialized() && mProbeInfo.mIrradianceCubemap->isInitialized())
|
||||
if (mEnabled && mProbeInfo.mPrefilterCubemap.isValid() && mProbeInfo.mIrradianceCubemap.isValid())
|
||||
{
|
||||
mProbeInfo.mIsEnabled = true;
|
||||
|
||||
|
|
@ -1009,7 +1023,7 @@ void ReflectionProbe::setPreviewMatParameters(SceneRenderState* renderState, Bas
|
|||
GFX->setTexture(0, deferredTexObject);
|
||||
|
||||
//Set the cubemap
|
||||
GFX->setCubeTexture(1, mPrefilterMap->mCubemap);
|
||||
GFX->setTexture(1, mPrefilterMap->mCubemap);
|
||||
|
||||
//Set the invViewMat
|
||||
MatrixSet &matrixSet = renderState->getRenderPass()->getMatrixSet();
|
||||
|
|
@ -1036,3 +1050,4 @@ DefineEngineMethod(ReflectionProbe, Bake, void, (), ,
|
|||
clientProbe->bake();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -94,8 +94,8 @@ public:
|
|||
|
||||
F32 mScore;
|
||||
|
||||
GFXCubemapHandle mPrefilterCubemap;
|
||||
GFXCubemapHandle mIrradianceCubemap;
|
||||
GFXTexHandle mPrefilterCubemap;
|
||||
GFXTexHandle mIrradianceCubemap;
|
||||
|
||||
/// The priority of this light used for
|
||||
/// light and shadow scoring.
|
||||
|
|
@ -233,7 +233,7 @@ protected:
|
|||
/// </summary>
|
||||
StringTableEntry mCubemapName;
|
||||
CubemapData *mStaticCubemap;
|
||||
GFXCubemapHandle mDynamicCubemap;
|
||||
GFXTexHandle mDynamicCubemap;
|
||||
|
||||
//String cubeDescName;
|
||||
//U32 cubeDescId;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue