Merge branch 'PBR_ProbeArrayGLWIP' of https://github.com/Areloch/Torque3D into PBR_ProbeArrayGLWIP

This commit is contained in:
AzaezelX 2019-04-28 20:37:03 -05:00
commit 2ec197c38c
5 changed files with 86 additions and 60 deletions

View file

@ -343,27 +343,28 @@ void GFXGLCubemapArray::init(GFXCubemapHandle *cubemaps, const U32 cubemapCount)
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, GFXGLTextureInternalFormat[mFormat], mSize, mSize, cubemapCount * 6, 0, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
for (U32 i = 0; i < cubemapCount; i++)
{
GFXGLCubemap* glTex = static_cast<GFXGLCubemap*>(cubemaps[i].getPointer());
for (U32 face = 0; face < 6; face++)
{
for (U32 currentMip = 0; currentMip < mMipMapLevels; currentMip++)
//U32 currentMip = 0;
{
U8 *pixelData = glTex->getTextureData(face, currentMip);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, mCubemap);
const U32 mipSize = getMax(U32(1), mSize >> currentMip);
/*if (isCompressed)
if (isCompressed)
{
const U32 mipDataSize = getCompressedSurfaceSize(mFormat, mSize, mSize, currentMip);
glCompressedTexImage2D(faceList[face], currentMip, GFXGLTextureInternalFormat[mFormat], mipSize, mipSize, 0, mipDataSize, pixelData);
glCompressedTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, currentMip, GFXGLTextureInternalFormat[mFormat], 0, 0, i * 6 + face, 0, mipDataSize, pixelData);
}
else
{*/ //TODO figure out xyzOffsets
glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, currentMip, 0, 0, 0, mipSize, mipSize, i * face, GL_RGBA, GFXGLTextureType[mFormat], pixelData);
//}
{
glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, currentMip, 0, 0, i * 6 + face, mipSize, mipSize, 1, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], pixelData);
}
glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, 0);
delete[] pixelData;
}
}
@ -396,32 +397,6 @@ void GFXGLCubemapArray::init(const U32 cubemapCount, const U32 cubemapFaceSize,
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
/*for (U32 i = 0; i < cubemapCount; i++)
{
GFXGLCubemap* glTex = static_cast<GFXGLCubemap*>(cubemaps[i].getPointer());
for (U32 face = 0; face < 6; face++)
{
for (U32 currentMip = 0; currentMip < mMipMapLevels; currentMip++)
{
U8 *pixelData = glTex->getTextureData(face, currentMip);
const U32 mipSize = getMax(U32(1), mSize >> currentMip);
if (isCompressed)
{
const U32 mipDataSize = getCompressedSurfaceSize(mFormat, mSize, mSize, currentMip);
glCompressedTexImage2D(faceList[face], currentMip, GFXGLTextureInternalFormat[mFormat], mipSize, mipSize, 0, mipDataSize, pixelData);
}
else
{
glTexImage2D(faceList[face], currentMip, GFXGLTextureInternalFormat[mFormat], mipSize, mipSize,
0, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], pixelData);
}
delete[] pixelData;
}
}
}*/
}
void GFXGLCubemapArray::updateTexture(const GFXCubemapHandle &cubemap, const U32 slot)
@ -431,24 +406,26 @@ void GFXGLCubemapArray::updateTexture(const GFXCubemapHandle &cubemap, const U32
return;
const bool isCompressed = ImageUtil::isCompressedFormat(mFormat);
GFXGLCubemap* glTex = static_cast<GFXGLCubemap*>(cubemap.getPointer());
GFXGLCubemap* glTex = static_cast<GFXGLCubemap*>(cubemap.getPointer());
for (U32 face = 0; face < 6; face++)
{
for (U32 currentMip = 0; currentMip < mMipMapLevels; currentMip++)
{
U8 *pixelData = glTex->getTextureData(face, currentMip);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, mCubemap);
const U32 mipSize = getMax(U32(1), mSize >> currentMip);
/*if (isCompressed)
if (isCompressed)
{
const U32 mipDataSize = getCompressedSurfaceSize(mFormat, mSize, mSize, currentMip);
glCompressedTexImage2D(faceList[face], currentMip, GFXGLTextureInternalFormat[mFormat], mipSize, mipSize, 0, mipDataSize, pixelData);
glCompressedTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, currentMip, GFXGLTextureInternalFormat[mFormat], 0, 0, slot * 6 + face, 0, mipDataSize, pixelData);
}
else
{*/ //TODO figure out xyzOffsets
glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, mCubemap);
glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, currentMip, 0, 0, slot * 6 + face, mipSize, mipSize, 1, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], pixelData);
{
glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, currentMip, 0, 0, slot * 6 + face, mipSize, mipSize, 1, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], pixelData);
}
glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, 0);
//}
delete[] pixelData;
}
}

