Skip to content

[10.x.x] Axf: add normal gradients and all mapping modes (uv, planar, triplanar) #583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added CPU and GPU timings for ray tracing effects.
- Added support to combine RTSSS and RTGI (1248733).
- Added IES Profile support for Point, Spot and Rectangular-Area lights
- Added support for multiple mapping modes in AxF.

### Fixed
- Fix when rescale probe all direction below zero (1219246)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ Note: The AxF Importer imports every Texture as half float, linear, sRGB gamut (

| **Property** | **Description** |
| --------------------- | ------------------------------------------------------------ |
| **Main Tiling & Offset** | Sets the tiling rate (xy) and offsets (zw) for every Texture in the **Surface Inputs** section. HDRP uses these values to tile the Textures along the xy-axes of the Material’s surface, in the object's tangent space. Each texture property can also specify additional tiling and offset values that are applied on top of these main values (Texture property-specific tiling rates are multiplied and offsets are added to the main values set here) |
| **Mapping Mode** | Controls the texture mapping mode of the material for all textures.<br/>&#8226; **UV0..UV3**: Like in Lit, uses a UV set from UV0 to UV3 vertex attributes. Note that UV1 is used for baked lightmaps in Unity, so it isn't recommended to use this set.<br/>&#8226; **PlanarXY,YZ,ZX**: Uses planar mapping along the specified plane.<br/>&#8226; **Triplanar**: Uses triplanar mapping.<br/>&#8226; **Planar Space**: When a planar or triplanar mapping mode is selected, you can select whether the coordinates used are world space or object space using the "planar space" option set to (respectively) "world" or "local". |
| **Main Tiling & Offset** | Sets the tiling rate (xy) and offsets (zw) for every Texture in the **Surface Inputs** section. HDRP uses these values to tile the Textures along the xy-axes of the Material’s surface, in the object's tangent space. Each texture property can also specify additional tiling and offset values that are applied on top of these main values (Texture property-specific tiling rates are multiplied and offsets are added to the main values set here). These additional tiling and offsets appear next to each texture property on the same line. |
| **BRDF Type** | Controls the main AxF Material representation.<br/>&#8226; **SVBRDF**: For information on the properties Unity makes visible when you select this option, see [BRDF Type - SVBRDF](#SVBRDF).<br/>&#8226;**CAR_PAINT**: For information on the properties Unity makes visible when you select this option, see [BRDF Type - CAR_PAINT](#CAR_PAINT). |

<a name="SVBRDF"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ internal enum AxfBrdfType
BTF,
}

internal enum AxFMappingMode
{
UV0,
UV1,
UV2,
UV3,
PlanarXY,
PlanarYZ,
PlanarZX,
Triplanar,
}

/// <summary>
/// GUI for HDRP AxF materials
/// </summary>
Expand Down Expand Up @@ -50,6 +62,34 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro
const string kEnableGeometricSpecularAA = "_EnableGeometricSpecularAA";
const string kSpecularOcclusionMode = "_SpecularOcclusionMode"; // match AdvancedOptionsUIBlock.kSpecularOcclusionMode : TODO move both to HDStringConstants.

const string kMappingMode = "_MappingMode";
const string kMappingMask = "_MappingMask";
const string kPlanarSpace = "_PlanarSpace";

static public Vector4 AxFMappingModeToMask(AxFMappingMode mappingMode)
{
Vector4 mask = Vector4.zero;
if (mappingMode <= AxFMappingMode.UV3)
{
float X,Y,Z,W;
X = (mappingMode == AxFMappingMode.UV0) ? 1.0f : 0.0f;
Y = (mappingMode == AxFMappingMode.UV1) ? 1.0f : 0.0f;
Z = (mappingMode == AxFMappingMode.UV2) ? 1.0f : 0.0f;
W = (mappingMode == AxFMappingMode.UV3) ? 1.0f : 0.0f;
mask = new Vector4(X, Y, Z, W);
}
else if (mappingMode < AxFMappingMode.Triplanar)
{
float X,Y,Z,W;
X = (mappingMode == AxFMappingMode.PlanarYZ) ? 1.0f : 0.0f;
Y = (mappingMode == AxFMappingMode.PlanarZX) ? 1.0f : 0.0f;
Z = (mappingMode == AxFMappingMode.PlanarXY) ? 1.0f : 0.0f;
W = 0.0f;
mask = new Vector4(X, Y, Z, W);
}
return mask;
}

