浏览代码

Adding support for the tangent map

Correcting review problems
/main
Anis Benyoub 6 年前
当前提交
57c8659e
共有 4 个文件被更改,包括 38 次插入11 次删除
  1. 11
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Fabric/FabricUI.cs
  2. 4
      com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/Fabric.shader
  3. 32
      com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/FabricData.hlsl
  4. 2
      com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/FabricProperties.hlsl

11
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Fabric/FabricUI.cs


// public static GUIContent bentNormalMapText = new GUIContent("Bent normal map", "Use only with indirect diffuse lighting (Lightmap/light-probe) - Cosine weighted Bent Normal Map (average un-occluded direction) (BC7/BC5/DXT5(nm))");
// Tangent map
// public static GUIContent tangentMapText = new GUIContent("Tangent Map", "Tangent Map (BC7/BC5/DXT5(nm))");
public static GUIContent tangentMapText = new GUIContent("Tangent Map", "Tangent Map (BC7/BC5/DXT5(nm))");
// Anisotropy
public static GUIContent anisotropyText = new GUIContent("Anisotropy", "Anisotropy scale factor");

protected const string kNormalMap = "_NormalMap";
// protected MaterialProperty bentNormalMap = null;
// protected const string kBentNormalMap = "_BentNormalMap";
// Tangent Map
protected MaterialProperty tangentMap = null;
protected const string kTangentMap = "_TangentMap";
// Fuzz Tint
protected MaterialProperty fuzzTint = null;

normalMap = FindProperty(kNormalMap, props);
normalScale = FindProperty(kNormalScale, props);
// bentNormalMap = FindProperty(kBentNormalMap, props);
// Tangent map
tangentMap = FindProperty(kTangentMap, props);
// Fuzz tint
fuzzTint = FindProperty(kFuzzTint, props);

FabricType fabricType = (FabricType)material.GetFloat(kFabricType);
if(fabricType == FabricType.Silk)
{
//m_MaterialEditor.TexturePropertySingleLine(Styles.tangentMapText, tangentMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.tangentMapText, tangentMap);
m_MaterialEditor.ShaderProperty(anisotropy, Styles.anisotropyText);
m_MaterialEditor.TexturePropertySingleLine(Styles.anisotropyMapText, anisotropyMap);
}

4
com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/Fabric.shader


_NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map
_NormalScale("_NormalScale", Range(0.0, 2.0)) = 1
// TODO
// _TangentMap("TangentMap", 2D) = "bump" {}
// Tangent map
_TangentMap("TangentMap", 2D) = "bump" {}
// Smoothness values (overriden by the mask map)
_Smoothness("Smoothness", Range(0.0, 1.0)) = 1.0

32
com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/FabricData.hlsl


void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
{
// TODO: Remove this zero initialize once we have written all the code
ZERO_INITIALIZE(SurfaceData, surfaceData);
// Initial value of the material features
surfaceData.materialFeatures = 0;
surfaceData.materialFeatures = MATERIALFEATUREFLAGS_FABRIC_COTTON_WOOL;
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_FABRIC_COTTON_WOOL;
#endif
#ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING

#ifdef _NORMALMAP
float2 derivative = UnpackDerivativeNormalRGorAG(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, uvBase), _NormalScale);
float3 gradient = SurfaceGradientFromTBN(derivative, input.worldToTangent[0], input.worldToTangent[1]) + detailGradient * detailMasks.x;
#ifdef _DETAIL_MAP
float3 gradient = SurfaceGradientFromTBN(derivative, input.worldToTangent[0], input.worldToTangent[1]) + detailGradient * detailMasks.x;
#else
float3 gradient = SurfaceGradientFromTBN(derivative, input.worldToTangent[0], input.worldToTangent[1]);
#endif
#ifdef _TANGENTMAP
float3 tangentTS = UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D(_TangentMap, sampler_TangentMap, uvBase, 1.0));
surfaceData.tangentWS = TransformTangentToWorld(tangentTS, input.worldToTangent);
#else
surfaceData.tangentWS = normalize(input.worldToTangent[0].xyz); // The tangent is not normalize in worldToTangent for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
#endif
// Make the tagent match the normal
surfaceData.tangentWS = Orthonormalize(input.worldToTangent[0], surfaceData.normalWS);

surfaceData.perceptualSmoothness = lerp(surfaceData.perceptualSmoothness, saturate(smoothnessOverlay), detailMask.x);
#endif
// If a detail map was provided, modify the matching ao
#ifdef _DETAIL_MAP
float aoDetailSpeed = saturate(abs(detailAO) * _DetailAOScale);
float aoOverlay = lerp(surfaceData.ambientOcclusion, (aoDetailSpeed < 0.0) ? 0.0 : 1.0, aoDetailSpeed);
surfaceData.ambientOcclusion = lerp(surfaceData.ambientOcclusion, saturate(aoOverlay), detailMask.x);
#endif
// Propagate the fuzz tint
surfaceData.fuzzTint = _FuzzTint.xyz;

#else
surfaceData.subsurfaceMask = _SubsurfaceMask;
#endif
#else
surfaceData.subsurfaceMask = 0.0;
surfaceData.diffusionProfile = 0;
#endif
#ifdef _MATERIALFEATUREFLAGS_FABRIC_TRANSMISSION

2
com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/FabricProperties.hlsl


TEXTURE2D(_TangentMap);
SAMPLER(sampler_TangentMap);
TEXTURE2D(_TangentMapOS);
SAMPLER(sampler_TangentMapOS);
TEXTURE2D(_AnisotropyMap);
SAMPLER(sampler_AnisotropyMap);

正在加载...
取消
保存