浏览代码

HDRenderPipeline: Lot of change, still motion vector pass to fix

/main
Sebastien Lagarde 8 年前
当前提交
1c86fa3a
共有 10 个文件被更改,包括 175 次插入182 次删除
  1. 1
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitAttributesVarying.hlsl
  2. 77
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl
  3. 25
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
  4. 55
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl
  5. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader
  6. 35
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitVertexShare.hlsl
  7. 76
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitVelocityPass.hlsl
  8. 65
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tessellation/TessellationShare.hlsl
  9. 1
      Assets/ScriptableRenderLoop/ShaderLibrary/CommonMaterial.hlsl
  10. 10
      Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl

1
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitAttributesVarying.hlsl


TESSELLATION_INTERPOLATE_BARY(normalWS, baryCoords);
#endif
#ifdef VARYING_DS_WANT_TANGENT
// This will interpolate the sign but should be ok in practice as we may expect a triangle to have same sign (? TO CHECK)
TESSELLATION_INTERPOLATE_BARY(tangentWS, baryCoords);
#endif
#ifdef VARYING_DS_WANT_TEXCOORD0

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


}
}
float4 SampleLayerLod(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layerUV, float3 weights, float lod)
{
if (layerUV.isTriplanar)
{
float4 val = float4(0.0, 0.0, 0.0, 0.0);
if (weights.x > 0.0)
val += weights.x * SAMPLE_TEXTURE2D_LOD(layerTex, layerSampler, layerUV.uvYZ, lod);
if (weights.y > 0.0)
val += weights.y * SAMPLE_TEXTURE2D_LOD(layerTex, layerSampler, layerUV.uvZX, lod);
if (weights.z > 0.0)
val += weights.z * SAMPLE_TEXTURE2D_LOD(layerTex, layerSampler, layerUV.uvXY, lod);
return val;
}
else
{
return SAMPLE_TEXTURE2D_LOD(layerTex, layerSampler, layerUV.uv, lod);
}
}
// TODO: Handle BC5 format, currently this code is for DXT5nm
// THis function below must call UnpackNormalmapRGorAG
float3 SampleNormalLayer(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layerUV, float3 weights, float scale)

// Macro to improve readibility of surface data
#define SAMPLE_LAYER_TEXTURE2D(textureName, samplerName, coord) SampleLayer(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.weights)
#define SAMPLE_LAYER_TEXTURE2D_LOD(textureName, samplerName, coord, lod) SampleLayerLod(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.weights, lod)
#define SAMPLE_LAYER_NORMALMAP(textureName, samplerName, coord, scale) SampleNormalLayer(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.weights, scale)
#define SAMPLE_LAYER_NORMALMAP_AG(textureName, samplerName, coord, scale) SampleNormalLayerAG(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.weights, scale)
#define SAMPLE_LAYER_NORMALMAP_RGB(textureName, samplerName, coord, scale) SampleNormalLayerRGB(TEXTURE2D_PARAM(textureName, samplerName), coord, layerTexCoord.weights, scale)

#define ADD_IDX(Name) Name
#define ADD_ZERO_IDX(Name) Name
#include "LitDataInternal.hlsl"
#ifdef TESSELLATION_ON
#include "LitTessellation.hlsl"
#endif
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
void GetLayerTexCoord(float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3,
float3 positionWS, float3 normalWS, out LayerTexCoord layerTexCoord)
LayerTexCoord layerTexCoord;
layerTexCoord.weights = ComputeTriplanarWeights(input.tangentToWorld[2].xyz);
layerTexCoord.weights = ComputeTriplanarWeights(normalWS);
#endif
// Be sure that the compiler is aware that we don't touch UV1 to UV3 for base layer in case of non layer shader

