浏览代码

HDRenderPipeline: Large refactor of all the pass attribute and varying system

/main
sebastienlagarde 8 年前
当前提交
3b0e1c97
共有 40 个文件被更改,包括 1050 次插入943 次删除
  1. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
  2. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  3. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader
  4. 3
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl
  5. 14
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl
  6. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader
  7. 35
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDepthPass.hlsl
  8. 35
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDistortionPass.hlsl
  9. 57
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitMetaPass.hlsl
  10. 46
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitSharePass.hlsl
  11. 133
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitVelocityPass.hlsl
  12. 111
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.shader
  13. 22
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDebugViewMaterial.hlsl
  14. 22
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl
  15. 22
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDistortion.hlsl
  16. 22
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassForward.hlsl
  17. 22
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl
  18. 22
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl
  19. 49
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl
  20. 112
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassVelocity.hlsl
  21. 13
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl
  22. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl.meta
  23. 59
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/TessellationShare.hlsl
  24. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/TessellationShare.hlsl.meta
  25. 363
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl
  26. 174
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VertMesh.hlsl
  27. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VertMesh.hlsl.meta
  28. 13
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitMetaPass.hlsl
  29. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitSharePass.hlsl
  30. 83
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitVertexShare.hlsl
  31. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitVertexShare.hlsl.meta
  32. 392
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitAttributesVarying.hlsl
  33. 61
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/UnlitSharePass.hlsl
  34. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl.meta
  35. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tessellation.meta
  36. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl.meta
  37. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitSharePass.hlsl.meta
  38. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl

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


#include "common.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/FragInputs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
//-------------------------------------------------------------------------------------

#include "../../Material/Material.hlsl"
#include "../Lit/ShaderPass/LitSharePass.hlsl"
#include "../Lit/LitData.hlsl"
#include "../../ShaderPass/ShaderPassGBuffer.hlsl"
ENDHLSL

#include "../../Material/Material.hlsl"
#include "../Lit/ShaderPass/LitSharePass.hlsl"
#include "../Lit/LitData.hlsl"
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl"
ENDHLSL

#include "../../Material/Material.hlsl"
#include "../Lit/ShaderPass/LitMetaPass.hlsl"
#include "../Lit/LitData.hlsl"
#include "../../ShaderPass/ShaderPassLightTransport.hlsl"
ENDHLSL

#include "../../Material/Material.hlsl"
#include "../Lit/ShaderPass/LitVelocityPass.hlsl"
#include "../Lit/LitData.hlsl"
#include "../../ShaderPass/ShaderPassVelocity.hlsl"
ENDHLSL

#include "../../Material/Material.hlsl"
#include "../Lit/ShaderPass/LitDepthPass.hlsl"
#include "../Lit/LitData.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL

#include "../../Material/Material.hlsl"
#include "../Lit/ShaderPass/LitDepthPass.hlsl"
#include "../Lit/LitData.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL

#include "../../Material/Material.hlsl"
#include "../Lit/ShaderPass/LitDistortionPass.hlsl"
#include "../Lit/LitData.hlsl"
#include "../../ShaderPass/ShaderPassDistortion.hlsl"
ENDHLSL

#include "../../Lighting/Lighting.hlsl"
#include "../Lit/ShaderPass/LitSharePass.hlsl"
#include "../Lit/LitData.hlsl"
#include "../../ShaderPass/ShaderPassForward.hlsl"
ENDHLSL

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


#include "tesselation.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/FragInputs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
//-------------------------------------------------------------------------------------

#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 VertTesselation
#pragma hull Hull
#pragma domain Domain

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

// 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.
#pragma vertex Vert
#define SHADERPASS SHADERPASS_LIGHT_TRANSPORT
#include "../../Material/Material.hlsl"
#include "../Lit/ShaderPass/LitMetaPass.hlsl"

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

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

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

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

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

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


#include "common.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/FragInputs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
//-------------------------------------------------------------------------------------

#include "../../Material/Material.hlsl"
#include "ShaderPass/LitSharePass.hlsl"
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassGBuffer.hlsl"
ENDHLSL

#include "../../Material/Material.hlsl"
#include "ShaderPass/LitSharePass.hlsl"
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl"
ENDHLSL

#include "../../Material/Material.hlsl"
#include "ShaderPass/LitMetaPass.hlsl"
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassLightTransport.hlsl"
ENDHLSL

#include "../../Material/Material.hlsl"
#include "ShaderPass/LitDepthPass.hlsl"
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL

#include "../../Material/Material.hlsl"
#include "ShaderPass/LitDepthPass.hlsl"
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL

HLSLPROGRAM
#define SHADERPASS SHADERPASS_VELOCITY
#include "../../Material/Material.hlsl"
#include "../../Material/Material.hlsl"
#include "../../ShaderPass/ShaderPassVelocity.hlsl"
ENDHLSL

#include "../../Material/Material.hlsl"
#include "ShaderPass/LitDistortionPass.hlsl"
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassDistortion.hlsl"
ENDHLSL

#include "../../Lighting/Lighting.hlsl"
#include "ShaderPass/LitSharePass.hlsl"
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassForward.hlsl"
ENDHLSL

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


builtinData.emissiveColor = float3(0.0, 0.0, 0.0);
#endif
builtinData.velocity = CalculateVelocity(input.positionCS, input.previousPositionCS);
builtinData.velocity = float2(0.0, 0.0);
#ifdef _DISTORTION_ON
float3 distortion = SAMPLE_TEXTURE2D(_DistortionVectorMap, sampler_DistortionVectorMap, input.texCoord0).rgb;

#ifdef _DEPTHOFFSET_ON
ApplyDepthOffsetPositionInput(V, depthOffset, posInput);
ApplyDepthOffsetAttribute(depthOffset, input);
#endif
// We perform the conversion to world of the normalTS outside of the GetSurfaceData

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


return DistanceBasedTess(p0, p1, p2, 0.0, _TessellationFactorMaxDistance, _WorldSpaceCameraPos) * _TessellationFactorFixed.xxxx;
}
float3 GetDisplacement(VaryingsDS input)
float3 GetDisplacement(VaryingsMeshToDS input)
#ifdef VARYING_DS_WANT_TEXCOORD0
#ifdef VARYINGS_DS_NEED_TEXCOORD0
#ifdef VARYING_DS_WANT_TEXCOORD1
#ifdef VARYINGS_DS_NEED_TEXCOORD1
#ifdef VARYING_DS_WANT_TEXCOORD2
#ifdef VARYINGS_DS_NEED_TEXCOORD2
#ifdef VARYING_DS_WANT_TEXCOORD3
#ifdef VARYINGS_DS_NEED_TEXCOORD3
input.texCoord3,
#else
float2(0.0, 0.0),

float height = 0.0;
#endif
#ifdef VARYINGS_DS_NEED_NORMAL
#else
return input.positionWS;
#endif
}

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


#include "tessellation.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/FragInputs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
//-------------------------------------------------------------------------------------

#include "ShaderPass/LitSharePass.hlsl"
#include "LitData.hlsl"
#include "../Tessellation/TessellationShare.hlsl"
#include "../../ShaderPass/ShaderPassGBuffer.hlsl"
ENDHLSL

#include "ShaderPass/LitSharePass.hlsl"
#include "LitData.hlsl"
#include "../Tessellation/TessellationShare.hlsl"
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl"
ENDHLSL

#include "../../Material/Material.hlsl"
#include "ShaderPass/LitMetaPass.hlsl"
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassLightTransport.hlsl"
ENDHLSL

#include "ShaderPass/LitDepthPass.hlsl"
#include "LitData.hlsl"
#include "../Tessellation/TessellationShare.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL

#include "ShaderPass/LitDepthPass.hlsl"
#include "LitData.hlsl"
#include "../Tessellation/TessellationShare.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL

#include "ShaderPass/LitVelocityPass.hlsl"
#include "LitData.hlsl"
#include "../Tessellation/TessellationShare.hlsl"
#include "../../ShaderPass/ShaderPassVelocity.hlsl"
ENDHLSL

#include "ShaderPass/LitDistortionPass.hlsl"
#include "LitData.hlsl"
#include "../Tessellation/TessellationShare.hlsl"
#include "../../ShaderPass/ShaderPassDistortion.hlsl"
ENDHLSL

#include "ShaderPass/LitSharePass.hlsl"
#include "LitData.hlsl"
#include "../Tessellation/TessellationShare.hlsl"
#include "../../ShaderPass/ShaderPassForward.hlsl"
ENDHLSL

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


