浏览代码

HDRenderPipeline: Second part of modification still not compiling/working

/main
Sebastien Lagarde 8 年前
当前提交
fd23a655
共有 15 个文件被更改,包括 205 次插入461 次删除
  1. 37
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs
  2. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
  3. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  4. 24
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
  5. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader
  6. 52
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitAttributesVarying.hlsl
  7. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader
  8. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitVertexShare.hlsl
  9. 22
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDepthPass.hlsl
  10. 174
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDistortionPass.hlsl
  11. 52
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitMetaPass.hlsl
  12. 250
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitSharePass.hlsl
  13. 20
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitVelocityPass.hlsl
  14. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitAttributesVarying.hlsl.meta
  15. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitVertexShare.hlsl.meta

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


}
// We have to check for each layer if the UV2 or UV3 is needed.
bool UV2orUV3needed = false;
bool needUV3 = false;
bool needUV2 = false;
if (
((UVDetailMapping)material.GetFloat(uvDetail) == UVDetailMapping.UV2) ||
((LayerUVBaseMapping)material.GetFloat(uvBase) == LayerUVBaseMapping.UV2) ||
((UVDetailMapping)material.GetFloat(uvDetail) == UVDetailMapping.UV3) ||
((LayerUVBaseMapping)material.GetFloat(uvBase) == LayerUVBaseMapping.UV3)
)
if ( ((UVDetailMapping)material.GetFloat(uvDetail) == UVDetailMapping.UV2) ||
((LayerUVBaseMapping)material.GetFloat(uvBase) == LayerUVBaseMapping.UV2) )
{
needUV2 = true;
}
if ( ((UVDetailMapping)material.GetFloat(uvDetail) == UVDetailMapping.UV3) ||
((LayerUVBaseMapping)material.GetFloat(uvBase) == LayerUVBaseMapping.UV3) )
UV2orUV3needed = true;
break;
needUV3 = true;
break; // If we find it UV3 let's early out
SetKeyword(material, "_REQUIRE_UV2_OR_UV3", UV2orUV3needed);
if (needUV3)
{
material.DisableKeyword("_REQUIRE_UV2");
material.EnableKeyword("_REQUIRE_UV3");
}
else if (needUV2)
{
material.EnableKeyword("_REQUIRE_UV2");
material.DisableKeyword("_REQUIRE_UV3");
}
else
{
material.DisableKeyword("_REQUIRE_UV2");
material.DisableKeyword("_REQUIRE_UV3");
}
}
void SetupLayersKeywords(Material material)

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader


#pragma shader_feature _DETAIL_MAP_WITH_NORMAL
#pragma shader_feature _NORMALMAP_TANGENT_SPACE
#pragma shader_feature _PER_PIXEL_DISPLACEMENT
#pragma shader_feature _REQUIRE_UV2_OR_UV3
#pragma shader_feature _ _REQUIRE_UV2 _REQUIRE_UV3
#pragma shader_feature _EMISSIVE_COLOR
#pragma shader_feature _NORMALMAP

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader


#pragma shader_feature _DETAIL_MAP_WITH_NORMAL
#pragma shader_feature _NORMALMAP_TANGENT_SPACE
#pragma shader_feature _PER_PIXEL_DISPLACEMENT
#pragma shader_feature _REQUIRE_UV2_OR_UV3
#pragma shader_feature _ _REQUIRE_UV2 _REQUIRE_UV3
#pragma shader_feature _EMISSIVE_COLOR
#pragma shader_feature _NORMALMAP

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


SetKeyword(material, "_ANISOTROPYMAP", material.GetTexture(kAnisotropyMap));
SetKeyword(material, "_DETAIL_MAP", material.GetTexture(kDetailMap));
SetKeyword(material, "_REQUIRE_UV2_OR_UV3", (
((UVDetailMapping)material.GetFloat(kUVDetail) == UVDetailMapping.UV2 || (UVDetailMapping)material.GetFloat(kUVDetail) == UVDetailMapping.UV3)
&& (UVBaseMapping)material.GetFloat(kUVBase) == UVBaseMapping.UV0)
);
}
bool needUV2 = (UVDetailMapping)material.GetFloat(kUVDetail) == UVDetailMapping.UV2 && (UVBaseMapping)material.GetFloat(kUVBase) == UVBaseMapping.UV0);
bool needUV3 = (UVDetailMapping)material.GetFloat(kUVDetail) == UVDetailMapping.UV3 && (UVBaseMapping)material.GetFloat(kUVBase) == UVBaseMapping.UV0);
if (needUV3)
{
material.DisableKeyword("_REQUIRE_UV2");
material.EnableKeyword("_REQUIRE_UV3");
}
else if (needUV2)
{
material.EnableKeyword("_REQUIRE_UV2");
material.DisableKeyword("_REQUIRE_UV3");
}
else
{
material.DisableKeyword("_REQUIRE_UV2");
material.DisableKeyword("_REQUIRE_UV3");
}
}
}
} // namespace UnityEditor

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader


