|
@@ -111,7 +111,7 @@ float3 iblBoxDiffuse(Surface surface, ProbeData probe)
|
|
|
float3 iblBoxSpecular(Surface surface, ProbeData probe)
|
|
|
{
|
|
|
// BRDF
|
|
|
- float2 brdf = TORQUE_TEX2DLOD(BRDFTexture, float4(surface.roughness, surface.NdotV, 0.0, 0.0)).xy;
|
|
|
+ //float2 brdf = TORQUE_TEX2DLOD(BRDFTexture, float4(surface.roughness, surface.NdotV, 0.0, 0.0)).xy;
|
|
|
|
|
|
float3 dir = boxProject(surface, probe);
|
|
|
|
|
@@ -122,7 +122,7 @@ float3 iblBoxSpecular(Surface surface, ProbeData probe)
|
|
|
float lod = 0;
|
|
|
#endif
|
|
|
|
|
|
- float3 color = TORQUE_TEXCUBEARRAYLOD(cubeMapAR, dir, probe.cubemapIdx, lod).xyz * (brdf.x + brdf.y);
|
|
|
+ float3 color = TORQUE_TEXCUBEARRAYLOD(cubeMapAR, dir, probe.cubemapIdx, lod).xyz;
|
|
|
return color;
|
|
|
}
|
|
|
|
|
@@ -135,7 +135,7 @@ float3 iblSkylightDiffuse(Surface surface)
|
|
|
float3 iblSkylightSpecular(Surface surface)
|
|
|
{
|
|
|
// BRDF
|
|
|
- float2 brdf = TORQUE_TEX2DLOD(BRDFTexture, float4(surface.roughness, surface.NdotV, 0.0, 0.0)).xy;
|
|
|
+ //float2 brdf = TORQUE_TEX2DLOD(BRDFTexture, float4(surface.roughness, surface.NdotV, 0.0, 0.0)).xy;
|
|
|
|
|
|
// Radiance (Specular)
|
|
|
#if DEBUGVIZ_SPECCUBEMAP == 0
|
|
@@ -144,7 +144,7 @@ float3 iblSkylightSpecular(Surface surface)
|
|
|
float lod = 0;
|
|
|
#endif
|
|
|
|
|
|
- float3 color = TORQUE_TEXCUBELOD(skylightPrefilterMap, float4(surface.R, lod)).xyz * (brdf.x + brdf.y);
|
|
|
+ float3 color = TORQUE_TEXCUBELOD(skylightPrefilterMap, float4(surface.R, lod)).xyz;
|
|
|
return color;
|
|
|
}
|
|
|
|
|
@@ -202,13 +202,12 @@ float4 main(PFXVertToPix IN) : SV_TARGET
|
|
|
probehits++;
|
|
|
}
|
|
|
|
|
|
- if (probes[i].contribution>1 || probes[i].contribution<0)
|
|
|
- probes[i].contribution = 0;
|
|
|
+ //probes[i].contribution = max(probes[i].contribution, 0);
|
|
|
|
|
|
blendSum += probes[i].contribution;
|
|
|
invBlendSum += (1.0f - probes[i].contribution);
|
|
|
|
|
|
- alpha -= probes[i].contribution;
|
|
|
+ //alpha -= probes[i].contribution;
|
|
|
}
|
|
|
|
|
|
// Weight0 = normalized NDF, inverted to have 1 at center, 0 at boundary.
|
|
@@ -216,20 +215,20 @@ float4 main(PFXVertToPix IN) : SV_TARGET
|
|
|
// respect constraint B.
|
|
|
// Weight1 = normalized inverted NDF, so we have 1 at center, 0 at boundary
|
|
|
// and respect constraint A.
|
|
|
- for (i = 0; i < numProbes; i++)
|
|
|
- {
|
|
|
- if (probehits>1.0)
|
|
|
- {
|
|
|
- blendFactor[i] = ((probes[i].contribution / blendSum)) / (probehits - 1);
|
|
|
- blendFactor[i] *= ((probes[i].contribution) / invBlendSum);
|
|
|
- blendFacSum += blendFactor[i];
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- blendFactor[i] = probes[i].contribution;
|
|
|
- blendFacSum = probes[i].contribution;
|
|
|
- }
|
|
|
- }
|
|
|
+ if (probehits>1.0)
|
|
|
+ {
|
|
|
+ for (i = 0; i < numProbes; i++)
|
|
|
+ {
|
|
|
+ blendFactor[i] = ((probes[i].contribution / blendSum)) / (probehits - 1);
|
|
|
+ blendFactor[i] *= ((probes[i].contribution) / invBlendSum);
|
|
|
+ blendFacSum += blendFactor[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ blendFactor[i] = probes[i].contribution;
|
|
|
+ blendFacSum = probes[i].contribution;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
// Normalize blendVal
|
|
@@ -246,9 +245,10 @@ float4 main(PFXVertToPix IN) : SV_TARGET
|
|
|
for (i = 0; i < numProbes; ++i)
|
|
|
{
|
|
|
blendFactor[i] *= invBlendSumWeighted;
|
|
|
- probes[i].contribution = saturate(blendFactor[i]);
|
|
|
+ //probes[i].contribution = saturate(blendFactor[i]);
|
|
|
+ probes[i].contribution *= blendFactor[i];
|
|
|
|
|
|
- alpha -= probes[i].contribution;
|
|
|
+ alpha -= probes[i].contribution;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -258,18 +258,16 @@ float4 main(PFXVertToPix IN) : SV_TARGET
|
|
|
{
|
|
|
attenVis += probes[i].contribution;
|
|
|
}
|
|
|
- return float4(attenVis, attenVis, attenVis, 1);
|
|
|
+
|
|
|
+ //return float4(attenVis, attenVis, attenVis, 1);
|
|
|
+ return float4(blendSum, blendSum, blendSum, 1);
|
|
|
#endif
|
|
|
|
|
|
#if DEBUGVIZ_CONTRIB == 1
|
|
|
-
|
|
|
float3 finalContribColor = float3(0, 0, 0);
|
|
|
for (i = 0; i < numProbes; ++i)
|
|
|
{
|
|
|
- if (probes[i].contribution == 0)
|
|
|
- continue;
|
|
|
-
|
|
|
- finalContribColor += probes[i].contribution * probeContribColors[i].rgb;
|
|
|
+ finalContribColor += probes[i].contribution *probeContribColors[i].rgb;
|
|
|
}
|
|
|
|
|
|
return float4(finalContribColor, 1);
|
|
@@ -280,32 +278,36 @@ float4 main(PFXVertToPix 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;
|
|
|
- float contrib = 0;
|
|
|
+ //float contrib = 0;
|
|
|
for (i = 0; i < numProbes; ++i)
|
|
|
{
|
|
|
if (probes[i].contribution == 0)
|
|
|
continue;
|
|
|
|
|
|
- if (probes[i].type == 2) //skip skylight
|
|
|
- continue;
|
|
|
-
|
|
|
- irradiance += iblBoxDiffuse(surface, probes[i])*probes[i].contribution;
|
|
|
- specular += F*iblBoxSpecular(surface, probes[i])*probes[i].contribution;
|
|
|
- contrib +=probes[i].contribution;
|
|
|
+ irradiance += iblBoxDiffuse(surface, probes[i]) * probes[i].contribution;
|
|
|
+ specular += iblBoxSpecular(surface, probes[i]) * probes[i].contribution;
|
|
|
+ //contrib +=probes[i].contribution;
|
|
|
}
|
|
|
//contrib = saturate(contrib);
|
|
|
|
|
|
- if (hasSkylight && alpha != 0)
|
|
|
+ if (hasSkylight && alpha != 1)
|
|
|
{
|
|
|
- irradiance = lerp(irradiance, iblSkylightDiffuse(surface), alpha);
|
|
|
- specular = lerp(specular, F*iblSkylightSpecular(surface), alpha);
|
|
|
+ irradiance = lerp(irradiance, iblSkylightDiffuse(surface), blendSum);
|
|
|
+ specular = lerp(specular, iblSkylightSpecular(surface), blendSum);
|
|
|
}
|
|
|
|
|
|
+ float3 F = FresnelSchlickRoughness(surface.NdotV, surface.f0, surface.roughness);
|
|
|
+
|
|
|
+ //energy conservation
|
|
|
+ float3 kD = 1.0.xxx - F;
|
|
|
+ kD *= 1.0 - surface.metalness;
|
|
|
+
|
|
|
+ //apply brdf
|
|
|
+ //Do it once to save on texture samples
|
|
|
+ float2 brdf = TORQUE_TEX2DLOD(BRDFTexture, float4(surface.roughness, surface.NdotV, 0.0, 0.0)).xy;
|
|
|
+ specular *= brdf.x * F + brdf.y;
|
|
|
+
|
|
|
//final diffuse color
|
|
|
float3 diffuse = kD * irradiance * surface.baseColor.rgb;
|
|
|
float4 finalColor = float4(diffuse + specular * surface.ao, 1.0);
|