浏览代码

HDRenderPipeline: Big renaming Tesselation => Tessellation

/main
Sebastien Lagarde 8 年前
当前提交
83594dd2
共有 21 个文件被更改,包括 230 次插入132 次删除
  1. 16
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs
  2. 8
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl
  3. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl
  4. 42
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader
  5. 28
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDepthPass.hlsl
  6. 24
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDistortionPass.hlsl
  7. 32
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitSharePass.hlsl
  8. 26
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitVelocityPass.hlsl
  9. 20
      Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl
  10. 43
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl
  11. 78
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tessellation/TessellationShare.hlsl
  12. 41
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTesselation.hlsl
  13. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  14. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader.meta
  15. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl.meta
  16. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tessellation.meta
  17. 0
      /Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl.meta
  18. 0
      /Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl
  19. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tessellation/TessellationShare.hlsl.meta

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


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 string tessellationModeText = "Tesselation Mode";
public static string tessellationModeText = "Tessellation Mode";
public static readonly string[] tessellationModeNames = Enum.GetNames(typeof(TessellationMode));
public static GUIContent tessellationText = new GUIContent("Tessellation options", "Tessellation options");

public static GUIContent tessellationShapeFactorText = new GUIContent("Shape factor", "Strength of Phong tesselation shape (lerp factor)");
public static GUIContent tessellationShapeFactorText = new GUIContent("Shape factor", "Strength of Phong tessellation 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");
}

if (tessMode == TessellationMode.Phong)
{
material.DisableKeyword("_TESSELATION_DISPLACEMENT");
material.DisableKeyword("_TESSELATION_DISPLACEMENT_PHONG");
material.DisableKeyword("_TESSELLATION_DISPLACEMENT");
material.DisableKeyword("_TESSELLATION_DISPLACEMENT_PHONG");
material.EnableKeyword("_TESSELATION_DISPLACEMENT");
material.DisableKeyword("_TESSELATION_DISPLACEMENT_PHONG");
material.EnableKeyword("_TESSELLATION_DISPLACEMENT");
material.DisableKeyword("_TESSELLATION_DISPLACEMENT_PHONG");
material.DisableKeyword("_TESSELATION_DISPLACEMENT");
material.EnableKeyword("_TESSELATION_DISPLACEMENT_PHONG");
material.DisableKeyword("_TESSELLATION_DISPLACEMENT");
material.EnableKeyword("_TESSELLATION_DISPLACEMENT_PHONG");
}
}
}

8
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl


#define ADD_IDX(Name) Name
#define ADD_ZERO_IDX(Name) Name
#include "LitDataInternal.hlsl"
#ifdef TESSELATION_ON
#include "LitTesselation.hlsl"
#ifdef TESSELLATION_ON
#include "LitTessellation.hlsl"
#endif
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)

#define LAYER_INDEX 0
#define ADD_IDX(Name) Name##0
#include "LitDataInternal.hlsl"
#ifdef TESSELATION_ON
#include "LitTesselation.hlsl" // Include only one time for layer 0
#ifdef TESSELLATION_ON
#include "LitTessellation.hlsl" // Include only one time for layer 0
#endif
#undef LAYER_INDEX
#undef ADD_IDX

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


#endif // LAYERED_LIT_SHADER
// Tesselation specific
// Tessellation specific
#ifdef TESSELATION_ON
#ifdef TESSELLATION_ON
float _TessellationFactorFixed;
float _TessellationFactorMaxDistance;
float _TessellationFactorTriangleSize;

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


