conversionwork courtessy of jeff. seeems float3f aligned arrays were nonfuncntional, so shifts a few over to float4s

This commit is contained in:
Azaezel 2019-02-06 10:59:36 -06:00
parent e8c2912498
commit 2e485c4946
2 changed files with 145 additions and 179 deletions

View file

@ -638,198 +638,164 @@ void RenderProbeMgr::render( SceneRenderState *state )
ReflectProbeMaterialInfo* reflProbeMat = getReflectProbeMaterial();
/*for (U32 i = 0; i < ProbeRenderInst::all.size(); i++)
{
ProbeRenderInst* curEntry = ProbeRenderInst::all[i];
if (reflProbeMat == nullptr || reflProbeMat->matInstance == nullptr)
return;
if (!curEntry->mIsEnabled)
continue;
MaterialParameters *matParams = reflProbeMat->matInstance->getMaterialParameters();
if (curEntry->numPrims == 0)
continue;
MaterialParameterHandle *numProbesSC = reflProbeMat->matInstance->getMaterialParameterHandle("$numProbes");
if (curEntry->mIsSkylight && (!skylightMat || !skylightMat->matInstance))
continue;
if (!curEntry->mIsSkylight && (!reflProbeMat || !reflProbeMat->matInstance))
break;
if (curEntry->mIsSkylight)
{
//Setup
MatrixF probeTrans = curEntry->getTransform();
// Set geometry
GFX->setVertexBuffer(curEntry->vertBuffer);
GFX->setPrimitiveBuffer(curEntry->primBuffer);
probeTrans.scale(10); //force it to be big enough to surround the camera
sgData.objTrans = &probeTrans;
skylightMat->setProbeParameters(curEntry, state, worldToCameraXfm);
while (skylightMat->matInstance->setupPass(state, sgData))
{
// Set transforms
matrixSet.setWorld(*sgData.objTrans);
skylightMat->matInstance->setTransforms(matrixSet, state);
skylightMat->matInstance->setSceneInfo(state, sgData);
GFX->drawPrimitive(GFXTriangleList, 0, curEntry->numPrims);
}
}
}*/
MaterialParameterHandle *probePositionSC = reflProbeMat->matInstance->getMaterialParameterHandle("$inProbePosArray");
MaterialParameterHandle *probeWorldToObjSC = reflProbeMat->matInstance->getMaterialParameterHandle("$worldToObjArray");
MaterialParameterHandle *probeBBMinSC = reflProbeMat->matInstance->getMaterialParameterHandle("$bbMinArray");
MaterialParameterHandle *probeBBMaxSC = reflProbeMat->matInstance->getMaterialParameterHandle("$bbMaxArray");
MaterialParameterHandle *probeUseSphereModeSC = reflProbeMat->matInstance->getMaterialParameterHandle("$useSphereMode");
MaterialParameterHandle *probeRadiusSC = reflProbeMat->matInstance->getMaterialParameterHandle("$radius");
MaterialParameterHandle *probeAttenuationSC = reflProbeMat->matInstance->getMaterialParameterHandle("$attenuation");
//Array rendering
static U32 MAXPROBECOUNT = 50;
U32 probeCount = ProbeRenderInst::all.size();
if (probeCount != 0)
if (probeCount == 0)
return;
MatrixF trans = MatrixF::Identity;
sgData.objTrans = &trans;
Vector<Point3F> probePositions;
Vector<MatrixF> probeWorldToObj;
Vector<Point3F> probeBBMin;
Vector<Point3F> probeBBMax;
Vector<float> probeUseSphereMode;
Vector<float> probeRadius;
Vector<float> probeAttenuation;
probePositions.setSize(MAXPROBECOUNT);
probeWorldToObj.setSize(MAXPROBECOUNT);
probeBBMin.setSize(MAXPROBECOUNT);
probeBBMax.setSize(MAXPROBECOUNT);
probeUseSphereMode.setSize(MAXPROBECOUNT);
probeRadius.setSize(MAXPROBECOUNT);
probeAttenuation.setSize(MAXPROBECOUNT);
Vector<GFXCubemapHandle> cubeMaps;
Vector<GFXCubemapHandle> irradMaps;
U32 effectiveProbeCount = 0;
for (U32 i = 0; i < probeCount; i++)
{
MatrixF trans = MatrixF::Identity;
sgData.objTrans = &trans;
if (effectiveProbeCount >= MAXPROBECOUNT)
break;
AlignedArray<Point3F> probePositions(MAXPROBECOUNT, sizeof(Point3F));
Vector<MatrixF> probeWorldToObj;
AlignedArray<Point3F> probeBBMin(MAXPROBECOUNT, sizeof(Point3F));
AlignedArray<Point3F> probeBBMax(MAXPROBECOUNT, sizeof(Point3F));
AlignedArray<float> probeUseSphereMode(MAXPROBECOUNT, sizeof(float));
AlignedArray<float> probeRadius(MAXPROBECOUNT, sizeof(float));
AlignedArray<float> probeAttenuation(MAXPROBECOUNT, sizeof(float));
ProbeRenderInst* curEntry = ProbeRenderInst::all[i];
if (!curEntry->mIsEnabled)
continue;
dMemset(probePositions.getBuffer(), 0, probePositions.getBufferSize());
probeWorldToObj.setSize(MAXPROBECOUNT);
dMemset(probeBBMin.getBuffer(), 0, probeBBMin.getBufferSize());
dMemset(probeBBMax.getBuffer(), 0, probeBBMax.getBufferSize());
dMemset(probeUseSphereMode.getBuffer(), 0, probeUseSphereMode.getBufferSize());
dMemset(probeRadius.getBuffer(), 0, probeRadius.getBufferSize());
dMemset(probeAttenuation.getBuffer(), 0, probeAttenuation.getBufferSize());
if (curEntry->mCubemap.isNull() || curEntry->mIrradianceCubemap.isNull())
continue;
Vector<GFXCubemapHandle> cubeMaps;
Vector<GFXCubemapHandle> irradMaps;
if (!curEntry->mCubemap->isInitialised())
continue;
if (reflProbeMat && reflProbeMat->matInstance)
if (curEntry->mIsSkylight)
continue;
//Setup
const Point3F &probePos = curEntry->getPosition();
probePositions[i] = probePos + curEntry->mProbePosOffset;
MatrixF trans = curEntry->getTransform();
trans.inverse();
probeWorldToObj.push_back(trans);
probeBBMin[i] = curEntry->mBounds.minExtents;
probeBBMax[i] = curEntry->mBounds.maxExtents;
probeUseSphereMode[i] = curEntry->mProbeShapeType == ProbeRenderInst::Sphere ? 1 : 0;
probeRadius[i] = curEntry->mRadius;
probeAttenuation[i] = 1;
cubeMaps.push_back(curEntry->mCubemap);
irradMaps.push_back(curEntry->mIrradianceCubemap);
effectiveProbeCount++;
}
if (effectiveProbeCount != 0)
{
matParams->setSafe(numProbesSC, (float)effectiveProbeCount);
GFXCubemapArrayHandle mCubemapArray;
mCubemapArray = GFXCubemapArrayHandle(GFX->createCubemapArray());
GFXCubemapArrayHandle mIrradArray;
mIrradArray = GFXCubemapArrayHandle(GFX->createCubemapArray());
mCubemapArray->initStatic(cubeMaps.address(), cubeMaps.size());
mIrradArray->initStatic(irradMaps.address(), irradMaps.size());
NamedTexTarget *deferredTarget = NamedTexTarget::find(RenderDeferredMgr::BufferName);
if (deferredTarget)
GFX->setTexture(0, deferredTarget->getTexture());
else
GFX->setTexture(0, NULL);
NamedTexTarget *colorTarget = NamedTexTarget::find(RenderDeferredMgr::ColorBufferName);
if (colorTarget)
GFX->setTexture(1, colorTarget->getTexture());
else
GFX->setTexture(1, NULL);
NamedTexTarget *matinfoTarget = NamedTexTarget::find(RenderDeferredMgr::MatInfoBufferName);
if (matinfoTarget)
GFX->setTexture(2, matinfoTarget->getTexture());
else
GFX->setTexture(2, NULL);
if (mBrdfTexture)
{
MaterialParameters *matParams = reflProbeMat->matInstance->getMaterialParameters();
MaterialParameterHandle *numProbesSC = reflProbeMat->matInstance->getMaterialParameterHandle("$numProbes");
MaterialParameterHandle *probePositionSC = reflProbeMat->matInstance->getMaterialParameterHandle("$inProbePosArray");
MaterialParameterHandle *probeWorldToObjSC = reflProbeMat->matInstance->getMaterialParameterHandle("$worldToObjArray");
MaterialParameterHandle *probeBBMinSC = reflProbeMat->matInstance->getMaterialParameterHandle("$bbMinArray");
MaterialParameterHandle *probeBBMaxSC = reflProbeMat->matInstance->getMaterialParameterHandle("$bbMaxArray");
MaterialParameterHandle *probeUseSphereModeSC = reflProbeMat->matInstance->getMaterialParameterHandle("$useSphereMode");
MaterialParameterHandle *probeRadiusSC = reflProbeMat->matInstance->getMaterialParameterHandle("$radius");
MaterialParameterHandle *probeAttenuationSC = reflProbeMat->matInstance->getMaterialParameterHandle("$attenuation");
U32 effectiveProbeCount = 0;
for (U32 i = 0; i < probeCount; i++)
{
if (effectiveProbeCount >= MAXPROBECOUNT)
break;
ProbeRenderInst* curEntry = ProbeRenderInst::all[i];
if (!curEntry->mIsEnabled)
continue;
if (curEntry->mCubemap.isNull() || curEntry->mIrradianceCubemap.isNull())
continue;
if (!curEntry->mCubemap->isInitialised())
continue;
GFX->setTexture(3, mBrdfTexture);
}
else
GFX->setTexture(3, NULL);
//Setup
const Point3F &probePos = curEntry->getPosition();
probePositions[i] = probePos + curEntry->mProbePosOffset;
GFX->setCubeArrayTexture(4, mCubemapArray);
GFX->setCubeArrayTexture(5, mIrradArray);
//Final packing
AlignedArray<Point4F> _probePositions(effectiveProbeCount, sizeof(Point4F), (U8*)probePositions.address(), false);
AlignedArray<Point4F> _probeBBMin(effectiveProbeCount, sizeof(Point4F), (U8*)probeBBMin.address(), false);
AlignedArray<Point4F> _probeBBMax(effectiveProbeCount, sizeof(Point4F), (U8*)probeBBMax.address(), false);
AlignedArray<float> _probeUseSphereMode(effectiveProbeCount, sizeof(float), (U8*)probeUseSphereMode.address(), false);
AlignedArray<float> _probeRadius(effectiveProbeCount, sizeof(float), (U8*)probeRadius.address(), false);
AlignedArray<float> _probeAttenuation(effectiveProbeCount, sizeof(float), (U8*)probeAttenuation.address(), false);
MatrixF trans = curEntry->getTransform();
trans.inverse();
matParams->set(probePositionSC, _probePositions);
matParams->set(probeWorldToObjSC, probeWorldToObj.address(), effectiveProbeCount);
matParams->set(probeBBMinSC, _probeBBMin);
matParams->set(probeBBMaxSC, _probeBBMax);
matParams->set(probeUseSphereModeSC, _probeUseSphereMode);
matParams->set(probeRadiusSC, _probeRadius);
matParams->set(probeAttenuationSC, _probeAttenuation);
probeWorldToObj[i] = trans;
// Set geometry
GFX->setVertexBuffer(mFarFrustumQuadVerts);
GFX->setPrimitiveBuffer(NULL);
probeBBMin[i] = curEntry->mBounds.minExtents;
probeBBMax[i] = curEntry->mBounds.maxExtents;
while (reflProbeMat->matInstance->setupPass(state, sgData))
{
// Set transforms
matrixSet.setWorld(*sgData.objTrans);
reflProbeMat->matInstance->setTransforms(matrixSet, state);
reflProbeMat->matInstance->setSceneInfo(state, sgData);
probeUseSphereMode[i] = curEntry->mProbeShapeType == ProbeRenderInst::Sphere ? 1 : 0;
probeRadius[i] = curEntry->mRadius;
probeAttenuation[i] = 1;
cubeMaps.push_back(curEntry->mCubemap);
irradMaps.push_back(curEntry->mIrradianceCubemap);
effectiveProbeCount++;
}
if (effectiveProbeCount != 0)
{
matParams->setSafe(numProbesSC, (float)effectiveProbeCount);
GFXCubemapArrayHandle mCubemapArray;
mCubemapArray = GFXCubemapArrayHandle(GFX->createCubemapArray());
GFXCubemapArrayHandle mIrradArray;
mIrradArray = GFXCubemapArrayHandle(GFX->createCubemapArray());
mCubemapArray->initStatic(cubeMaps.address(), cubeMaps.size());
mIrradArray->initStatic(irradMaps.address(), irradMaps.size());
NamedTexTarget *deferredTarget = NamedTexTarget::find(RenderDeferredMgr::BufferName);
if (deferredTarget)
GFX->setTexture(0, deferredTarget->getTexture());
else
GFX->setTexture(0, NULL);
NamedTexTarget *colorTarget = NamedTexTarget::find(RenderDeferredMgr::ColorBufferName);
if (colorTarget)
GFX->setTexture(1, colorTarget->getTexture());
else
GFX->setTexture(1, NULL);
NamedTexTarget *matinfoTarget = NamedTexTarget::find(RenderDeferredMgr::MatInfoBufferName);
if (matinfoTarget)
GFX->setTexture(2, matinfoTarget->getTexture());
else
GFX->setTexture(2, NULL);
if (mBrdfTexture)
{
GFX->setTexture(3, mBrdfTexture);
}
else
GFX->setTexture(3, NULL);
GFX->setCubeArrayTexture(4, mCubemapArray);
GFX->setCubeArrayTexture(5, mIrradArray);
matParams->set(probePositionSC, probePositions);
matParams->set(probeWorldToObjSC, probeWorldToObj.address(), probeWorldToObj.size());
matParams->set(probeBBMinSC, probeBBMin);
matParams->set(probeBBMaxSC, probeBBMax);
matParams->set(probeUseSphereModeSC, probeUseSphereMode);
matParams->set(probeRadiusSC, probeRadius);
matParams->set(probeAttenuationSC, probeAttenuation);
// Set geometry
GFX->setVertexBuffer(mFarFrustumQuadVerts);
GFX->setPrimitiveBuffer(NULL);
while (reflProbeMat->matInstance->setupPass(state, sgData))
{
// Set transforms
matrixSet.setWorld(*sgData.objTrans);
reflProbeMat->matInstance->setTransforms(matrixSet, state);
reflProbeMat->matInstance->setSceneInfo(state, sgData);
GFX->drawPrimitive(GFXTriangleStrip, 0, 2);
}
}
GFX->drawPrimitive(GFXTriangleStrip, 0, 2);
}
}
//
//
GFX->popActiveRenderTarget();

