timmy merge work

This commit is contained in:
Tim Barnes 2018-11-28 17:51:52 +10:00
parent 5fa2c5b4a6
commit 15aeba20e7
29 changed files with 295 additions and 925 deletions

View file

@ -1,3 +1,26 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "T3D/lighting/IBLUtilities.h"
#include "console/engineAPI.h"
#include "materials/shaderData.h"
#include "gfx/gfxTextureManager.h"
@ -167,62 +190,7 @@ namespace IBLUtilities
{
Con::errorf("IBLUtilities::GenerateAndSavePrefilterMap - Failed to properly save out the baked irradiance!");
}
}
void GenerateBRDFTexture(GFXTexHandle &textureOut)
{
GFXTransformSaver saver;
ShaderData *brdfShaderData;
GFXShaderRef brdfShader = Sim::findObject("BRDFLookupShader", brdfShaderData) ? brdfShaderData->getShader() : NULL;
if (!brdfShader)
{
Con::errorf("IBLUtilities::GenerateBRDFTexture() - could not find BRDFLookupShader");
return;
}
U32 textureSize = textureOut->getWidth();
GFXTextureTargetRef renderTarget = GFX->allocRenderToTextureTarget();
GFX->pushActiveRenderTarget();
GFX->setShader(brdfShader);
renderTarget->attachTexture(GFXTextureTarget::Color0, textureOut);
GFX->setActiveRenderTarget(renderTarget);//potential bug here with the viewport not updating with the new size
GFX->setViewport(RectI(0, 0, textureSize, textureSize));//see above comment
GFX->clear(GFXClearTarget, LinearColorF::BLUE, 1.0f, 0);
GFX->drawPrimitive(GFXTriangleList, 0, 3);
renderTarget->resolve();
GFX->popActiveRenderTarget();
}
GFXTexHandle GenerateAndSaveBRDFTexture(String outputPath, S32 resolution)
{
GFXTexHandle brdfTexture = TEXMGR->createTexture(resolution, resolution, GFXFormatR8G8B8A8, &GFXRenderTargetProfile, 1, 0);
GenerateBRDFTexture(brdfTexture);
FileStream fs;
if (fs.open(outputPath, Torque::FS::File::Write))
{
// Read back the render target, dxt compress it, and write it to disk.
GBitmap brdfBmp(brdfTexture.getHeight(), brdfTexture.getWidth(), false, GFXFormatR8G8B8A8);
brdfTexture.copyToBmp(&brdfBmp);
brdfBmp.extrudeMipLevels();
DDSFile *brdfDDS = DDSFile::createDDSFileFromGBitmap(&brdfBmp);
ImageUtil::ddsCompress(brdfDDS, GFXFormatBC1);
// Write result to file stream
brdfDDS->write(fs);
delete brdfDDS;
}
fs.close();
return brdfTexture;
}
}
void bakeReflection(String outputPath, S32 resolution)
{
@ -662,9 +630,3 @@ namespace IBLUtilities
return angle;
}
};
DefineEngineFunction(GenerateBRDFTexture, bool, (String outputPath, S32 resolution), ("", 256),
"@brief returns true if control object is inside the fog\n\n.")
{
return IBLUtilities::GenerateAndSaveBRDFTexture(outputPath, resolution);
}

View file

@ -1,4 +1,40 @@
#pragma once
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef IBL_UTILS_H_
#define IBL_UTILS_H_
#ifndef _GFXTARGET_H_
#include "gfx/gfxTarget.h"
#endif
#ifndef _GFXCUBEMAP_H_
#include "gfx/gfxCubemap.h"
#endif
#ifndef _COLOR_H_
#include "core/color.h"
#endif
namespace IBLUtilities
{
@ -10,9 +46,6 @@ namespace IBLUtilities
void SaveCubeMap(String outputPath, GFXCubemapHandle &cubemap);
GFXTexHandle GenerateAndSaveBRDFTexture(String outputPath, S32 resolution);
void GenerateBRDFTexture(GFXTexHandle &textureOut);
void bakeReflection(String outputPath, S32 resolution);
LinearColorF decodeSH(Point3F normal, const LinearColorF SHTerms[9], const F32 SHConstants[5]);
@ -32,4 +65,6 @@ namespace IBLUtilities
F32 texelSolidAngle(F32 aU, F32 aV, U32 width, U32 height);
F32 areaElement(F32 x, F32 y);
};
};
#endif

