浏览代码

HDRenderPipeline: Add Phong tesselation

/main
Sebastien Lagarde 8 年前
当前提交
8f97c56c
共有 12 个文件被更改,包括 199 次插入77 次删除
  1. 11
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs
  2. 15
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTesselation.shader
  3. 133
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs
  4. 14
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
  5. 7
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl
  6. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTesselation.hlsl
  7. 13
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader
  8. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDepthPass.hlsl
  9. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDistortionPass.hlsl
  10. 18
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitSharePass.hlsl
  11. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitVelocityPass.hlsl
  12. 31
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tesselation/TesselationShare.hlsl

11
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs


MaterialProperty layerEmissiveColor = null;
MaterialProperty layerEmissiveColorMap = null;
MaterialProperty layerEmissiveIntensity = null;
MaterialProperty layerTesselationFactor = null;
override protected void FindMaterialProperties(MaterialProperty[] props)
{

layerEmissiveColor = FindProperty(kEmissiveColor, props);
layerEmissiveColorMap = FindProperty(kEmissiveColorMap, props);
layerEmissiveIntensity = FindProperty(kEmissiveIntensity, props);
layerTesselationFactor = FindProperty(kTesselationFactor, props, false);
}
int numLayer

m_MaterialEditor.ShaderProperty(layerEmissiveIntensity, Styles.emissiveIntensityText);
m_MaterialEditor.LightmapEmissionProperty(1);
EditorGUI.indentLevel--;
if (layerTesselationFactor != null)
{
GUILayout.Label(Styles.tesselationText, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(layerTesselationFactor, Styles.tesselationFactorText);
EditorGUI.indentLevel--;
}
CheckLayerConsistency();

15
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTesselation.shader


[HideInInspector] _UVDetailsMappingMask1("_UVDetailsMappingMask1", Color) = (1, 0, 0, 0)
[HideInInspector] _UVDetailsMappingMask2("_UVDetailsMappingMask2", Color) = (1, 0, 0, 0)
[HideInInspector] _UVDetailsMappingMask3("_UVDetailsMappingMask3", Color) = (1, 0, 0, 0)
_TesselationFactor("Tesselation Factor", Float) = 3.0
[Enum(Phong, 0, Displacement, 1, DisplacementPhong, 2)] _TessellationMode("Tessellation mode", Float) = 1
_TessellationFactorFixed("Tessellation Factor", Float) = -1.0 // if != -1.0 force fixed factor
_TessellationFactorMaxDistance("Tessellation max distance factor", Float) = 12.0
_TessellationFactorTriangleSize("Tessellation triangle size", Float) = 20.0
_TessellationShapeFactor("Tessellation shape factor", Range(0.0, 1.0)) = 0.75 // Only use with Phong
_TessellationBackFaceCullEpsilon("Tessellation back face epsilon", Range(-1.0, 1.0)) = 0.25
[ToggleOff] _TessellationObjectScale("Tessellation object scale", Float) = 0.0
// TODO: Handle culling mode for backface culling
}
HLSLINCLUDE

#pragma shader_feature _DISTORTION_ON
#pragma shader_feature _DEPTHOFFSET_ON
#pragma shader_feature _ _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
// Default is _TESSELATION_PHONG
#pragma shader_feature _ _TESSELATION_DISPLACEMENT _TESSELATION_DISPLACEMENT_PHONG
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _LAYER_MAPPING_TRIPLANAR_0

#pragma shader_feature _DETAIL_MAP
#pragma shader_feature _ _LAYER_MASK_VERTEX_COLOR_MUL _LAYER_MASK_VERTEX_COLOR_ADD
#pragma shader_feature _HEIGHT_BASED_BLEND
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED

133
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs


{
protected static class Styles
{
public static string OptionText = "Options";
public static string SurfaceTypeText = "Surface Type";
public static string BlendModeText = "Blend Mode";
public static string optionText = "Options";
public static string surfaceTypeText = "Surface Type";
public static string blendModeText = "Blend Mode";
public static string detailText = "Inputs Detail";
public static string lightingText = "Inputs Lighting";

public static GUIContent emissiveWarning = new GUIContent("Emissive value is animated but the material has not been configured to support emissive. Please make sure the material itself has some amount of emissive.");
public static GUIContent emissiveColorWarning = new GUIContent("Ensure emissive color is non-black for emission to have effect.");
public static GUIContent tesselationText = new GUIContent("Tesselation options", "Tesselation options");
public static GUIContent tesselationFactorText = new GUIContent("Tesselation factor", "Tesselation factor");
public static string tessellationModeText = "Tesselation Mode";
public static readonly string[] tessellationModeNames = Enum.GetNames(typeof(TessellationMode));
public static GUIContent tessellationText = new GUIContent("Tessellation options", "Tessellation options");
public static GUIContent tessellationFactorFixedText = new GUIContent("Fixed tessellation factor", "If non negative, this value is a fixed tessellation factor use for tessellation");
public static GUIContent tessellationFactorMaxDistanceText = new GUIContent("Max Distance", "Maximun distance to the camera where triangle are tesselated");
public static GUIContent tessellationFactorTriangleSizeText = new GUIContent("Triangle size", "Desired screen space sized of triangle. Smaller value mean smaller triangle.");
public static GUIContent tessellationShapeFactorText = new GUIContent("Shape factor", "Strength of Phong tesselation shape (lerp factor)");
public static GUIContent tessellationBackFaceCullEpsilonText = new GUIContent("Triangle culling Epsilon", "If non zero, backface culling is enabled for tessellation, smaller number mean more aggressive culling and better performance");
public static GUIContent tessellationObjectScaleText = new GUIContent("Enable object scale", "Scale displacement taking into account the object scale");
}
public enum SurfaceType

}
public enum BlendMode
{
Lerp,

Premultiply
}
public enum DoubleSidedMode
{
None,

}
public enum TessellationMode
{
Phong,
Displacement,
DisplacementPhong,
}
void SurfaceTypePopup()
{
EditorGUI.showMixedValue = surfaceType.hasMixedValue;

mode = (SurfaceType)EditorGUILayout.Popup(Styles.SurfaceTypeText, (int)mode, Styles.surfaceTypeNames);
mode = (SurfaceType)EditorGUILayout.Popup(Styles.surfaceTypeText, (int)mode, Styles.surfaceTypeNames);
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo("Surface Type");

EditorGUI.showMixedValue = false;
}
void TessellationModePopup()
{
EditorGUI.showMixedValue = tessellationMode.hasMixedValue;
var mode = (TessellationMode)tessellationMode.floatValue;
EditorGUI.BeginChangeCheck();
mode = (TessellationMode)EditorGUILayout.Popup(Styles.tessellationModeText, (int)mode, Styles.tessellationModeNames);
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo("Tessellation Mode");
tessellationMode.floatValue = (float)mode;
}
EditorGUI.showMixedValue = false;
}
GUILayout.Label(Styles.OptionText, EditorStyles.boldLabel);
GUILayout.Label(Styles.optionText, EditorStyles.boldLabel);
SurfaceTypePopup();
if ((SurfaceType)surfaceType.floatValue == SurfaceType.Transparent)
{

m_MaterialEditor.ShaderProperty(depthOffsetEnable, Styles.depthOffsetEnableText.text);
EditorGUI.indentLevel--;
if (tessellationMode != null)
{
GUILayout.Label(Styles.tessellationText, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
TessellationModePopup();
m_MaterialEditor.ShaderProperty(tessellationFactorFixed, Styles.tessellationFactorFixedText);
m_MaterialEditor.ShaderProperty(tessellationFactorMaxDistance, Styles.tessellationFactorMaxDistanceText);
m_MaterialEditor.ShaderProperty(tessellationFactorTriangleSize, Styles.tessellationFactorTriangleSizeText);
if ((TessellationMode)tessellationMode.floatValue == TessellationMode.Phong ||
(TessellationMode)tessellationMode.floatValue == TessellationMode.DisplacementPhong)
{
m_MaterialEditor.ShaderProperty(tessellationShapeFactor, Styles.tessellationShapeFactorText);
}
m_MaterialEditor.ShaderProperty(tessellationBackFaceCullEpsilon, Styles.tessellationBackFaceCullEpsilonText);
m_MaterialEditor.ShaderProperty(tessellationObjectScale, Styles.tessellationObjectScaleText);
EditorGUI.indentLevel--;
}
}
private void BlendModePopup()

EditorGUI.BeginChangeCheck();
mode = (BlendMode)EditorGUILayout.Popup(Styles.BlendModeText, (int)mode, Styles.blendModeNames);
mode = (BlendMode)EditorGUILayout.Popup(Styles.blendModeText, (int)mode, Styles.blendModeNames);
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo("Blend Mode");

distortionOnly = FindProperty(kDistortionOnly, props);
distortionDepthTest = FindProperty(kDistortionDepthTest, props);
depthOffsetEnable = FindProperty(kDepthOffsetEnable, props);
// tessellation specific, silent if not found
tessellationMode = FindProperty(kTessellationMode, props, false);
tessellationFactorFixed = FindProperty(kTessellationFactorFixed, props, false);
tessellationFactorMaxDistance = FindProperty(kTessellationFactorMaxDistance, props, false);
tessellationFactorTriangleSize = FindProperty(kTessellationFactorTriangleSize, props, false);
tessellationShapeFactor = FindProperty(kTessellationShapeFactor, props, false);
tessellationBackFaceCullEpsilon = FindProperty(kTessellationBackFaceCullEpsilon, props, false);
tessellationObjectScale = FindProperty(kTessellationObjectScale, props, false);
}
protected void SetupCommonOptionsKeywords(Material material)