View file

@ -21,10 +21,10 @@ uniform float cubeMips;
uniform float numProbes;
TORQUE_UNIFORM_SAMPLERCUBEARRAY(cubeMapAR, 4);
TORQUE_UNIFORM_SAMPLERCUBEARRAY(irradianceCubemapAR, 5);
uniform float3 inProbePosArray[MAX_PROBES];
uniform float4 inProbePosArray[MAX_PROBES];
uniform float4x4 worldToObjArray[MAX_PROBES];
uniform float3 bbMinArray[MAX_PROBES];
uniform float3 bbMaxArray[MAX_PROBES];
uniform float4 bbMinArray[MAX_PROBES];
uniform float4 bbMaxArray[MAX_PROBES];
uniform float useSphereMode[MAX_PROBES];
uniform float radius[MAX_PROBES];
uniform float2 attenuation[MAX_PROBES];
@ -48,7 +48,7 @@ float3 boxProject(float3 wsPosition, float3 reflectDir, float3 boxWSPos, float3
float3 iblBoxDiffuse( Surface surface, int id)
{
float3 cubeN = boxProject(surface.P, surface.N, inProbePosArray[id], bbMinArray[id], bbMaxArray[id]);
float3 cubeN = boxProject(surface.P, surface.N, inProbePosArray[id].xyz, bbMinArray[id].xyz, bbMaxArray[id].xyz);
cubeN.z *=-1;
return TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR,cubeN,id,0).xyz;
}
@ -64,7 +64,7 @@ float3 iblBoxSpecular(Surface surface, float3 surfToEye, TORQUE_SAMPLER2D(brdfTe
float lod = surface.roughness*cubeMips;
float3 r = reflect(surfToEye, surface.N);
float3 cubeR = normalize(r);
cubeR = boxProject(surface.P, surface.N, inProbePosArray[id], bbMinArray[id], bbMaxArray[id]);
cubeR = boxProject(surface.P, surface.N, inProbePosArray[id].xyz, bbMinArray[id].xyz, bbMaxArray[id].xyz);
float3 radiance = TORQUE_TEXCUBEARRAYLOD(cubeMapAR,cubeR,id,lod).xyz * (brdf.x + brdf.y);
@ -76,8 +76,8 @@ float defineBoxSpaceInfluence(Surface surface, int id)
float tempAttenVal = 3.5; //replace with per probe atten
float3 surfPosLS = mul( worldToObjArray[id], float4(surface.P,1.0)).xyz;
float3 boxMinLS = inProbePosArray[id]-(float3(1,1,1)*radius[id]);
float3 boxMaxLS = inProbePosArray[id]+(float3(1,1,1)*radius[id]);
float3 boxMinLS = inProbePosArray[id].xyz-(float3(1,1,1)*radius[0]);
float3 boxMaxLS = inProbePosArray[id].xyz+(float3(1,1,1)*radius[0]);
float boxOuterRange = length(boxMaxLS - boxMinLS);
float boxInnerRange = boxOuterRange / tempAttenVal;
@ -105,18 +105,18 @@ float4 main( FarFrustumQuadConnectP IN ) : SV_TARGET
float blendVal[MAX_PROBES];
float3 surfToEye = normalize(surface.P - eyePosWorld);
int i;
int i = 0;
float blendSum = 0;
float invBlendSum = 0;
for(i=0; i < numProbes; i++)
{
float3 probeWS = inProbePosArray[i];
float3 probeWS = inProbePosArray[i].xyz;
float3 L = probeWS - surface.P;
if(useSphereMode[i])
{
float3 L = inProbePosArray[i] - surface.P;
float3 L = inProbePosArray[i].xyz - surface.P;
blendVal[i] = 1.0-length(L)/radius[i];
blendVal[i] = max(0,blendVal[i]);
}