#pragma shader_feature _DETAIL_MAP_WITH_NORMAL
#pragma shader_feature _NORMALMAP_TANGENT_SPACE
#pragma shader_feature _PER_PIXEL_DISPLACEMENT
#pragma shader_feature _REQUIRE_UV2_OR_UV3
#pragma shader_feature _ _REQUIRE_UV2 _REQUIRE_UV3
#pragma shader_feature _EMISSIVE_COLOR
#pragma shader_feature _NORMALMAP

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


#ifdef ATTRIBUTES_WANT_NORMAL
float3 normalOS : NORMAL;
#endif
#ifdef ATTRIBUTES_WANT_TANGENT_TO_WORLD
#ifdef ATTRIBUTES_WANT_TANGENT
float4 tangentOS : TANGENT; // Store sign in w
#endif
#ifdef ATTRIBUTES_WANT_UV0

#ifdef VARYING_WANT_COLOR
float4 interpolators6 : TEXCOORD6;
#endif
#if defined(VARYING_WANT_CULLFACE) && SHADER_STAGE_FRAGMENT
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMATIC;
#endif
};
// Functions to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions

output.color = input.interpolators6;
#endif
#if defined(VARYING_WANT_CULLFACE) && SHADER_STAGE_FRAGMENT
output.isFrontFace = IS_FRONT_VFACE(input.cullFace, true, false);
#endif
return output;
}

// We need to pass to DS any varying required by pixel shader
// If we have required an attribute it mean we will use it at least for DS
#ifdef VARYING_WANT_TANGENT_TO_WORLD
#define VARYING_DS_WANT_TANGENT_TO_WORLD
#define VARYING_DS_WANT_NORMAL
#define VARYING_DS_WANT_TANGENT
#endif
#if defined(VARYING_WANT_TEXCOORD0) || defined(ATTRIBUTES_WANT_UV0)
#define VARYING_DS_WANT_TEXCOORD0

#if defined(VARYING_WANT_COLOR) || defined(ATTRIBUTES_WANT_COLOR)
float4 VARYING_DS_WANT_COLOR;
#endif
#endif
#endif // TESSELLATION_ON
// Varying for domain shader
// Position and normal are always present (for tessellation) and in world space

#ifdef VARYING_DS_WANT_NORMAL
#ifdef VARYING_DS_WANT_TANGENT_TO_WORLD
#endif
#ifdef VARYING_DS_WANT_TANGENT
float4 tangentWS;
#endif
#ifdef VARYING_DS_WANT_TEXCOORD0

struct PackedVaryingsDS
{
float3 interpolators0 : TEXCOORD0; // positionWS
float3 interpolators1 : TEXCOORD1; // normalWS
float3 interpolators0 : INTERNALTESSPOS; // positionWS
#ifdef VARYING_DS_WANT_TANGENT_TO_WORLD
float4 interpolators2 : TEXCOORD2;
#ifdef VARYING_DS_WANT_NORMAL
float3 interpolators1 : NORMAL;
#endif
#ifdef VARYING_DS_WANT_TANGENT
float4 interpolators2 : TANGENT;
float4 interpolators3 : TEXCOORD3;
float4 interpolators3 : TEXCOORD0;
float2 interpolators3 : TEXCOORD3;
float2 interpolators3 : TEXCOORD0;
float4 interpolators4 : TEXCOORD4;
float4 interpolators4 : TEXCOORD1;
float2 interpolators4 : TEXCOORD4;
float2 interpolators4 : TEXCOORD1;
float4 interpolators5 : TEXCOORD5;
float4 interpolators5 : TEXCOORD2;
#endif
};