Shader "HDRenderPipeline/LitTesselation"
Shader "HDRenderPipeline/LitTessellation"
{
Properties
{

[HideInInspector] _UVDetailsMappingMask("_UVDetailsMappingMask", Color) = (1, 0, 0, 0)
[Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1
// Tesselation specific
// Tessellation specific
[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

#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
// Default is _TESSELLATION_PHONG
#pragma shader_feature _ _TESSELLATION_DISPLACEMENT _TESSELLATION_DISPLACEMENT_PHONG
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _MAPPING_TRIPLANAR

//-------------------------------------------------------------------------------------
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#define TESSELATION_ON
#define TESSELLATION_ON
//-------------------------------------------------------------------------------------
// Include

#include "tesselation.hlsl"
#include "tessellation.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl"

HLSLPROGRAM
#pragma vertex VertTesselation
#pragma vertex VertTessellation
#pragma hull Hull
#pragma domain Domain

#include "LitData.hlsl"
#include "../Tesselation/TesselationShare.hlsl"
#include "../Tessellation/TessellationShare.hlsl"
#include "../../ShaderPass/ShaderPassGBuffer.hlsl"

HLSLPROGRAM
#pragma vertex VertTesselation
#pragma vertex VertTessellation
#pragma hull Hull
#pragma domain Domain

#include "LitData.hlsl"
#include "../Tesselation/TesselationShare.hlsl"
#include "../Tessellation/TessellationShare.hlsl"
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl"

// DYNAMICLIGHTMAP_ON is used when we have an "enlighten lightmap" ie a lightmap updated at runtime by enlighten.This lightmap contain indirect lighting from realtime lights and realtime emissive material.Offline baked lighting(from baked material / light,
// both direct and indirect lighting) will hand up in the "regular" lightmap->LIGHTMAP_ON.
// No tesselation for Meta pass
// No tessellation for Meta pass
#pragma vertex Vert
#define SHADERPASS SHADERPASS_LIGHT_TRANSPORT

HLSLPROGRAM
#pragma vertex VertTesselation
#pragma vertex VertTessellation
#pragma hull Hull
#pragma domain Domain

#include "LitData.hlsl"
#include "../Tesselation/TesselationShare.hlsl"
#include "../Tessellation/TessellationShare.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"

HLSLPROGRAM
#pragma vertex VertTesselation
#pragma vertex VertTessellation
#pragma hull Hull
#pragma domain Domain

#include "LitData.hlsl"
#include "../Tesselation/TesselationShare.hlsl"
#include "../Tessellation/TessellationShare.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"

HLSLPROGRAM
#pragma vertex VertTesselation
#pragma vertex VertTessellation
#pragma hull Hull
#pragma domain Domain

#include "LitData.hlsl"
#include "../Tesselation/TesselationShare.hlsl"
#include "../Tessellation/TessellationShare.hlsl"
#include "../../ShaderPass/ShaderPassVelocity.hlsl"

HLSLPROGRAM
#pragma vertex VertTesselation
#pragma vertex VertTessellation
#pragma hull Hull
#pragma domain Domain

#include "LitData.hlsl"
#include "../Tesselation/TesselationShare.hlsl"
#include "../Tessellation/TessellationShare.hlsl"
#include "../../ShaderPass/ShaderPassDistortion.hlsl"

HLSLPROGRAM
#pragma vertex VertTesselation
#pragma vertex VertTessellation
#pragma hull Hull
#pragma domain Domain

#include "../../Lighting/Lighting.hlsl"
#include "ShaderPass/LitSharePass.hlsl"
#include "LitData.hlsl"
#include "../Tesselation/TesselationShare.hlsl"
#include "../Tessellation/TessellationShare.hlsl"
#include "../../ShaderPass/ShaderPassForward.hlsl"

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


// Check if Alpha test is enabled. If it is, check if parallax is enabled on this material
#define NEED_TEXCOORD0 1 // defined(_ALPHATEST_ON)
#define NEED_TANGENT_TO_WORLD 1 // NEED_TEXCOORD0 && (defined(_HEIGHTMAP) && defined(_PER_PIXEL_DISPLACEMENT)) TEMP!!!: until we fix tesselation so it can access normalOS
#define NEED_TANGENT_TO_WORLD 1 // NEED_TEXCOORD0 && (defined(_HEIGHTMAP) && defined(_PER_PIXEL_DISPLACEMENT)) TEMP!!!: until we fix tessellation so it can access normalOS
// When modifying this structure, update the tesselation code below
// When modifying this structure, update the tessellation code below
struct Attributes
{
float3 positionOS : POSITION;

#endif
};
#ifdef TESSELATION_ON
#ifdef TESSELLATION_ON
struct AttributesTesselation
struct AttributesTessellation
{
float3 positionOS : INTERNALTESSPOS;
#if NEED_TEXCOORD0

#endif
};
AttributesTesselation AttributesToAttributesTesselation(Attributes input)
AttributesTessellation AttributesToAttributesTessellation(Attributes input)
AttributesTesselation output;
AttributesTessellation output;
output.positionOS = input.positionOS;
#if NEED_TEXCOORD0
output.uv0 = input.uv0;

return output;
}
Attributes AttributesTesselationToAttributes(AttributesTesselation input)
Attributes AttributesTessellationToAttributes(AttributesTessellation input)
{
Attributes output;
output.positionOS = input.positionOS;

return output;
}
AttributesTesselation InterpolateWithBaryCoords(AttributesTesselation input0, AttributesTesselation input1, AttributesTesselation input2, float3 baryCoords)
AttributesTessellation InterpolateWithBaryCoords(AttributesTessellation input0, AttributesTessellation input1, AttributesTessellation input2, float3 baryCoords)
AttributesTesselation ouput;
AttributesTessellation ouput;
TESSELATION_INTERPOLATE_BARY(positionOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(positionOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(uv0, baryCoords);
TESSELLATION_INTERPOLATE_BARY(uv0, baryCoords);
TESSELATION_INTERPOLATE_BARY(normalOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(tangentOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(normalOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(tangentOS, baryCoords);
#endif // TESSELATION_ON
#endif // TESSELLATION_ON
struct Varyings
{

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


#endif
};
#ifdef TESSELATION_ON
#ifdef TESSELLATION_ON
struct AttributesTesselation
struct AttributesTessellation
{
float3 positionOS : INTERNALTESSPOS;
float2 uv0 : TEXCOORD0;

#endif
};
AttributesTesselation AttributesToAttributesTesselation(Attributes input)
AttributesTessellation AttributesToAttributesTessellation(Attributes input)
AttributesTesselation output;
AttributesTessellation output;
output.positionOS = input.positionOS;
output.uv0 = input.uv0;
#if NEED_TANGENT_TO_WORLD

return output;
}
Attributes AttributesTesselationToAttributes(AttributesTesselation input)
Attributes AttributesTessellationToAttributes(AttributesTessellation input)
{
Attributes output;
output.positionOS = input.positionOS;

return output;
}
AttributesTesselation InterpolateWithBaryCoords(AttributesTesselation input0, AttributesTesselation input1, AttributesTesselation input2, float3 baryCoords)
AttributesTessellation InterpolateWithBaryCoords(AttributesTessellation input0, AttributesTessellation input1, AttributesTessellation input2, float3 baryCoords)
AttributesTesselation ouput;
AttributesTessellation ouput;
TESSELATION_INTERPOLATE_BARY(positionOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(uv0, baryCoords);
TESSELLATION_INTERPOLATE_BARY(positionOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(uv0, baryCoords);
TESSELATION_INTERPOLATE_BARY(normalOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(tangentOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(normalOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(tangentOS, baryCoords);
#endif // TESSELATION_ON
#endif // TESSELLATION_ON
struct Varyings
{

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


// UNITY_INSTANCE_ID
};
#ifdef TESSELATION_ON
#ifdef TESSELLATION_ON
struct AttributesTesselation
struct AttributesTessellation
{
float3 positionOS : INTERNALTESSPOS;
float3 normalOS : NORMAL;

float4 color : COLOR;
};
AttributesTesselation AttributesToAttributesTesselation(Attributes input)
AttributesTessellation AttributesToAttributesTessellation(Attributes input)
AttributesTesselation output;
AttributesTessellation output;
output.positionOS = input.positionOS;
output.normalOS = input.normalOS;
output.uv0 = input.uv0;

return output;
}
Attributes AttributesTesselationToAttributes(AttributesTesselation input)
Attributes AttributesTessellationToAttributes(AttributesTessellation input)
{
Attributes output;
output.positionOS = input.positionOS;

return output;
}
AttributesTesselation InterpolateWithBaryCoords(AttributesTesselation input0, AttributesTesselation input1, AttributesTesselation input2, float3 baryCoords)
AttributesTessellation InterpolateWithBaryCoords(AttributesTessellation input0, AttributesTessellation input1, AttributesTessellation input2, float3 baryCoords)
AttributesTesselation ouput;
AttributesTessellation ouput;
TESSELATION_INTERPOLATE_BARY(positionOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(normalOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(uv0, baryCoords);
TESSELATION_INTERPOLATE_BARY(uv1, baryCoords);
TESSELLATION_INTERPOLATE_BARY(positionOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(normalOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(uv0, baryCoords);
TESSELLATION_INTERPOLATE_BARY(uv1, baryCoords);
TESSELATION_INTERPOLATE_BARY(uv2, baryCoords);
TESSELLATION_INTERPOLATE_BARY(uv2, baryCoords);
TESSELATION_INTERPOLATE_BARY(uv3, baryCoords);
TESSELLATION_INTERPOLATE_BARY(uv3, baryCoords);
TESSELATION_INTERPOLATE_BARY(tangentOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(color, baryCoords);
TESSELLATION_INTERPOLATE_BARY(tangentOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(color, baryCoords);
#endif // TESSELATION_ON
#endif // TESSELLATION_ON
struct Varyings

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


#endif
};
#ifdef TESSELATION_ON
#ifdef TESSELLATION_ON
struct AttributesTesselation
struct AttributesTessellation
{
float3 positionOS : INTERNALTESSPOS;
float3 previousPositionOS : NORMAL;

#endif
};
AttributesTesselation AttributesToAttributesTesselation(Attributes input)
AttributesTessellation AttributesToAttributesTessellation(Attributes input)
AttributesTesselation output;
AttributesTessellation output;
output.positionOS = input.positionOS;
output.previousPositionOS = input.previousPositionOS;
#if NEED_TEXCOORD0

return output;
}
Attributes AttributesTesselationToAttributes(AttributesTesselation input)
Attributes AttributesTessellationToAttributes(AttributesTessellation input)
{
Attributes output;
output.positionOS = input.positionOS;

return output;
}
AttributesTesselation InterpolateWithBaryCoords(AttributesTesselation input0, AttributesTesselation input1, AttributesTesselation input2, float3 baryCoords)
AttributesTessellation InterpolateWithBaryCoords(AttributesTessellation input0, AttributesTessellation input1, AttributesTessellation input2, float3 baryCoords)
AttributesTesselation ouput;
AttributesTessellation ouput;
TESSELATION_INTERPOLATE_BARY(positionOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(previousPositionOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(positionOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(previousPositionOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(uv0, baryCoords);
TESSELLATION_INTERPOLATE_BARY(uv0, baryCoords);
// TESSELATION_INTERPOLATE_BARY(normalOS, baryCoords);
TESSELATION_INTERPOLATE_BARY(tangentOS, baryCoords);
// TESSELLATION_INTERPOLATE_BARY(normalOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(tangentOS, baryCoords);
#endif // TESSELATION_ON
#endif // TESSELLATION_ON
struct Varyings
{

20
Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl


#define TESSELATION_INTERPOLATE_BARY(name, bary) ouput.name = input0.name * bary.x + input1.name * bary.y + input2.name * bary.z
#define TESSELLATION_INTERPOLATE_BARY(name, bary) ouput.name = input0.name * bary.x + input1.name * bary.y + input2.name * bary.z
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);
}
// ---- utility functions
float UnityCalcDistanceTessFactor(float3 positionOS, float minDist, float maxDist, float tess, float4x4 objectToWorld, float3 cameraPosWS)

43
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl


/*
float _Tess;
float _TessNear;
float _TessFar;
float _UseDisplacementfalloff;
float _DisplacementfalloffNear;
float _DisplacementfalloffFar;
*/
float4 TesselationEdge(float3 p0, float3 p1, float3 p2, float3 n0, float3 n1, float3 n2)
{
if (_TessellationFactorFixed >= 0.0f)
{
return _TessellationFactorFixed.xxxx;
}
return _TessellationFactorFixed.xxxx;
// return UnityDistanceBasedTess(input0.positionOS, input1.positionOS, input2.positionOS, minDist, maxDist, 0.5 /* _Tess */, unity_ObjectToWorld, _WorldSpaceCameraPos);
}
void Displacement(inout Attributes v)
{
/*
float LengthLerp = length(ObjSpaceViewDir(v.vertex));
LengthLerp -= _DisplacementfalloffNear;
LengthLerp /= _DisplacementfalloffFar - _DisplacementfalloffNear;
LengthLerp = 1 - (saturate(LengthLerp));
float d = ((tex2Dlod(_DispTex, float4(v.texcoord.xy * _Tiling, 0, 0)).r) - _DisplacementCenter) * (_Displacement * LengthLerp);
d /= max(0.0001, _Tiling);
*/
#ifdef _HEIGHTMAP
float height = (SAMPLE_TEXTURE2D_LOD(ADD_ZERO_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), v.uv0, 0).r - ADD_ZERO_IDX(_HeightCenter)) * ADD_IDX(_HeightAmplitude);
#else
float height = 0.0;
#endif
#if (SHADERPASS != SHADERPASS_VELOCITY) && (SHADERPASS != SHADERPASS_DISTORTION)
v.positionOS.xyz += height * v.normalOS;
#endif
}

78
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tessellation/TessellationShare.hlsl


AttributesTessellation VertTessellation(Attributes input)
{
return AttributesToAttributesTessellation(input);
}
struct TessellationFactors
{
float edge[3] : SV_TessFactor;
float inside : SV_InsideTessFactor;
};
TessellationFactors HullConstant(InputPatch<AttributesTessellation, 3> input)
{
Attributes params[3];
params[0] = AttributesTessellationToAttributes(input[0]);
params[1] = AttributesTessellationToAttributes(input[1]);
params[2] = AttributesTessellationToAttributes(input[2]);
#if (SHADERPASS != SHADERPASS_VELOCITY) && (SHADERPASS != SHADERPASS_DISTORTION)
// TEMP: We will provide world position but for now convert to world position here
float3 p0 = TransformObjectToWorld(input[0].positionOS);
float3 n0 = TransformObjectToWorldNormal(input[0].normalOS);
float3 p1 = TransformObjectToWorld(input[1].positionOS);
float3 n1 = TransformObjectToWorldNormal(input[1].normalOS);
float3 p2 = TransformObjectToWorld(input[2].positionOS);
float3 n2 = TransformObjectToWorldNormal(input[2].normalOS);
float4 tf = TessellationEdge(p0, p1, p2, n0, n1, n2);
#else
float4 tf = float4(0.0, 0.0, 0.0, 0.0);
#endif
TessellationFactors ouput;
ouput.edge[0] = tf.x;
ouput.edge[1] = tf.y;
ouput.edge[2] = tf.z;
ouput.inside = tf.w;
return ouput;
}
[maxtessfactor(15.0)] // AMD recommand this value for GCN http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/05/GCNPerformanceTweets.pdf
[domain("tri")]
[partitioning("fractional_odd")]
[outputtopology("triangle_cw")]
[patchconstantfunc("HullConstant")]
[outputcontrolpoints(3)]
AttributesTessellation Hull(InputPatch<AttributesTessellation, 3> input, uint id : SV_OutputControlPointID)
{
return input[id];
}
[domain("tri")]
PackedVaryings Domain(TessellationFactors tessFactors, const OutputPatch<AttributesTessellation, 3> input, float3 baryCoords : SV_DomainLocation)
{
Attributes params = InterpolateWithBaryCoords(input[0], input[1], input[2], baryCoords);
#ifndef _TESSELLATION_DISPLACEMENT // We have Phong tessellation 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);
// Evaluate regular vertex shader
PackedVaryings outout = Vert(params);
return outout;
}

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


/*
float _Tess;
float _TessNear;
float _TessFar;
float _UseDisplacementfalloff;
float _DisplacementfalloffNear;
float _DisplacementfalloffFar;
*/
float4 TesselationEdge(Attributes input0, Attributes input1, Attributes input2)
{
// float minDist = 0; // _TessNear;
// float maxDist = 15; // _TessFar;
// return UnityDistanceBasedTess(input0.positionOS, input1.positionOS, input2.positionOS, minDist, maxDist, 0.5 /* _Tess */, unity_ObjectToWorld, _WorldSpaceCameraPos);
return float4(_TessellationFactorFixed, _TessellationFactorFixed, _TessellationFactorFixed, _TessellationFactorFixed);
}
void Displacement(inout Attributes v)
{
/*
float LengthLerp = length(ObjSpaceViewDir(v.vertex));
LengthLerp -= _DisplacementfalloffNear;
LengthLerp /= _DisplacementfalloffFar - _DisplacementfalloffNear;
LengthLerp = 1 - (saturate(LengthLerp));
float d = ((tex2Dlod(_DispTex, float4(v.texcoord.xy * _Tiling, 0, 0)).r) - _DisplacementCenter) * (_Displacement * LengthLerp);
d /= max(0.0001, _Tiling);
*/
#ifdef _HEIGHTMAP
float height = (SAMPLE_TEXTURE2D_LOD(ADD_ZERO_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), v.uv0, 0).r - ADD_ZERO_IDX(_HeightCenter)) * ADD_IDX(_HeightAmplitude);
#else
float height = 0.0;
#endif
#if (SHADERPASS != SHADERPASS_VELOCITY) && (SHADERPASS != SHADERPASS_DISTORTION)
v.positionOS.xyz += height * v.normalOS;
#endif
}

/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTesselation.shader → /Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader

/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTesselation.shader.meta → /Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader.meta

/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTesselation.hlsl.meta → /Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl.meta

/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tesselation.meta → /Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tessellation.meta

/Assets/ScriptableRenderLoop/ShaderLibrary/Tesselation.hlsl.meta → /Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl.meta

/Assets/ScriptableRenderLoop/ShaderLibrary/Tesselation.hlsl → /Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl

/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tesselation/TesselationShare.hlsl.meta → /Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tessellation/TessellationShare.hlsl.meta

正在加载...
取消
保存