浏览代码

HDRenderPipeline: Fix a lot of thing, tesselation work with lit shader but fail with layeredLit + planar and triplanr doesn't work

/main
sebastienlagarde 8 年前
当前提交
097f767c
共有 13 个文件被更改,包括 63 次插入68 次删除
  1. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl
  2. 22
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/UnlitData.hlsl
  3. 6
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl
  4. 5
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDebugViewMaterial.hlsl
  5. 5
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl
  6. 5
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDistortion.hlsl
  7. 5
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassForward.hlsl
  8. 5
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl
  9. 5
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl
  10. 16
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassVelocity.hlsl
  11. 20
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/TessellationShare.hlsl
  12. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl
  13. 23
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VertMesh.hlsl

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


// Mutually exclusive with _HEIGHT_BASED_BLEND
#if defined(_LAYER_MASK_VERTEX_COLOR_MUL) // Used when no layer mask is set
maskValues *= input.vertexColor.rgb;
maskValues *= input.color.rgb;
maskValues = saturate(maskValues + input.vertexColor.rgb * 2.0 - 1.0);
maskValues = saturate(maskValues + input.color.rgb * 2.0 - 1.0);
baseLayerHeight = ApplyHeightBasedBlend(maskValues.r, baseLayerHeight, height1, _HeightOffset1, _HeightFactor1, _BlendSize1, input.vertexColor.r);
baseLayerHeight = ApplyHeightBasedBlend(maskValues.g, baseLayerHeight, height2, _HeightOffset2 + _HeightOffset1, _HeightFactor2, _BlendSize2, input.vertexColor.g);
ApplyHeightBasedBlend(maskValues.b, baseLayerHeight, height3, _HeightOffset3 + _HeightOffset2 + _HeightOffset1, _HeightFactor3, _BlendSize3, input.vertexColor.b);
baseLayerHeight = ApplyHeightBasedBlend(maskValues.r, baseLayerHeight, height1, _HeightOffset1, _HeightFactor1, _BlendSize1, input.color.r);
baseLayerHeight = ApplyHeightBasedBlend(maskValues.g, baseLayerHeight, height2, _HeightOffset2 + _HeightOffset1, _HeightFactor2, _BlendSize2, input.color.g);
ApplyHeightBasedBlend(maskValues.b, baseLayerHeight, height3, _HeightOffset3 + _HeightOffset2 + _HeightOffset1, _HeightFactor3, _BlendSize3, input.color.b);
#endif
float weights[_MAX_LAYER];

22
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/UnlitData.hlsl


builtinData.depthOffset = 0.0;
}
#ifdef TESSELLATION_ON
float4 TessellationEdge(float3 p0, float3 p1, float3 p2, float3 n0, float3 n1, float3 n2)
{
return DistanceBasedTess(p0, p1, p2, 0.0, _TessellationFactorMaxDistance, unity_ObjectToWorld, _WorldSpaceCameraPos) * _TessellationFactorFixed.xxxx;
}
void Displacement(inout Attributes v)
{
#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
}
#endif

6
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl


float2 texCoord2;
float2 texCoord3;
float3 tangentToWorld[3];
float4 vertexColor;
float4 color; // vertex color
// For two sided lighting
bool isFrontFace;

result = input.tangentToWorld[2].xyz * 0.5 + 0.5;
break;
case DEBUGVIEWVARYING_VERTEX_COLOR:
result = input.vertexColor.rgb; needLinearToSRGB = true;
result = input.color.rgb; needLinearToSRGB = true;
result = input.vertexColor.aaa;
result = input.color.aaa;
break;
}
}

5
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDebugViewMaterial.hlsl