PackedVaryingsDS output;
output.interpolators0 = input.positionWS;
#ifdef VARYING_DS_WANT_NORMAL
#ifdef VARYING_DS_WANT_TANGENT_TO_WORLD
#endif
#ifdef VARYING_DS_WANT_TANGENT
output.interpolators2 = input.tangentWS;
#endif
#ifdef VARYING_DS_WANT_TEXCOORD0

VaryingsDS output;
output.positionWS = input.interpolators0;
#ifdef VARYING_DS_WANT_NORMAL
#ifdef VARYING_DS_WANT_TANGENT_TO_WORLD
#endif
#ifdef VARYING_DS_WANT_TANGENT
output.tangentWS = input.interpolators2;
#endif
#ifdef VARYING_DS_WANT_TEXCOORD0

VaryingsDS ouput;
TESSELLATION_INTERPOLATE_BARY(positionWS, baryCoords);
#ifdef VARYING_DS_WANT_NORMAL
#ifdef VARYING_DS_WANT_TANGENT_TO_WORLD
#endif
#ifdef VARYING_DS_WANT_TANGENT
TESSELLATION_INTERPOLATE_BARY(tangentWS, baryCoords);
#endif
#ifdef VARYING_DS_WANT_TEXCOORD0

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


#pragma shader_feature _DETAIL_MAP_WITH_NORMAL
#pragma shader_feature _NORMALMAP_TANGENT_SPACE
#pragma shader_feature _PER_PIXEL_DISPLACEMENT
#pragma shader_feature _REQUIRE_UV2_OR_UV3
#pragma shader_feature _ _REQUIRE_UV2 _REQUIRE_UV3
#pragma shader_feature _EMISSIVE_COLOR
#pragma shader_feature _NORMALMAP

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


// TODO: Here we will also have all the vertex deformation (GPU skinning, vertex animation, morph target...) or we will need to generate a compute shaders instead (better! but require work to deal with unpacking like fp16)
PackedVaryingsType Vert(Attributes input)
{
VaryingsType output;

// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix)
#if defined(VARYING_DS_WANT_TANGENT_TO_WORLD) || defined(VARYING_DS_WANT_NORMAL)
#if defined(VARYING_DS_WANT_TANGENT_TO_WORLD) || defined(VARYING_WANT_TANGENT_TO_WORLD)
#endif
#if defined(VARYING_DS_WANT_TANGENT_TO_WORLD) || defined(VARYING_DS_WANT_TANGENT)
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix)
output.positionCS = TransformWorldToHClip(positionWS);
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix)
output.positionCS = TransformWorldToHClip(positionWS);
#ifdef VARYING_WANT_TANGENT_TO_WORLD
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);

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


#endif
// Attributes
#define ATTRIBUTES_TESSELATION_WANT_UV (defined(TESSELLATION_ON) && (defined(_TESSELATION_DISPLACEMENT) || defined(_TESSELATION_DISPLACEMENT_PHONG)))
#define REQUIRE_UV_FOR_TESSELATION (defined(TESSELLATION_ON) && (defined(_TESSELATION_DISPLACEMENT) || defined(_TESSELATION_DISPLACEMENT_PHONG)))
#define REQUIRE_TANGENT_TO_WORLD (defined(_HEIGHTMAP) && defined(_PER_PIXEL_DISPLACEMENT))
#if defined(TESSELLATION_ON) || (defined(_HEIGHTMAP) && defined(_PER_PIXEL_DISPLACEMENT))
// Tesselation require normal
#if defined(TESSELLATION_ON) || REQUIRE_TANGENT_TO_WORLD
#if defined(_HEIGHTMAP) && defined(_PER_PIXEL_DISPLACEMENT)
#if REQUIRE_TANGENT_TO_WORLD
#define ATTRIBUTES_WANT_TANGENT
#endif
// About UV

#if ATTRIBUTES_TESSELATION_WANT_UV || (defined(_HEIGHTMAP) && defined(_PER_PIXEL_DISPLACEMENT)) || defined(_ALPHATEST_ON)
#if REQUIRE_UV_FOR_TESSELATION || REQUIRE_TANGENT_TO_WORLD || defined(_ALPHATEST_ON)
#ifdef _REQUIRE_UV2_OR_UV3
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3)
#endif
#if defined(_REQUIRE_UV3)
#define ATTRIBUTES_WANT_UV3
#endif
#endif