#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))
// This first set of define allow to say which attributes will be use by the mesh in the vertex and domain shader (for tesselation)
#define ATTRIBUTES_WANT_NORMAL
#define ATTRIBUTES_NEED_NORMAL
#define ATTRIBUTES_WANT_TANGENT
#define ATTRIBUTES_NEED_TANGENT
#define ATTRIBUTES_WANT_UV0
#define ATTRIBUTES_NEED_TEXCOORD0
#define ATTRIBUTES_WANT_UV1
#define ATTRIBUTES_NEED_TEXCOORD1
#define ATTRIBUTES_WANT_UV2
#define ATTRIBUTES_NEED_TEXCOORD2
#define ATTRIBUTES_WANT_UV3
#define ATTRIBUTES_NEED_TEXCOORD3
// This second set of define allow to say which varyings will be output in the vertex (no more tesselation)
#define VARYING_WANT_TANGENT_TO_WORLD
#define VARYINGS_NEED_TANGENT_TO_WORLD
#define VARYING_WANT_TEXCOORD0
#define VARYINGS_NEED_TEXCOORD0
#define VARYING_WANT_TEXCOORD1
#define VARYINGS_NEED_TEXCOORD1
#define VARYING_WANT_TEXCOORD2
#define VARYINGS_NEED_TEXCOORD2
#define VARYING_WANT_TEXCOORD3
#define VARYINGS_NEED_TEXCOORD3
// Varying DS - Use for domain shader, are deduced from the above
// Include structure declaration and packing functions
#include "LitAttributesVarying.hlsl"
#include "LitVertexShare.hlsl"
// This include will define the various Attributes/Varyings structure
#include "../../ShaderPass/VaryingMesh.hlsl"

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


#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))
// This first set of define allow to say which attributes will be use by the mesh in the vertex and domain shader (for tesselation)
#define ATTRIBUTES_WANT_NORMAL
#define ATTRIBUTES_NEED_NORMAL
#define ATTRIBUTES_WANT_TANGENT
#define ATTRIBUTES_NEED_TANGENT
#define ATTRIBUTES_WANT_UV0
#define ATTRIBUTES_NEED_TEXCOORD0
#define ATTRIBUTES_WANT_UV1
#define ATTRIBUTES_NEED_TEXCOORD1
#define ATTRIBUTES_WANT_UV2
#define ATTRIBUTES_NEED_TEXCOORD2
#define ATTRIBUTES_WANT_UV3
#define ATTRIBUTES_NEED_TEXCOORD3
// This second set of define allow to say which varyings will be output in the vertex (no more tesselation)
#define VARYING_WANT_TANGENT_TO_WORLD
#define VARYINGS_NEED_TANGENT_TO_WORLD
#define VARYING_WANT_TEXCOORD0
#define VARYINGS_NEED_TEXCOORD0
#define VARYING_WANT_TEXCOORD1
#define VARYINGS_NEED_TEXCOORD1
#define VARYING_WANT_TEXCOORD2
#define VARYINGS_NEED_TEXCOORD2
#define VARYING_WANT_TEXCOORD3
#define VARYINGS_NEED_TEXCOORD3
// Varying DS - Use for domain shader, are deduced from the above
// Include structure declaration and packing functions
#include "LitAttributesVarying.hlsl"
#include "LitVertexShare.hlsl"
// This include will define the various Attributes/Varyings structure
#include "../../ShaderPass/VaryingMesh.hlsl"

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


#error Undefine_SHADERPASS
#endif
CBUFFER_START(UnityMetaPass)
// x = use uv1 as raster position
// y = use uv2 as raster position
bool4 unity_MetaVertexControl;
#define ATTRIBUTES_NEED_TEXCOORD0
#define ATTRIBUTES_NEED_TEXCOORD1
#define ATTRIBUTES_NEED_TEXCOORD2
// x = return albedo
// y = return normal
bool4 unity_MetaFragmentControl;
CBUFFER_END
#define VARYINGS_NEED_TEXCOORD0
#define VARYINGS_NEED_TEXCOORD1
// This was not in constant buffer in original unity, so keep outiside. But should be in as ShaderRenderPass frequency
float unity_OneOverOutputBoost;
float unity_MaxOutputValue;
#define ATTRIBUTES_WANT_NORMAL
#define ATTRIBUTES_WANT_UV0
#define ATTRIBUTES_WANT_UV1
#define ATTRIBUTES_WANT_UV2
#define VARYING_WANT_TEXCOORD0
#define VARYING_WANT_TEXCOORD1
// Include structure declaration and packing functions
#include "LitAttributesVarying.hlsl"
PackedVaryings Vert(Attributes input)
{
Varyings output;
// Output UV coordinate in vertex shader
if (unity_MetaVertexControl.x)
{
input.positionOS.xy = input.uv1 * unity_LightmapST.xy + unity_LightmapST.zw;
// OpenGL right now needs to actually use incoming vertex position,
// so use it in a very dummy way
//v.positionOS.z = vertex.z > 0 ? 1.0e-4f : 0.0f;
}
if (unity_MetaVertexControl.y)
{
input.positionOS.xy = input.uv2 * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
// OpenGL right now needs to actually use incoming vertex position,
// so use it in a very dummy way
//v.positionOS.z = vertex.z > 0 ? 1.0e-4f : 0.0f;
}
float3 positionWS = TransformObjectToWorld(input.positionOS);
output.positionCS = TransformWorldToHClip(positionWS);
output.texCoord0 = input.uv0;
output.texCoord1 = input.uv1;
return PackVaryings(output);
}
// This include will define the various Attributes/Varyings structure
#include "../../ShaderPass/VaryingMesh.hlsl"

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


#error Undefine_SHADERPASS
#endif
// This first set of define allow to say which attributes will be use by the mesh in the vertex and domain shader (for tesselation)
#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
#define ATTRIBUTES_NEED_NORMAL
#define ATTRIBUTES_NEED_TANGENT // Always present as we require it also in case of anisotropic lighting
#define ATTRIBUTES_NEED_TEXCOORD0
#define ATTRIBUTES_NEED_TEXCOORD1
#define ATTRIBUTES_NEED_COLOR
#define ATTRIBUTES_WANT_UV2
#define ATTRIBUTES_NEED_TEXCOORD2
#define ATTRIBUTES_WANT_UV3
#define ATTRIBUTES_NEED_TEXCOORD3
#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
// Varying - Use for pixel shader
// This second set of define allow to say which varyings will be output in the vertex (no more tesselation)
#define VARYINGS_NEED_POSITION_WS
#define VARYINGS_NEED_TANGENT_TO_WORLD
#define VARYINGS_NEED_TEXCOORD0
#define VARYINGS_NEED_TEXCOORD1
#ifdef ATTRIBUTES_NEED_TEXCOORD2
#define VARYINGS_NEED_TEXCOORD2
#ifdef ATTRIBUTES_WANT_UV3
#define VARYING_WANT_TEXCOORD3
#ifdef ATTRIBUTES_NEED_TEXCOORD3
#define VARYINGS_NEED_TEXCOORD3
#define VARYING_WANT_COLOR
#define VARYINGS_NEED_COLOR
#define VARYING_WANT_CULLFACE
#define VARYINGS_NEED_CULLFACE
// Varying DS - Use for domain shader, are deduced from the above
// Include structure declaration and packing functions
#include "LitAttributesVarying.hlsl"
#include "LitVertexShare.hlsl"
// This include will define the various Attributes/Varyings structure
#include "../../ShaderPass/VaryingMesh.hlsl"

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