BlendMode blendMode = (BlendMode)material.GetFloat(kBlendMode);
DoubleSidedMode doubleSidedMode = (DoubleSidedMode)material.GetFloat(kDoubleSidedMode);
if (surfaceType == SurfaceType.Opaque)
{
material.SetOverrideTag("RenderType", alphaTestEnable ? "TransparentCutout" : "");

SetKeyword(material, "_DEPTHOFFSET_ON", depthOffsetEnable);
SetupEmissionGIFlags(material);
if (tessellationMode != null)
{
TessellationMode tessMode = (TessellationMode)material.GetFloat(kTessellationMode);
if (tessMode == TessellationMode.Phong)
{
material.DisableKeyword("_TESSELATION_DISPLACEMENT");
material.DisableKeyword("_TESSELATION_DISPLACEMENT_PHONG");
}
else if (tessMode == TessellationMode.Displacement)
{
material.EnableKeyword("_TESSELATION_DISPLACEMENT");
material.DisableKeyword("_TESSELATION_DISPLACEMENT_PHONG");
}
else
{
material.DisableKeyword("_TESSELATION_DISPLACEMENT");
material.EnableKeyword("_TESSELATION_DISPLACEMENT_PHONG");
}
}
}
protected void SetKeyword(Material m, string keyword, bool state)

protected MaterialEditor m_MaterialEditor;
MaterialProperty surfaceType = null;
const string kSurfaceType = "_SurfaceType";
const string kAlphaCutoffEnabled = "_AlphaCutoffEnable";
const string kBlendMode = "_BlendMode";
const string kAlphaCutoff = "_AlphaCutoff";
const string kDoubleSidedMode = "_DoubleSidedMode";
const string kDistortionEnable = "_DistortionEnable";
const string kDistortionOnly = "_DistortionOnly";
MaterialProperty depthOffsetEnable = null;
const string kSurfaceType = "_SurfaceType";
const string kBlendMode = "_BlendMode";
const string kAlphaCutoff = "_AlphaCutoff";
const string kAlphaCutoffEnabled = "_AlphaCutoffEnable";
const string kDoubleSidedMode = "_DoubleSidedMode";
const string kDistortionEnable = "_DistortionEnable";
const string kDistortionOnly = "_DistortionOnly";
MaterialProperty depthOffsetEnable = null;
// tessellation params
MaterialProperty tessellationMode = null;
const string kTessellationMode = "_TessellationMode";
MaterialProperty tessellationFactorFixed = null;
const string kTessellationFactorFixed = "_TessellationFactorFixed";
MaterialProperty tessellationFactorMaxDistance = null;
const string kTessellationFactorMaxDistance = "_TessellationFactorMaxDistance";
MaterialProperty tessellationFactorTriangleSize = null;
const string kTessellationFactorTriangleSize = "_TessellationFactorTriangleSize";
MaterialProperty tessellationShapeFactor = null;
const string kTessellationShapeFactor = "_TessellationShapeFactor";
MaterialProperty tessellationBackFaceCullEpsilon = null;
const string kTessellationBackFaceCullEpsilon = "_TessellationBackFaceCullEpsilon";
MaterialProperty tessellationObjectScale = null;
const string kTessellationObjectScale = "_TessellationObjectScale";
protected static string[] reservedProperties = new string[] { kSurfaceType, kBlendMode, kAlphaCutoff, kAlphaCutoffEnabled, kDoubleSidedMode };
protected abstract void FindMaterialProperties(MaterialProperty[] props);

14
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/LitUI.cs