#if defined(_HEIGHTMAP) && defined(_PER_PIXEL_DISPLACEMENT)
#if REQUIRE_TANGENT_TO_WORLD
#if defined(_HEIGHTMAP) && defined(_PER_PIXEL_DISPLACEMENT) || defined(_ALPHATEST_ON)
#if REQUIRE_TANGENT_TO_WORLD || defined(_ALPHATEST_ON)
#ifdef _REQUIRE_UV2_OR_UV3
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3)
#endif
#if defined(_REQUIRE_UV3)
#define VARYING_WANT_TEXCOORD3
#endif
#endif

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


#error Undefine_SHADERPASS
#endif
#define NEED_TANGENT_TO_WORLD NEED_TEXCOORD0 && (defined(_HEIGHTMAP) && defined(_PER_PIXEL_DISPLACEMENT))
struct Attributes
{
float3 positionOS : POSITION;
float2 uv0 : TEXCOORD0;
#if NEED_TANGENT_TO_WORLD
float3 normalOS : NORMAL;
float4 tangentOS : TANGENT;
#endif
};
// Attributes
#define REQUIRE_UV_FOR_TESSELATION (defined(TESSELLATION_ON) && (defined(_TESSELATION_DISPLACEMENT) || defined(_TESSELATION_DISPLACEMENT_PHONG)))
#define REQUIRE_TANGENT_TO_WORLD (defined(_HEIGHTMAP) && defined(_PER_PIXEL_DISPLACEMENT))
#ifdef TESSELLATION_ON
// Copy paste of above struct with POSITION rename to INTERNALTESSPOS (internal of unity shader compiler)
struct AttributesTessellation
{
float3 positionOS : INTERNALTESSPOS;
float2 uv0 : TEXCOORD0;
#if NEED_TANGENT_TO_WORLD
float3 normalOS : NORMAL;
float4 tangentOS : TANGENT;
// Tesselation require normal
#if defined(TESSELLATION_ON) || REQUIRE_TANGENT_TO_WORLD
#define ATTRIBUTES_WANT_NORMAL
};
AttributesTessellation AttributesToAttributesTessellation(Attributes input)
{
AttributesTessellation output;
output.positionOS = input.positionOS;
output.uv0 = input.uv0;
#if NEED_TANGENT_TO_WORLD
output.normalOS = input.normalOS;
output.tangentOS = input.tangentOS;
#if REQUIRE_TANGENT_TO_WORLD
#define ATTRIBUTES_WANT_TANGENT
return output;
}
Attributes AttributesTessellationToAttributes(AttributesTessellation input)
{
Attributes output;
output.positionOS = input.positionOS;
output.uv0 = input.uv0;
#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(uv0, baryCoords);
#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;
float3 positionWS;
float2 texCoord0;
#if NEED_TANGENT_TO_WORLD
float3 tangentToWorld[3];
#endif
};
struct PackedVaryings
{
float4 positionCS : SV_Position;
#if NEED_TANGENT_TO_WORLD
float4 interpolators[4] : TEXCOORD0;
#else
float4 interpolators[2] : TEXCOORD0;
// About UV
// If we have a lit shader, only the UV0 is available for opacity or heightmap
// If we have a layered shader, any UV can be use for this. To reduce the number of variant we groupt UV0/UV1 and UV2/UV3 instead of having variant for UV0/UV1/UV2/UV3
// When UVX is present, we assume that UVX - 1 ... UV0 is present
#if REQUIRE_UV_FOR_TESSELATION || REQUIRE_TANGENT_TO_WORLD || defined(_ALPHATEST_ON) || defined(_DISTORTION_ON)
#define ATTRIBUTES_WANT_UV0
#ifdef LAYERED_LIT_SHADER
#define ATTRIBUTES_WANT_UV1
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3)
#define ATTRIBUTES_WANT_UV2
#endif
#if defined(_REQUIRE_UV3)
#define ATTRIBUTES_WANT_UV3
#endif
#endif
};
// Function to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions
PackedVaryings PackVaryings(Varyings input)
{
PackedVaryings output;
output.positionCS = input.positionCS;
output.interpolators[0] = float4(input.positionWS, 0.0);
output.interpolators[0].w = input.texCoord0.x;
output.interpolators[1] = float4(0.0, 0.0, 0.0, input.texCoord0.y);
#if NEED_TANGENT_TO_WORLD
output.interpolators[1].xyz = input.tangentToWorld[0];
output.interpolators[2].xyz = input.tangentToWorld[1];
output.interpolators[3].xyz = input.tangentToWorld[2];
// Varying - Use for pixel shader
#if REQUIRE_TANGENT_TO_WORLD
#define VARYING_WANT_TANGENT_TO_WORLD
return output;
}
FragInputs UnpackVaryings(PackedVaryings input)
{
FragInputs output;
ZERO_INITIALIZE(FragInputs, output);
output.unPositionSS = input.positionCS; // input.positionCS is SV_Position
output.positionWS = input.interpolators[0].xyz;
#if NEED_TANGENT_TO_WORLD
output.texCoord0.xy = float2(input.interpolators[0].w, input.interpolators[1].w);
output.tangentToWorld[0] = input.interpolators[1].xyz;
output.tangentToWorld[1] = input.interpolators[2].xyz;
output.tangentToWorld[2] = input.interpolators[3].xyz;
#if REQUIRE_TANGENT_TO_WORLD || defined(_ALPHATEST_ON) || defined(_DISTORTION_ON)
#define VARYING_WANT_TEXCOORD0
#ifdef LAYERED_LIT_SHADER
#define VARYING_WANT_TEXCOORD1
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3)
#define VARYING_WANT_TEXCOORD2
#endif
#if defined(_REQUIRE_UV3)
#define VARYING_WANT_TEXCOORD3
#endif
#endif
return output;
}
// Varying DS - Use for domain shader, are deduced from the above
PackedVaryings Vert(Attributes input)
{
Varyings output;
// Include structure declaration and packing functions
#include "LitAttributesVarying.hlsl"
output.positionWS = TransformObjectToWorld(input.positionOS);
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix)
output.positionCS = TransformWorldToHClip(output.positionWS);
output.texCoord0 = input.uv0;
#if NEED_TANGENT_TO_WORLD
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w);
output.tangentToWorld[0] = tangentToWorld[0];
output.tangentToWorld[1] = tangentToWorld[1];
output.tangentToWorld[2] = tangentToWorld[2];
#endif
return PackVaryings(output);
}
#include "LitVertexShare.hlsl"