#error Undefine_SHADERPASS
#endif
// TODO: For now disable per pixel and per vertex displacement mapping with motion vector
// as vertex normal is not available + force UV0 for alpha test (not compatible with layered system...)
#define VARYING_WANT_POSITION_WS
#define VARYING_WANT_PASS_SPECIFIC
// TODO: Caution - For now the tesselation doesn't displace along the normal with Velocity shader as the previous previous position
// conflict with the normal in the semantic. This need to be fix! Also no per pixel displacement is possible either.
// Attributes
#define REQUIRE_UV_FOR_TESSELATION (defined(TESSELLATION_ON) && (defined(_TESSELATION_DISPLACEMENT) || defined(_TESSELATION_DISPLACEMENT_PHONG)))
#define REQUIRE_TANGENT_TO_WORLD 0 /* (defined(_HEIGHTMAP) && defined(_PER_PIXEL_DISPLACEMENT)) */
// This first set of define allow to say which attributes will be use by the mesh in the vertex and domain shader (for tesselation)
// Tesselation require normal
#if defined(TESSELLATION_ON) || REQUIRE_TANGENT_TO_WORLD
// #define ATTRIBUTES_NEED_NORMAL
#endif
#if REQUIRE_TANGENT_TO_WORLD
#define ATTRIBUTES_NEED_TANGENT
#endif
// 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
#define ATTRIBUTES_WANT_UV0
#define ATTRIBUTES_NEED_TEXCOORD0
#define ATTRIBUTES_WANT_UV1
#define ATTRIBUTES_NEED_TEXCOORD1
#define ATTRIBUTES_WANT_UV2
#define ATTRIBUTES_NEED_TEXCOORD2
#define ATTRIBUTES_WANT_UV3
#define ATTRIBUTES_NEED_TEXCOORD3
// Varying - Use for pixel shader
// This second set of define allow to say which varyings will be output in the vertex (no more tesselation)
#define VARYINGS_NEED_POSITION_WS
#define VARYING_WANT_TEXCOORD0
#define VARYINGS_NEED_TEXCOORD0
#define VARYING_WANT_TEXCOORD1
#define VARYINGS_NEED_TEXCOORD1
#define VARYING_WANT_TEXCOORD2
#define VARYINGS_NEED_TEXCOORD2
#define VARYING_WANT_TEXCOORD3
#define VARYINGS_NEED_TEXCOORD3
// Available semantic start from TEXCOORD4
struct AttributesPass
{
float3 previousPositionOS : NORMAL; // Contain previous transform position (in case of skinning for example)
};
struct VaryingsPass
{
// Note: Z component is not use
float4 transferPositionCS;
float4 transferPreviousPositionCS;
};
// Available interpolator start from TEXCOORD8
struct PackedVaryingsPass
{
// Note: Z component is not use
float3 interpolators0 : TEXCOORD8
float3 interpolators1 : TEXCOORD9;
};
PackedVaryingsPass PackVaryingsPass(VaryingsPass input)
{
PackedVaryingsPass output;
output.interpolators0 = float3(input.transferPositionCS.xyw);
output.interpolators1 = float3(input.transferPreviousPositionCS.xyw);
}
VaryingsPass UnpackVaryingsPass(PackedVaryingsPass input)
{
PackedVaryingsPass output;
output.interpolators0 = float3(input.transferPositionCS.xyw);
output.interpolators1 = float3(input.transferPreviousPositionCS.xyw);
}
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;
output.positionCS = float4(input.interpolators[1].xy, 0.0, input.interpolators[1].z);
output.previousPositionCS = float4(input.interpolators[1].xy, 0.0, input.interpolators[2].z);
#if NEED_TANGENT_TO_WORLD
output.texCoord0.xy = float2(input.interpolators[0].w, input.interpolators[1].w);
output.tangentToWorld[0] = input.interpolators[3].xyz;
output.tangentToWorld[1] = input.interpolators[4].xyz;
output.tangentToWorld[2] = float3(input.interpolators[2].w, input.interpolators[3].w, input.interpolators[4].w);
#elif NEED_TEXCOORD0
output.texCoord0.xy = float2(input.interpolators[0].w, input.interpolators[1].w);
#endif
return output;
}
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);
// TODO: Clean this code, put in function ?
output.transferPositionCS = mul(_NonJitteredVP, mul(unity_ObjectToWorld, float4(input.positionOS, 1.0)));
output.transferPreviousPositionCS = mul(_PreviousVP, mul(_PreviousM, _HasLastPositionData ? float4(input.previousPositionOS, 1.0) : float4(input.positionOS, 1.0)));
#if NEED_TEXCOORD0
output.texCoord0 = input.uv0;
#endif
#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);
}
// This include will define the various Attributes/Varyings structure
#include "../../ShaderPass/VaryingMesh.hlsl"

111
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.shader


#include "common.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/FragInputs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
//-------------------------------------------------------------------------------------

#define SHADERPASS SHADERPASS_DEBUG_VIEW_MATERIAL
#include "../../Material/Material.hlsl"
#include "UnlitSharePass.hlsl"
#include "UnlitData.hlsl"
#include "ShaderPass/UnlitSharePass.hlsl"
#include "UnlitData.hlsl"
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl"
ENDHLSL

#define SHADERPASS SHADERPASS_FORWARD_UNLIT
#include "../../Material/Material.hlsl"
#include "UnlitSharePass.hlsl"
#include "ShaderPass/UnlitSharePass.hlsl"
#include "../../ShaderPass/ShaderPassForwardUnlit.hlsl"
ENDHLSL

#define SHADERPASS SHADERPASS_FORWARD_UNLIT
#include "../../Material/Material.hlsl"
#include "UnlitSharePass.hlsl"
#include "ShaderPass/UnlitSharePass.hlsl"
#include "../../ShaderPass/ShaderPassForwardUnlit.hlsl"
ENDHLSL

// both direct and indirect lighting) will hand up in the "regular" lightmap->LIGHTMAP_ON.
#define SHADERPASS SHADERPASS_LIGHT_TRANSPORT
#include "UnlitData.hlsl"
#include "../../Material/Material.hlsl"
CBUFFER_START(UnityMetaPass)
// x = use uv1 as raster position
// y = use uv2 as raster position
bool4 unity_MetaVertexControl;
// x = return albedo
// 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
float unity_OneOverOutputBoost;
float unity_MaxOutputValue;
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);
output.unPositionSS = input.positionCS;
output.texCoord0 = input.interpolators[0].xy;
output.texCoord1 = input.interpolators[0].zw;
return output;
}
PackedVaryings Vert(Attributes input)
{
Varyings output;
// Output UV coordinate in vertex shader
if (unity_MetaVertexControl.x)
{
input.positionOS.xy = input.uv1 * unity_LightmapST.xy + unity_LightmapST.zw;
// OpenGL right now needs to actually use incoming vertex position,
// so use it in a very dummy way
//v.positionOS.z = vertex.z > 0 ? 1.0e-4f : 0.0f;
}
if (unity_MetaVertexControl.y)
{
input.positionOS.xy = input.uv2 * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
// OpenGL right now needs to actually use incoming vertex position,
// so use it in a very dummy way
//v.positionOS.z = vertex.z > 0 ? 1.0e-4f : 0.0f;
}
float3 positionWS = TransformObjectToWorld(input.positionOS);
output.positionCS = TransformWorldToHClip(positionWS);
output.texCoord0 = input.uv0;
output.texCoord1 = input.uv1;
return PackVaryings(output);
}
#include "../../Material/Material.hlsl"
#include "ShaderPass/UnlitMetaPass.hlsl"
#include "UnlitData.hlsl"
#include "../../ShaderPass/ShaderPassLightTransport.hlsl"
ENDHLSL

#define SHADERPASS SHADERPASS_DISTORTION
#include "../../Material/Material.hlsl"
#include "UnlitSharePass.hlsl"
#include "ShaderPass/UnlitSharePass.hlsl"
#include "../../ShaderPass/ShaderPassDistortion.hlsl"
ENDHLSL

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


#include "Color.hlsl"
int _DebugViewMaterial;
#include "VertMesh.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh)
{
VaryingsType varyingsType;
varyingsType.vmesh = VertMesh(inputMesh);
return PackVaryingsType(varyingsType);
}
#ifdef TESSELLATION_ON
PackVaryingsToPS VertTesselation(VaryingsToDS input)
{
VaryingsToPS output;
output.vmesh = VertMeshTesselation(input.vmesh);
return PackVaryingsToPS(output);
}
#endif // TESSELLATION_ON
FragInputs input = UnpackVaryings(packedInput);
FragInputs input = UnpackVaryingsMeshToPS(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);

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