#ifdef _MAPPING_TRIPLANAR
isTriplanar = true;
#endif
ComputeLayerTexCoord(input, isTriplanar, layerTexCoord);
ComputeLayerTexCoord( texCoord0, texCoord1, texCoord2, texCoord3,
positionWS, normalWS, isTriplanar, layerTexCoord);
}
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
{
LayerTexCoord layerTexCoord;
GetLayerTexCoord(input.texCoord0, input.texCoord1, input.texCoord2, input.texCoord3,
input.positionWS, input.tangentToWorld[2].xyz, layerTexCoord);
// Transform view vector in tangent space
float3 viewDirTS = TransformWorldToTangent(V, input.tangentToWorld);
ApplyDisplacement(input, viewDirTS, layerTexCoord);

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

#define SURFACEDATA_BLEND_SCALAR(surfaceData, name, mask) BlendLayeredScalar(surfaceData##0.##name, surfaceData##1.##name, surfaceData##2.##name, surfaceData##3.##name, mask);
#define PROP_BLEND_SCALAR(name, mask) BlendLayeredScalar(name##0, name##1, name##2, name##3, mask);
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
void GetLayerTexCoord(float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3,
float3 positionWS, float3 normalWS, out LayerTexCoord layerTexCoord)
LayerTexCoord layerTexCoord;
layerTexCoord.weights = ComputeTriplanarWeights(input.tangentToWorld[2].xyz);
layerTexCoord.weights = ComputeTriplanarWeights(normalWS);
#endif
bool isTriplanar = false;

ComputeLayerTexCoord0(input, isTriplanar, layerTexCoord);
ComputeLayerTexCoord0( texCoord0, texCoord1, texCoord2, texCoord3,
positionWS, normalWS, isTriplanar, layerTexCoord);
ComputeLayerTexCoord1(input, isTriplanar, layerTexCoord);
ComputeLayerTexCoord1( texCoord0, texCoord1, texCoord2, texCoord3,
positionWS, normalWS, isTriplanar, layerTexCoord);
ComputeLayerTexCoord2(input, isTriplanar, layerTexCoord);
ComputeLayerTexCoord2( texCoord0, texCoord1, texCoord2, texCoord3,
positionWS, normalWS, isTriplanar, layerTexCoord);
ComputeLayerTexCoord3(input, isTriplanar, layerTexCoord);
ComputeLayerTexCoord3( texCoord0, texCoord1, texCoord2, texCoord3,
positionWS, normalWS, isTriplanar, layerTexCoord);
}
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
{
LayerTexCoord layerTexCoord;
GetLayerTexCoord(input.texCoord0, input.texCoord1, input.texCoord2, input.texCoord3,
input.positionWS, input.tangentToWorld[2].xyz, layerTexCoord);
// Transform view vector in tangent space
float3 viewDirTS = TransformWorldToTangent(V, input.tangentToWorld);

}
#endif // #ifndef LAYERED_LIT_SHADER
#ifdef TESSELLATION_ON
#include "LitTessellation.hlsl" // Must be after GetLayerTexCoord() declaration
#endif

25
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl


void ADD_IDX(ComputeLayerTexCoord)(FragInputs input, bool isTriplanar, inout LayerTexCoord layerTexCoord)
void ADD_IDX(ComputeLayerTexCoord)( float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3,
float3 positionWS, float3 normalWS, bool isTriplanar, inout LayerTexCoord layerTexCoord)
float2 uvBase = ADD_IDX(_UVMappingMask).x * input.texCoord0 +
ADD_IDX(_UVMappingMask).y * input.texCoord1 +
ADD_IDX(_UVMappingMask).z * input.texCoord2 +
ADD_IDX(_UVMappingMask).w * input.texCoord3;
float2 uvBase = ADD_IDX(_UVMappingMask).x * texCoord0 +
ADD_IDX(_UVMappingMask).y * texCoord1 +
ADD_IDX(_UVMappingMask).z * texCoord2 +
ADD_IDX(_UVMappingMask).w * texCoord3;
float2 uvDetails = ADD_IDX(_UVDetailsMappingMask).x * input.texCoord0 +
ADD_IDX(_UVDetailsMappingMask).y * input.texCoord1 +
ADD_IDX(_UVDetailsMappingMask).z * input.texCoord2 +
ADD_IDX(_UVDetailsMappingMask).w * input.texCoord3;
float2 uvDetails = ADD_IDX(_UVDetailsMappingMask).x * texCoord0 +
ADD_IDX(_UVDetailsMappingMask).y * texCoord1 +
ADD_IDX(_UVDetailsMappingMask).z * texCoord2 +
ADD_IDX(_UVDetailsMappingMask).w * texCoord3;
//float3 position = localTriplanar ? TransformWorldToObject(input.positionWS) : input.positionWS;
float3 position = input.positionWS;
//float3 position = localTriplanar ? TransformWorldToObject(positionWS) : positionWS;
float3 position = positionWS;
position *= ADD_IDX(_TexWorldScale);
if (ADD_IDX(_UVMappingPlanar) > 0.0)