protected MaterialProperty emissiveIntensity = null;
protected const string kEmissiveIntensity = "_EmissiveIntensity";
// tesselation params
protected MaterialProperty tesselationFactor = null;
protected const string kTesselationFactor = "_TesselationFactor";
// These are options that are shared with the LayeredLit shader. Don't put anything that can't be shared here:
// For instance, properties like BaseColor and such don't exist in the LayeredLit so don't put them here.

emissiveColor = FindProperty(kEmissiveColor, props);
emissiveColorMap = FindProperty(kEmissiveColorMap, props);
emissiveIntensity = FindProperty(kEmissiveIntensity, props);
// tesselation specific, don't care if not found
tesselationFactor = FindProperty(kTesselationFactor, props, false);
}
override protected void ShaderInputOptionsGUI()

EditorGUI.indentLevel--;
EditorGUILayout.Space();
if (tesselationFactor != null)
{
GUILayout.Label(Styles.tesselationText, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(tesselationFactor, Styles.tesselationFactorText);
EditorGUI.indentLevel--;
}
}
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)

7
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl


// Tesselation specific
#ifdef TESSELATION_ON
float _TesselationFactor;
float _TessellationFactorFixed;
float _TessellationFactorMaxDistance;
float _TessellationFactorTriangleSize;
float _TessellationShapeFactor;
float _TessellationBackFaceCullEpsilon;
float _TessellationObjectScale;
#endif

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTesselation.hlsl


// return UnityDistanceBasedTess(input0.positionOS, input1.positionOS, input2.positionOS, minDist, maxDist, 0.5 /* _Tess */, unity_ObjectToWorld, _WorldSpaceCameraPos);
return float4(_TesselationFactor, _TesselationFactor, _TesselationFactor, _TesselationFactor);
return float4(_TessellationFactorFixed, _TessellationFactorFixed, _TessellationFactorFixed, _TessellationFactorFixed);
}
void Displacement(inout Attributes v)

13
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader


[Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1
// Tesselation specific
_TesselationFactor("Tesselation Factor", Float) = 3.0
[Enum(Phong, 0, Displacement, 1, DisplacementPhong, 2)] _TessellationMode("Tessellation mode", Float) = 0
_TessellationFactorFixed("Tessellation Factor", Float) = -1.0 // if != -1.0 force fixed factor
_TessellationFactorMaxDistance("Tessellation max distance factor", Float) = 12.0
_TessellationFactorTriangleSize("Tessellation triangle size", Float) = 20.0
_TessellationShapeFactor("Tessellation shape factor", Range(0.0, 1.0)) = 0.75 // Only use with Phong
_TessellationBackFaceCullEpsilon("Tessellation back face epsilon", Range(-1.0, 1.0)) = 0.25
[ToggleOff] _TessellationObjectScale("Tessellation object scale", Float) = 0.0
// TODO: Handle culling mode for backface culling
}
HLSLINCLUDE

#pragma shader_feature _DISTORTION_ON
#pragma shader_feature _DEPTHOFFSET_ON
#pragma shader_feature _ _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
// Default is _TESSELATION_PHONG
#pragma shader_feature _ _TESSELATION_DISPLACEMENT _TESSELATION_DISPLACEMENT_PHONG
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _MAPPING_TRIPLANAR

#pragma shader_feature _HEIGHTMAP
#pragma shader_feature _TANGENTMAP
#pragma shader_feature _ANISOTROPYMAP
#pragma shader_feature _DETAIL_MAP
#pragma shader_feature _DETAIL_MAP
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED

10
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDepthPass.hlsl