52
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitMetaPass.hlsl


#ifndef SHADERPASS
#error Undefine_SHADERPASS
#endif
CBUFFER_START(UnityMetaPass)
// x = use uv1 as raster position
// y = use uv2 as raster position

// y = return normal
bool4 unity_MetaFragmentControl;
CBUFFER_END
// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency

struct Attributes
{
float3 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
};
struct Varyings
{
float4 positionCS;
float2 texCoord0;
float2 texCoord1;
};
struct PackedVaryings
{
float4 positionCS : SV_Position;
float4 interpolators[1] : TEXCOORD0;
};
// Function to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions
PackedVaryings PackVaryings(Varyings input)
{
PackedVaryings output;
output.positionCS = input.positionCS;
output.interpolators[0].xy = input.texCoord0;
output.interpolators[0].zw = input.texCoord1;
return output;
}
FragInputs UnpackVaryings(PackedVaryings input)
{
FragInputs output;
ZERO_INITIALIZE(FragInputs, output);
#define ATTRIBUTES_WANT_NORMAL
#define ATTRIBUTES_WANT_UV0
#define ATTRIBUTES_WANT_UV1
#define ATTRIBUTES_WANT_UV2
output.unPositionSS = input.positionCS; // input.positionCS is SV_Position
output.texCoord0 = input.interpolators[0].xy;
output.texCoord1 = input.interpolators[0].zw;
#define VARYING_WANT_TEXCOORD0
#define VARYING_WANT_TEXCOORD1
return output;
}
// Include structure declaration and packing functions
#include "LitAttributesVarying.hlsl"
PackedVaryings Vert(Attributes input)
{

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


#error Undefine_SHADERPASS
#endif
//-------------------------------------------------------------------------------------
// Attribute/Varying
//-------------------------------------------------------------------------------------
#define WANT_UV2 (DYNAMICLIGHTMAP_ON) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL) || defined(_REQUIRE_UV2_OR_UV3)
#define WANT_UV3 (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL) || defined(_REQUIRE_UV2_OR_UV3)
struct Attributes
{
float3 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
#if WANT_UV2
float2 uv2 : TEXCOORD2;
#endif
#if WANT_UV3
float2 uv3 : TEXCOORD3;
#endif
float4 tangentOS : TANGENT; // Always present as we require it also in case of anisotropic lighting
float4 color : COLOR;
// UNITY_INSTANCE_ID
};
#ifdef TESSELLATION_ON
// Copy paste of above struct with POSITION rename to INTERNALTESSPOS (internal of unity shader compiler)
struct AttributesTessellation
{
float3 positionOS : INTERNALTESSPOS;
float3 normalOS : NORMAL;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
#if WANT_UV2
float2 uv2 : TEXCOORD2;
#endif
#if WANT_UV3
float2 uv3 : TEXCOORD3;
#endif
float4 tangentOS : TANGENT; // Always present as we require it also in case of anisotropic lighting
float4 color : COLOR;
};
AttributesTessellation AttributesToAttributesTessellation(Attributes input)
{
AttributesTessellation output;
output.positionOS = input.positionOS;
output.normalOS = input.normalOS;
output.uv0 = input.uv0;
output.uv1 = input.uv1;
#if WANT_UV2
output.uv2 = input.uv2;
#endif
#if WANT_UV3
output.uv3 = input.uv3;
#endif
output.tangentOS = input.tangentOS;
output.color = input.color;
return output;
}
Attributes AttributesTessellationToAttributes(AttributesTessellation input)
{
Attributes output;
output.positionOS = input.positionOS;
output.normalOS = input.normalOS;
output.uv0 = input.uv0;
output.uv1 = input.uv1;
#if WANT_UV2
output.uv2 = input.uv2;
#endif
#if WANT_UV3
output.uv3 = input.uv3;
#endif
output.tangentOS = input.tangentOS;
output.color = input.color;
return output;
}
AttributesTessellation InterpolateWithBaryCoords(AttributesTessellation input0, AttributesTessellation input1, AttributesTessellation input2, float3 baryCoords)
{
AttributesTessellation ouput;
TESSELLATION_INTERPOLATE_BARY(positionOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(normalOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(uv0, baryCoords);
TESSELLATION_INTERPOLATE_BARY(uv1, baryCoords);
#if WANT_UV2
TESSELLATION_INTERPOLATE_BARY(uv2, baryCoords);
#endif
#if WANT_UV3
TESSELLATION_INTERPOLATE_BARY(uv3, baryCoords);
#endif
TESSELLATION_INTERPOLATE_BARY(tangentOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(color, baryCoords);
return ouput;
}
#endif // TESSELLATION_ON
struct Varyings
{
float4 positionCS;
float3 positionWS;
float2 texCoord0;
float2 texCoord1;
#if WANT_UV2
float2 texCoord2;
#endif
#if WANT_UV3
float2 texCoord3;
#endif
float3 tangentToWorld[3];
float4 color;
};
struct PackedVaryings
{
float4 positionCS : SV_Position;
#if (WANT_UV2) || (WANT_UV3)
float4 interpolators[6] : TEXCOORD0;
#else
float4 interpolators[5] : TEXCOORD0;
#endif
// Attributes
#define ATTRIBUTES_WANT_NORMAL
#define ATTRIBUTES_WANT_TANGENT // Always present as we require it also in case of anisotropic lighting
#define ATTRIBUTES_WANT_UV0
#define ATTRIBUTES_WANT_UV1
#define ATTRIBUTES_WANT_COLOR
#if SHADER_STAGE_FRAGMENT
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMATIC;
#endif
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3) || defined(DYNAMICLIGHTMAP_ON) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL)
#define ATTRIBUTES_WANT_UV2
};
// Function to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions
PackedVaryings PackVaryings(Varyings input)
{
PackedVaryings output;
output.positionCS = input.positionCS;
output.interpolators[0].xyz = input.positionWS.xyz;
output.interpolators[1].xyz = input.tangentToWorld[0];
output.interpolators[2].xyz = input.tangentToWorld[1];
output.interpolators[3].xyz = input.tangentToWorld[2];
output.interpolators[0].w = input.texCoord0.x;
output.interpolators[1].w = input.texCoord0.y;
output.interpolators[2].w = input.texCoord1.x;
output.interpolators[3].w = input.texCoord1.y;
output.interpolators[4] = input.color;
#if (WANT_UV2) || (WANT_UV3)
output.interpolators[5] = float4(0.0, 0.0, 0.0, 0.0);
#if WANT_UV2
output.interpolators[5].xy = input.texCoord2.xy;
#if defined(_REQUIRE_UV3) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL)
#define ATTRIBUTES_WANT_UV3
#if WANT_UV3
output.interpolators[5].zw = input.texCoord3.xy;
#define VARYING_WANT_POSITION_WS
#define VARYING_WANT_TANGENT_TO_WORLD
#define VARYING_WANT_TEXCOORD0
#define VARYING_WANT_TEXCOORD1
#ifdef ATTRIBUTES_WANT_UV2
#define VARYING_WANT_TEXCOORD2
#ifdef ATTRIBUTES_WANT_UV3
#define VARYING_WANT_TEXCOORD3
#define VARYING_WANT_COLOR
return output;
}
FragInputs UnpackVaryings(PackedVaryings input)
{
FragInputs output;
ZERO_INITIALIZE(FragInputs, output);
output.unPositionSS = input.positionCS; // input.positionCS is SV_Position
output.positionWS.xyz = input.interpolators[0].xyz;
output.tangentToWorld[0] = input.interpolators[1].xyz;
output.tangentToWorld[1] = input.interpolators[2].xyz;
output.tangentToWorld[2] = input.interpolators[3].xyz;
output.texCoord0.xy = float2(input.interpolators[0].w, input.interpolators[1].w);
output.texCoord1.xy = float2(input.interpolators[2].w, input.interpolators[3].w);
output.vertexColor = input.interpolators[4];
#if WANT_UV2
output.texCoord2 = input.interpolators[5].xy;
#endif
#if WANT_UV3
output.texCoord3 = input.interpolators[5].zw;
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
#define VARYING_WANT_CULLFACE
#if SHADER_STAGE_FRAGMENT
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
output.isFrontFace = IS_FRONT_VFACE(input.cullFace, true, false);
#endif
#endif
return output;
}
//-------------------------------------------------------------------------------------
// Vertex shader
//-------------------------------------------------------------------------------------
// TODO: Here we will also have all the vertex deformation (GPU skinning, vertex animation, morph target...) or we will need to generate a compute shaders instead (better! but require work to deal with unpacking like fp16)
PackedVaryings Vert(Attributes input)
{
Varyings output;
output.positionWS = TransformObjectToWorld(input.positionOS);
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix)
output.positionCS = TransformWorldToHClip(output.positionWS);
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
// Varying DS - Use for domain shader, are deduced from the above
output.texCoord0 = input.uv0;
output.texCoord1 = input.uv1;
#if WANT_UV2
output.texCoord2 = input.uv2;
#endif
// Include structure declaration and packing functions
#include "LitAttributesVarying.hlsl"
#if WANT_UV3
output.texCoord3 = input.uv3;
#endif
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w);
output.tangentToWorld[0] = tangentToWorld[0];
output.tangentToWorld[1] = tangentToWorld[1];
output.tangentToWorld[2] = tangentToWorld[2];
output.color = input.color;
return PackVaryings(output);
}
#include "LitVertexShare.hlsl"

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


