浏览代码

HDRP: add geometric filtering to lit shader

/main
sebastienlagarde 6 年前
当前提交
730f3273
共有 10 个文件被更改,包括 78 次插入1 次删除
  1. 15
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/CommonMaterial.hlsl
  2. 1
      ScriptableRenderPipeline/HDRenderPipeline/CHANGELOG.md
  3. 28
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/BaseLitUI.cs
  4. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLit.shader
  5. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLitData.hlsl
  6. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLitTessellation.shader
  7. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.shader
  8. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitData.hlsl
  9. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitProperties.hlsl
  10. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitTessellation.shader

15
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/CommonMaterial.hlsl


return sqrt(2.0 / (variance + 2.0));
}
// Reference: Error Reduction and Simplification for Shading Anti-Aliasing
// take perceptualSmoothness and return modified perceptualSmoothness
float GeometricFilterPerceptualSmoothness(float perceptualSmoothness, float3 geometricNormalWS, float screenSpaceVariance, float threshold)
{
float3 deltaU = ddx(geometricNormalWS);
float3 deltaV = ddy(geometricNormalWS);
float variance = screenSpaceVariance * (dot(deltaU, deltaU) + dot(deltaV, deltaV));
float roughness = PerceptualSmoothnessToRoughness(perceptualSmoothness);
float squaredRoughness = saturate(roughness * roughness + min(2.0 * variance, threshold * threshold)); // threshold can be really low, square the value for easier control
return 1.0 - RoughnessToPerceptualRoughness(sqrt(squaredRoughness));
}
// ----------------------------------------------------------------------------
// Helper for Disney parametrization
// ----------------------------------------------------------------------------

1
ScriptableRenderPipeline/HDRenderPipeline/CHANGELOG.md


- Added Screen Space Reflection with Proxy Projection Model
- Support correctly scene selection for alpha tested object
- Add per light shadow mask mode control (i.e shadow mask distance and shadow mask). It use the option NonLightmappedOnly
- Add geometric filtering to Lit shader (allow to reduce specular aliasing)
### Changed, Removals and deprecations
- Removed GlobalLightLoopSettings.maxPlanarReflectionProbes and instead use value of GlobalLightLoopSettings.planarReflectionProbeCacheSize

28
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/BaseLitUI.cs


public static GUIContent windShiverDirectionalityText = new GUIContent("Shiver Directionality");
public static GUIContent supportDBufferText = new GUIContent("Enable Decal", "Allow to specify if the material can receive decal or not");
public static GUIContent enableGeometricSpecularAAText = new GUIContent("Enable geometric specular AA", "This reduce specular aliasing on highly dense mesh (Particularly useful when they don't use using normal map)");
public static GUIContent specularAAScreenSpaceVarianceText = new GUIContent("Screen space variance", "Allow to control the strength of the specular AA reduction. Higher mean more blurry result and less aliasing");
public static GUIContent specularAAThresholdText = new GUIContent("Threshold", "Allow to limit the effect of specular AA reduction. 0 mean don't apply reduction, higher value mean allow higher reduction");
}
public enum DoubleSidedNormalMode

// Decal
protected MaterialProperty supportDBuffer = null;
protected const string kSupportDBuffer = "_SupportDBuffer";
protected MaterialProperty enableGeometricSpecularAA = null;
protected const string kEnableGeometricSpecularAA = "_EnableGeometricSpecularAA";
protected MaterialProperty specularAAScreenSpaceVariance = null;
protected const string kSpecularAAScreenSpaceVariance = "_SpecularAAScreenSpaceVariance";
protected MaterialProperty specularAAThreshold = null;
protected const string kSpecularAAThreshold = "_SpecularAAThreshold";
protected override void FindBaseMaterialProperties(MaterialProperty[] props)
{

// Decal
supportDBuffer = FindProperty(kSupportDBuffer, props);
// specular AA
enableGeometricSpecularAA = FindProperty(kEnableGeometricSpecularAA, props, false);
specularAAScreenSpaceVariance = FindProperty(kSpecularAAScreenSpaceVariance, props, false);
specularAAThreshold = FindProperty(kSpecularAAThreshold, props, false);
}
void TessellationModePopup()

}
m_MaterialEditor.ShaderProperty(supportDBuffer, StylesBaseLit.supportDBufferText);
m_MaterialEditor.ShaderProperty(enableGeometricSpecularAA, StylesBaseLit.enableGeometricSpecularAAText);
if (enableGeometricSpecularAA.floatValue > 0.0)
{
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(specularAAScreenSpaceVariance, StylesBaseLit.specularAAScreenSpaceVarianceText);
m_MaterialEditor.ShaderProperty(specularAAThreshold, StylesBaseLit.specularAAThresholdText);
EditorGUI.indentLevel--;
}
m_MaterialEditor.ShaderProperty(enableMotionVectorForVertexAnimation, StylesBaseUnlit.enableMotionVectorForVertexAnimationText);

// Use negation so we don't create keyword by default
CoreUtils.SetKeyword(material, "_DISABLE_DBUFFER", material.GetFloat(kSupportDBuffer) == 0.0);
CoreUtils.SetKeyword(material, "_ENABLE_GEOMETRIC_SPECULAR_AA", material.GetFloat(kEnableGeometricSpecularAA) == 1.0);
}
static public void SetupBaseLitMaterialPass(Material material)

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLit.shader


