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

# Conflicts:
#	Templates/Full/game/shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl
This commit is contained in:
Azaezel 2019-03-03 11:54:24 -06:00
commit 6a7d046a19
11 changed files with 226 additions and 54 deletions

View file

@ -32,8 +32,55 @@ uniform float4 probeConfigData[MAX_PROBES]; //r,g,b/mode,radius,atten
uniform float4 probeContribColors[MAX_PROBES];
#endif
//Probe IBL stuff
struct ProbeData
// Box Projected IBL Lighting
// Based on: http://www.gamedev.net/topic/568829-box-projected-cubemap-environment-mapping/
// and https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/
/*float3 boxProject(float3 wsPosition, float3 wsEyeRay, float3 reflectDir, float3 boxWSPos, float3 boxMin, float3 boxMax)
{
float3 positionLS = mul(worldToObjArray[id], float4(wsEyeRay, 1.0)).xyz;
//float3 rayLS = mul(worldToObjArray[id], float4(wsEyeRay, 1.0)).xyz;
//float3 reflCameraLS = mul(worldToObjArray[id], float4(reflectDir), 1.0)).xyz;
float3 nrdir = reflectDir;
float3 offset = wsPosition;
float3 plane1vec = (boxMax - offset) / nrdir;
float3 plane2vec = (boxMin - offset) / nrdir;
float3 furthestPlane = max(plane1vec, plane2vec);
float dist = min(min(furthestPlane.x, furthestPlane.y), furthestPlane.z);
float3 posonbox = offset + nrdir * dist;
return posonbox - boxWSPos;
}*/
float3 iblSkylightDiffuse(Surface surface, ProbeData probe)
{
float lod = surface.roughness*cubeMips;
float3 color = TORQUE_TEXCUBEARRAYLOD(irradianceCubemapAR, surface.N, probe.probeIdx, lod).xyz;
return color;
}
float3 iblSkylightSpecular(Surface surface, ProbeData probe)
{
// BRDF
float2 brdf = TORQUE_TEX2DLOD(BRDFTexture, float4(surface.roughness, surface.NdotV, 0.0, 0.0)).xy;
// Radiance (Specular)
#if DEBUGVIZ_SPECCUBEMAP == 0
float lod = surface.roughness*cubeMips;
#elif DEBUGVIZ_SPECCUBEMAP == 1
float lod = 0;
#endif
float3 color = TORQUE_TEXCUBEARRAYLOD(cubeMapAR, surface.N, probe.probeIdx, 0).xyz * (brdf.x + brdf.y);
//float3 color = float3(1, 1, 1);
return color;
}
float3 iblBoxDiffuse( Surface surface, ProbeData probe)
{
float3 wsPosition;
float radius;
@ -169,14 +216,19 @@ float4 main( PFXVertToPix IN ) : SV_TARGET
{
probes[i].defineBoxSpaceInfluence(surface, IN.wsEyeRay);
}
else
else if (probes[i].type == 1) //sphere
{
probes[i].defineSphereSpaceInfluence(surface,IN.wsEyeRay);
}
if (probes[i].contribution>1||probes[i].contribution<0)
probes[i].contribution = 0;
blendSum += probes[i].contribution;
invBlendSum += (1.0f - probes[i].contribution);
else //skylight
{
//
blendVal[i] = 1;
}
blendVal[i] = saturate(blendVal[i]);
blendSum += blendVal[i];
invBlendSum += (1.0f - blendVal[i]);
}
// Weight0 = normalized NDF, inverted to have 1 at center, 0 at boundary.
@ -248,9 +300,18 @@ float4 main( PFXVertToPix IN ) : SV_TARGET
if (probes[i].contribution == 0)
continue;
irradiance += probes[i].iblBoxDiffuse(surface);
specular += F*probes[i].iblBoxSpecular(surface);
if (probes[i].type == 2) //skylight
{
irradiance += blendFactor[i] * iblSkylightDiffuse(surface, probes[i]);
specular += blendFactor[i] * F * iblSkylightSpecular(surface, probes[i]);
}
else
{
irradiance += blendFactor[i] * iblBoxDiffuse(surface, probes[i]);
specular += blendFactor[i] * F*iblBoxSpecular(surface, probes[i]);
}
}
//final diffuse color
@ -263,7 +324,14 @@ float4 main( PFXVertToPix IN ) : SV_TARGET
float3 cubeColor = float3(0, 0, 0);
for (i = 0; i < numProbes; ++i)
{
cubeColor += probes[i].iblBoxSpecular(surface);
//if (probes[i].type == 2) //skylight
//{
cubeColor += blendFactor[i] * iblSkylightSpecular(surface, probes[i]);
/*}
else
{
cubeColor += blendFactor[i] * iblBoxSpecular(surface, probes[i]);
}*/
}
return float4(cubeColor, 1);
@ -271,7 +339,14 @@ float4 main( PFXVertToPix IN ) : SV_TARGET
float3 cubeColor = float3(0, 0, 0);
for (i = 0; i < numProbes; ++i)
{
cubeColor += probes[i].iblBoxDiffuse(surface);
//if (probes[i].type == 2) //skylight
//{
cubeColor += blendFactor[i] * iblSkylightDiffuse(surface, probes[i]);
/*}
else
{
cubeColor += blendFactor[i] * iblBoxDiffuse(surface, probes[i]);
}*/
}
return float4(cubeColor, 1);