// All Setup Keyword functions must be static. It allow to create script to automatically update the shaders with a script if code change
static public void SetupMaterialKeywordsAndPass(Material material)
{
Expand All @@ -62,6 +102,33 @@ static public void SetupMaterialKeywordsAndPass(Material material)
CoreUtils.SetKeyword(material, "_AXF_BRDF_TYPE_CAR_PAINT", BRDFType == AxfBrdfType.CAR_PAINT);
CoreUtils.SetKeyword(material, "_AXF_BRDF_TYPE_BTF", BRDFType == AxfBrdfType.BTF);


// Mapping Modes:
AxFMappingMode mappingMode = (AxFMappingMode)material.GetFloat(kMappingMode);

// Make sure the mask is synched:
material.SetVector(kMappingMask, AxFMappingModeToMask(mappingMode));

bool mappingIsPlanar = (mappingMode >= AxFMappingMode.PlanarXY) && (mappingMode < AxFMappingMode.Triplanar);
bool planarIsLocal = (material.GetFloat(kPlanarSpace) > 0.0f);

CoreUtils.SetKeyword(material, "_MAPPING_PLANAR", mappingIsPlanar);
CoreUtils.SetKeyword(material, "_MAPPING_TRIPLANAR", mappingMode == AxFMappingMode.Triplanar);

if (mappingIsPlanar || mappingMode == AxFMappingMode.Triplanar)
{
CoreUtils.SetKeyword(material, "_PLANAR_LOCAL", planarIsLocal);
}

// Note: for ShaderPass defines for vertmesh/varyingmesh setup, we still use the same
// defines _REQUIRE_UV2 and _REQUIRE_UV3, and thus if eg _REQUIRE_UV3 is defined, _REQUIRE_UV2 will
// be assumed to be needed. But here in the AxFData sampling code, we use these to indicate precisely
// the single set used (if not using planar/triplanar) only and thus add _REQUIRE_UV1.
// Extra UVs might be transfered but we only need and support a single set at a time for the whole material.
CoreUtils.SetKeyword(material, "_REQUIRE_UV1", mappingMode == AxFMappingMode.UV1);
CoreUtils.SetKeyword(material, "_REQUIRE_UV2", mappingMode == AxFMappingMode.UV2);
CoreUtils.SetKeyword(material, "_REQUIRE_UV3", mappingMode == AxFMappingMode.UV3);

// Keywords for opt-out of decals and SSR:
bool decalsEnabled = material.HasProperty(kEnableDecals) && material.GetFloat(kEnableDecals) > 0.0f;
CoreUtils.SetKeyword(material, "_DISABLE_DECALS", decalsEnabled == false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public class Styles
{
public const string header = "Surface Inputs";

public static GUIContent mappingModeText = new GUIContent("Mapping Mode");
public static GUIContent planarSpaceText = new GUIContent("Planar Space");

public static GUIContent materialTilingOffsetText = new GUIContent("Main Tiling & Offset");
/////////////////////////////////////////////////////////////////////////////////////////////////
// SVBRDF Parameters
public static GUIContent diffuseColorMapText = new GUIContent("Diffuse Color");
Expand Down Expand Up @@ -110,10 +114,20 @@ enum SvbrdfFresnelVariant
SCHLICK, // Schlick's Approximation (1994)
}
static readonly string[] SvbrdfFresnelVariantNames = Enum.GetNames(typeof(SvbrdfFresnelVariant));
static readonly string[] MappingModeNames = Enum.GetNames(typeof(AxFMappingMode));

/////////////////////////////////////////////////////////////////////////////////////////////////
// Generic Parameters


static string m_MappingModeText = "_MappingMode";
MaterialProperty m_MappingMode = null;

static string m_MappingMaskText = "_MappingMask";
MaterialProperty m_MappingMask = null;

static string m_PlanarSpaceText = "_PlanarSpace";
MaterialProperty m_PlanarSpace = null;

MaterialProperty m_MaterialTilingOffset = null;
MaterialProperty m_DiffuseColorMapST = null;
MaterialProperty m_SpecularColorMapST = null;
Expand Down Expand Up @@ -234,6 +248,10 @@ public AxfSurfaceInputsUIBlock(Expandable expandableBit)

public override void LoadMaterialProperties()
{
m_MappingMode = FindProperty(m_MappingModeText);
m_MappingMask = FindProperty(m_MappingMaskText);
m_PlanarSpace = FindProperty(m_PlanarSpaceText);

m_MaterialTilingOffset = FindProperty(m_MaterialTilingOffsetText);

m_DiffuseColorMapST = FindProperty(m_DiffuseColorMapText + tilingOffsetPropNameSuffix);
Expand Down Expand Up @@ -344,7 +362,27 @@ public static void ExtractFlags(uint flags,

void DrawAxfSurfaceOptionsGUI()
{
materialEditor.ShaderProperty(m_MaterialTilingOffset, "Main Tiling & Offset");
//materialEditor.ShaderProperty(m_MappingMode, Styles.mappingModeText);
EditorGUI.BeginChangeCheck();
float val = EditorGUILayout.Popup(Styles.mappingModeText, (int)m_MappingMode.floatValue, MappingModeNames);
if (EditorGUI.EndChangeCheck())
{
Material material = materialEditor.target as Material;
Undo.RecordObject(material, "Change Mapping Mode");
m_MappingMode.floatValue = val;
}

AxFMappingMode mappingMode = (AxFMappingMode)m_MappingMode.floatValue;
m_MappingMask.vectorValue = AxFGUI.AxFMappingModeToMask(mappingMode);

if (mappingMode >= AxFMappingMode.PlanarXY)
{
++EditorGUI.indentLevel;
materialEditor.ShaderProperty(m_PlanarSpace, Styles.planarSpaceText);
--EditorGUI.indentLevel;
}

materialEditor.ShaderProperty(m_MaterialTilingOffset, Styles.materialTilingOffsetText);

AxfBrdfType AxF_BRDFType = (AxfBrdfType)m_AxF_BRDFType.floatValue;
AxF_BRDFType = (AxfBrdfType)EditorGUILayout.Popup("BRDF Type", (int)AxF_BRDFType, AxfBrdfTypeNames);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,35 @@ public struct SurfaceData
public float anisotropyAngle;

// Car Paint Variables
[SurfaceDataAttributes("Flakes UV")]
public Vector2 flakesUV;

[SurfaceDataAttributes("Flakes Mip")]
public float flakesMipLevel;

[SurfaceDataAttributes("Flakes UV (or PlanarZY)")]
public Vector2 flakesUVZY;
[SurfaceDataAttributes("Flakes PlanarXZ")]
public Vector2 flakesUVXZ;
[SurfaceDataAttributes("Flakes PlanarXY")]
public Vector2 flakesUVXY;

[SurfaceDataAttributes("Flakes Mip (and for PlanarZY)")]
public float flakesMipLevelZY;
[SurfaceDataAttributes("Flakes Mip for PlanarXZ")]
public float flakesMipLevelXZ;
[SurfaceDataAttributes("Flakes Mip for PlanarXY")]
public float flakesMipLevelXY;
[SurfaceDataAttributes("Flakes Triplanar Weights")]
public Vector3 flakesTriplanarWeights;

// if non null, we will prefer gradients (to be used statically only!)
[SurfaceDataAttributes("Flakes ddx (and for PlanarZY)")]
public Vector2 flakesDdxZY;
[SurfaceDataAttributes("Flakes ddy (and for PlanarZY)")]
public Vector2 flakesDdyZY;
[SurfaceDataAttributes("Flakes ddx for PlanarXZ")]
public Vector2 flakesDdxXZ;
[SurfaceDataAttributes("Flakes ddy for PlanarXZ")]
public Vector2 flakesDdyXZ;
[SurfaceDataAttributes("Flakes ddx for PlanarXY")]
public Vector2 flakesDdxXY;
[SurfaceDataAttributes("Flakes ddy for PlanarXY")]
public Vector2 flakesDdyXY;
// BTF Variables

// Clearcoat
Expand Down Expand Up @@ -127,11 +150,19 @@ public struct BSDFData
public float height_mm;

// Car Paint Variables
[SurfaceDataAttributes("")]
public Vector2 flakesUV;

[SurfaceDataAttributes("Flakes Mip")]
public float flakesMipLevel;
public Vector2 flakesUVZY;
public Vector2 flakesUVXZ;
public Vector2 flakesUVXY;
public float flakesMipLevelZY;
public float flakesMipLevelXZ;
public float flakesMipLevelXY;
public Vector3 flakesTriplanarWeights;
public Vector2 flakesDdxZY; // if non null, we will prefer gradients (to be used statically only!)
public Vector2 flakesDdyZY;
public Vector2 flakesDdxXZ;
public Vector2 flakesDdyXZ;
public Vector2 flakesDdxXY;
public Vector2 flakesDdyXY;

// BTF Variables

Expand Down
Loading