Shifted the rest of the probe render code to hook into the array'd uniforms, made the reflection probe shader definition refer to the array shader.

This commit is contained in:
Areloch 2019-01-19 00:31:42 -06:00
parent 1f38bb6d2d
commit f5da79b39f
5 changed files with 159 additions and 77 deletions

View file

@ -309,7 +309,7 @@ void LightManager::_update4LightConsts( const SceneData &sgData,
GFXShaderConstHandle *lightInvRadiusSqSC,
GFXShaderConstHandle *lightSpotDirSC,
GFXShaderConstHandle *lightSpotAngleSC,
GFXShaderConstHandle *lightSpotFalloffSC,
GFXShaderConstHandle *lightSpotFalloffSC,
GFXShaderConstBuffer *shaderConsts )
{
PROFILE_SCOPE( LightManager_Update4LightConsts );
@ -324,12 +324,12 @@ void LightManager::_update4LightConsts( const SceneData &sgData,
{
PROFILE_SCOPE( LightManager_Update4LightConsts_setLights );
static AlignedArray<Point4F> lightPositions( 3, sizeof( Point4F ) );
static AlignedArray<Point4F> lightSpotDirs( 3, sizeof( Point4F ) );
static AlignedArray<Point4F> lightPositions( 3, sizeof( Point4F ) );
static AlignedArray<Point4F> lightSpotDirs( 3, sizeof( Point4F ) );
static AlignedArray<Point4F> lightColors( 4, sizeof( Point4F ) );
static Point4F lightInvRadiusSq;
static Point4F lightSpotAngle;
static Point4F lightSpotFalloff;
static Point4F lightSpotFalloff;
F32 range;
// Need to clear the buffers so that we don't leak

View file

@ -295,12 +295,28 @@ void RenderProbeMgr::render( SceneRenderState *state )
//Array rendering
static U32 MAXPROBECOUNT = 50;
U32 probeCount = PROBEMGR->mRegisteredProbes.size();
U32 probeCount = ProbeRenderInst::all.size();
if (probeCount != 0)
{
MatrixF trans = MatrixF::Identity;
sgData.objTrans = &trans;
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));
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 (reflProbeMat && reflProbeMat->matInstance)
{
@ -309,12 +325,13 @@ void RenderProbeMgr::render( SceneRenderState *state )
MaterialParameterHandle *numProbesSC = reflProbeMat->matInstance->getMaterialParameterHandle("$numProbes");
matParams->setSafe(numProbesSC, (float)probeCount);
//ProcessedShaderMaterial* processedMat = reflProbeMat->matInstance->getProcessedShaderMaterial();
//GFXShaderConstBuffer* shaderConsts = processedMat->_getShaderConstBuffer(0);
//ProbeShaderConstants *psc = PROBEMGR->getProbeShaderConstants(shaderConsts);
MaterialParameterHandle *probePositionSC = reflProbeMat->matInstance->getMaterialParameterHandle("$inProbePosArray");
MaterialParameterHandle *probeWorldToObjSC = reflProbeMat->matInstance->getMaterialParameterHandle("$worldToObjArray");
MaterialParameterHandle *probeBBMinSC = reflProbeMat->matInstance->getMaterialParameterHandle("$bbMinArrayy");
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;
@ -323,57 +340,34 @@ void RenderProbeMgr::render( SceneRenderState *state )
if (effectiveProbeCount >= MAXPROBECOUNT)
break;
ProbeRenderInst* curEntry = ProbeRenderInst::all[PROBEMGR->mRegisteredProbes[i]];
ProbeRenderInst* curEntry = ProbeRenderInst::all[i];
/*if (!curEntry->mIsEnabled)
continue;
if (curEntry->numPrims == 0)
continue;
if (curEntry->mIsSkylight && (!skylightMat || !skylightMat->matInstance))
continue;
if (!curEntry->mIsSkylight && (!reflProbeMat || !reflProbeMat->matInstance))
break;*/
//Setup
//Setup
const Point3F &probePos = curEntry->getPosition();
probePositions[i].x = probePos.x;
probePositions[i].y = probePos.y;
probePositions[i].z = probePos.z;
probePositions[i] = probePos + curEntry->mProbePosOffset;
Point3F test = probePositions[i];
probeWorldToObj[i] = curEntry->getTransform();
MatrixF probeTrans = curEntry->getTransform();
probeBBMin[i] = curEntry->mBounds.minExtents;
probeBBMax[i] = curEntry->mBounds.maxExtents;
//if (!curEntry->mIsSkylight)
{
//if (curEntry->mProbeShapeType == ProbeRenderInst::Sphere)
// probeTrans.scale(curEntry->mRadius * 1.01f);
probeUseSphereMode[i] = curEntry->mProbeShapeType == ProbeRenderInst::Sphere ? 1 : 0;
sgData.objTrans = &probeTrans;
reflProbeMat->setProbeParameters(curEntry, state, worldToCameraXfm);
}
probeRadius[i] = curEntry->mRadius;
probeAttenuation[i] = 1;
effectiveProbeCount++;
}
if (effectiveProbeCount != 0)
{
//Con::printf("Probe aligned position count: %i", probeCount);
for (U32 p = 0; p < probeCount; p++)
{
Point3F prb = probePositions[p];
//Con::printf("Probe %i aligned position is: %g %g %g", p, prb.x, prb.y, prb.z);
bool tasadfh = true;
}
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);
@ -437,7 +431,7 @@ void RenderProbeMgr::render( SceneRenderState *state )
GFX->popActiveRenderTarget();
//PROBEMGR->unregisterAllProbes();
PROBEMGR->mRegisteredProbes.clear();
//PROBEMGR->mRegisteredProbes.clear();
PROFILE_END();

View file

@ -280,12 +280,25 @@ new CustomMaterial( AL_ParticlePointLightMaterial )
//Reflection probe Specular
new ShaderData( ReflectionProbeShader )
{
DXVertexShaderFile = "shaders/common/lighting/advanced/convexGeometryV.hlsl";
/*DXVertexShaderFile = "shaders/common/lighting/advanced/convexGeometryV.hlsl";
DXPixelShaderFile = "shaders/common/lighting/advanced/reflectionProbeP.hlsl";
OGLVertexShaderFile = "shaders/common/lighting/advanced/gl/convexGeometryV.glsl";
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/reflectionProbeP.glsl";
samplerNames[0] = "$deferredBuffer";
samplerNames[1] = "$colorBuffer";
samplerNames[2] = "$matInfoBuffer";
samplerNames[3] = "$cubeMap";
samplerNames[4] = "$irradianceCubemap";
samplerNames[5] = "$BRDFTexture";*/
DXVertexShaderFile = "shaders/common/lighting/advanced/convexGeometryV.hlsl";
DXPixelShaderFile = "shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl";
OGLVertexShaderFile = "shaders/common/lighting/advanced/gl/convexGeometryV.glsl";
OGLPixelShaderFile = "shaders/common/lighting/advanced/gl/reflectionProbeArrayP.glsl";
samplerNames[0] = "$deferredBuffer";
samplerNames[1] = "$colorBuffer";
samplerNames[2] = "$matInfoBuffer";

View file

@ -134,7 +134,7 @@ new SimGroup(MissionGroup) {
ReflectionMode = "Baked Cubemap";
reflectionPath = "levels/probeTest/probes/";
Bake = "0";
position = "0 0.0825528 4.53387";
position = "0 0.0825528 2.18272";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
@ -156,7 +156,7 @@ new SimGroup(MissionGroup) {
surface = "0 0 0 1 0 0 0.5";
surface = "0 1 0 0 0 0 -0.5";
surface = "0.707107 0 0 0.707107 0 0.5 0";
surface = "0.707107 0 0 0.707106 0 0.5 0";
surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@ -171,7 +171,7 @@ new SimGroup(MissionGroup) {
surface = "0 0 0 1 0 0 0.5";
surface = "0 1 0 0 0 0 -0.5";
surface = "0.707107 0 0 0.707107 0 0.5 0";
surface = "0.707107 0 0 0.707106 0 0.5 0";
surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@ -186,7 +186,7 @@ new SimGroup(MissionGroup) {
surface = "0 0 0 1 0 0 0.5";
surface = "0 1 0 0 0 0 -0.5";
surface = "0.707107 0 0 0.707106 0 0.5 0";
surface = "0.707107 0 0 0.707107 0 0.5 0";
surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@ -201,7 +201,7 @@ new SimGroup(MissionGroup) {
surface = "0 0 0 1 0 0 0.5";
surface = "0 1 0 0 0 0 -0.5";
surface = "0.707107 0 0 0.707106 0 0.5 0";
surface = "0.707107 0 0 0.707107 0 0.5 0";
surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@ -216,7 +216,7 @@ new SimGroup(MissionGroup) {
surface = "0 0 0 1 0 0 0.5";
surface = "0 1 0 0 0 0 -0.5";
surface = "0.707107 0 0 0.707106 0 0.5 0";
surface = "0.707107 0 0 0.707107 0 0.5 0";
surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@ -231,7 +231,7 @@ new SimGroup(MissionGroup) {
surface = "0 0 0 1 0 0 0.5";
surface = "0 1 0 0 0 0 -0.5";
surface = "0.707107 0 0 0.707107 0 0.5 0";
surface = "0.707107 0 0 0.707106 0 0.5 0";
surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@ -246,7 +246,7 @@ new SimGroup(MissionGroup) {
surface = "0 0 0 1 0 0 0.5";
surface = "0 1 0 0 0 0 -0.5";
surface = "0.707107 0 0 0.707106 0 0.5 0";
surface = "0.707107 0 0 0.707107 0 0.5 0";
surface = "0 0.707107 -0.707107 0 0 -0.5 -2.84217e-14";
surface = "0.5 0.5 -0.5 0.5 -0.5 0 -9.93411e-08";
surface = "0.5 -0.5 0.5 0.5 0.5 0 -9.93411e-08";
@ -313,5 +313,65 @@ new SimGroup(MissionGroup) {
canSave = "1";
canSaveDynamicFields = "1";
};
new ReflectionProbe() {
enabled = "1";
ProbeShape = "Box";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
reflectionPath = "levels/probeTest/probes/";
Bake = "0";
position = "-8.24487 0.0825528 2.5031";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "e9c2eed2-1ae9-11e9-9c9a-df9135416cc7";
GroundColor = "0.8 0.7 0.5 1";
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
SkyColor = "0.5 0.5 1 1";
};
new ReflectionProbe() {
enabled = "1";
ProbeShape = "Box";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
reflectionPath = "levels/probeTest/probes/";
Bake = "0";
position = "-8.24487 3.18253 2.18272";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "f281a5ff-1ae9-11e9-9c9a-df9135416cc7";
GroundColor = "0.8 0.7 0.5 1";
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
SkyColor = "0.5 0.5 1 1";
};
new ReflectionProbe() {
enabled = "1";
ProbeShape = "Box";
radius = "5";
posOffset = "0 0 0";
ReflectionMode = "Baked Cubemap";
reflectionPath = "levels/probeTest/probes/";
Bake = "0";
position = "-8.24487 -3.37372 2.18272";
rotation = "1 0 0 0";
scale = "5 5 5";
canSave = "1";
canSaveDynamicFields = "1";
persistentId = "f4db4dde-1ae9-11e9-9c9a-df9135416cc7";
GroundColor = "0.8 0.7 0.5 1";
IndirectLight = "1 1 1 1";
IndirectLightMode = "Spherical Harmonics";
Intensity = "1";
SkyColor = "0.5 0.5 1 1";
};
};
//--- OBJECT WRITE END ---

View file

@ -4,11 +4,19 @@
#include "../../lighting.hlsl"
#include "../../torque.hlsl"
struct ConvexConnectP
/*struct ConvexConnectP
{
float4 pos : TORQUE_POSITION;
float4 uv0 : TEXCOORD1;
float4 vsEyeDir : TEXCOORD2;
};*/
struct ConvexConnectP
{
float4 pos : TORQUE_POSITION;
float4 wsEyeDir : TEXCOORD0;
float4 ssPos : TEXCOORD1;
float4 vsEyeDir : TEXCOORD2;
};
TORQUE_UNIFORM_SAMPLER2D(deferredBuffer, 0);
@ -57,7 +65,8 @@ float3 iblBoxDiffuse( Surface surface, int id)
{
float3 cubeN = boxProject(surface.P, surface.N, inProbePosArray[id], bbMinArray[id], bbMaxArray[id]);
cubeN.z *=-1;
return TORQUE_TEXCUBEARRAYLOD(irradianceCubemap,cubeN,id,0).xyz;
//return TORQUE_TEXCUBEARRAYLOD(irradianceCubemap,cubeN,id,0).xyz;
return float3(1,1,1);
}
float3 iblBoxSpecular(Surface surface, float3 surfToEye, TORQUE_SAMPLER2D(brdfTexture), int id)
@ -73,7 +82,8 @@ float3 iblBoxSpecular(Surface surface, float3 surfToEye, TORQUE_SAMPLER2D(brdfTe
float3 cubeR = normalize(r);
cubeR = boxProject(surface.P, surface.N, inProbePosArray[id], bbMinArray[id], bbMaxArray[id]);
float3 radiance = TORQUE_TEXCUBEARRAYLOD(cubeMap,cubeR,id,lod).xyz * (brdf.x + brdf.y);
//float3 radiance = TORQUE_TEXCUBEARRAYLOD(cubeMap,cubeR,id,lod).xyz * (brdf.x + brdf.y);
float3 radiance = float3(1,1,1);
return radiance;
}
@ -97,16 +107,20 @@ float defineBoxSpaceInfluence(Surface surface, int id)
float4 main( ConvexConnectP IN ) : SV_TARGET
{
// Compute scene UV
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
//eye ray WS/LS
float3 vsEyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
float3 wsEyeRay = mul(cameraToWorld, float4(vsEyeRay, 0)).xyz;
//unpack normal and linear depth
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, IN.uv0.xy);
float4 normDepth = TORQUE_DEFERRED_UNCONDITION(deferredBuffer, uvScene);
//create surface
Surface surface = createSurface( normDepth, TORQUE_SAMPLER2D_MAKEARG(colorBuffer),TORQUE_SAMPLER2D_MAKEARG(matInfoBuffer),
IN.uv0.xy, eyePosWorld, wsEyeRay, cameraToWorld);
uvScene, eyePosWorld, wsEyeRay, cameraToWorld);
//early out if emissive
if (getFlag(surface.matFlag, 0))
{
@ -121,22 +135,22 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
for(i=0; i < numProbes; i++)
{
float3 probeWS = inProbePosArray[i];
float3 L = probeWS - surface.P;
float3 probeWS = inProbePosArray[i];
float3 L = probeWS - surface.P;
if(useSphereMode[i])
{
float3 L = inProbePosArray[i] - surface.P;
blendVal[i] = 1.0-length(L)/radius[i];
blendVal[i] = max(0,blendVal[i]);
}
else
{
blendVal[i] = defineBoxSpaceInfluence(surface, i);
blendVal[i] = max(0,blendVal[i]);
}
if(useSphereMode[i])
{
float3 L = inProbePosArray[i] - surface.P;
blendVal[i] = 1.0-length(L)/radius[i];
blendVal[i] = max(0,blendVal[i]);
}
else
{
blendVal[i] = defineBoxSpaceInfluence(surface, i);
blendVal[i] = max(0,blendVal[i]);
}
blendSum += blendVal[i];
invBlendSum +=(1.0f - blendVal[i]);
invBlendSum +=(1.0f - blendVal[i]);
}
// Weight0 = normalized NDF, inverted to have 1 at center, 0 at boundary.
@ -166,6 +180,7 @@ float4 main( ConvexConnectP IN ) : SV_TARGET
float3 irradiance = float3(0,0,0);
float3 specular = float3(0,0,0);
float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
//energy conservation
float3 kD = 1.0.xxx - F;
kD *= 1.0 - surface.metalness;