return output;
}
AttributesTesselation InterpolateWithBary(AttributesTesselation input0, AttributesTesselation input1, AttributesTesselation input2, float3 baryWeight)
AttributesTesselation InterpolateWithBaryCoords(AttributesTesselation input0, AttributesTesselation input1, AttributesTesselation input2, float3 baryCoords)
TESSELATION_INTERPOLATE_BARY(positionOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(positionOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(uv0, baryWeight);
TESSELATION_INTERPOLATE_BARY(uv0, baryCoords);
TESSELATION_INTERPOLATE_BARY(normalOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(tangentOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(normalOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(tangentOS, baryCoords);
#endif
return ouput;

10
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDistortionPass.hlsl


return output;
}
AttributesTesselation InterpolateWithBary(AttributesTesselation input0, AttributesTesselation input1, AttributesTesselation input2, float3 baryWeight)
AttributesTesselation InterpolateWithBaryCoords(AttributesTesselation input0, AttributesTesselation input1, AttributesTesselation input2, float3 baryCoords)
TESSELATION_INTERPOLATE_BARY(positionOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(uv0, baryWeight);
TESSELATION_INTERPOLATE_BARY(positionOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(uv0, baryCoords);
TESSELATION_INTERPOLATE_BARY(normalOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(tangentOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(normalOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(tangentOS, baryCoords);
#endif
return ouput;

18
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitSharePass.hlsl


return output;
}
AttributesTesselation InterpolateWithBary(AttributesTesselation input0, AttributesTesselation input1, AttributesTesselation input2, float3 baryWeight)
AttributesTesselation InterpolateWithBaryCoords(AttributesTesselation input0, AttributesTesselation input1, AttributesTesselation input2, float3 baryCoords)
TESSELATION_INTERPOLATE_BARY(positionOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(normalOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(uv0, baryWeight);
TESSELATION_INTERPOLATE_BARY(uv1, baryWeight);
TESSELATION_INTERPOLATE_BARY(positionOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(normalOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(uv0, baryCoords);
TESSELATION_INTERPOLATE_BARY(uv1, baryCoords);
TESSELATION_INTERPOLATE_BARY(uv2, baryWeight);
TESSELATION_INTERPOLATE_BARY(uv2, baryCoords);
TESSELATION_INTERPOLATE_BARY(uv3, baryWeight);
TESSELATION_INTERPOLATE_BARY(uv3, baryCoords);
TESSELATION_INTERPOLATE_BARY(tangentOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(color, baryWeight);
TESSELATION_INTERPOLATE_BARY(tangentOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(color, baryCoords);
return ouput;
}

12
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitVelocityPass.hlsl


return output;
}
AttributesTesselation InterpolateWithBary(AttributesTesselation input0, AttributesTesselation input1, AttributesTesselation input2, float3 baryWeight)
AttributesTesselation InterpolateWithBaryCoords(AttributesTesselation input0, AttributesTesselation input1, AttributesTesselation input2, float3 baryCoords)
TESSELATION_INTERPOLATE_BARY(positionOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(previousPositionOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(positionOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(previousPositionOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(uv0, baryWeight);
TESSELATION_INTERPOLATE_BARY(uv0, baryCoords);
// TESSELATION_INTERPOLATE_BARY(normalOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(tangentOS, baryWeight);
// TESSELATION_INTERPOLATE_BARY(normalOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(tangentOS, baryCoords);
#endif
return ouput;

31
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tesselation/TesselationShare.hlsl


return input[id];
}
float3 ProjectPointOnPlane(float3 position, float3 planePosition, float3 planeNormal)
{
return position - (dot(position - planePosition, planeNormal) * planeNormal);
}
// p0, p1, p2 triangle world position
// p0, p1, p2 triangle world vertex normal
float3 PhongTessellation(float3 positionWS, float3 p0, float3 p1, float3 p2, float3 n0, float3 n1, float3 n2, float3 baryCoords, float shape)
{
float3 c0 = ProjectPointOnPlane(positionWS, p0, n0);
float3 c1 = ProjectPointOnPlane(positionWS, p1, n1);
float3 c2 = ProjectPointOnPlane(positionWS, p2, n2);
float3 phongPositionWS = baryCoords.x * c0 + baryCoords.y * c1 + baryCoords.z * c2;
return lerp(positionWS, phongPositionWS, shape);
}
PackedVaryings Domain(TessellationFactors tessFactors, const OutputPatch<AttributesTesselation, 3> input, float3 baryWeight : SV_DomainLocation)
PackedVaryings Domain(TessellationFactors tessFactors, const OutputPatch<AttributesTesselation, 3> input, float3 baryCoords : SV_DomainLocation)
Attributes params = InterpolateWithBary(input[0], input[1], input[2], baryWeight);
Attributes params = InterpolateWithBaryCoords(input[0], input[1], input[2], baryCoords);
#ifndef _TESSELATION_DISPLACEMENT // We have Phong tesselation in all case where we don't have only displacement
#if (SHADERPASS != SHADERPASS_VELOCITY) && (SHADERPASS != SHADERPASS_DISTORTION)
params.positionOS = PhongTessellation( params.positionOS,
input[0].positionOS, input[1].positionOS, input[2].positionOS,
input[0].normalOS, input[1].normalOS, input[2].normalOS,
baryCoords, _TessellationShapeFactor);
#endif
#endif
// perform displacement
Displacement(params);

正在加载...
取消
保存