[ToggleUI] _DisplacementLockTilingScale("displacement lock tiling scale", Float) = 1.0
[ToggleUI] _DepthOffsetEnable("Depth Offset View space", Float) = 0.0
[ToggleUI] _EnableGeometricSpecularAA("EnableGeometricSpecularAA", Float) = 0.0
_SpecularAAScreenSpaceVariance("SpecularAAScreenSpaceVariance", Range(0.0, 1.0)) = 0.1
_SpecularAAThreshold("SpecularAAThreshold", Range(0.0, 1.0)) = 0.2
[ToggleUI] _EnableMotionVectorForVertexAnimation("EnableMotionVectorForVertexAnimation", Float) = 0.0
_PPDMinSamples("Min sample for POM", Range(1.0, 64.0)) = 5

#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS
#pragma shader_feature _DISABLE_DBUFFER
#pragma shader_feature _ENABLE_GEOMETRIC_SPECULAR_AA
// Keyword for transparent
#pragma shader_feature _SURFACE_TYPE_TRANSPARENT

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLitData.hlsl


surfaceData.metallic = 0;
}
#endif
#ifdef _ENABLE_GEOMETRIC_SPECULAR_AA
// Specular AA
surfaceData.perceptualSmoothness = GeometricFilterPerceptualSmoothness(surfaceData.perceptualSmoothness, input.worldToTangent[2], _SpecularAAScreenSpaceVariance, _SpecularAAThreshold);
#endif
GetBuiltinData(input, surfaceData, alpha, bentNormalWS, depthOffset, builtinData);
}

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/LayeredLit/LayeredLitTessellation.shader


[ToggleUI] _DisplacementLockTilingScale("displacement lock tiling scale", Float) = 1.0
[ToggleUI] _DepthOffsetEnable("Depth Offset View space", Float) = 0.0
[ToggleUI] _EnableGeometricSpecularAA("EnableGeometricSpecularAA", Float) = 0.0
_SpecularAAScreenSpaceVariance("SpecularAAScreenSpaceVariance", Range(0.0, 1.0)) = 0.1
_SpecularAAThreshold("SpecularAAThreshold", Range(0.0, 1.0)) = 0.2
[ToggleUI] _EnableMotionVectorForVertexAnimation("EnableMotionVectorForVertexAnimation", Float) = 0.0
_PPDMinSamples("Min sample for POM", Range(1.0, 64.0)) = 5

#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS
#pragma shader_feature _DISABLE_DBUFFER
#pragma shader_feature _ENABLE_GEOMETRIC_SPECULAR_AA
// Keyword for transparent
#pragma shader_feature _SURFACE_TYPE_TRANSPARENT

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.shader


[ToggleUI] _DisplacementLockTilingScale("displacement lock tiling scale", Float) = 1.0
[ToggleUI] _DepthOffsetEnable("Depth Offset View space", Float) = 0.0
[ToggleUI] _EnableGeometricSpecularAA("EnableGeometricSpecularAA", Float) = 0.0
_SpecularAAScreenSpaceVariance("SpecularAAScreenSpaceVariance", Range(0.0, 1.0)) = 0.1
_SpecularAAThreshold("SpecularAAThreshold", Range(0.0, 1.0)) = 0.2
[ToggleUI] _EnableMotionVectorForVertexAnimation("EnableMotionVectorForVertexAnimation", Float) = 0.0
_PPDMinSamples("Min sample for POM", Range(1.0, 64.0)) = 5

#pragma shader_feature _TRANSMITTANCECOLORMAP
#pragma shader_feature _DISABLE_DBUFFER
#pragma shader_feature _ENABLE_GEOMETRIC_SPECULAR_AA
// Keyword for transparent
#pragma shader_feature _SURFACE_TYPE_TRANSPARENT

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitData.hlsl


}
#endif
#ifdef _ENABLE_GEOMETRIC_SPECULAR_AA
// Specular AA
surfaceData.perceptualSmoothness = GeometricFilterPerceptualSmoothness(surfaceData.perceptualSmoothness, input.worldToTangent[2], _SpecularAAScreenSpaceVariance, _SpecularAAThreshold);
#endif
// Caution: surfaceData must be fully initialize before calling GetBuiltinData
GetBuiltinData(input, surfaceData, alpha, bentNormalWS, depthOffset, builtinData);
}

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitProperties.hlsl


float _ShiverDrag;
float _ShiverDirectionality;
// Specular AA
float _EnableGeometricSpecularAA;
float _SpecularAAScreenSpaceVariance;
float _SpecularAAThreshold;
#ifndef LAYERED_LIT_SHADER
// Set of users variables

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitTessellation.shader


[ToggleUI] _DisplacementLockTilingScale("displacement lock tiling scale", Float) = 1.0
[ToggleUI] _DepthOffsetEnable("Depth Offset View space", Float) = 0.0
[ToggleUI] _EnableGeometricSpecularAA("EnableGeometricSpecularAA", Float) = 0.0
_SpecularAAScreenSpaceVariance("SpecularAAScreenSpaceVariance", Range(0.0, 1.0)) = 0.1
_SpecularAAThreshold("SpecularAAThreshold", Range(0.0, 1.0)) = 0.2
[ToggleUI] _EnableMotionVectorForVertexAnimation("EnableMotionVectorForVertexAnimation", Float) = 0.0
_PPDMinSamples("Min sample for POM", Range(1.0, 64.0)) = 5

#pragma shader_feature _TRANSMITTANCECOLORMAP
#pragma shader_feature _DISABLE_DBUFFER
#pragma shader_feature _ENABLE_GEOMETRIC_SPECULAR_AA
// Keyword for transparent
#pragma shader_feature _SURFACE_TYPE_TRANSPARENT

正在加载...
取消
保存