View file

@ -171,6 +171,19 @@ void ProbeShaderConstants::init(GFXShader* shader)
mInit = true;
}
bool ProbeShaderConstants::isValid()
{
if (mProbePositionSC->isValid() ||
mProbeConfigDataSC->isValid() ||
mProbeBoxMinSC->isValid() ||
mProbeBoxMaxSC->isValid() ||
mProbeSpecularCubemapSC->isValid() ||
mProbeIrradianceCubemapSC->isValid())
return true;
return false;
}
void ProbeShaderConstants::_onShaderReload()
{
if (mShader.isValid())
@ -536,12 +549,7 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
PROFILE_SCOPE(ProbeManager_Update4ProbeConsts);
// Skip over gathering lights if we don't have to!
if (probeShaderConsts->mProbePositionSC->isValid() ||
probeShaderConsts->mProbeConfigDataSC->isValid() ||
probeShaderConsts->mProbeBoxMinSC->isValid() ||
probeShaderConsts->mProbeBoxMaxSC->isValid() ||
probeShaderConsts->mProbeSpecularCubemapSC->isValid() ||
probeShaderConsts->mProbeIrradianceCubemapSC->isValid()/* && (!ProbeRenderInst::all.empty())*/)
if (probeShaderConsts->isValid())
{
PROFILE_SCOPE(ProbeManager_Update4ProbeConsts_setProbes);
@ -653,7 +661,7 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
if (!curEntry.mIsEnabled)
continue;
if (curEntry.mIsSkylight)
/*if (curEntry.mIsSkylight)
{
if (curEntry.mPrefilterCubemap.isValid() && curEntry.mPrefilterCubemap.isValid())
{
@ -664,8 +672,8 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
hasSkylight = true;
continue;
}
}
else
}*/
if(!curEntry.mIsSkylight)
{
/*probePositions[effectiveProbeCount] = curEntry.getPosition();
probeRefPositions[effectiveProbeCount] = curEntry.mProbeRefOffset;
@ -694,6 +702,39 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData &sgData,
//GFX->setCubeArrayTexture(probeShaderConsts->mProbeSpecularCubemapSC->getSamplerRegister(), mPrefilterArray);
//GFX->setCubeArrayTexture(probeShaderConsts->mProbeIrradianceCubemapSC->getSamplerRegister(), mIrradianceArray);
//if (!hasSkylight)
// shaderConsts->setSafe(probeShaderConsts->mHasSkylight, 0.0f);
}
//check for skylight action
if (probeShaderConsts->mHasSkylight->isValid()
&& probeShaderConsts->mSkylightIrradMap->isValid()
&& probeShaderConsts->mSkylightSpecularMap->isValid())
{
//Array rendering
U32 probeCount = ProbeRenderInst::all.size();
bool hasSkylight = false;
for (U32 i = 0; i < probeCount; i++)
{
const ProbeRenderInst& curEntry = *ProbeRenderInst::all[i];
if (!curEntry.mIsEnabled)
continue;
if (curEntry.mIsSkylight)
{
if (curEntry.mPrefilterCubemap.isValid() && curEntry.mPrefilterCubemap.isValid())
{
GFX->setCubeTexture(probeShaderConsts->mSkylightSpecularMap->getSamplerRegister(), curEntry.mPrefilterCubemap);
GFX->setCubeTexture(probeShaderConsts->mSkylightIrradMap->getSamplerRegister(), curEntry.mIrradianceCubemap);
shaderConsts->setSafe(probeShaderConsts->mHasSkylight, 1.0f);
hasSkylight = true;
break;
}
}
}
if (!hasSkylight)
shaderConsts->setSafe(probeShaderConsts->mHasSkylight, 0.0f);
}

View file

@ -152,6 +152,8 @@ struct ProbeShaderConstants
void init(GFXShader* buffer);
bool isValid();
void _onShaderReload();
};

View file

@ -3114,7 +3114,11 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
Var *wsEyePos = (Var*)LangElement::find("eyePosWorld");
Var *worldToCamera = (Var*)LangElement::find("worldToCamera");
Var *worldToTangent = (Var*)LangElement::find("worldToTangent");
if (!worldToTangent)
return;
/*Var *worldToCamera = (Var*)LangElement::find("worldToCamera");
if (!worldToCamera)
{
worldToCamera = new Var;
@ -3122,13 +3126,13 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
worldToCamera->setName("worldToCamera");
worldToCamera->uniform = true;
worldToCamera->constSortPos = cspPass;
}
}*/
//Reflection vec
Var *surface = new Var("surface", "Surface");
meta->addStatement(new GenOp(" @ = createForwardSurface(@,@,@,@,@,@,@,@);\r\n\n", new DecOp(surface), diffuseColor, bumpNormal, matinfo,
inTex, wsPosition, wsEyePos, wsView, worldToCamera));
String computeForwardProbes = String::String(" @.rgb += computeForwardProbes(@,@,@,@,@,@,@,@,@,\r\n\t\t");
inTex, wsPosition, wsEyePos, wsView, worldToTangent));
String computeForwardProbes = String::String(" @.rgb = computeForwardProbes(@,@,@,@,@,@,@,@,@,\r\n\t\t");
computeForwardProbes += String::String("@,TORQUE_SAMPLER2D_MAKEARG(@),\r\n\t\t");
computeForwardProbes += String::String("TORQUE_SAMPLERCUBE_MAKEARG(@), TORQUE_SAMPLERCUBE_MAKEARG(@), \r\n\t\t");
computeForwardProbes += String::String("TORQUE_SAMPLERCUBEARRAY_MAKEARG(@),TORQUE_SAMPLERCUBEARRAY_MAKEARG(@)).rgb; \r\n");

View file

@ -148,17 +148,18 @@ inline Surface createSurface(float4 gbuffer0, TORQUE_SAMPLER2D(gbufferTex1), TOR
return surface;
}
inline Surface createForwardSurface(float4 baseColor, float4 normal, float4 pbrProperties, in float2 uv, in float3 wsPosition, in float3 wsEyePos, in float3 wsEyeRay, in float4x4 invView)
inline Surface createForwardSurface(float4 baseColor, float4 normal, float4 pbrProperties, in float2 uv,
in float3 wsPosition, in float3 wsEyePos, in float3 wsEyeRay, in float3x3 worldToTangent)
{
Surface surface = (Surface)0;
surface.depth = 0;
surface.P = wsPosition;
surface.N = mul(invView, float4(normal.xyz,0)).xyz; //TODO move t3d to use WS normals
surface.N = normalize( mul( normal.xyz, worldToTangent ) );
surface.V = normalize(wsEyePos - surface.P);
surface.baseColor = baseColor;
const float minRoughness=1e-4;
surface.roughness = clamp(1.0 - pbrProperties.b, minRoughness, 1.0); //t3d uses smoothness, so we convert to roughness.
surface.roughness = clamp(1.0 - pbrProperties.b, minRoughness, 1); //t3d uses smoothness, so we convert to roughness.
surface.roughness_brdf = surface.roughness * surface.roughness;
surface.metalness = pbrProperties.a;
surface.ao = pbrProperties.g;
@ -372,7 +373,7 @@ float4 computeForwardProbes(Surface surface,
float lod = surface.roughness*cubeMips;
float alpha = 1;
for (i = 0; i < numProbes; ++i)
/*for (i = 0; i < numProbes; ++i)
{
float contrib = contribution[i];
if (contrib != 0)
@ -384,7 +385,7 @@ float4 computeForwardProbes(Surface surface,
specular += TORQUE_TEXCUBEARRAYLOD(specularCubemapAR, dir, cubemapIdx, lod).xyz * contrib;
alpha -= contrib;
}
}
}*/
if (hasSkylight && alpha > 0.001)
{
@ -396,7 +397,7 @@ float4 computeForwardProbes(Surface surface,
//energy conservation
float3 kD = 1.0.xxx - F;
kD *= 1.0 - surface.metalness;
kD *= clamp(1.0 - surface.metalness, 0.1, 1);
//apply brdf
//Do it once to save on texture samples
@ -407,5 +408,6 @@ float4 computeForwardProbes(Surface surface,
float3 diffuse = kD * irradiance * surface.baseColor.rgb;
float4 finalColor = float4(diffuse + specular * surface.ao, 1.0);
finalColor = float4(specular,1);
return finalColor;
}