-
Notifications
You must be signed in to change notification settings - Fork 812
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HDRP][Path Tracing] AxF material support (#4525)
* Merge stacklit changes. * Updated changelog. * Updated docs Removed Stacklit material limitation from Path tracing docs., * Fixed issue with NaNs generated on backfaces. * Merged AxF base support, and SVBRDF implementation. * Switched isoGGX to visible normal anisoGGX implementation. * Refined SVBRDF and added Car Paint support. * Updated changelog, and minor cosmetic changes. * ... * ... * Updated couple test reference images (marginal changes). * Changed test 1000 PT, which had also marginally changed. Co-authored-by: Vic-Cooper <vic.cooper@unity3d.com>
- Loading branch information
1 parent
b88f16e
commit 8387320
Showing
19 changed files
with
684 additions
and
87 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
...dowsEditor/Direct3D12/None/1000_RaytracingQualityKeyword_PathTracer_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...s/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5005_PathTracing_Fog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...s/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5006_PathTracing_DoF.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFPathTracing.hlsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingIntersection.hlsl" | ||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingMaterial.hlsl" | ||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingBSDF.hlsl" | ||
|
||
// AxF Material Data: | ||
// | ||
// bsdfWeight0 Diffuse BRDF | ||
// bsdfWeight1 Clearoat BRDF | ||
// bsdfWeight2 Specular BRDF(s) | ||
|
||
float3 GetCoatNormal(MaterialData mtlData) | ||
{ | ||
return mtlData.bsdfData.clearcoatNormalWS; | ||
} | ||
|
||
#ifdef _AXF_BRDF_TYPE_CAR_PAINT | ||
float GetSpecularCoeffSum(MaterialData mtlData) | ||
{ | ||
return mtlData.bsdfData.height_mm; | ||
} | ||
#endif | ||
|
||
void ProcessBSDFData(PathIntersection pathIntersection, BuiltinData builtinData, MaterialData mtlData, inout BSDFData bsdfData) | ||
{ | ||
// Adjust roughness to reduce fireflies | ||
bsdfData.roughness.x = max(pathIntersection.maxRoughness, bsdfData.roughness.x); | ||
bsdfData.roughness.y = max(pathIntersection.maxRoughness, bsdfData.roughness.y); | ||
#ifdef _AXF_BRDF_TYPE_CAR_PAINT | ||
bsdfData.roughness.z = max(pathIntersection.maxRoughness, bsdfData.roughness.z); | ||
#endif | ||
|
||
// One of the killer features of AxF, optional specular Fresnel... | ||
if (!HasFresnelTerm()) | ||
bsdfData.fresnel0 = 1.0; | ||
|
||
// Make sure we can get valid coat normal reflection directions | ||
if (HasClearcoat()) | ||
bsdfData.clearcoatNormalWS = ComputeConsistentShadingNormal(mtlData.V, bsdfData.geomNormalWS, bsdfData.clearcoatNormalWS); | ||
|
||
#ifdef _AXF_BRDF_TYPE_CAR_PAINT | ||
// We hijack height_mm, as it is not used here otherwise, to store the specular coefficients sum | ||
bsdfData.height_mm = 0.0; | ||
UNITY_UNROLL | ||
for (uint i = 0; i < CARPAINT2_LOBE_COUNT; i++) | ||
bsdfData.height_mm += _CarPaint2_CTCoeffs[i]; | ||
#endif | ||
} | ||
|
||
bool CreateMaterialData(PathIntersection pathIntersection, BuiltinData builtinData, BSDFData bsdfData, inout float3 shadingPosition, inout float theSample, out MaterialData mtlData) | ||
{ | ||
// Alter values in the material's bsdfData struct, to better suit path tracing | ||
mtlData.V = -WorldRayDirection(); | ||
mtlData.Nv = ComputeConsistentShadingNormal(mtlData.V, bsdfData.geomNormalWS, bsdfData.normalWS); | ||
mtlData.bsdfData = bsdfData; | ||
ProcessBSDFData(pathIntersection, builtinData, mtlData, mtlData.bsdfData); | ||
|
||
mtlData.bsdfWeight = 0.0; | ||
|
||
// First determine if our incoming direction V is above (exterior) or below (interior) the surface | ||
if (IsAbove(mtlData)) | ||
{ | ||
float NcoatdotV = dot(GetCoatNormal(mtlData), mtlData.V); | ||
float NspecdotV = dot(GetSpecularNormal(mtlData), mtlData.V); | ||
float Fcoat = F_Schlick(IorToFresnel0(bsdfData.clearcoatIOR), NcoatdotV); | ||
float Fspec = Luminance(F_Schlick(mtlData.bsdfData.fresnel0, NspecdotV)); | ||
|
||
#if defined(_AXF_BRDF_TYPE_SVBRDF) | ||
float specularCoeff = Luminance(mtlData.bsdfData.specularColor); | ||
#elif defined(_AXF_BRDF_TYPE_CAR_PAINT) | ||
float specularCoeff = GetSpecularCoeffSum(mtlData); | ||
#endif | ||
|
||
mtlData.bsdfWeight[1] = HasClearcoat() ? Fcoat * Luminance(mtlData.bsdfData.clearcoatColor) : 0.0; | ||
float clearcoatTransmission = HasClearcoat() ? 1.0 - Fcoat : 1.0; | ||
mtlData.bsdfWeight[2] = clearcoatTransmission * lerp(Fspec, 0.5, GetScalarRoughness(mtlData.bsdfData.roughness)) * specularCoeff; | ||
mtlData.bsdfWeight[0] = clearcoatTransmission * Luminance(mtlData.bsdfData.diffuseColor) * mtlData.bsdfData.ambientOcclusion; | ||
} | ||
|
||
// Normalize the weights | ||
float wSum = mtlData.bsdfWeight[0] + mtlData.bsdfWeight[1] + mtlData.bsdfWeight[2]; | ||
|
||
if (wSum < BSDF_WEIGHT_EPSILON) | ||
return false; | ||
|
||
mtlData.bsdfWeight /= wSum; | ||
|
||
return true; | ||
} | ||
|
||
#if defined(_AXF_BRDF_TYPE_SVBRDF) | ||
# include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFPathTracingSVBRDF.hlsl" | ||
#elif defined(_AXF_BRDF_TYPE_CAR_PAINT) | ||
# include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxFPathTracingCarPaint.hlsl" | ||
#endif | ||
|
||
float3 GetLightNormal(MaterialData mtlData) | ||
{ | ||
// If both diffuse and specular normals are quasi-indentical, return one of them, otherwise return a null vector | ||
return dot(GetDiffuseNormal(mtlData), GetSpecularNormal(mtlData)) > 0.99 ? GetDiffuseNormal(mtlData) : float3(0.0, 0.0, 0.0); | ||
} | ||
|
||
float AdjustPathRoughness(MaterialData mtlData, MaterialResult mtlResult, bool isSampleBelow, float pathRoughness) | ||
{ | ||
// Adjust the max roughness, based on the estimated diff/spec ratio | ||
float maxSpecRoughness = Max3(mtlData.bsdfData.roughness.x, mtlData.bsdfData.roughness.y, mtlData.bsdfData.roughness.z); | ||
float adjustedPathRoughness = (mtlResult.specPdf * maxSpecRoughness + mtlResult.diffPdf) / (mtlResult.diffPdf + mtlResult.specPdf); | ||
|
||
return adjustedPathRoughness; | ||
} | ||
|
||
float3 ApplyAbsorption(MaterialData mtlData, SurfaceData surfaceData, float dist, bool isSampleBelow, float3 value) | ||
{ | ||
return value; | ||
} |
Oops, something went wrong.