#error SHADERPASS_is_not_correctly_define
#endif
#include "VertMesh.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh)
{
VaryingsType varyingsType;
varyingsType.vmesh = VertMesh(inputMesh);
return PackVaryingsType(varyingsType);
}
#ifdef TESSELLATION_ON
PackVaryingsToPS VertTesselation(VaryingsToDS input)
{
VaryingsToPS output;
output.vmesh = VertMeshTesselation(input.vmesh);
return PackVaryingsToPS(output);
}
#endif // TESSELLATION_ON
void Frag( PackedVaryings packedInput,
out float4 outColor : SV_Target
#ifdef _DEPTHOFFSET_ON

{
FragInputs input = UnpackVaryings(packedInput);
FragInputs input = UnpackVaryingsMeshToPS(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);

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


#error SHADERPASS_is_not_correctly_define
#endif
#include "VertMesh.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh)
{
VaryingsType varyingsType;
varyingsType.vmesh = VertMesh(inputMesh);
return PackVaryingsType(varyingsType);
}
#ifdef TESSELLATION_ON
PackVaryingsToPS VertTesselation(VaryingsToDS input)
{
VaryingsToPS output;
output.vmesh = VertMeshTesselation(input.vmesh);
return PackVaryingsToPS(output);
}
#endif // TESSELLATION_ON
FragInputs input = UnpackVaryings(packedInput);
FragInputs input = UnpackVaryingsMeshToPS(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);

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


#error SHADERPASS_is_not_correctly_define
#endif
#include "VertMesh.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh)
{
VaryingsType varyingsType;
varyingsType.vmesh = VertMesh(inputMesh);
return PackVaryingsType(varyingsType);
}
#ifdef TESSELLATION_ON
PackVaryingsToPS VertTesselation(VaryingsToDS input)
{
VaryingsToPS output;
output.vmesh = VertMeshTesselation(input.vmesh);
return PackVaryingsToPS(output);
}
#endif // TESSELLATION_ON
void Frag( PackedVaryings packedInput,
out float4 outColor : SV_Target
#ifdef _DEPTHOFFSET_ON

{
FragInputs input = UnpackVaryings(packedInput);
FragInputs input = UnpackVaryingsMeshToPS(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);

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


#error SHADERPASS_is_not_correctly_define
#endif
#include "VertMesh.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh)
{
VaryingsType varyingsType;
varyingsType.vmesh = VertMesh(inputMesh);
return PackVaryingsType(varyingsType);
}
#ifdef TESSELLATION_ON
PackVaryingsToPS VertTesselation(VaryingsToDS input)
{
VaryingsToPS output;
output.vmesh = VertMeshTesselation(input.vmesh);
return PackVaryingsToPS(output);
}
#endif // TESSELLATION_ON
FragInputs input = UnpackVaryings(packedInput);
FragInputs input = UnpackVaryingsMeshToPS(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);

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


#error SHADERPASS_is_not_correctly_define
#endif
#include "VertMesh.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh)
{
VaryingsType varyingsType;
varyingsType.vmesh = VertMesh(inputMesh);
return PackVaryingsType(varyingsType);
}
#ifdef TESSELLATION_ON
PackVaryingsToPS VertTesselation(VaryingsToDS input)
{
VaryingsToPS output;
output.vmesh = VertMeshTesselation(input.vmesh);
return PackVaryingsToPS(output);
}
#endif // TESSELLATION_ON
void Frag( PackedVaryings packedInput,
OUTPUT_GBUFFER(outGBuffer)
OUTPUT_GBUFFER_VELOCITY(outVelocityBuffer)

)
{
FragInputs input = UnpackVaryings(packedInput);
FragInputs input = UnpackVaryingsMeshToPS(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);

49
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl


#include "Color.hlsl"
float4 Frag(PackedVaryings packedInput) : SV_Target
CBUFFER_START(UnityMetaPass)
// x = use uv1 as raster position
// y = use uv2 as raster position
bool4 unity_MetaVertexControl;
// x = return albedo
// 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
float unity_OneOverOutputBoost;
float unity_MaxOutputValue;
#include "VertMesh.hlsl"
PackedVaryingsToPS Vert(AttributesMesh inputMesh)
{
VaryingsToPS output;
// Output UV coordinate in vertex shader
if (unity_MetaVertexControl.x)
{
inputMesh.positionOS.xy = inputMesh.uv1 * unity_LightmapST.xy + unity_LightmapST.zw;
// OpenGL right now needs to actually use incoming vertex position,
// so use it in a very dummy way
//v.positionOS.z = vertex.z > 0 ? 1.0e-4f : 0.0f;
}
if (unity_MetaVertexControl.y)
{
inputMesh.positionOS.xy = inputMesh.uv2 * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
// OpenGL right now needs to actually use incoming vertex position,
// so use it in a very dummy way
//v.positionOS.z = vertex.z > 0 ? 1.0e-4f : 0.0f;
}
float3 positionWS = TransformObjectToWorld(inputMesh.positionOS);
output.positionCS = TransformWorldToHClip(positionWS);
output.texCoord0 = inputMesh.uv0;
output.texCoord1 = inputMesh.uv1;
return PackVaryingsToPS(output);
}
float4 Frag(PackedVaryingsToPS packedInput) : SV_Target
FragInputs input = UnpackVaryings(packedInput);
FragInputs input = UnpackVaryingsMeshToPS(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);

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


#error SHADERPASS_is_not_correctly_define
#endif
#if SHADER_STAGE_VERTEX
// Available semantic start from TEXCOORD4
struct AttributesPass
{
float3 previousPositionOS : NORMAL; // Contain previous transform position (in case of skinning for example)
#endif
// TODO: Caution - For now the tesselation doesn't displace along the normal with Velocity shader as the previous previous position
// conflict with the normal in the semantic. This need to be fix!
};
#if SHADER_STAGE_FRAGMENT
struct VaryingsPassToPS
{
// Note: Z component is not use currently
// This is the clip space position. Warning, do not confuse with the value of positionCS in PackedVarying which is SV_POSITION and store in unPositionSS
float4 positionCS;
float4 previousPositionCS;
};
float4 Frag(PackedVaryings packedInput) : SV_Target
// Available interpolator start from TEXCOORD8
struct PackedVaryingsPassToPS
FragInputs input = UnpackVaryings(packedInput);
// Note: Z component is not use
float3 interpolators0 : TEXCOORD8;
float3 interpolators1 : TEXCOORD9;
};
PackedVaryingsPassToPS PackVaryingsPassToPS(VaryingsPassToPS input)
{
PackedVaryingsPassToPS output;
output.interpolators0 = float3(input.positionCS.xyw);
output.interpolators1 = float3(input.previousPositionCS.xyw);
}
VaryingsPassToPS UnpackVaryingsPassToPS(PackedVaryingsPassToPS input)
{
VaryingsPassToPS output;
output.positionCS = float4(input.interpolators0.xy, 0.0, input.interpolators0.z);
output.previousPositionCS = float4(input.interpolators1.xy, 0.0, input.interpolators1.z);
}
#ifdef TESSELLATION_ON
// Available interpolator start from TEXCOORD4
// Same as ToPS here
#define VaryingsPassToDS VaryingsPassToPS
#define PackedVaryingsPassToDS PackedVaryingsPassToPS
#define PackVaryingsPassToDS PackVaryingsPassToPS
#define UnpackVaryingsPassToDS UnpackVaryingsPassToPS
VaryingsPassToDS InterpolateWithBaryCoordsPassToDS(VaryingsPassToDS input0, VaryingsPassToDS input1, VaryingsPassToDS input2, float3 baryCoords)
{
VaryingsPassToDS varyingsPass;
TESSELLATION_INTERPOLATE_BARY(varyingsPass.positionCS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(varyingsPass.previousPositionCS, baryCoords);
return ouput;
}
#endif // TESSELLATION_ON
// We will use custom attributes for this pass
#define VARYINGS_DS_NEED_PASS
#include "VertMesh.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh,
AttributesPass inputPass)
{
VaryingsType varyingsType;
varyingsType.vmesh = VertMesh(inputMesh);
VaryingsPass varyingPass;
// It is not possible to correctly generate the motion vector for tesselated geometry as tessellation parameters can change
// from one frame to another (adaptative, lod) + in Unity we only receive information for one non tesselated vertex.
// So motion vetor will be based on interpolate previous position at vertex level instead.
varyingPass.positionCS = mul(_NonJitteredVP, mul(unity_ObjectToWorld, float4(inputMesh.positionOS, 1.0)));
varyingPass.previousPositionCS = mul(_PreviousVP, mul(_PreviousM, _HasLastPositionData ? float4(inputPass.previousPositionOS, 1.0) : float4(inputMesh.positionOS, 1.0)));
return PackVaryingsType(varyingsType);
}
#ifdef TESSELLATION_ON
PackVaryingsToPS VertTesselation(VaryingsToDS input)
{
VaryingsToPS output;
output.vmesh = VertMeshTesselation(input.vmesh);
output.vpass.positionCS = input.vmesh.positionCS;
output.vpass.previousPositionCS = input.vmesh.previousPositionCS;
return PackVaryingsToPS(output);
}
#endif // TESSELLATION_ON
float4 Frag(PackedVaryingsToPS packedInput) : SV_Target
{
FragInputs input = UnpackVaryingsMeshToPS(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);

BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
VaryingsPassToPS inputPass = UnpackVaryingsPassToPS(packedInput.vpass);
#ifdef _DEPTHOFFSET_ON
inputPass.positionCS.w += builtinData.depthOffset;
inputPass.previousPositionCS.w += builtinData.depthOffset;
#endif
// TODO: How to allow overriden velocity vector from GetSurfaceAndBuiltinData ?
float2 velocity = CalculateVelocity(inputPass.positionCS, inputPass.previousPositionCS);
EncodeVelocity(builtinData.velocity, outBuffer);
EncodeVelocity(velocity, outBuffer);
#endif

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


float3 tangentToWorld[3];
float4 vertexColor;
// CAUTION: Only use with velocity currently, null else
// Note: Z component is not use currently
// This is the clip space position. Warning, do not confuse with the value of positionCS in PackedVarying which is SV_POSITION and store in unPositionSS
float4 positionCS;
float4 previousPositionCS;
// end velocity specific
void ApplyDepthOffsetAttribute(float depthOffsetVS, inout FragInputs fragInput)
{
fragInput.positionCS.w += depthOffsetVS;
fragInput.previousPositionCS.w += depthOffsetVS;
}
void GetVaryingsDataDebug(uint paramId, FragInputs input, inout float3 result, inout bool needLinearToSRGB)
{

9
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl.meta


fileFormatVersion: 2
guid: 1e29a17691259ac4e9de48d4cfd72d06
timeCreated: 1484313687
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

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


struct TessellationFactors
{
float edge[3] : SV_TessFactor;
float inside : SV_InsideTessFactor;
};
TessellationFactors HullConstant(InputPatch<PackedVaryingsToDS, 3> input)
{
VaryingsToDS varying0 = UnpackVaryingsToDS(input[0]);
VaryingsToDS varying1 = UnpackVaryingsToDS(input[1]);
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);
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)]
PackedVaryingsToDS Hull(InputPatch<PackedVaryingsToDS, 3> input, uint id : SV_OutputControlPointID)
{
// Pass-through
return input[id];
}
[domain("tri")]
PackedVaryings Domain(TessellationFactors tessFactors, const OutputPatch<PackedVaryingsToDS, 3> input, float3 baryCoords : SV_DomainLocation)
{
VaryingsToDS varying0 = UnpackVaryingsToDS(input[0]);
VaryingsToDS varying1 = UnpackVaryingsToDS(input[1]);
VaryingsToDS varying2 = UnpackVaryingsToDS(input[2]);
VaryingsToDS varying = InterpolateWithBaryCoords(varying0, varying1, varying2, baryCoords);
// We have Phong tessellation in all case where we don't have displacement only
#ifndef _TESSELLATION_DISPLACEMENT
varying.vmesh.positionWS = PhongTessellation( varying.positionWS,
varying0.vmesh.positionWS, varying1.vmesh.positionWS, varying2.vmesh.positionWS,
varying0.vmesh.normalWS, varying1.vmesh.normalWS, varying2.vmesh.normalWS,
baryCoords, _TessellationShapeFactor);
#endif
#if defined(_TESSELLATION_DISPLACEMENT) || defined(_TESSELLATION_DISPLACEMENT_PHONG)
varying.vmesh.positionWS = GetDisplacement(varying.vmesh);
#endif
return VertTesselation(varying);
}

9
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/TessellationShare.hlsl.meta


fileFormatVersion: 2
guid: 7a951f9236225024eb694af870ee4efe
timeCreated: 1484313687
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

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


struct AttributesMesh
{
float3 positionOS : POSITION;
#ifdef ATTRIBUTES_NEED_NORMAL
float3 normalOS : NORMAL;
#endif
#ifdef ATTRIBUTES_NEED_TANGENT
float4 tangentOS : TANGENT; // Store sign in w
#endif
#ifdef ATTRIBUTES_NEED_TEXCOORD0
float2 uv0 : TEXCOORD0;
#endif
#ifdef ATTRIBUTES_NEED_TEXCOORD1
float2 uv1 : TEXCOORD1;
#endif
#ifdef ATTRIBUTES_NEED_TEXCOORD2
float2 uv2 : TEXCOORD2;
#endif
#ifdef ATTRIBUTES_NEED_TEXCOORD3
float2 uv3 : TEXCOORD3;
#endif
#ifdef ATTRIBUTES_NEED_COLOR
float4 color : COLOR;
#endif
// UNITY_INSTANCE_ID
};
struct VaryingsMeshToPS
{
float4 positionCS;
#ifdef VARYINGS_NEED_POSITION_WS
float3 positionWS;
#endif
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD
float3 tangentToWorld[3];
#endif
#ifdef VARYINGS_NEED_TEXCOORD0
float2 texCoord0;
#endif
#ifdef VARYINGS_NEED_TEXCOORD1
float2 texCoord1;
#endif
#ifdef VARYINGS_NEED_TEXCOORD2
float2 texCoord2;
#endif
#ifdef VARYINGS_NEED_TEXCOORD3
float2 texCoord3;
#endif
#ifdef VARYINGS_NEED_COLOR
float4 color;
#endif
};
struct PackedVaryingsMeshToPS
{
float4 positionCS : SV_Position;
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD
#ifdef VARYINGS_NEED_POSITION_WS
// if present, pack positionWS
float4 interpolators1 : TEXCOORD1;
float4 interpolators2 : TEXCOORD2;
float4 interpolators3 : TEXCOORD3;
#else
float3 interpolators1 : TEXCOORD1;
float3 interpolators2 : TEXCOORD2;
float3 interpolators3 : TEXCOORD3;
#endif
#else
#ifdef VARYINGS_NEED_POSITION_WS
float3 interpolators0 : TEXCOORD0;
#endif
#endif
// Allocate only necessary space if shader compiler in the future are able to automatically pack
#ifdef VARYINGS_NEED_TEXCOORD1
float4 interpolators4 : TEXCOORD4;
#elif defined(VARYINGS_NEED_TEXCOORD0)
float2 interpolators4 : TEXCOORD4;
#endif
#ifdef VARYINGS_NEED_TEXCOORD3
float4 interpolators5 : TEXCOORD5;
#elif defined(VARYINGS_NEED_TEXCOORD2)
float2 interpolators5 : TEXCOORD5;
#endif
#ifdef VARYINGS_NEED_COLOR
float4 interpolators6 : TEXCOORD6;
#endif
#if defined(VARYINGS_NEED_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
PackedVaryingsMeshToPS PackVaryingsMeshToPS(VaryingsMeshToPS input)
{
PackedVaryingsMeshToPS output;
output.positionCS = input.positionCS;
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD
output.interpolators1.xyz = input.tangentToWorld[0];
output.interpolators2.xyz = input.tangentToWorld[1];
output.interpolators3.xyz = input.tangentToWorld[2];
#ifdef VARYINGS_NEED_POSITION_WS
output.interpolators1.w = input.positionWS.x;
output.interpolators2.w = input.positionWS.y;
output.interpolators3.w = input.positionWS.z;
#else
output.interpolators1.w = 0.0;
output.interpolators2.w = 0.0;
output.interpolators3.w = 0.0;
#endif
#else
#ifdef VARYINGS_NEED_POSITION_WS
output.interpolators0.xyz = input.positionWS;
output.interpolators0.w = 0.0;
#endif
#endif
#ifdef VARYINGS_NEED_TEXCOORD0
output.interpolators4.xy = input.texCoord0;
#endif
#ifdef VARYINGS_NEED_TEXCOORD1
output.interpolators4.zw = input.texCoord1;
#endif
#ifdef VARYINGS_NEED_TEXCOORD2
output.interpolators5.xy = input.texCoord2;
#endif
#ifdef VARYINGS_NEED_TEXCOORD3
output.interpolators5.zw = input.texCoord3;
#endif
#ifdef VARYINGS_NEED_COLOR
output.interpolators6 = input.color;
#endif
return output;
}
FragInputs UnpackVaryingsMeshToPS(PackedVaryingsMeshToPS input)
{
FragInputs output;
ZERO_INITIALIZE(FragInputs, output);
output.unPositionSS = input.positionCS; // input.positionCS is SV_Position
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD
output.tangentToWorld[0] = input.interpolators1.xyz;
output.tangentToWorld[1] = input.interpolators2.xyz;
output.tangentToWorld[2] = input.interpolators3.xyz;
#ifdef WANT_PER_PIXEL_WORLDPOS
output.positionWS.xyz = float3(input.interpolators1.w, input.interpolators2.w, input.interpolators3.w);
#endif
#else
#ifdef VARYINGS_NEED_POSITION_WS
output.positionWS.xyz = input.interpolators0.xyz;
#endif
#endif
#ifdef VARYINGS_NEED_TEXCOORD0
output.texCoord0 = input.interpolators4.xy;
#endif
#ifdef VARYINGS_NEED_TEXCOORD1
output.texCoord1 = input.interpolators4.zw;
#endif
#ifdef VARYINGS_NEED_TEXCOORD2
output.texCoord2 = input.interpolators5.xy;
#endif
#ifdef VARYINGS_NEED_TEXCOORD3
output.texCoord3 = input.interpolators5.zw;
#endif
#ifdef VARYINGS_NEED_COLOR
output.color = input.interpolators6;
#endif
#if defined(VARYINGS_NEED_CULLFACE) && SHADER_STAGE_FRAGMENT
output.isFrontFace = IS_FRONT_VFACE(input.cullFace, true, false);
#endif
return output;
}
#ifdef TESSELLATION_ON
// Varying DS - use for domain shader
// We can deduce these defines from the other defines
// We need to pass to DS any varying required by pixel shader
// If we have required an attributes that is not present in varyings it mean we will be for DS
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD
#define VARYINGS_DS_NEED_NORMAL
#define VARYINGS_DS_NEED_TANGENT
#endif
#if defined(VARYINGS_NEED_TEXCOORD0) || defined(ATTRIBUTES_NEED_TEXCOORD0)
#define VARYINGS_DS_NEED_TEXCOORD0
#endif
#if defined(VARYINGS_NEED_TEXCOORD1) || defined(ATTRIBUTES_NEED_TEXCOORD1)
#define VARYINGS_DS_NEED_TEXCOORD1
#endif
#if defined(VARYINGS_NEED_TEXCOORD2) || defined(ATTRIBUTES_NEED_TEXCOORD2)
#define VARYINGS_DS_NEED_TEXCOORD2
#endif
#if defined(VARYINGS_NEED_TEXCOORD3) || defined(ATTRIBUTES_NEED_TEXCOORD3)
#define VARYINGS_DS_NEED_TEXCOORD3
#endif
#if defined(VARYINGS_NEED_COLOR) || defined(ATTRIBUTES_NEED_COLOR)
float4 VARYINGS_DS_NEED_COLOR;
#endif
// Varying for domain shader
// Position and normal are always present (for tessellation) and in world space
struct VaryingsMeshToDS
{
float3 positionWS;
#ifdef VARYINGS_DS_NEED_NORMAL
float3 normalWS;
#endif
#ifdef VARYINGS_DS_NEED_TANGENT
float4 tangentWS;
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD0
float2 texCoord0;
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD1
float2 texCoord1;
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD2
float2 texCoord2;
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD3
float2 texCoord3;
#endif
#ifdef VARYINGS_DS_NEED_COLOR
float4 color;
#endif
};
struct PackedVaryingsMeshToDS
{
float3 interpolators0 : INTERNALTESSPOS; // positionWS
#ifdef VARYINGS_DS_NEED_NORMAL
float3 interpolators1 : NORMAL;
#endif
#ifdef VARYINGS_DS_NEED_TANGENT
float4 interpolators2 : TANGENT;
#endif
// Allocate only necessary space if shader compiler in the future are able to automatically pack
#ifdef VARYINGS_DS_NEED_TEXCOORD1
float4 interpolators3 : TEXCOORD0;
#elif defined(VARYINGS_DS_NEED_TEXCOORD0)
float2 interpolators3 : TEXCOORD0;
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD3
float4 interpolators4 : TEXCOORD1;
#elif defined(VARYINGS_DS_NEED_TEXCOORD2)
float2 interpolators4 : TEXCOORD1;
#endif
#ifdef VARYINGS_DS_NEED_COLOR
float4 interpolators5 : TEXCOORD2;
#endif
};
// Functions to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions
PackedVaryingsMeshToDS PackVaryingsMeshToDS(VaryingsDS input)
{
PackedVaryingsMeshToDS output;
output.interpolators0 = input.positionWS;
#ifdef VARYINGS_DS_NEED_NORMAL
output.interpolators1 = input.normalWS;
#endif
#ifdef VARYINGS_DS_NEED_TANGENT
output.interpolators2 = input.tangentWS;
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD0
output.interpolators3.xy = input.texCoord0;
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD1
output.interpolators3.zw = input.texCoord1;
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD2
output.interpolators4.xy = input.texCoord2;
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD3
output.interpolators4.zw = input.texCoord3;
#endif
#ifdef VARYINGS_DS_NEED_COLOR
output.interpolators5 = input.color;
#endif
return output;
}
VaryingsMeshToDS UnpackVaryingsMeshToDS(PackedVaryingsMeshToDS input)
{
VaryingsDS output;
output.positionWS = input.interpolators0;
#ifdef VARYINGS_DS_NEED_NORMAL
output.normalWS = input.interpolators1;
#endif
#ifdef VARYINGS_DS_NEED_TANGENT
output.tangentWS = input.interpolators2;
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD0
output.texCoord0 = input.interpolators3.xy;
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD1
output.texCoord1 = input.interpolators3.zw;
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD2
output.texCoord2 = input.interpolators4.xy;
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD3
output.texCoord3 = input.interpolators4.zw;
#endif
#ifdef VARYINGS_DS_NEED_COLOR
output.color = input.interpolators5;
#endif
return output;
}
VaryingsMeshToDS InterpolateWithBaryCoordsMeshToDS(VaryingsMeshToDS input0, VaryingsMeshToDS input1, VaryingsMeshToDS input2, float3 baryCoords)
{
VaryingsMeshToDS ouput;
TESSELLATION_INTERPOLATE_BARY(positionWS, baryCoords);
#ifdef VARYINGS_DS_NEED_NORMAL
TESSELLATION_INTERPOLATE_BARY(normalWS, baryCoords);
#endif
#ifdef VARYINGS_DS_NEED_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 VARYINGS_DS_NEED_TEXCOORD0
TESSELLATION_INTERPOLATE_BARY(texCoord0, baryCoords);
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD1
TESSELLATION_INTERPOLATE_BARY(texCoord1, baryCoords);
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD2
TESSELLATION_INTERPOLATE_BARY(texCoord2, baryCoords);
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD3
TESSELLATION_INTERPOLATE_BARY(texCoord3, baryCoords);
#endif
#ifdef VARYINGS_DS_NEED_COLOR
TESSELLATION_INTERPOLATE_BARY(color, baryCoords);
#endif
return ouput;
}
#endif // TESSELLATION_ON

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


struct VaryingsToPS
{
VaryingsMeshToPS vmesh;
#ifdef VARYINGS_DS_NEED_PASS
VaryingsPassToPS vpass;
#endif
};
struct PackedVaryingsToPS
{
PackedVaryingsMeshToPS vmesh;
#ifdef VARYINGS_DS_NEED_PASS
PackedVaryingsPassToPS vpass;
#endif
};
PackedVaryingsToPS PackVaryingsToPS(VaryingsToPS input)
{
PackedVaryingsToPS output;
output.vmesh = PackVaryingsMeshToPS(input.vmesh);
#ifdef VARYINGS_DS_NEED_PASS
output.vpass = PackVaryingsPassToPS(input.vpass);
#endif
}
VaryingsToPS UnpackVaryingsToPS(PackedVaryingsToPS input)
{
VaryingsToDS output;
output.vmesh = UnpackVaryingsMeshToPS(input.vmesh);
#ifdef VARYINGS_DS_NEED_PASS
output.vpass = UnpackVaryingsPassToPS(input.vpass);
#endif
}
#ifdef TESSELLATION_ON
struct VaryingsToDS
{
VaryingsMeshToDS vmesh;
#ifdef VARYINGS_DS_NEED_PASS
VaryingsPassToDS vpass;
#endif
};
struct PackedVaryingsToDS
{
PackedVaryingsDS vmesh;
#ifdef VARYINGS_DS_NEED_PASS
PackedVaryingsPassDS vpass;
#endif
};
PackedVaryingsToDS PackVaryingsToDS(VaryingsToDS input)
{
PackedVaryingsToDS output;
output.vmesh = PackVaryingsMeshToDS(input.vmesh);
#ifdef VARYINGS_DS_NEED_PASS
output.vpass = PackVaryingsPassToDS(input.vpass);
#endif
}
VaryingsToDS UnpackVaryingsToDS(PackedVaryingsToDS input)
{
VaryingsToDS output;
output.vmesh = UnpackVaryingsMeshToDS(input.vmesh);
#ifdef VARYINGS_DS_NEED_PASS
output.vpass = UnpackVaryingsPassToDS(input.vpass);
#endif
}
VaryingsToDS InterpolateWithBaryCoordsToDS(VaryingsToDS input0, VaryingsToDS input1, VaryingsToDS input2, float3 baryCoords)
{
VaryingsToDS ouput;
ouput.vmesh = InterpolateWithBaryCoordsMeshToDS(input0.vmesh, input1.vmesh, input2.vmesh, baryCoords);
#ifdef VARYINGS_DS_NEED_PASS
ouput.vpass = InterpolateWithBaryCoordsPassToDS(input0.vpass, input1.vpass, input2.vpass, baryCoords);
#endif
return output;
}
#endif // TESSELLATION_ON
#ifdef TESSELLATION_ON
#define VaryingsType VaryingsToDS
#define PackedVaryingsType PackedVaryingsToDS
#define PackVaryingsType PackVaryingsToDS
#else
#define VaryingsType VaryingsToPS
#define PackedVaryingsType PackedVaryingsToPS
#define PackVaryingsType PackVaryingsToPS
#endif
// 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)
VaryingsType VertMesh(AttributesMesh input)
{
VaryingsType output;
#if defined(TESSELLATION_ON)
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)
#if defined(VARYING_NEED_TANGENT_TO_WORLD) || defined(VARYINGS_DS_NEED_NORMAL)
output.normalWS = TransformObjectToWorldNormal(input.normalOS);
#endif
#if defined(VARYING_NEED_TANGENT_TO_WORLD) || defined(VARYINGS_DS_NEED_TANGENT)
output.tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
#endif
#else
float3 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(positionWS);
#ifdef VARYINGS_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
#endif
#if defined(VARYINGS_NEED_TEXCOORD0) || defined(VARYINGS_DS_NEED_TEXCOORD0)
output.texCoord0 = input.uv0;
#endif
#if defined(VARYINGS_NEED_TEXCOORD1) || defined(VARYINGS_DS_NEED_TEXCOORD1)
output.texCoord1 = input.uv1;
#endif
#if defined(VARYINGS_NEED_TEXCOORD2) || defined(VARYINGS_DS_NEED_TEXCOORD2)
output.texCoord2 = input.uv2;
#endif
#if defined(VARYINGS_NEED_TEXCOORD3) || defined(VARYINGS_DS_NEED_TEXCOORD3)
output.texCoord3 = input.uv3;
#endif
#if defined(VARYINGS_NEED_COLOR) || defined(VARYINGS_DS_NEED_COLOR)
output.color = input.color;
#endif
return output;
}
#ifdef TESSELLATION_ON
VaryingMeshToPS VertMeshTesselation(VaryingMeshToDS input)
{
VaryingMeshToPS output;
output.positionCS = TransformWorldToHClip(input.positionWS);
#ifdef VARYINGS_NEED_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 VARYINGS_NEED_TEXCOORD0
output.texCoord0 = input.uv0;
#endif
#ifdef VARYINGS_NEED_TEXCOORD1
output.texCoord1 = input.uv1;
#endif
#ifdef VARYINGS_NEED_TEXCOORD2
output.texCoord2 = input.uv2;
#endif
#ifdef VARYINGS_NEED_TEXCOORD3
output.texCoord3 = input.uv3;
#endif
#ifdef VARYINGS_NEED_COLOR
output.color = input.color;
#endif
}
#endif // TESSELLATION_ON

9
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VertMesh.hlsl.meta


fileFormatVersion: 2
guid: 5f7d62bf425b54942b9b212cad7efb1a
timeCreated: 1484313687
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

13
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitMetaPass.hlsl


#ifndef SHADERPASS
#error Undefine_SHADERPASS
#endif
#define ATTRIBUTES_NEED_TEXCOORD0
#define ATTRIBUTES_NEED_TEXCOORD1
#define ATTRIBUTES_NEED_TEXCOORD2
#define VARYINGS_NEED_TEXCOORD0
#define VARYINGS_NEED_TEXCOORD1
// This include will define the various Attributes/Varyings structure
#include "../../ShaderPass/VaryingMesh.hlsl"

10
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitSharePass.hlsl


#ifndef SHADERPASS
#error Undefine_SHADERPASS
#endif
#define ATTRIBUTES_NEED_TEXCOORD0
#define VARYINGS_NEED_TEXCOORD0
// This include will define the various Attributes/Varyings structure
#include "../../ShaderPass/VaryingMesh.hlsl"

83
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;
#if defined(TESSELLATION_ON)
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)
#if defined(VARYING_DS_WANT_TANGENT_TO_WORLD) || defined(VARYING_DS_WANT_NORMAL)
output.normalWS = TransformObjectToWorldNormal(input.normalOS);
#endif
#if defined(VARYING_DS_WANT_TANGENT_TO_WORLD) || defined(VARYING_DS_WANT_TANGENT)
output.tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
#endif
#else
float3 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(positionWS);
#ifdef VARYING_WANT_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
#endif
#if defined(VARYING_WANT_TEXCOORD0) || defined(VARYING_DS_WANT_TEXCOORD0)
output.texCoord0 = input.uv0;
#endif
#if defined(VARYING_WANT_TEXCOORD1) || defined(VARYING_DS_WANT_TEXCOORD1)
output.texCoord1 = input.uv1;
#endif
#if defined(VARYING_WANT_TEXCOORD2) || defined(VARYING_DS_WANT_TEXCOORD2)
output.texCoord2 = input.uv2;
#endif
#if defined(VARYING_WANT_TEXCOORD3) || defined(VARYING_DS_WANT_TEXCOORD3)
output.texCoord3 = input.uv3;
#endif
#if defined(VARYING_WANT_COLOR) || defined(VARYING_DS_WANT_COLOR)
output.color = input.color;
#endif
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

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


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

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


struct Attributes
{
float3 positionOS : POSITION;
#ifdef ATTRIBUTES_WANT_NORMAL
float3 normalOS : NORMAL;
#endif
#ifdef ATTRIBUTES_WANT_TANGENT
float4 tangentOS : TANGENT; // Store sign in w
#endif
#ifdef ATTRIBUTES_WANT_UV0
float2 uv0 : TEXCOORD0;
#endif
#ifdef ATTRIBUTES_WANT_UV1
float2 uv1 : TEXCOORD1;
#endif
#ifdef ATTRIBUTES_WANT_UV2
float2 uv2 : TEXCOORD2;
#endif
#ifdef ATTRIBUTES_WANT_UV3
float2 uv3 : TEXCOORD3;
#endif
#ifdef ATTRIBUTES_WANT_COLOR
float4 color : COLOR;
#endif
#ifdef VARYING_WANT_PASS_SPECIFIC
AttributesPass attributesPass;
#endif
// UNITY_INSTANCE_ID
};
struct Varyings
{
float4 positionCS;
#ifdef VARYING_WANT_POSITION_WS
float3 positionWS;
#endif
#ifdef VARYING_WANT_TANGENT_TO_WORLD
float3 tangentToWorld[3];
#endif
#ifdef VARYING_WANT_TEXCOORD0
float2 texCoord0;
#endif
#ifdef VARYING_WANT_TEXCOORD1
float2 texCoord1;
#endif
#ifdef VARYING_WANT_TEXCOORD2
float2 texCoord2;
#endif
#ifdef VARYING_WANT_TEXCOORD3
float2 texCoord3;
#endif
#ifdef VARYING_WANT_COLOR
float4 color;
#endif
#ifdef VARYING_WANT_PASS_SPECIFIC
VaryingsPass varyingPass;
#endif
};
struct PackedVaryings
{
float4 positionCS : SV_Position;
#ifdef VARYING_WANT_TANGENT_TO_WORLD
#ifdef VARYING_WANT_POSITION_WS
// if present, pack positionWS
float4 interpolators1 : TEXCOORD1;
float4 interpolators2 : TEXCOORD2;
float4 interpolators3 : TEXCOORD3;
#else
float3 interpolators1 : TEXCOORD1;
float3 interpolators2 : TEXCOORD2;
float3 interpolators3 : TEXCOORD3;
#endif
#else
#ifdef VARYING_WANT_POSITION_WS
float3 interpolators0 : TEXCOORD0;
#endif
#endif
// Allocate only necessary space if shader compiler in the future are able to automatically pack
#ifdef VARYING_WANT_TEXCOORD1
float4 interpolators4 : TEXCOORD4;
#elif defined(VARYING_WANT_TEXCOORD0)
float2 interpolators4 : TEXCOORD4;
#endif
#ifdef VARYING_WANT_TEXCOORD3
float4 interpolators5 : TEXCOORD5;
#elif defined(VARYING_WANT_TEXCOORD2)
float2 interpolators5 : TEXCOORD5;
#endif
#ifdef VARYING_WANT_COLOR
float4 interpolators6 : TEXCOORD6;
#endif
#ifdef VARYING_WANT_PASS_SPECIFIC
PackedVaryingsPass packedVaryingsPass;
#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
PackedVaryings PackVaryings(Varyings input)
{
PackedVaryings output;
output.positionCS = input.positionCS;
#ifdef VARYING_WANT_TANGENT_TO_WORLD
output.interpolators1.xyz = input.tangentToWorld[0];
output.interpolators2.xyz = input.tangentToWorld[1];
output.interpolators3.xyz = input.tangentToWorld[2];
#ifdef VARYING_WANT_POSITION_WS
output.interpolators1.w = input.positionWS.x;
output.interpolators2.w = input.positionWS.y;
output.interpolators3.w = input.positionWS.z;
#else
output.interpolators1.w = 0.0;
output.interpolators2.w = 0.0;
output.interpolators3.w = 0.0;
#endif
#else
#ifdef VARYING_WANT_POSITION_WS
output.interpolators0.xyz = input.positionWS;
output.interpolators0.w = 0.0;
#endif
#endif
#ifdef VARYING_WANT_TEXCOORD0
output.interpolators4.xy = input.texCoord0;
#endif
#ifdef VARYING_WANT_TEXCOORD1
output.interpolators4.zw = input.texCoord1;
#endif
#ifdef VARYING_WANT_TEXCOORD2
output.interpolators5.xy = input.texCoord2;
#endif
#ifdef VARYING_WANT_TEXCOORD3
output.interpolators5.zw = input.texCoord3;
#endif
#ifdef VARYING_WANT_COLOR
output.interpolators6 = input.color;
#endif
#ifdef VARYING_WANT_PASS_SPECIFIC
output.packedVaryingsPass = PackVaryingsPass(input.varyingPass);
#endif
return output;
}
FragInputs UnpackVaryings(PackedVaryings input)
{
FragInputs output;
ZERO_INITIALIZE(FragInputs, output);
output.unPositionSS = input.positionCS; // input.positionCS is SV_Position
#ifdef VARYING_WANT_TANGENT_TO_WORLD
output.tangentToWorld[0] = input.interpolators1.xyz;
output.tangentToWorld[1] = input.interpolators2.xyz;
output.tangentToWorld[2] = input.interpolators3.xyz;
#ifdef WANT_PER_PIXEL_WORLDPOS
output.positionWS.xyz = float3(input.interpolators1.w, input.interpolators2.w, input.interpolators3.w);
#endif
#else
#ifdef VARYING_WANT_POSITION_WS
output.positionWS.xyz = input.interpolators0.xyz;
#endif
#endif
#ifdef VARYING_WANT_TEXCOORD0
output.texCoord0 = input.interpolators4.xy;
#endif
#ifdef VARYING_WANT_TEXCOORD1
output.texCoord1 = input.interpolators4.zw;
#endif
#ifdef VARYING_WANT_TEXCOORD2
output.texCoord2 = input.interpolators5.xy;
#endif
#ifdef VARYING_WANT_TEXCOORD3
output.texCoord3 = input.interpolators5.zw;
#endif
#ifdef VARYING_WANT_COLOR
output.color = input.interpolators6;
#endif
#ifdef VARYING_WANT_PASS_SPECIFIC
output.varyingPass = UnpackVaryingsPass(input.packedVaryingsPass);
#endif
#if defined(VARYING_WANT_CULLFACE) && SHADER_STAGE_FRAGMENT
output.isFrontFace = IS_FRONT_VFACE(input.cullFace, true, false);
#endif
return output;
}
#ifdef TESSELLATION_ON
// Varying DS - use for domain shader
// We can deduce these define from the other define
// 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_NORMAL
#define VARYING_DS_WANT_TANGENT
#endif
#if defined(VARYING_WANT_TEXCOORD0) || defined(ATTRIBUTES_WANT_UV0)
#define VARYING_DS_WANT_TEXCOORD0
#endif
#if defined(VARYING_WANT_TEXCOORD1) || defined(ATTRIBUTES_WANT_UV1)
#define VARYING_DS_WANT_TEXCOORD1
#endif
#if defined(VARYING_WANT_TEXCOORD2) || defined(ATTRIBUTES_WANT_UV2)
#define VARYING_DS_WANT_TEXCOORD2
#endif
#if defined(VARYING_WANT_TEXCOORD3) || defined(ATTRIBUTES_WANT_UV3)
#define VARYING_DS_WANT_TEXCOORD3
#endif
#if defined(VARYING_WANT_COLOR) || defined(ATTRIBUTES_WANT_COLOR)
float4 VARYING_DS_WANT_COLOR;
#endif
// Varying for domain shader
// Position and normal are always present (for tessellation) and in world space
struct VaryingsDS
{
float3 positionWS;
#ifdef VARYING_DS_WANT_NORMAL
float3 normalWS;
#endif
#ifdef VARYING_DS_WANT_TANGENT
float4 tangentWS;
#endif
#ifdef VARYING_DS_WANT_TEXCOORD0
float2 texCoord0;
#endif
#ifdef VARYING_DS_WANT_TEXCOORD1
float2 texCoord1;
#endif
#ifdef VARYING_DS_WANT_TEXCOORD2
float2 texCoord2;
#endif
#ifdef VARYING_DS_WANT_TEXCOORD3
float2 texCoord3;
#endif
#ifdef VARYING_DS_WANT_COLOR
float4 color;
#endif
};
struct PackedVaryingsDS
{
float3 interpolators0 : INTERNALTESSPOS; // positionWS
#ifdef VARYING_DS_WANT_NORMAL
float3 interpolators1 : NORMAL;
#endif
#ifdef VARYING_DS_WANT_TANGENT
float4 interpolators2 : TANGENT;
#endif
// Allocate only necessary space if shader compiler in the future are able to automatically pack
#ifdef VARYING_DS_WANT_TEXCOORD1
float4 interpolators3 : TEXCOORD0;
#elif defined(VARYING_DS_WANT_TEXCOORD0)
float2 interpolators3 : TEXCOORD0;
#endif
#ifdef VARYING_DS_WANT_TEXCOORD3
float4 interpolators4 : TEXCOORD1;
#elif defined(VARYING_DS_WANT_TEXCOORD2)
float2 interpolators4 : TEXCOORD1;
#endif
#ifdef VARYING_DS_WANT_COLOR
float4 interpolators5 : TEXCOORD2;
#endif
};
// Functions to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions
PackedVaryingsDS PackVaryingsDS(VaryingsDS input)
{
PackedVaryingsDS output;
output.interpolators0 = input.positionWS;
#ifdef VARYING_DS_WANT_NORMAL
output.interpolators1 = input.normalWS;
#endif
#ifdef VARYING_DS_WANT_TANGENT
output.interpolators2 = input.tangentWS;
#endif
#ifdef VARYING_DS_WANT_TEXCOORD0
output.interpolators3.xy = input.texCoord0;
#endif
#ifdef VARYING_DS_WANT_TEXCOORD1
output.interpolators3.zw = input.texCoord1;
#endif
#ifdef VARYING_DS_WANT_TEXCOORD2
output.interpolators4.xy = input.texCoord2;
#endif
#ifdef VARYING_DS_WANT_TEXCOORD3
output.interpolators4.zw = input.texCoord3;
#endif
#ifdef VARYING_DS_WANT_COLOR
output.interpolators5 = input.color;
#endif
return output;
}
VaryingsDS UnpackVaryingsDS(PackedVaryingsDS input)
{
VaryingsDS output;
output.positionWS = input.interpolators0;
#ifdef VARYING_DS_WANT_NORMAL
output.normalWS = input.interpolators1;
#endif
#ifdef VARYING_DS_WANT_TANGENT
output.tangentWS = input.interpolators2;
#endif
#ifdef VARYING_DS_WANT_TEXCOORD0
output.texCoord0 = input.interpolators3.xy;
#endif
#ifdef VARYING_DS_WANT_TEXCOORD1
output.texCoord1 = input.interpolators3.zw;
#endif
#ifdef VARYING_DS_WANT_TEXCOORD2
output.texCoord2 = input.interpolators4.xy;
#endif
#ifdef VARYING_DS_WANT_TEXCOORD3
output.texCoord3 = input.interpolators4.zw;
#endif
#ifdef VARYING_DS_WANT_COLOR
output.color = input.interpolators5;
#endif
return output;
}
VaryingsDS InterpolateWithBaryCoords(VaryingsDS input0, VaryingsDS input1, VaryingsDS input2, float3 baryCoords)
{
VaryingsDS ouput;
TESSELLATION_INTERPOLATE_BARY(positionWS, baryCoords);
#ifdef VARYING_DS_WANT_NORMAL
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
TESSELLATION_INTERPOLATE_BARY(texCoord0, baryCoords);
#endif
#ifdef VARYING_DS_WANT_TEXCOORD1
TESSELLATION_INTERPOLATE_BARY(texCoord1, baryCoords);
#endif
#ifdef VARYING_DS_WANT_TEXCOORD2
TESSELLATION_INTERPOLATE_BARY(texCoord2, baryCoords);
#endif
#ifdef VARYING_DS_WANT_TEXCOORD3
TESSELLATION_INTERPOLATE_BARY(texCoord3, baryCoords);
#endif
#ifdef VARYING_DS_WANT_COLOR
TESSELLATION_INTERPOLATE_BARY(color, baryCoords);
#endif
return ouput;
}
#endif // TESSELLATION_ON
#ifdef TESSELLATION_ON
#define VaryingsType VaryingsDS
#define PackedVaryingsType PackedVaryingsDS
#define PackVaryingsType PackVaryingsDS
#else
#define VaryingsType Varyings
#define PackedVaryingsType PackedVaryings
#define PackVaryingsType PackVaryings
#endif

61
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/UnlitSharePass.hlsl


#ifndef SHADERPASS
#error Undefine_SHADERPASS
#endif
//-------------------------------------------------------------------------------------
// Attribute/Varying
//-------------------------------------------------------------------------------------
struct Attributes
{
float3 positionOS : POSITION;
float2 uv0 : TEXCOORD0;
};
struct Varyings
{
float4 positionCS;
float2 texCoord0;
};
struct PackedVaryings
{
float4 positionCS : SV_Position;
float4 interpolators[1] : TEXCOORD0;
};
PackedVaryings PackVaryings(Varyings input)
{
PackedVaryings output;
output.positionCS = input.positionCS;
output.interpolators[0] = float4(input.texCoord0.xy, 0.0, 0.0);
return output;
}
FragInputs UnpackVaryings(PackedVaryings input)
{
FragInputs output;
ZERO_INITIALIZE(FragInputs, output);
output.unPositionSS = input.positionCS;
output.texCoord0.xy = input.interpolators[0].xy;
return output;
}
//-------------------------------------------------------------------------------------
// Vertex shader
//-------------------------------------------------------------------------------------
PackedVaryings Vert(Attributes input)
{
Varyings output;
float3 positionWS = TransformObjectToWorld(input.positionOS);
output.positionCS = TransformWorldToHClip(positionWS);
output.texCoord0 = input.uv0;
return PackVaryings(output);
}

9
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl.meta


fileFormatVersion: 2
guid: 6d56e29698894b440905cc5d63814ef9
timeCreated: 1479292899
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tessellation.meta


fileFormatVersion: 2
guid: 9582236b174d65b4391e0f9890fd2194
folderAsset: yes
timeCreated: 1483692743
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitAttributesVarying.hlsl.meta → /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl.meta

/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/UnlitSharePass.hlsl.meta → /Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitSharePass.hlsl.meta

/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl → /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl

正在加载...
取消
保存