// triplanar
ADD_IDX(layerTexCoord.base).isTriplanar = isTriplanar;
float3 direction = sign(input.tangentToWorld[2].xyz);
float3 direction = sign(normalWS);
// In triplanar, if we are facing away from the world axis, a different axis will be flipped for each direction.
// This is particularly problematic for tangent space normal maps which need to be in the right direction.

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


/*
float _Tess;
float _TessNear;
float _TessFar;
float _UseDisplacementfalloff;
float _DisplacementfalloffNear;
float _DisplacementfalloffFar;
*/
float4 TessellationEdge(float3 p0, float3 p1, float3 p2, float3 n0, float3 n1, float3 n2)
{
// if (_TessellationFactorFixed >= 0.0f)

return DistanceBasedTess(p0, p1, p2, 0.0, _TessellationFactorMaxDistance, unity_ObjectToWorld, _WorldSpaceCameraPos) * _TessellationFactorFixed.xxxx;
return DistanceBasedTess(p0, p1, p2, 0.0, _TessellationFactorMaxDistance, _WorldSpaceCameraPos) * _TessellationFactorFixed.xxxx;
void Displacement(inout Attributes v)
float3 GetDisplacement(VaryingsDS input)
/*
float LengthLerp = length(ObjSpaceViewDir(v.vertex));
LengthLerp -= _DisplacementfalloffNear;
LengthLerp /= _DisplacementfalloffFar - _DisplacementfalloffNear;
LengthLerp = 1 - (saturate(LengthLerp));
// This call will work for both LayeredLit and Lit shader
LayerTexCoord layerTexCoord;
GetLayerTexCoord(
#ifdef VARYING_DS_WANT_TEXCOORD0
input.texCoord0,
#else
float2(0.0, 0.0),
#endif
#ifdef VARYING_DS_WANT_TEXCOORD1
input.texCoord1,
#else
float2(0.0, 0.0),
#endif
#ifdef VARYING_DS_WANT_TEXCOORD2
input.texCoord2,
#else
float2(0.0, 0.0),
#endif
#ifdef VARYING_DS_WANT_TEXCOORD3
input.texCoord3,
#else
float2(0.0, 0.0),
#endif
input.positionWS,
input.normalWS,
layerTexCoord);
float d = ((tex2Dlod(_DispTex, float4(v.texcoord.xy * _Tiling, 0, 0)).r) - _DisplacementCenter) * (_Displacement * LengthLerp);
d /= max(0.0001, _Tiling);
*/
// TODO: For now just use Layer0, but we are suppose to apply the same heightmap blending than in the pixel shader
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);
float height = (SAMPLE_LAYER_TEXTURE2D_LOD(ADD_ZERO_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), ADD_ZERO_IDX(layerTexCoord.base), 0).r - ADD_ZERO_IDX(_HeightCenter)) * ADD_ZERO_IDX(_HeightAmplitude);
#if (SHADERPASS != SHADERPASS_VELOCITY) && (SHADERPASS != SHADERPASS_DISTORTION)
v.positionOS.xyz += height * v.normalOS;
#endif
return input.positionWS + height * input.normalWS;
}

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


#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl"
// All our shaders use same name for entry point
#pragma vertex Vert
#pragma fragment Frag
ENDHLSL

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

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

// both direct and indirect lighting) will hand up in the "regular" lightmap->LIGHTMAP_ON.
// No tessellation for Meta pass
#pragma vertex Vert
#define SHADERPASS SHADERPASS_LIGHT_TRANSPORT
#include "../../Material/Material.hlsl"

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

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

HLSLPROGRAM
#pragma vertex VertTessellation
#pragma hull Hull
#pragma domain Domain
// TODO: Tesselation can't work with velocity for now...
#define SHADERPASS SHADERPASS_VELOCITY
#include "../../Material/Material.hlsl"

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

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

35
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitVertexShare.hlsl