#error Undefine_SHADERPASS
#endif
#define NEED_TEXCOORD0 defined(_ALPHATEST_ON)
#define NEED_TANGENT_TO_WORLD NEED_TEXCOORD0 && (defined(_HEIGHTMAP) && defined(_PER_PIXEL_DISPLACEMENT))
// 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
struct Attributes
{
float3 positionOS : POSITION;
float3 previousPositionOS : NORMAL; // Contain previous transform position (in case of skinning for example)
#if NEED_TEXCOORD0
float2 uv0 : TEXCOORD0;
#endif
#if NEED_TANGENT_TO_WORLD
// float3 normalOS : NORMAL; // TODO: This won't compile as we conflict with previousPositionOS. FIXME
float4 tangentOS : TANGENT;
#endif
};
#ifdef ATTRIBUTES_WANT_PREVIOUS_POSITION
float3 previousPositionOS : NORMAL; // Caution : Currently use same semantic than normal, so conflict for tesselation...
#endif
#ifdef TESSELLATION_ON
// Copy paste of above struct with POSITION rename to INTERNALTESSPOS (internal of unity shader compiler)

9
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitAttributesVarying.hlsl.meta


fileFormatVersion: 2
guid: ccef7a3da040ef845a907f77250d85b2
timeCreated: 1484258505
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitVertexShare.hlsl.meta


fileFormatVersion: 2
guid: a09588881dc3d264188b6d25d553717c
timeCreated: 1484258505
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存