Skip to content

Commit 2ccd42a

Browse files
Axf - Add specaa, add baked ao, fix reflection hierarchy for carpaint. (#41)
* AxF: Add support for specular AA from geometric curvature. * AxF: Add internal support for baked ambient and specular occlusion (no baked AO input map currently). Fix AO factor to adapt better to carpaint.model. * AxF: Fix a typo that caused a bug for SVBRDF materials using precise Fresnel variants to always use full reflectance (1) for delta lights. * AxF: Fix ignored reflection hierarchy + proxy intersection for carpaint. Add comments about problems if two directions are differents. Also add an option (disabled for now) to have BRDFColor with base angle of dominant direction. Rename some variables to make clearer direction on top for bottom lobe. * AxF: Use get scalar roughness function to factor out code. * AxF: Add internal support for baked ambient and specular occlusion (no baked AO input map currently). Fix AO factor to adapt better to carpaint.model. * Add changelog entries. Co-authored-by: sebastienlagarde <[email protected]>
1 parent 7a17df0 commit 2ccd42a

File tree

8 files changed

+260
-117
lines changed

8 files changed

+260
-117
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
9797
- Added support for alpha to coverage for HDRP shaders and shader graph
9898
- Added support for Quality Levels to Subsurface Scattering.
9999
- Added option to disable XR rendering on the camera settings.
100-
- Added a frame setting for alpha to mask.
100+
- Added support for specular AA from geometric curvature in AxF
101+
- Added support for baked AO (no input for now) in AxF
101102

102103
### Fixed
103104
- Fix when rescale probe all direction below zero (1219246)
@@ -516,6 +517,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
516517
- Fixed a regression in the ray traced indirect diffuse due to the new probe system.
517518
- Fix for range compression factor for probes going negative (now clamped to positive values).
518519
- Fixed path validation when creating new volume profile (case 1229933)
520+
- Fix reflection hierarchy for CARPAINT in AxF.
521+
- Fix precise fresnel for delta lights for SVBRDF in AxF.
519522

520523
### Changed
521524
- Color buffer pyramid is not allocated anymore if neither refraction nor distortion are enabled

com.unity.render-pipelines.high-definition/Editor/Material/AxF/AxFGUI.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AxFGUI : ShaderGUI
2626
{
2727
new SurfaceOptionUIBlock(MaterialUIBlock.Expandable.Base, features: SurfaceOptionUIBlock.Features.Unlit | SurfaceOptionUIBlock.Features.ReceiveSSR),
2828
new AxfSurfaceInputsUIBlock(MaterialUIBlock.Expandable.Input),
29-
new AdvancedOptionsUIBlock(MaterialUIBlock.Expandable.Advance, AdvancedOptionsUIBlock.Features.Instancing | AdvancedOptionsUIBlock.Features.AddPrecomputedVelocity),
29+
new AdvancedOptionsUIBlock(MaterialUIBlock.Expandable.Advance, AdvancedOptionsUIBlock.Features.Instancing | AdvancedOptionsUIBlock.Features.SpecularOcclusion | AdvancedOptionsUIBlock.Features.AddPrecomputedVelocity),
3030
};
3131

3232
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
@@ -46,15 +46,17 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro
4646

4747
/////////////////////////////////////////////////////////////////////////////////////////////////
4848
// AxF material keywords
49-
static string m_AxF_BRDFTypeText = "_AxF_BRDFType";
49+
const string kAxF_BRDFType = "_AxF_BRDFType";
50+
const string kEnableGeometricSpecularAA = "_EnableGeometricSpecularAA";
51+
const string kSpecularOcclusionMode = "_SpecularOcclusionMode"; // match AdvancedOptionsUIBlock.kSpecularOcclusionMode : TODO move both to HDStringConstants.
5052

5153
// All Setup Keyword functions must be static. It allow to create script to automatically update the shaders with a script if code change
5254
static public void SetupMaterialKeywordsAndPass(Material material)
5355
{
5456
material.SetupBaseUnlitKeywords();
5557
material.SetupBaseUnlitPass();
5658

57-
AxfBrdfType BRDFType = (AxfBrdfType)material.GetFloat(m_AxF_BRDFTypeText);
59+
AxfBrdfType BRDFType = (AxfBrdfType)material.GetFloat(kAxF_BRDFType);
5860

5961
CoreUtils.SetKeyword(material, "_AXF_BRDF_TYPE_SVBRDF", BRDFType == AxfBrdfType.SVBRDF);
6062
CoreUtils.SetKeyword(material, "_AXF_BRDF_TYPE_CAR_PAINT", BRDFType == AxfBrdfType.CAR_PAINT);
@@ -65,6 +67,8 @@ static public void SetupMaterialKeywordsAndPass(Material material)
6567
CoreUtils.SetKeyword(material, "_DISABLE_DECALS", decalsEnabled == false);
6668
bool ssrEnabled = material.HasProperty(kEnableSSR) && material.GetFloat(kEnableSSR) > 0.0f;
6769
CoreUtils.SetKeyword(material, "_DISABLE_SSR", ssrEnabled == false);
70+
CoreUtils.SetKeyword(material, "_ENABLE_GEOMETRIC_SPECULAR_AA", material.HasProperty(kEnableGeometricSpecularAA) && material.GetFloat(kEnableGeometricSpecularAA) > 0.0f);
71+
CoreUtils.SetKeyword(material, "_SPECULAR_OCCLUSION_NONE", material.HasProperty(kSpecularOcclusionMode) && material.GetFloat(kSpecularOcclusionMode) == 0.0f);
6872

6973
BaseLitGUI.SetupStencil(material, receivesSSR: ssrEnabled, useSplitLighting: false);
7074

com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ public enum FeatureFlags
4444
[GenerateHLSL(PackingRules.Exact, false, false, true, 1200)]
4545
public struct SurfaceData
4646
{
47+
[MaterialSharedPropertyMapping(MaterialSharedProperty.AmbientOcclusion)]
48+
[SurfaceDataAttributes("Ambient Occlusion")]
49+
public float ambientOcclusion;
50+
51+
[SurfaceDataAttributes("Specular Occlusion")]
52+
public float specularOcclusion;
53+
4754
[MaterialSharedPropertyMapping(MaterialSharedProperty.Normal)]
4855
[SurfaceDataAttributes(new string[] {"Normal", "Normal View Space"}, true)]
4956
public Vector3 normalWS;
@@ -64,7 +71,7 @@ public struct SurfaceData
6471
public Vector3 fresnelF0;
6572

6673
[SurfaceDataAttributes("Specular Lobe")]
67-
public Vector2 specularLobe;
74+
public Vector3 specularLobe; // .xy for SVBRDF, .xyz for CARPAINT2, for _CarPaint2_CTSpreads per lobe roughnesses
6875

6976
[SurfaceDataAttributes("Height")]
7077
public float height_mm;
@@ -102,6 +109,9 @@ public struct SurfaceData
102109
[GenerateHLSL(PackingRules.Exact, false, false, true, 1250)]
103110
public struct BSDFData
104111
{
112+
public float ambientOcclusion;
113+
public float specularOcclusion;
114+
105115
[SurfaceDataAttributes(new string[] { "Normal WS", "Normal View Space" }, true)]
106116
public Vector3 normalWS;
107117
[SurfaceDataAttributes("", true)]
@@ -113,7 +123,7 @@ public struct BSDFData
113123
public Vector3 diffuseColor;
114124
public Vector3 specularColor;
115125
public Vector3 fresnelF0;
116-
public Vector2 roughness;
126+
public Vector3 roughness; // .xy for SVBRDF, .xyz for CARPAINT2, for _CarPaint2_CTSpreads per lobe roughnesses
117127
public float height_mm;
118128

119129
// Car Paint Variables

com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.cs.hlsl

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,53 +18,59 @@
1818
//
1919
// UnityEngine.Rendering.HighDefinition.AxF+SurfaceData: static fields
2020
//
21-
#define DEBUGVIEW_AXF_SURFACEDATA_NORMAL (1200)
22-
#define DEBUGVIEW_AXF_SURFACEDATA_NORMAL_VIEW_SPACE (1201)
23-
#define DEBUGVIEW_AXF_SURFACEDATA_TANGENT (1202)
24-
#define DEBUGVIEW_AXF_SURFACEDATA_DIFFUSE_COLOR (1203)
25-
#define DEBUGVIEW_AXF_SURFACEDATA_SPECULAR_COLOR (1204)
26-
#define DEBUGVIEW_AXF_SURFACEDATA_FRESNEL_F0 (1205)
27-
#define DEBUGVIEW_AXF_SURFACEDATA_SPECULAR_LOBE (1206)
28-
#define DEBUGVIEW_AXF_SURFACEDATA_HEIGHT (1207)
29-
#define DEBUGVIEW_AXF_SURFACEDATA_ANISOTROPIC_ANGLE (1208)
30-
#define DEBUGVIEW_AXF_SURFACEDATA_FLAKES_UV (1209)
31-
#define DEBUGVIEW_AXF_SURFACEDATA_FLAKES_MIP (1210)
32-
#define DEBUGVIEW_AXF_SURFACEDATA_CLEARCOAT_COLOR (1211)
33-
#define DEBUGVIEW_AXF_SURFACEDATA_CLEARCOAT_NORMAL (1212)
34-
#define DEBUGVIEW_AXF_SURFACEDATA_CLEARCOAT_IOR (1213)
35-
#define DEBUGVIEW_AXF_SURFACEDATA_GEOMETRIC_NORMAL (1214)
36-
#define DEBUGVIEW_AXF_SURFACEDATA_GEOMETRIC_NORMAL_VIEW_SPACE (1215)
21+
#define DEBUGVIEW_AXF_SURFACEDATA_AMBIENT_OCCLUSION (1200)
22+
#define DEBUGVIEW_AXF_SURFACEDATA_SPECULAR_OCCLUSION (1201)
23+
#define DEBUGVIEW_AXF_SURFACEDATA_NORMAL (1202)
24+
#define DEBUGVIEW_AXF_SURFACEDATA_NORMAL_VIEW_SPACE (1203)
25+
#define DEBUGVIEW_AXF_SURFACEDATA_TANGENT (1204)
26+
#define DEBUGVIEW_AXF_SURFACEDATA_DIFFUSE_COLOR (1205)
27+
#define DEBUGVIEW_AXF_SURFACEDATA_SPECULAR_COLOR (1206)
28+
#define DEBUGVIEW_AXF_SURFACEDATA_FRESNEL_F0 (1207)
29+
#define DEBUGVIEW_AXF_SURFACEDATA_SPECULAR_LOBE (1208)
30+
#define DEBUGVIEW_AXF_SURFACEDATA_HEIGHT (1209)
31+
#define DEBUGVIEW_AXF_SURFACEDATA_ANISOTROPIC_ANGLE (1210)
32+
#define DEBUGVIEW_AXF_SURFACEDATA_FLAKES_UV (1211)
33+
#define DEBUGVIEW_AXF_SURFACEDATA_FLAKES_MIP (1212)
34+
#define DEBUGVIEW_AXF_SURFACEDATA_CLEARCOAT_COLOR (1213)
35+
#define DEBUGVIEW_AXF_SURFACEDATA_CLEARCOAT_NORMAL (1214)
36+
#define DEBUGVIEW_AXF_SURFACEDATA_CLEARCOAT_IOR (1215)
37+
#define DEBUGVIEW_AXF_SURFACEDATA_GEOMETRIC_NORMAL (1216)
38+
#define DEBUGVIEW_AXF_SURFACEDATA_GEOMETRIC_NORMAL_VIEW_SPACE (1217)
3739

3840
//
3941
// UnityEngine.Rendering.HighDefinition.AxF+BSDFData: static fields
4042
//
41-
#define DEBUGVIEW_AXF_BSDFDATA_NORMAL_WS (1250)
42-
#define DEBUGVIEW_AXF_BSDFDATA_NORMAL_VIEW_SPACE (1251)
43-
#define DEBUGVIEW_AXF_BSDFDATA_TANGENT_WS (1252)
44-
#define DEBUGVIEW_AXF_BSDFDATA_BI_TANGENT_WS (1253)
45-
#define DEBUGVIEW_AXF_BSDFDATA_DIFFUSE_COLOR (1254)
46-
#define DEBUGVIEW_AXF_BSDFDATA_SPECULAR_COLOR (1255)
47-
#define DEBUGVIEW_AXF_BSDFDATA_FRESNEL_F0 (1256)
48-
#define DEBUGVIEW_AXF_BSDFDATA_ROUGHNESS (1257)
49-
#define DEBUGVIEW_AXF_BSDFDATA_HEIGHT_MM (1258)
50-
#define DEBUGVIEW_AXF_BSDFDATA_FLAKES_UV (1259)
51-
#define DEBUGVIEW_AXF_BSDFDATA_FLAKES_MIP (1260)
52-
#define DEBUGVIEW_AXF_BSDFDATA_CLEARCOAT_COLOR (1261)
53-
#define DEBUGVIEW_AXF_BSDFDATA_CLEARCOAT_NORMAL_WS (1262)
54-
#define DEBUGVIEW_AXF_BSDFDATA_CLEARCOAT_IOR (1263)
55-
#define DEBUGVIEW_AXF_BSDFDATA_GEOMETRIC_NORMAL (1264)
56-
#define DEBUGVIEW_AXF_BSDFDATA_GEOMETRIC_NORMAL_VIEW_SPACE (1265)
43+
#define DEBUGVIEW_AXF_BSDFDATA_AMBIENT_OCCLUSION (1250)
44+
#define DEBUGVIEW_AXF_BSDFDATA_SPECULAR_OCCLUSION (1251)
45+
#define DEBUGVIEW_AXF_BSDFDATA_NORMAL_WS (1252)
46+
#define DEBUGVIEW_AXF_BSDFDATA_NORMAL_VIEW_SPACE (1253)
47+
#define DEBUGVIEW_AXF_BSDFDATA_TANGENT_WS (1254)
48+
#define DEBUGVIEW_AXF_BSDFDATA_BI_TANGENT_WS (1255)
49+
#define DEBUGVIEW_AXF_BSDFDATA_DIFFUSE_COLOR (1256)
50+
#define DEBUGVIEW_AXF_BSDFDATA_SPECULAR_COLOR (1257)
51+
#define DEBUGVIEW_AXF_BSDFDATA_FRESNEL_F0 (1258)
52+
#define DEBUGVIEW_AXF_BSDFDATA_ROUGHNESS (1259)
53+
#define DEBUGVIEW_AXF_BSDFDATA_HEIGHT_MM (1260)
54+
#define DEBUGVIEW_AXF_BSDFDATA_FLAKES_UV (1261)
55+
#define DEBUGVIEW_AXF_BSDFDATA_FLAKES_MIP (1262)
56+
#define DEBUGVIEW_AXF_BSDFDATA_CLEARCOAT_COLOR (1263)
57+
#define DEBUGVIEW_AXF_BSDFDATA_CLEARCOAT_NORMAL_WS (1264)
58+
#define DEBUGVIEW_AXF_BSDFDATA_CLEARCOAT_IOR (1265)
59+
#define DEBUGVIEW_AXF_BSDFDATA_GEOMETRIC_NORMAL (1266)
60+
#define DEBUGVIEW_AXF_BSDFDATA_GEOMETRIC_NORMAL_VIEW_SPACE (1267)
5761

5862
// Generated from UnityEngine.Rendering.HighDefinition.AxF+SurfaceData
5963
// PackingRules = Exact
6064
struct SurfaceData
6165
{
66+
float ambientOcclusion;
67+
float specularOcclusion;
6268
float3 normalWS;
6369
float3 tangentWS;
6470
float3 diffuseColor;
6571
float3 specularColor;
6672
float3 fresnelF0;
67-
float2 specularLobe;
73+
float3 specularLobe;
6874
float height_mm;
6975
float anisotropyAngle;
7076
float2 flakesUV;
@@ -79,13 +85,15 @@ struct SurfaceData
7985
// PackingRules = Exact
8086
struct BSDFData
8187
{
88+
float ambientOcclusion;
89+
float specularOcclusion;
8290
float3 normalWS;
8391
float3 tangentWS;
8492
float3 biTangentWS;
8593
float3 diffuseColor;
8694
float3 specularColor;
8795
float3 fresnelF0;
88-
float2 roughness;
96+
float3 roughness;
8997
float height_mm;
9098
float2 flakesUV;
9199
float flakesMipLevel;
@@ -102,6 +110,12 @@ void GetGeneratedSurfaceDataDebug(uint paramId, SurfaceData surfacedata, inout f
102110
{
103111
switch (paramId)
104112
{
113+
case DEBUGVIEW_AXF_SURFACEDATA_AMBIENT_OCCLUSION:
114+
result = surfacedata.ambientOcclusion.xxx;
115+
break;
116+
case DEBUGVIEW_AXF_SURFACEDATA_SPECULAR_OCCLUSION:
117+
result = surfacedata.specularOcclusion.xxx;
118+
break;
105119
case DEBUGVIEW_AXF_SURFACEDATA_NORMAL:
106120
result = surfacedata.normalWS * 0.5 + 0.5;
107121
break;
@@ -123,7 +137,7 @@ void GetGeneratedSurfaceDataDebug(uint paramId, SurfaceData surfacedata, inout f
123137
result = surfacedata.fresnelF0;
124138
break;
125139
case DEBUGVIEW_AXF_SURFACEDATA_SPECULAR_LOBE:
126-
result = float3(surfacedata.specularLobe, 0.0);
140+
result = surfacedata.specularLobe;
127141
break;
128142
case DEBUGVIEW_AXF_SURFACEDATA_HEIGHT:
129143
result = surfacedata.height_mm.xxx;
@@ -162,6 +176,12 @@ void GetGeneratedBSDFDataDebug(uint paramId, BSDFData bsdfdata, inout float3 res
162176
{
163177
switch (paramId)
164178
{
179+
case DEBUGVIEW_AXF_BSDFDATA_AMBIENT_OCCLUSION:
180+
result = bsdfdata.ambientOcclusion.xxx;
181+
break;
182+
case DEBUGVIEW_AXF_BSDFDATA_SPECULAR_OCCLUSION:
183+
result = bsdfdata.specularOcclusion.xxx;
184+
break;
165185
case DEBUGVIEW_AXF_BSDFDATA_NORMAL_WS:
166186
result = bsdfdata.normalWS * 0.5 + 0.5;
167187
break;
@@ -184,7 +204,7 @@ void GetGeneratedBSDFDataDebug(uint paramId, BSDFData bsdfdata, inout float3 res
184204
result = bsdfdata.fresnelF0;
185205
break;
186206
case DEBUGVIEW_AXF_BSDFDATA_ROUGHNESS:
187-
result = float3(bsdfdata.roughness, 0.0);
207+
result = bsdfdata.roughness;
188208
break;
189209
case DEBUGVIEW_AXF_BSDFDATA_HEIGHT_MM:
190210
result = bsdfdata.height_mm.xxx;

0 commit comments

Comments
 (0)