return PackVaryingsType(output);
}
#ifdef TESSELLATION_ON
PackedVaryings VertTesselation(VaryingDS input)
{
VaryingsType output;
output.positionCS = TransformWorldToHClip(input.positionWS);
#ifdef VARYING_WANT_TANGENT_TO_WORLD
float3x3 tangentToWorld = CreateTangentToWorld(input.normalWS, input.tangentWS.xyz, input.tangentWS.w);
output.tangentToWorld[0] = tangentToWorld[0];
output.tangentToWorld[1] = tangentToWorld[1];
output.tangentToWorld[2] = tangentToWorld[2];
#endif
#ifdef VARYING_WANT_TEXCOORD0
output.texCoord0 = input.uv0;
#endif
#ifdef VARYING_WANT_TEXCOORD1
output.texCoord1 = input.uv1;
#endif
#ifdef VARYING_WANT_TEXCOORD2
output.texCoord2 = input.uv2;
#endif
#ifdef VARYING_WANT_TEXCOORD3
output.texCoord3 = input.uv3;
#endif
#ifdef VARYING_WANT_COLOR
output.color = input.color;
#endif
return PackVaryingsType(output);
}
#endif // TESSELLATION_ON

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


#endif
// TODO: For now disable per pixel and per vertex displacement mapping with motion vector
// as vertex normal is not available
#define ATTRIBUTES_WANT_PREVIOUS_POSITION
#ifdef ATTRIBUTES_WANT_PREVIOUS_POSITION
float3 previousPositionOS : NORMAL; // Caution : Currently use same semantic than normal, so conflict for tesselation...
#endif
// as vertex normal is not available + force UV0 for alpha test (not compatible with layered system...)
#ifdef TESSELLATION_ON
// Copy paste of above struct with POSITION rename to INTERNALTESSPOS (internal of unity shader compiler)
struct AttributesTessellation
struct Attributes
float3 positionOS : INTERNALTESSPOS;
float3 previousPositionOS : NORMAL;
#if NEED_TEXCOORD0
float3 positionOS : POSITION;
float3 previousPositionOS : NORMAL; // Contain previous transform position (in case of skinning for example)
#endif
#if NEED_TANGENT_TO_WORLD
// float3 normalOS : NORMAL;
float4 tangentOS : TANGENT;
#endif
AttributesTessellation AttributesToAttributesTessellation(Attributes input)
{
AttributesTessellation output;
output.positionOS = input.positionOS;
output.previousPositionOS = input.previousPositionOS;
#if NEED_TEXCOORD0
output.uv0 = input.uv0;
#endif
#if NEED_TANGENT_TO_WORLD
// output.normalOS = input.normalOS;
output.tangentOS = input.tangentOS;
#endif
return output;
}
Attributes AttributesTessellationToAttributes(AttributesTessellation input)
{
Attributes output;
output.positionOS = input.positionOS;
output.previousPositionOS = input.previousPositionOS;
#if NEED_TEXCOORD0
output.uv0 = input.uv0;
#endif
#if NEED_TANGENT_TO_WORLD
// output.normalOS = input.normalOS;
output.tangentOS = input.tangentOS;
#endif
return output;
}
AttributesTessellation InterpolateWithBaryCoords(AttributesTessellation input0, AttributesTessellation input1, AttributesTessellation input2, float3 baryCoords)
{
AttributesTessellation ouput;
TESSELLATION_INTERPOLATE_BARY(positionOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(previousPositionOS, baryCoords);
#if NEED_TEXCOORD0
TESSELLATION_INTERPOLATE_BARY(uv0, baryCoords);
#endif
#if NEED_TANGENT_TO_WORLD
// TESSELLATION_INTERPOLATE_BARY(normalOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(tangentOS, baryCoords);
#endif
return ouput;
}
#endif // TESSELLATION_ON
struct Varyings
{
float4 positionCS;

float4 transferPreviousPositionCS;
#if NEED_TEXCOORD0
#endif
#if NEED_TANGENT_TO_WORLD
float3 tangentToWorld[3];
#endif
};
struct PackedVaryings

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


AttributesTessellation VertTessellation(Attributes input)
{
return AttributesToAttributesTessellation(input);
}
struct TessellationFactors
{
float edge[3] : SV_TessFactor;

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);
TessellationFactors HullConstant(InputPatch<PackedVaryingsDS, 3> input)
{
VaryingsDS varyingDS0 = UnpackVaryingsDS(input[0]);
VaryingsDS varyingDS1 = UnpackVaryingsDS(input[1]);
VaryingsDS varyingDS2 = UnpackVaryingsDS(input[2]);
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
float4 tf = TessellationEdge( varyingDS0.positionWS, varyingDS1.positionWS, varyingDS2.positionWS,
varyingDS0.normalWS, varyingDS1.normalWS, varyingDS2.normalWS);
TessellationFactors ouput;
ouput.edge[0] = tf.x;

[outputtopology("triangle_cw")]
[patchconstantfunc("HullConstant")]
[outputcontrolpoints(3)]
AttributesTessellation Hull(InputPatch<AttributesTessellation, 3> input, uint id : SV_OutputControlPointID)
PackedVaryingsDS Hull(InputPatch<PackedVaryingsDS, 3> input, uint id : SV_OutputControlPointID)
// Pass-through
PackedVaryings Domain(TessellationFactors tessFactors, const OutputPatch<AttributesTessellation, 3> input, float3 baryCoords : SV_DomainLocation)
PackedVaryings Domain(TessellationFactors tessFactors, const OutputPatch<PackedVaryingsDS, 3> input, float3 baryCoords : SV_DomainLocation)
Attributes params = InterpolateWithBaryCoords(input[0], input[1], input[2], baryCoords);
VaryingsDS varyingDS0 = UnpackVaryingsDS(input[0]);
VaryingsDS varyingDS1 = UnpackVaryingsDS(input[1]);
VaryingsDS varyingDS2 = UnpackVaryingsDS(input[2]);
#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
VaryingsDS varyingDS = InterpolateWithBaryCoords(varyingDS0, varyingDS1, varyingDS2, baryCoords);
// We have Phong tessellation in all case where we don't have displacement only
#ifndef _TESSELLATION_DISPLACEMENT
varyingDS.positionWS = PhongTessellation( varyingDS.positionWS,
varyingDS0.positionWS, varyingDS1.positionWS, varyingDS2.positionWS,
varyingDS0.normalWS, varyingDS1.normalWS, varyingDS2.normalWS,
baryCoords, _TessellationShapeFactor);
// perform displacement
Displacement(params);
varyingDS.positionWS = GetDisplacement(varyingDS);
// Evaluate regular vertex shader
PackedVaryings outout = Vert(params);
// Evaluate part of the vertex shader not done
PackedVaryings outout = VertTesselation(varyingDS);
return outout;
}

1
Assets/ScriptableRenderLoop/ShaderLibrary/CommonMaterial.hlsl


float3 ComputeTriplanarWeights(float3 normal)
{
// Determine the blend weights for the 3 planar projections.
// N_orig is the vertex-interpolated normal vector.
float3 blendWeights = abs(normal);
// Tighten up the blending zone
blendWeights = (blendWeights - 0.2) * 7.0;

10
Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl


}
// ---- utility functions
float CalcDistanceTessFactor(float3 positionWS, float minDist, float maxDist, float4x4 objectToWorld, float3 cameraPosWS)
float CalcDistanceTessFactor(float3 positionWS, float minDist, float maxDist, float3 cameraPosWS)
{
float dist = distance(positionWS, cameraPosWS);
float f = clamp(1.0 - (dist - minDist) / (maxDist - minDist), 0.01, 1.0);

// Distance based tessellation:
// Tessellation level is "tess" before "minDist" from camera, and linearly decreases to 1
// up to "maxDist" from camera.
float4 DistanceBasedTess(float3 p0, float3 p1, float3 p2, float minDist, float maxDist, float4x4 objectToWorld, float3 cameraPosWS)
float4 DistanceBasedTess(float3 p0, float3 p1, float3 p2, float minDist, float maxDist, float3 cameraPosWS)
f.x = CalcDistanceTessFactor(p0, minDist, maxDist, objectToWorld, cameraPosWS);
f.y = CalcDistanceTessFactor(p1, minDist, maxDist, objectToWorld, cameraPosWS);
f.z = CalcDistanceTessFactor(p2, minDist, maxDist, objectToWorld, cameraPosWS);
f.x = CalcDistanceTessFactor(p0, minDist, maxDist, cameraPosWS);
f.y = CalcDistanceTessFactor(p1, minDist, maxDist, cameraPosWS);
f.z = CalcDistanceTessFactor(p2, minDist, maxDist, cameraPosWS);
return UnityCalcTriEdgeTessFactors(f);
}

正在加载...
取消
保存