View file

@ -36,7 +36,6 @@
#include "core/fileObject.h"
#include "core/resourceManager.h"
#include "console/simPersistId.h"
#include <string>
#include "T3D/gameFunctions.h"
#include "postFx/postEffect.h"
#include "renderInstance/renderProbeMgr.h"
@ -620,16 +619,13 @@ bool ReflectionProbe::createClientResources()
Con::errorf("ReflectionProbe::createClientResources() - Unable to load baked prefilter map at %s", getPrefilterMapPath().c_str());
}
//brdf lookup resources
//make the brdf lookup texture the same size as the prefilter texture
//brdf lookup texture
String brdfPath = Con::getVariable("$Core::BRDFTexture", "core/art/pbr/brdfTexture.dds");
mBrdfTexture = TEXMGR->createTexture(brdfPath, &GFXTexturePersistentProfile);
if (!mBrdfTexture)
{
mBrdfTexture = IBLUtilities::GenerateAndSaveBRDFTexture(brdfPath, 512);
return false;
}
mResourcesCreated = true;
@ -652,8 +648,8 @@ void ReflectionProbe::prepRenderImage(SceneRenderState *state)
//Culling distance. Can be adjusted for performance options considerations via the scalar
if (dist > mMaxDrawDistance * Con::getFloatVariable("$pref::GI::ProbeDrawDistScale", 1.0))
{
mProbeInfo->mScore = mMaxDrawDistance;
return;
mProbeInfo->mScore = mMaxDrawDistance;
return;
}
if (mReflectionModeType == DynamicCubemap && mRefreshRateMS < (Platform::getRealMilliseconds() - mDynamicLastBakeMS))
@ -685,7 +681,7 @@ void ReflectionProbe::prepRenderImage(SceneRenderState *state)
Point3F cameraOffset;
getRenderTransform().getColumn(3, &cameraOffset);
cameraOffset -= state->getDiffuseCameraPosition();
F32 dist = cameraOffset.len();
dist = cameraOffset.len();
if (dist < 0.01f)
dist = 0.01f;
@ -832,7 +828,7 @@ String ReflectionProbe::getPrefilterMapPath()
}
char fileName[256];
dSprintf(fileName, 256, "%s%s_Prefilter.DDS", mReflectionPath.c_str(), mProbeUniqueID.c_str());
dSprintf(fileName, 256, "%s%s_Prefilter.dds", mReflectionPath.c_str(), mProbeUniqueID.c_str());
return fileName;
}
@ -846,7 +842,7 @@ String ReflectionProbe::getIrradianceMapPath()
}
char fileName[256];
dSprintf(fileName, 256, "%s%s_Irradiance.DDS", mReflectionPath.c_str(), mProbeUniqueID.c_str());
dSprintf(fileName, 256, "%s%s_Irradiance.dds", mReflectionPath.c_str(), mProbeUniqueID.c_str());
return fileName;
}

View file

@ -36,7 +36,6 @@
#include "core/fileObject.h"
#include "core/resourceManager.h"
#include "console/simPersistId.h"
#include <string>
#include "T3D/gameFunctions.h"
#include "postFx/postEffect.h"
#include "renderInstance/renderProbeMgr.h"
@ -183,9 +182,6 @@ void Skylight::prepRenderImage(SceneRenderState *state)
if (!mEnabled || !Skylight::smRenderSkylights)
return;
Point3F distVec = getPosition() - state->getCameraPosition();
F32 dist = distVec.len();
//special hook-in for skylights
Point3F camPos = state->getCameraPosition();
mProbeInfo->mBounds.setCenter(camPos);