int _DebugViewMaterial;
#include "VertMesh.hlsl"
#include "TessellationShare.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh)
{

#ifdef TESSELLATION_ON
PackVaryingsToPS VertTesselation(VaryingsToDS input)
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
#include "TessellationShare.hlsl"
#endif // TESSELLATION_ON

5
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl


#endif
#include "VertMesh.hlsl"
#include "TessellationShare.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh)
{

#ifdef TESSELLATION_ON
PackVaryingsToPS VertTesselation(VaryingsToDS input)
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
#include "TessellationShare.hlsl"
#endif // TESSELLATION_ON

5
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDistortion.hlsl


#endif
#include "VertMesh.hlsl"
#include "TessellationShare.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh)
{

#ifdef TESSELLATION_ON
PackVaryingsToPS VertTesselation(VaryingsToDS input)
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
#include "TessellationShare.hlsl"
#endif // TESSELLATION_ON

5
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassForward.hlsl


#endif
#include "VertMesh.hlsl"
#include "TessellationShare.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh)
{

#ifdef TESSELLATION_ON
PackVaryingsToPS VertTesselation(VaryingsToDS input)
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
#include "TessellationShare.hlsl"
#endif // TESSELLATION_ON

5
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl


#endif
#include "VertMesh.hlsl"
#include "TessellationShare.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh)
{

#ifdef TESSELLATION_ON
PackVaryingsToPS VertTesselation(VaryingsToDS input)
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
#include "TessellationShare.hlsl"
#endif // TESSELLATION_ON

5
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl


#endif
#include "VertMesh.hlsl"
#include "TessellationShare.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh)
{

#ifdef TESSELLATION_ON
PackVaryingsToPS VertTesselation(VaryingsToDS input)
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
#include "TessellationShare.hlsl"
#endif // TESSELLATION_ON

16
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassVelocity.hlsl


VaryingsPassToDS InterpolateWithBaryCoordsPassToDS(VaryingsPassToDS input0, VaryingsPassToDS input1, VaryingsPassToDS input2, float3 baryCoords)
{
VaryingsPassToDS varyingsPass;
VaryingsPassToDS ouput;
TESSELLATION_INTERPOLATE_BARY(varyingsPass.positionCS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(varyingsPass.previousPositionCS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(positionCS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(previousPositionCS, baryCoords);
return ouput;
}

// We will use custom attributes for this pass
#define VARYINGS_NEED_PASS
#include "VertMesh.hlsl"
#include "TessellationShare.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh,
AttributesPass inputPass)

#ifdef TESSELLATION_ON
PackVaryingsToPS VertTesselation(VaryingsToDS input)
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
output.vpass.positionCS = input.vmesh.positionCS;
output.vpass.previousPositionCS = input.vmesh.previousPositionCS;
output.vpass.positionCS = input.vpass.positionCS;
output.vpass.previousPositionCS = input.vpass.previousPositionCS;
#include "TessellationShare.hlsl"
#endif // TESSELLATION_ON

20
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/TessellationShare.hlsl


#ifdef TESSELLATION_ON
struct TessellationFactors
{
float edge[3] : SV_TessFactor;

VaryingsToDS varying2 = UnpackVaryingsToDS(input[2]);
float4 tf = TessellationEdge( varying0.vmesh.positionWS, varying1.vmesh.positionWS, varying2.vmesh.positionWS,
varying0.vmesh.normalWS, varying1.vmesh.normalWS, varying2.vmesh.normalWS);
#ifdef VARYINGS_DS_NEED_NORMAL
varying0.vmesh.normalWS, varying1.vmesh.normalWS, varying2.vmesh.normalWS
#else
float3(0.0, 0.0, 1.0), float3(0.0, 0.0, 1.0), float3(0.0, 0.0, 1.0)
#endif
);
TessellationFactors ouput;
ouput.edge[0] = tf.x;

}
[domain("tri")]
PackedVaryings Domain(TessellationFactors tessFactors, const OutputPatch<PackedVaryingsToDS, 3> input, float3 baryCoords : SV_DomainLocation)
PackedVaryingsToPS Domain(TessellationFactors tessFactors, const OutputPatch<PackedVaryingsToDS, 3> input, float3 baryCoords : SV_DomainLocation)
VaryingsToDS varying = InterpolateWithBaryCoords(varying0, varying1, varying2, baryCoords);
VaryingsToDS varying = InterpolateWithBaryCoordsToDS(varying0, varying1, varying2, baryCoords);
varying.vmesh.positionWS = PhongTessellation( varying.positionWS,
varying.vmesh.positionWS = PhongTessellation( varying.vmesh.positionWS,
#ifdef VARYINGS_DS_NEED_NORMAL
#else
float3(0.0, 0.0, 1.0), float3(0.0, 0.0, 1.0), float3(0.0, 0.0, 1.0),
#endif
baryCoords, _TessellationShapeFactor);
#endif

return VertTesselation(varying);
}
#endif // TESSELLATION_ON

4
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl


output.texCoord3 = input.interpolators5.zw;
#endif
#ifdef VARYINGS_NEED_COLOR
output.vertexColor = input.interpolators6;
output.color = input.interpolators6;
#endif
#if defined(VARYINGS_NEED_CULLFACE) && SHADER_STAGE_FRAGMENT

#define VARYINGS_DS_NEED_TEXCOORD3
#endif
#if defined(VARYINGS_NEED_COLOR) || defined(ATTRIBUTES_NEED_COLOR)
float4 VARYINGS_DS_NEED_COLOR;
#define VARYINGS_DS_NEED_COLOR
#endif
// Varying for domain shader

23
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VertMesh.hlsl


#ifdef TESSELLATION_ON
struct VaryingsToDS
{
VaryingsMeshToDS vmesh;

struct PackedVaryingsToDS
{
PackedVaryingsToDS vmesh;
PackedVaryingsMeshToDS vmesh;
#ifdef VARYINGS_NEED_PASS
PackedVaryingsPassToDS vpass;
#endif

VaryingsToDS InterpolateWithBaryCoordsToDS(VaryingsToDS input0, VaryingsToDS input1, VaryingsToDS input2, float3 baryCoords)
{
VaryingsToDS ouput;
VaryingsToDS output;
ouput.vmesh = InterpolateWithBaryCoordsMeshToDS(input0.vmesh, input1.vmesh, input2.vmesh, baryCoords);
output.vmesh = InterpolateWithBaryCoordsMeshToDS(input0.vmesh, input1.vmesh, input2.vmesh, baryCoords);
ouput.vpass = InterpolateWithBaryCoordsPassToDS(input0.vpass, input1.vpass, input2.vpass, baryCoords);
output.vpass = InterpolateWithBaryCoordsPassToDS(input0.vpass, input1.vpass, input2.vpass, baryCoords);
#endif
return output;

#ifdef TESSELLATION_ON
VaryingMeshToPS VertMeshTesselation(VaryingMeshToDS input)
VaryingsMeshToPS VertMeshTesselation(VaryingsMeshToDS input)
VaryingMeshToPS output;
VaryingsMeshToPS output;
output.positionCS = TransformWorldToHClip(input.positionWS);
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD

#endif
#ifdef VARYINGS_NEED_TEXCOORD0
output.texCoord0 = input.uv0;
output.texCoord0 = input.texCoord0;
output.texCoord1 = input.uv1;
output.texCoord1 = input.texCoord1;
output.texCoord2 = input.uv2;
output.texCoord2 = input.texCoord2;
output.texCoord3 = input.uv3;
output.texCoord3 = input.texCoord3;
return output;
}
#endif // TESSELLATION_ON
正在加载...
取消
保存