浏览代码

Merge branch 'master' into Branch_fix-ps4-hdrenderloop

# Conflicts:
#	Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.shader
#	Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/Resources/SkyHDRI.shader
#	Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/SkyProcedural.shader
#	Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/GGXConvolve.shader
/main
Julien Ignace 8 年前
当前提交
c83f3d4a
共有 83 个文件被更改,包括 3277 次插入1572 次删除
  1. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/DebugViewMaterial.cs.hlsl
  2. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewTiles.shader
  3. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.asset.meta
  4. 83
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  5. 22
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl
  6. 14
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl
  7. 8
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Builtin/BuiltinData.cs.hlsl
  8. 48
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs
  9. 14
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
  10. 59
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  11. 154
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs
  12. 39
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
  13. 11
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs
  14. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs.hlsl
  15. 11
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.hlsl
  16. 46
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader
  17. 91
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl
  18. 31
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
  19. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl
  20. 89
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader
  21. 195
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDepthPass.hlsl
  22. 173
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDistortionPass.hlsl
  23. 91
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitMetaPass.hlsl
  24. 252
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitSharePass.hlsl
  25. 215
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitVelocityPass.hlsl
  26. 8
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.cs.hlsl
  27. 166
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.shader
  28. 7
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/UnlitData.hlsl
  29. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl
  30. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl
  31. 26
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDebugViewMaterial.hlsl
  32. 26
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl
  33. 26
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDistortion.hlsl
  34. 26
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassForward.hlsl
  35. 26
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl
  36. 26
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl
  37. 49
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl
  38. 126
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassVelocity.hlsl
  39. 6
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl
  40. 6
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs
  41. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/SkyProcedural.shader
  42. 26
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/GGXConvolve.shader
  43. 67
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs
  44. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs.hlsl
  45. 9
      Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl
  46. 14
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
  47. 1
      Assets/ScriptableRenderLoop/ShaderLibrary/CommonMaterial.hlsl
  48. 139
      Assets/ScriptableRenderLoop/ShaderLibrary/ImageBasedLighting.hlsl
  49. 195
      Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl
  50. 2
      Assets/ScriptableRenderLoop/common/TextureCache.cs
  51. 2
      README.md
  52. 26
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl
  53. 107
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl
  54. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass.meta
  55. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl.meta
  56. 86
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/TessellationShare.hlsl
  57. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/TessellationShare.hlsl.meta
  58. 363
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl
  59. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl.meta
  60. 182
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VertMesh.hlsl
  61. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/VertMesh.hlsl.meta
  62. 49
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/ComputeGgxIblSampleData.compute
  63. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/ComputeGgxIblSampleData.compute.meta
  64. 134
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/RuntimeFilterIBL.cs
  65. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/RuntimeFilterIBL.cs.meta
  66. 1001
      Assets/TestScenes/HDTest/GlobalIlluminationTest/LightingData.asset
  67. 8
      Assets/TestScenes/HDTest/GlobalIlluminationTest/LightingData.asset.meta
  68. 13
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitMetaPass.hlsl
  69. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitMetaPass.hlsl.meta
  70. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitSharePass.hlsl
  71. 41
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTesselation.hlsl
  72. 61
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/UnlitSharePass.hlsl
  73. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl.meta
  74. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tesselation.meta
  75. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader.meta
  76. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  77. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl.meta
  78. 0
      /Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl.meta
  79. 0
      /Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl
  80. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitSharePass.hlsl.meta
  81. 0
      /Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/FragInputs.hlsl

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/DebugViewMaterial.cs.hlsl


#ifndef DEBUGVIEWMATERIAL_CS_HLSL
#define DEBUGVIEWMATERIAL_CS_HLSL
//
// UnityEngine.Experimental.ScriptableRenderLoop.Attributes.DebugViewVarying: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.Attributes.DebugViewVarying: static fields
//
#define DEBUGVIEWVARYING_TEXCOORD0 (1)
#define DEBUGVIEWVARYING_TEXCOORD1 (2)

#define DEBUGVIEWVARYING_VERTEX_COLOR_ALPHA (9)
//
// UnityEngine.Experimental.ScriptableRenderLoop.Attributes.DebugViewGbuffer: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.Attributes.DebugViewGbuffer: static fields
//
#define DEBUGVIEWGBUFFER_DEPTH (10)
#define DEBUGVIEWGBUFFER_BAKE_DIFFUSE_LIGHTING (11)

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewTiles.shader


int n = -1;
if(tileCoord.x == 0)
{
n = count;
n = (int)count;
else if(lightListIndex >= 0 && lightListIndex < count)
else if(lightListIndex >= 0 && lightListIndex < (int)count)
{
n = FetchIndex(start, lightListIndex);
}

2
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.asset.meta


fileFormatVersion: 2
guid: e185fecca3c73cd47a09f1092663ef32
timeCreated: 1483606455
timeCreated: 1484329328
licenseType: Pro
NativeFormatImporter:
userData:

83
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


if (m_Owner != null)
m_Owner.Build();
}
public override void Dispose()
{
base.Dispose();

public override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
{

{
return new HDRenderPipelineInstance(this);
}
SkyManager m_SkyManager = new SkyManager();
public SkyManager skyManager
{

public bool useForwardRenderingOnly = false; // TODO: Currently there is no way to strip the extra forward shaders generated by the shaders compiler, so we can switch dynamically.
public bool useDepthPrepass = false;
public bool useDistortion = true;
// we have to fallback to forward-only rendering when scene view is using wireframe rendering mode --
// as rendering everything in wireframe + deferred do not play well together
public bool ShouldUseForwardRenderingOnly () { return useForwardRenderingOnly || GL.wireframe; }
}
DebugParameters m_DebugParameters = new DebugParameters();

{
m_lightLoop.Cleanup();
m_LitRenderLoop.Cleanup();
Utilities.Destroy(m_DebugViewMaterialGBuffer);
m_SkyManager.Cleanup();

cmd.GetTemporaryRT(m_CameraColorBuffer, w, h, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear, 1, true); // Enable UAV
cmd.GetTemporaryRT(m_CameraDepthBuffer, w, h, 24, FilterMode.Point, RenderTextureFormat.Depth);
if (!debugParameters.useForwardRenderingOnly)
if (!debugParameters.ShouldUseForwardRenderingOnly())
{
m_gbufferManager.InitGBuffers(w, h, cmd);
}

void RenderGBuffer(CullResults cull, Camera camera, ScriptableRenderContext renderContext)
{
if (debugParameters.useForwardRenderingOnly)
if (debugParameters.ShouldUseForwardRenderingOnly())
{
return ;
}

}
// This pass is use in case of forward opaque and deferred rendering. We need to render forward objects before tile lighting pass
void RenderForwardOnlyDepthPrepass(CullResults cull, Camera camera, ScriptableRenderContext renderContext)
void RenderForwardOnlyOpaqueDepthPrepass(CullResults cull, Camera camera, ScriptableRenderContext renderContext)
// If we are forward only we don't need to render ForwardOpaqueDepth object
// If we are forward only we don't need to render ForwardOnlyOpaqueDepthOnly object
if (debugParameters.useForwardRenderingOnly && !debugParameters.useDepthPrepass)
if (debugParameters.ShouldUseForwardRenderingOnly() && !debugParameters.useDepthPrepass)
RenderOpaqueRenderList(cull, camera, renderContext, "ForwardOnlyDepthOnly");
RenderOpaqueRenderList(cull, camera, renderContext, "ForwardOnlyOpaqueDepthOnly");
}
}

}
// Render GBuffer opaque
if (!debugParameters.useForwardRenderingOnly)
if (!debugParameters.ShouldUseForwardRenderingOnly())
{
Utilities.SetupMaterialHDCamera(hdCamera, m_DebugViewMaterialGBuffer);
m_DebugViewMaterialGBuffer.SetFloat("_DebugViewMaterial", (float)debugParameters.debugViewMaterial);

void RenderDeferredLighting(HDCamera hdCamera, ScriptableRenderContext renderContext)
{
if (debugParameters.useForwardRenderingOnly)
if (debugParameters.ShouldUseForwardRenderingOnly())
{
return ;
}

{
m_SkyManager.RenderSky(hdCamera, m_lightLoop.GetCurrentSunLight(), m_CameraColorBufferRT, m_CameraDepthBufferRT, renderContext);
}
if (!debugParameters.useForwardRenderingOnly && renderOpaque)
if (!debugParameters.ShouldUseForwardRenderingOnly() && renderOpaque)
return;
using (new Utilities.ProfilingSample("Forward Pass", renderContext))

}
}
// Render material that are forward opaque only (like eye)
// TODO: Think about hair that could be render both as opaque and transparent...
void RenderForwardOnly(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext)
// Render material that are forward opaque only (like eye), this include unlit material
void RenderForwardOnlyOpaque(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext)
{
using (new Utilities.ProfilingSample("Forward Only Pass", renderContext))
{

Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthBufferRT);
m_lightLoop.RenderForward(camera, renderContext, true);
RenderOpaqueRenderList(cullResults, camera, renderContext, "ForwardOnly");
}
}
void RenderForwardUnlit(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext)
{
using (new Utilities.ProfilingSample("Forward Unlit Pass", renderContext))
{
// Bind material data
m_LitRenderLoop.Bind();
Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthBufferRT);
RenderOpaqueRenderList(cullResults, camera, renderContext, "ForwardUnlit");
RenderTransparentRenderList(cullResults, camera, renderContext, "ForwardUnlit");
RenderOpaqueRenderList(cullResults, camera, renderContext, "ForwardOnlyOpaque");
}
}

{
// If opaque velocity have been render during GBuffer no need to render it here
if ((ShaderConfig.s_VelocityInGbuffer == 0) || debugParameters.useForwardRenderingOnly)
if ((ShaderConfig.s_VelocityInGbuffer == 0) || debugParameters.ShouldUseForwardRenderingOnly())
return ;
int w = camera.pixelWidth;

m_ShadowSettings.maxShadowDistance = m_CommonSettings.shadowMaxDistance;
}
}
public void Render(ScriptableRenderContext renderContext, IEnumerable<Camera> cameras)
{
if (!m_LitRenderLoop.isInit)

// Forward opaque with deferred/cluster tile require that we fill the depth buffer
// correctly to build the light list.
// TODO: avoid double lighting by tagging stencil or gbuffer that we must not lit.
RenderForwardOnlyDepthPrepass(cullResults, camera, renderContext);
RenderForwardOnlyOpaqueDepthPrepass(cullResults, camera, renderContext);
RenderGBuffer(cullResults, camera, renderContext);
if (debugParameters.debugViewMaterial != 0)

using (new Utilities.ProfilingSample("Shadow Pass", renderContext))
{
m_ShadowPass.Render(renderContext, cullResults, out shadows);
}
}
m_lightLoop.BuildGPULightLists(camera, renderContext, m_CameraDepthBufferRT);
m_lightLoop.BuildGPULightLists(camera, renderContext, m_CameraDepthBufferRT); // TODO: Use async compute here to run light culling during shadow
}
UpdateSkyEnvironment(hdCamera, renderContext);
}
// Caution: We require sun light here as some sky use the sun light to render, mean UpdateSkyEnvironment
// must be call after BuildGPULightLists.
// TODO: Try to arrange code so we can trigger this call earlier and use async compute here to run sky convolution during other passes (once we move convolution shader to compute).
UpdateSkyEnvironment(hdCamera, renderContext);
RenderForward(cullResults, camera, renderContext, true);
RenderForwardOnly(cullResults, camera, renderContext);
// For opaque forward we have split rendering in two categories
// Material that are always forward and material that can be deferred or forward depends on render pipeline options (like switch to rendering forward only mode)
// Material that are always forward are unlit and complex (Like Hair) and don't require sorting, so it is ok to split them.
RenderForward(cullResults, camera, renderContext, true); // Render deferred or forward opaque
RenderForwardOnlyOpaque(cullResults, camera, renderContext);
// Render all type of transparent forward (unlit, lit, complex (hair...)) to keep the sorting between transparent objects.
RenderForwardUnlit(cullResults, camera, renderContext);
RenderVelocity(cullResults, camera, renderContext); // Note we may have to render velocity earlier if we do temporalAO, temporal volumetric etc... Mean we will not take into account forward opaque in case of deferred rendering ?

22
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl


#ifndef LIGHTDEFINITION_CS_HLSL
#define LIGHTDEFINITION_CS_HLSL
//
// UnityEngine.Experimental.ScriptableRenderLoop.GPULightType: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.GPULightType: static fields
//
#define GPULIGHTTYPE_DIRECTIONAL (0)
#define GPULIGHTTYPE_SPOT (1)

#define GPULIGHTTYPE_CYLINDER (10)
//
// UnityEngine.Experimental.ScriptableRenderLoop.EnvShapeType: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.EnvShapeType: static fields
//
#define ENVSHAPETYPE_NONE (0)
#define ENVSHAPETYPE_BOX (1)

//
// UnityEngine.Experimental.ScriptableRenderLoop.EnvConstants: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.EnvConstants: static fields
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.LightData
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.LightData
// PackingRules = Exact
struct LightData
{

bool twoSided;
};
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.DirectionalLightData
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.DirectionalLightData
// PackingRules = Exact
struct DirectionalLightData
{

int cookieIndex;
};
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.ShadowData
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.ShadowData
// PackingRules = Exact
struct ShadowData
{

float4 invResolution;
};
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.EnvLightData
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.EnvLightData
// PackingRules = Exact
struct EnvLightData
{

};
//
// Accessors for UnityEngine.Experimental.ScriptableRenderLoop.LightData
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.LightData
//
float3 GetPositionWS(LightData value)
{

}
//
// Accessors for UnityEngine.Experimental.ScriptableRenderLoop.DirectionalLightData
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.DirectionalLightData
//
float3 GetForward(DirectionalLightData value)
{

}
//
// Accessors for UnityEngine.Experimental.ScriptableRenderLoop.ShadowData
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.ShadowData
//
float4x4 GetWorldToShadow(ShadowData value)
{

}
//
// Accessors for UnityEngine.Experimental.ScriptableRenderLoop.EnvLightData
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.EnvLightData
//
float3 GetPositionWS(EnvLightData value)
{

14
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl


#ifndef TILEPASS_CS_HLSL
#define TILEPASS_CS_HLSL
//
// UnityEngine.Experimental.ScriptableRenderLoop.TilePass.LightVolumeType: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.TilePass.LightVolumeType: static fields
//
#define LIGHTVOLUMETYPE_CONE (0)
#define LIGHTVOLUMETYPE_SPHERE (1)

//
// UnityEngine.Experimental.ScriptableRenderLoop.TilePass.LightCategory: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.TilePass.LightCategory: static fields
//
#define LIGHTCATEGORY_PUNCTUAL (0)
#define LIGHTCATEGORY_AREA (1)

//
// UnityEngine.Experimental.ScriptableRenderLoop.TilePass.LightDefinitions: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.TilePass.LightDefinitions: static fields
//
#define MAX_NR_LIGHTS_PER_CAMERA (1024)
#define MAX_NR_BIGTILE_LIGHTS_PLUSONE (512)

#define IS_BOX_PROJECTED (4)
#define HAS_SHADOW (8)
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.TilePass.SFiniteLightBound
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.TilePass.SFiniteLightBound
// PackingRules = Exact
struct SFiniteLightBound
{

float radius;
};
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.TilePass.LightVolumeData
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.TilePass.LightVolumeData
// PackingRules = Exact
struct LightVolumeData
{

};
//
// Accessors for UnityEngine.Experimental.ScriptableRenderLoop.TilePass.SFiniteLightBound
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.TilePass.SFiniteLightBound
//
float3 GetBoxAxisX(SFiniteLightBound value)
{

}
//
// Accessors for UnityEngine.Experimental.ScriptableRenderLoop.TilePass.LightVolumeData
// Accessors for UnityEngine.Experimental.Rendering.HDPipeline.TilePass.LightVolumeData
//
float3 GetLightPos(LightVolumeData value)
{

8
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Builtin/BuiltinData.cs.hlsl


#ifndef BUILTINDATA_CS_HLSL
#define BUILTINDATA_CS_HLSL
//
// UnityEngine.Experimental.ScriptableRenderLoop.Builtin.BuiltinData: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.Builtin.BuiltinData: static fields
//
#define DEBUGVIEW_BUILTIN_BUILTINDATA_OPACITY (100)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_BAKE_DIFFUSE_LIGHTING (101)

#define DEBUGVIEW_BUILTIN_BUILTINDATA_DEPTH_OFFSET (107)
//
// UnityEngine.Experimental.ScriptableRenderLoop.Builtin.LighTransportData: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.Builtin.LighTransportData: static fields
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.Builtin.BuiltinData
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Builtin.BuiltinData
// PackingRules = Exact
struct BuiltinData
{

float depthOffset;
};
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.Builtin.LighTransportData
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Builtin.LighTransportData
// PackingRules = Exact
struct LighTransportData
{

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


MaterialProperty layerEmissiveColor = null;
MaterialProperty layerEmissiveColorMap = null;
MaterialProperty layerEmissiveIntensity = null;
MaterialProperty layerTesselationFactor = null;
override protected void FindMaterialProperties(MaterialProperty[] props)
{

layerEmissiveColor = FindProperty(kEmissiveColor, props);
layerEmissiveColorMap = FindProperty(kEmissiveColorMap, props);
layerEmissiveIntensity = FindProperty(kEmissiveIntensity, props);
layerTesselationFactor = FindProperty(kTesselationFactor, props, false);
}
int numLayer

}
// 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)

m_MaterialEditor.ShaderProperty(layerEmissiveIntensity, Styles.emissiveIntensityText);
m_MaterialEditor.LightmapEmissionProperty(1);
EditorGUI.indentLevel--;
if (layerTesselationFactor != null)
{
GUILayout.Label(Styles.tesselationText, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(layerTesselationFactor, Styles.tesselationFactorText);
EditorGUI.indentLevel--;
}
CheckLayerConsistency();

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


#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _DISTORTION_ON
#pragma shader_feature _DEPTHOFFSET_ON
#pragma shader_feature _ _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
#pragma shader_feature _ _DOUBLESIDED _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _LAYER_MAPPING_TRIPLANAR_0

#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

#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/ShaderPass/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

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


_HeightFactor2("_HeightFactor2", Range(0, 5)) = 1
_HeightFactor3("_HeightFactor3", Range(0, 5)) = 1
_BlendSize1("_BlendSize1", Range(0, 0.05)) = 0.0
_BlendSize2("_BlendSize2", Range(0, 0.05)) = 0.0
_BlendSize3("_BlendSize3", Range(0, 0.05)) = 0.0
_BlendSize1("_BlendSize1", Range(0, 0.30)) = 0.0
_BlendSize2("_BlendSize2", Range(0, 0.30)) = 0.0
_BlendSize3("_BlendSize3", Range(0, 0.30)) = 0.0
_InheritBaseLayer1("_InheritBaseLayer1", Range(0, 1.0)) = 0.0
_InheritBaseLayer2("_InheritBaseLayer2", Range(0, 1.0)) = 0.0

[HideInInspector] _UVDetailsMappingMask1("_UVDetailsMappingMask1", Color) = (1, 0, 0, 0)
[HideInInspector] _UVDetailsMappingMask2("_UVDetailsMappingMask2", Color) = (1, 0, 0, 0)
[HideInInspector] _UVDetailsMappingMask3("_UVDetailsMappingMask3", Color) = (1, 0, 0, 0)
_TesselationFactor("Tesselation Factor", Float) = 3.0
[Enum(Phong, 0, Displacement, 1, DisplacementPhong, 2)] _TessellationMode("Tessellation mode", Float) = 1
_TessellationFactor("Tessellation Factor", Range(0.0, 15.0)) = 4.0
_TessellationFactorMinDistance("Tessellation start fading distance", Float) = 20.0
_TessellationFactorMaxDistance("Tessellation end fading distance", Float) = 50.0
_TessellationFactorTriangleSize("Tessellation triangle size", Float) = 100.0
_TessellationShapeFactor("Tessellation shape factor", Range(0.0, 1.0)) = 0.75 // Only use with Phong
_TessellationBackFaceCullEpsilon("Tessellation back face epsilon", Range(-1.0, 0.0)) = -0.25
[ToggleOff] _TessellationObjectScale("Tessellation object scale", Float) = 0.0
// TODO: Handle culling mode for backface culling
}
HLSLINCLUDE

#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _DISTORTION_ON
#pragma shader_feature _DEPTHOFFSET_ON
#pragma shader_feature _ _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
#pragma shader_feature _ _DOUBLESIDED _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
// Default is _TESSELLATION_PHONG
#pragma shader_feature _ _TESSELLATION_DISPLACEMENT _TESSELLATION_DISPLACEMENT_PHONG
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _LAYER_MAPPING_TRIPLANAR_0

#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

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

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

#endif
// Explicitely said that we are a layered shader as we share code between lit and layered lit
#define LAYERED_LIT_SHADER
#define LAYERED_LIT_SHADER
//-------------------------------------------------------------------------------------
// variable declaration

// 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

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

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

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

// 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
#include "../../ShaderPass/ShaderPassLightTransport.hlsl"
ENDHLSL

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

#include "../Lit/LitData.hlsl"
#include "../Tesselation/TesselationShare.hlsl"
#include "../../ShaderPass/ShaderPassVelocity.hlsl"
ENDHLSL

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

#include "../Lit/LitData.hlsl"
#include "../Tesselation/TesselationShare.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL

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

#include "../Lit/LitData.hlsl"
#include "../Tesselation/TesselationShare.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL

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

#include "../Lit/LitData.hlsl"
#include "../Tesselation/TesselationShare.hlsl"
#include "../../ShaderPass/ShaderPassDistortion.hlsl"
ENDHLSL

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

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

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


{
protected static class Styles
{
public static string OptionText = "Options";
public static string SurfaceTypeText = "Surface Type";
public static string BlendModeText = "Blend Mode";
public static string optionText = "Options";
public static string surfaceTypeText = "Surface Type";
public static string blendModeText = "Blend Mode";
public static string detailText = "Inputs Detail";
public static string lightingText = "Inputs Lighting";

public static GUIContent emissiveWarning = new GUIContent("Emissive value is animated but the material has not been configured to support emissive. Please make sure the material itself has some amount of emissive.");
public static GUIContent emissiveColorWarning = new GUIContent("Ensure emissive color is non-black for emission to have effect.");
public static GUIContent tesselationText = new GUIContent("Tesselation options", "Tesselation options");
public static GUIContent tesselationFactorText = new GUIContent("Tesselation factor", "Tesselation factor");
public static string tessellationModeText = "Tessellation Mode";
public static readonly string[] tessellationModeNames = Enum.GetNames(typeof(TessellationMode));
public static GUIContent tessellationText = new GUIContent("Tessellation options", "Tessellation options");
public static GUIContent tessellationFactorText = new GUIContent("Tessellation factor", "This value is the tessellation factor use for tessellation, higher mean more tessellated");
public static GUIContent tessellationFactorMinDistanceText = new GUIContent("Start fade distance", "Distance (in unity unit) at which the tessellation start to fade out. Must be inferior at Max distance");
public static GUIContent tessellationFactorMaxDistanceText = new GUIContent("End fade distance", "Maximum distance (in unity unit) to the camera where triangle are tessellated");
public static GUIContent tessellationFactorTriangleSizeText = new GUIContent("Triangle size", "Desired screen space sized of triangle (in pixel). Smaller value mean smaller triangle.");
public static GUIContent tessellationShapeFactorText = new GUIContent("Shape factor", "Strength of Phong tessellation shape (lerp factor)");
public static GUIContent tessellationBackFaceCullEpsilonText = new GUIContent("Triangle culling Epsilon", "If -1.0 back face culling is enabled for tessellation, higher number mean more aggressive culling and better performance");
public static GUIContent tessellationObjectScaleText = new GUIContent("Enable object scale", "Scale displacement taking into account the object scale");
}
public enum SurfaceType

}
public enum BlendMode
{
Lerp,

Premultiply
}
public enum DoubleSidedMode
{
None,

}
public enum TessellationMode
{
Phong,
Displacement,
DisplacementPhong,
}
void SurfaceTypePopup()
{
EditorGUI.showMixedValue = surfaceType.hasMixedValue;

mode = (SurfaceType)EditorGUILayout.Popup(Styles.SurfaceTypeText, (int)mode, Styles.surfaceTypeNames);
mode = (SurfaceType)EditorGUILayout.Popup(Styles.surfaceTypeText, (int)mode, Styles.surfaceTypeNames);
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo("Surface Type");

EditorGUI.showMixedValue = false;
}
void TessellationModePopup()
{
EditorGUI.showMixedValue = tessellationMode.hasMixedValue;
var mode = (TessellationMode)tessellationMode.floatValue;
EditorGUI.BeginChangeCheck();
mode = (TessellationMode)EditorGUILayout.Popup(Styles.tessellationModeText, (int)mode, Styles.tessellationModeNames);
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo("Tessellation Mode");
tessellationMode.floatValue = (float)mode;
}
EditorGUI.showMixedValue = false;
}
GUILayout.Label(Styles.OptionText, EditorStyles.boldLabel);
GUILayout.Label(Styles.optionText, EditorStyles.boldLabel);
SurfaceTypePopup();
if ((SurfaceType)surfaceType.floatValue == SurfaceType.Transparent)
{

m_MaterialEditor.ShaderProperty(depthOffsetEnable, Styles.depthOffsetEnableText.text);
EditorGUI.indentLevel--;
if (tessellationMode != null)
{
GUILayout.Label(Styles.tessellationText, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
TessellationModePopup();
m_MaterialEditor.ShaderProperty(tessellationFactor, Styles.tessellationFactorText);
m_MaterialEditor.ShaderProperty(tessellationFactorMinDistance, Styles.tessellationFactorMinDistanceText);
m_MaterialEditor.ShaderProperty(tessellationFactorMaxDistance, Styles.tessellationFactorMaxDistanceText);
// clamp min distance to be below max distance
tessellationFactorMinDistance.floatValue = Math.Min(tessellationFactorMaxDistance.floatValue, tessellationFactorMinDistance.floatValue);
m_MaterialEditor.ShaderProperty(tessellationFactorTriangleSize, Styles.tessellationFactorTriangleSizeText);
if ((TessellationMode)tessellationMode.floatValue == TessellationMode.Phong ||
(TessellationMode)tessellationMode.floatValue == TessellationMode.DisplacementPhong)
{
m_MaterialEditor.ShaderProperty(tessellationShapeFactor, Styles.tessellationShapeFactorText);
}
if ((DoubleSidedMode)doubleSidedMode.floatValue == DoubleSidedMode.None)
{
m_MaterialEditor.ShaderProperty(tessellationBackFaceCullEpsilon, Styles.tessellationBackFaceCullEpsilonText);
}
// TODO: Implement
// m_MaterialEditor.ShaderProperty(tessellationObjectScale, Styles.tessellationObjectScaleText);
EditorGUI.indentLevel--;
}
}
private void BlendModePopup()

EditorGUI.BeginChangeCheck();
mode = (BlendMode)EditorGUILayout.Popup(Styles.BlendModeText, (int)mode, Styles.blendModeNames);
mode = (BlendMode)EditorGUILayout.Popup(Styles.blendModeText, (int)mode, Styles.blendModeNames);
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo("Blend Mode");

distortionOnly = FindProperty(kDistortionOnly, props);
distortionDepthTest = FindProperty(kDistortionDepthTest, props);
depthOffsetEnable = FindProperty(kDepthOffsetEnable, props);
// tessellation specific, silent if not found
tessellationMode = FindProperty(kTessellationMode, props, false);
tessellationFactor = FindProperty(kTessellationFactor, props, false);
tessellationFactorMinDistance = FindProperty(kTessellationFactorMinDistance, props, false);
tessellationFactorMaxDistance = FindProperty(kTessellationFactorMaxDistance, props, false);
tessellationFactorTriangleSize = FindProperty(kTessellationFactorTriangleSize, props, false);
tessellationShapeFactor = FindProperty(kTessellationShapeFactor, props, false);
tessellationBackFaceCullEpsilon = FindProperty(kTessellationBackFaceCullEpsilon, props, false);
tessellationObjectScale = FindProperty(kTessellationObjectScale, props, false);
}
protected void SetupCommonOptionsKeywords(Material material)

BlendMode blendMode = (BlendMode)material.GetFloat(kBlendMode);
DoubleSidedMode doubleSidedMode = (DoubleSidedMode)material.GetFloat(kDoubleSidedMode);
if (surfaceType == SurfaceType.Opaque)
{
material.SetOverrideTag("RenderType", alphaTestEnable ? "TransparentCutout" : "");

if (doubleSidedMode == DoubleSidedMode.DoubleSidedLightingFlip)
{
material.DisableKeyword("_DOUBLESIDED");
material.DisableKeyword("_DOUBLESIDED");
else if (doubleSidedMode == DoubleSidedMode.DoubleSided)
{
material.EnableKeyword("_DOUBLESIDED");
material.DisableKeyword("_DOUBLESIDED_LIGHTING_FLIP");
material.DisableKeyword("_DOUBLESIDED_LIGHTING_MIRROR");
}
material.DisableKeyword("_DOUBLESIDED");
material.DisableKeyword("_DOUBLESIDED_LIGHTING_FLIP");
material.DisableKeyword("_DOUBLESIDED_LIGHTING_MIRROR");
}

SetKeyword(material, "_DEPTHOFFSET_ON", depthOffsetEnable);
SetupEmissionGIFlags(material);
if (tessellationMode != null)
{
TessellationMode tessMode = (TessellationMode)material.GetFloat(kTessellationMode);
if (tessMode == TessellationMode.Phong)
{
material.DisableKeyword("_TESSELLATION_DISPLACEMENT");
material.DisableKeyword("_TESSELLATION_DISPLACEMENT_PHONG");
}
else if (tessMode == TessellationMode.Displacement)
{
material.EnableKeyword("_TESSELLATION_DISPLACEMENT");
material.DisableKeyword("_TESSELLATION_DISPLACEMENT_PHONG");
}
else
{
material.DisableKeyword("_TESSELLATION_DISPLACEMENT");
material.EnableKeyword("_TESSELLATION_DISPLACEMENT_PHONG");
}
}
}
protected void SetKeyword(Material m, string keyword, bool state)

protected MaterialEditor m_MaterialEditor;
MaterialProperty surfaceType = null;
const string kSurfaceType = "_SurfaceType";
const string kAlphaCutoffEnabled = "_AlphaCutoffEnable";
MaterialProperty alphaCutoff = null;
MaterialProperty doubleSidedMode = null;
MaterialProperty distortionEnable = null;
MaterialProperty distortionOnly = null;
MaterialProperty distortionDepthTest = null;
MaterialProperty depthOffsetEnable = null;
const string kSurfaceType = "_SurfaceType";
MaterialProperty alphaCutoff = null;
const string kAlphaCutoffEnabled = "_AlphaCutoffEnable";
MaterialProperty doubleSidedMode = null;
MaterialProperty distortionEnable = null;
MaterialProperty distortionOnly = null;
MaterialProperty distortionDepthTest = null;
MaterialProperty depthOffsetEnable = null;
// tessellation params
MaterialProperty tessellationMode = null;
const string kTessellationMode = "_TessellationMode";
MaterialProperty tessellationFactor = null;
const string kTessellationFactor = "_TessellationFactor";
MaterialProperty tessellationFactorMinDistance = null;
const string kTessellationFactorMinDistance = "_TessellationFactorMinDistance";
MaterialProperty tessellationFactorMaxDistance = null;
const string kTessellationFactorMaxDistance = "_TessellationFactorMaxDistance";
MaterialProperty tessellationFactorTriangleSize = null;
const string kTessellationFactorTriangleSize = "_TessellationFactorTriangleSize";
MaterialProperty tessellationShapeFactor = null;
const string kTessellationShapeFactor = "_TessellationShapeFactor";
MaterialProperty tessellationBackFaceCullEpsilon = null;
const string kTessellationBackFaceCullEpsilon = "_TessellationBackFaceCullEpsilon";
MaterialProperty tessellationObjectScale = null;
const string kTessellationObjectScale = "_TessellationObjectScale";
protected static string[] reservedProperties = new string[] { kSurfaceType, kBlendMode, kAlphaCutoff, kAlphaCutoffEnabled, kDoubleSidedMode };
protected abstract void FindMaterialProperties(MaterialProperty[] props);

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


protected MaterialProperty emissiveIntensity = null;
protected const string kEmissiveIntensity = "_EmissiveIntensity";
// tesselation params
protected MaterialProperty tesselationFactor = null;
protected const string kTesselationFactor = "_TesselationFactor";
// These are options that are shared with the LayeredLit shader. Don't put anything that can't be shared here:
// For instance, properties like BaseColor and such don't exist in the LayeredLit so don't put them here.

emissiveColor = FindProperty(kEmissiveColor, props);
emissiveColorMap = FindProperty(kEmissiveColorMap, props);
emissiveIntensity = FindProperty(kEmissiveIntensity, props);
// tesselation specific, don't care if not found
tesselationFactor = FindProperty(kTesselationFactor, props, false);
}
override protected void ShaderInputOptionsGUI()

{
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(heightAmplitude, Styles.heightMapAmplitudeText);
heightAmplitude.floatValue = Math.Max(0.0f, heightAmplitude.floatValue); // Must be positive
m_MaterialEditor.ShaderProperty(heightCenter, Styles.heightMapCenterText);
EditorGUI.showMixedValue = false;
EditorGUI.indentLevel--;

EditorGUI.indentLevel--;
EditorGUILayout.Space();
if (tesselationFactor != null)
{
GUILayout.Label(Styles.tesselationText, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(tesselationFactor, Styles.tesselationFactorText);
EditorGUI.indentLevel--;
}
}
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)

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

11
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs


// Init precomputed texture
//-----------------------------------------------------------------------------
public bool isInit;
public bool isInit;
private Material m_InitPreFGD;
private Material m_InitPreFGD;
private RenderTexture m_PreIntegratedFGD;
// For area lighting

Material mat = new Material(Shader.Find(shaderPath) as Shader);
mat.hideFlags = HideFlags.HideAndDontSave;
return mat;
}
}
Texture2D CreateLUT(int width, int height, TextureFormat format, Color[] pixels)
{

const int count = k_LtcLUTResolution * k_LtcLUTResolution;
Color[] pixels = new Color[count];
// amplitude
for (int i = 0; i < count; i++)
{
pixels[i] = new Color(0, 0, 0, LUTScalar[i]);

const int count = k_LtcLUTResolution * k_LtcLUTResolution;
Color[] pixels = new Color[count];
// transformInv
for (int i = 0; i < count; i++)
{
// Both GGX and Disney Diffuse BRDFs have zero values in columns 1, 3, 5, 7.

}
return CreateLUT(k_LtcLUTResolution, k_LtcLUTResolution, format, pixels);
}
}
// TODO: switch to RGBA64 when it becomes available.
m_PreIntegratedFGD = new RenderTexture(128, 128, 0, RenderTextureFormat.ARGBHalf);
m_PreIntegratedFGD.filterMode = FilterMode.Bilinear;

12
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs.hlsl


#ifndef LIT_CS_HLSL
#define LIT_CS_HLSL
//
// UnityEngine.Experimental.ScriptableRenderLoop.Lit.MaterialId: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.Lit.MaterialId: static fields
//
#define MATERIALID_LIT_STANDARD (0)
#define MATERIALID_LIT_SSS (1)

//
// UnityEngine.Experimental.ScriptableRenderLoop.Lit.SurfaceData: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.Lit.SurfaceData: static fields
//
#define DEBUGVIEW_LIT_SURFACEDATA_BASE_COLOR (1000)
#define DEBUGVIEW_LIT_SURFACEDATA_SPECULAR_OCCLUSION (1001)

#define DEBUGVIEW_LIT_SURFACEDATA_SPECULAR_COLOR (1015)
//
// UnityEngine.Experimental.ScriptableRenderLoop.Lit.BSDFData: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.Lit.BSDFData: static fields
//
#define DEBUGVIEW_LIT_BSDFDATA_DIFFUSE_COLOR (1030)
#define DEBUGVIEW_LIT_BSDFDATA_FRESNEL0 (1031)

#define DEBUGVIEW_LIT_BSDFDATA_COAT_ROUGHNESS (1046)
//
// UnityEngine.Experimental.ScriptableRenderLoop.Lit.GBufferMaterial: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.Lit.GBufferMaterial: static fields
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.Lit.SurfaceData
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Lit.SurfaceData
// PackingRules = Exact
struct SurfaceData
{

float3 specularColor;
};
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.Lit.BSDFData
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Lit.BSDFData
// PackingRules = Exact
struct BSDFData
{

11
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.hlsl


float anisoGGXLambdaV;
float3 iblDirWS; // Dominant specular direction, used for IBL in EvaluateBSDF_Env()
float iblMipLevel;
float3 specularFGD; // Store preconvole BRDF for both specular and diffuse
float diffuseFGD;

// We need to take into account the modified normal for faking anisotropic here.
float3 iblR = reflect(-V, iblNormalWS);
preLightData.iblDirWS = GetSpecularDominantDir(bsdfData.normalWS, iblR, bsdfData.roughness);
preLightData.iblDirWS = GetSpecularDominantDir(bsdfData.normalWS, iblR, bsdfData.roughness, preLightData.NdotV);
preLightData.iblMipLevel = PerceptualRoughnessToMipmapLevel(bsdfData.perceptualRoughness);
// Area light specific
// UVs for sampling the LUTs

// TODO: we must always perform a weight calculation as due to tiled rendering we need to smooth out cubemap at boundaries.
// So goal is to split into two category and have an option to say if we parallax correct or not.
// TODO: compare current Morten version: offline cubemap with a particular remap + the bias in perceptualRoughnessToMipmapLevel
// to classic remap like unreal/Frobiste. The function GetSpecularDominantDir can result in a better matching in this case
// We let GetSpecularDominantDir currently as it still an improvement but not as good as it could be
float mip = perceptualRoughnessToMipmapLevel(bsdfData.perceptualRoughness);
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, R, mip);
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, R, preLightData.iblMipLevel);
specularLighting = preLD.rgb * preLightData.specularFGD;
// Apply specular occlusion on it

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


// Blending state
[HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0
[HideInInspector] _BlendMode ("__blendmode", Float) = 0.0
[HideInInspector] _SrcBlend ("__src", Float) = 1.0
[HideInInspector] _DstBlend ("__dst", Float) = 0.0
[HideInInspector] _ZWrite ("__zw", Float) = 1.0
[HideInInspector] _BlendMode("__blendmode", Float) = 0.0
[HideInInspector] _SrcBlend("__src", Float) = 1.0
[HideInInspector] _DstBlend("__dst", Float) = 0.0
[HideInInspector] _ZWrite("__zw", Float) = 1.0
// Material Id
[HideInInspector] _MaterialId("_MaterialId", FLoat) = 0

[Enum(UV0, 0, Planar, 1, TriPlanar, 2)] _UVBase("UV Set for base", Float) = 0
_TexWorldScale("Scale to apply on world coordinate", Float) = 1.0
[HideInInspector] _UVMappingMask("_UVMappingMask", Color) = (1,0,0,0)
[HideInInspector] _UVMappingMask("_UVMappingMask", Color) = (1, 0, 0, 0)
[HideInInspector] _UVDetailsMappingMask("_UVDetailsMappingMask", Color) = (1,0,0,0)
[HideInInspector] _UVDetailsMappingMask("_UVDetailsMappingMask", Color) = (1, 0, 0, 0)
[Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1
}

#pragma only_renderers d3d11 ps4// TEMP: unitl we go futher in dev
#pragma only_renderers d3d11 ps4// TEMP: until we go futher in dev
//-------------------------------------------------------------------------------------
// Variant

#pragma shader_feature _DISTORTION_ON
#pragma shader_feature _DEPTHOFFSET_ON
#pragma shader_feature _ _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
#pragma shader_feature _ _DOUBLESIDED _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _MAPPING_TRIPLANAR

#pragma shader_feature _REQUIRE_UV2_OR_UV3
#pragma shader_feature _ _REQUIRE_UV2 _REQUIRE_UV3
#pragma shader_feature _EMISSIVE_COLOR
#pragma shader_feature _NORMALMAP

#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/ShaderPass/FragInputs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
//-------------------------------------------------------------------------------------

HLSLPROGRAM
#define SHADERPASS SHADERPASS_GBUFFER
#include "../../Material/Material.hlsl"
#include "../../Material/Material.hlsl"
#include "../../ShaderPass/ShaderPassGBuffer.hlsl"
ENDHLSL

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

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

HLSLPROGRAM
#define SHADERPASS SHADERPASS_DEPTH_ONLY
#include "../../Material/Material.hlsl"
#include "../../Material/Material.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL

HLSLPROGRAM
#define SHADERPASS SHADERPASS_DEPTH_ONLY
#include "../../Material/Material.hlsl"
#include "../../Material/Material.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL

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

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

HLSLPROGRAM
#define SHADERPASS SHADERPASS_FORWARD
// TEMP until pragma work in include
// #include "../../Lighting/Forward.hlsl"

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

91
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;

else
{
return SAMPLE_TEXTURE2D(layerTex, layerSampler, layerUV.uv);
}
}
float4 SampleLayerLod(TEXTURE2D_ARGS(layerTex, layerSampler), LayerUV layerUV, float3 weights, float lod)
{
if (layerUV.isTriplanar)
{
float4 val = float4(0.0, 0.0, 0.0, 0.0);
if (weights.x > 0.0)
val += weights.x * SAMPLE_TEXTURE2D_LOD(layerTex, layerSampler, layerUV.uvYZ, lod);
if (weights.y > 0.0)
val += weights.y * SAMPLE_TEXTURE2D_LOD(layerTex, layerSampler, layerUV.uvZX, lod);
if (weights.z > 0.0)
val += weights.z * SAMPLE_TEXTURE2D_LOD(layerTex, layerSampler, layerUV.uvXY, lod);
return val;
}
else
{
return SAMPLE_TEXTURE2D_LOD(layerTex, layerSampler, layerUV.uv, lod);
}
}

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

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

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

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

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

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

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

#ifdef _DEPTHOFFSET_ON
ApplyDepthOffsetPositionInput(V, depthOffset, posInput);
ApplyDepthOffsetAttribute(depthOffset, input);
#endif
SurfaceData surfaceData0;

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

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

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


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

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

// Mirror the normal with the plane define by vertex normal
float3 oppositeNormalTS = reflect(normalTS, float3(0.0, 0.0, 1.0)); // Reflect around vertex normal (in tangent space this is z)
#endif
// TODO : Test if GetOdddNegativeScale() is necessary here in case of normal map, as GetOdddNegativeScale is take into account in CreateTangentToWorld();
// TODO : Test if GetOddNegativeScale() is necessary here in case of normal map, as GetOddNegativeScale is take into account in CreateTangentToWorld();
(GetOdddNegativeScale() >= 0.0 ? normalTS : oppositeNormalTS) :
(-GetOdddNegativeScale() >= 0.0 ? normalTS : oppositeNormalTS);
(GetOddNegativeScale() >= 0.0 ? normalTS : oppositeNormalTS) :
(-GetOddNegativeScale() >= 0.0 ? normalTS : oppositeNormalTS);
#endif
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A

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


#endif // LAYERED_LIT_SHADER
// Tesselation specific
// Tessellation specific
#ifdef TESSELATION_ON
float _TesselationFactor;
#ifdef TESSELLATION_ON
float _TessellationFactor;
float _TessellationFactorMinDistance;
float _TessellationFactorMaxDistance;
float _TessellationFactorTriangleSize;
float _TessellationShapeFactor;
float _TessellationBackFaceCullEpsilon;
float _TessellationObjectScale;
#endif

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


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

[HideInInspector] _UVDetailsMappingMask("_UVDetailsMappingMask", Color) = (1, 0, 0, 0)
[Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1
// Tesselation specific
_TesselationFactor("Tesselation Factor", Float) = 3.0
// Tessellation specific
[Enum(Phong, 0, Displacement, 1, DisplacementPhong, 2)] _TessellationMode("Tessellation mode", Float) = 0
_TessellationFactor("Tessellation Factor", Range(0.0, 15.0)) = 4.0
_TessellationFactorMinDistance("Tessellation start fading distance", Float) = 20.0
_TessellationFactorMaxDistance("Tessellation end fading distance", Float) = 50.0
_TessellationFactorTriangleSize("Tessellation triangle size", Float) = 100.0
_TessellationShapeFactor("Tessellation shape factor", Range(0.0, 1.0)) = 0.75 // Only use with Phong
_TessellationBackFaceCullEpsilon("Tessellation back face epsilon", Range(-1.0, 0.0)) = -0.25
[ToggleOff] _TessellationObjectScale("Tessellation object scale", Float) = 0.0
// TODO: Handle culling mode for backface culling
}
HLSLINCLUDE

#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _DISTORTION_ON
#pragma shader_feature _DEPTHOFFSET_ON
#pragma shader_feature _ _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
#pragma shader_feature _ _DOUBLESIDED _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
// Default is _TESSELLATION_PHONG
#pragma shader_feature _ _TESSELLATION_DISPLACEMENT _TESSELLATION_DISPLACEMENT_PHONG
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _MAPPING_TRIPLANAR

#pragma shader_feature _REQUIRE_UV2_OR_UV3
#pragma shader_feature _ _REQUIRE_UV2 _REQUIRE_UV3
#pragma shader_feature _EMISSIVE_COLOR
#pragma shader_feature _NORMALMAP

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

#include "tesselation.hlsl"
#include "tessellation.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/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
#pragma hull Hull
#pragma domain Domain
#include "LitData.hlsl"
#include "../Tesselation/TesselationShare.hlsl"
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassGBuffer.hlsl"
ENDHLSL

HLSLPROGRAM
#pragma vertex VertTesselation
#pragma hull Hull
#pragma domain Domain
#pragma hull Hull
#pragma domain Domain
#include "LitData.hlsl"
#include "../Tesselation/TesselationShare.hlsl"
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl"
ENDHLSL

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

HLSLPROGRAM
#pragma vertex VertTesselation
#pragma hull Hull
#pragma domain Domain
#pragma hull Hull
#pragma domain Domain
#include "LitData.hlsl"
#include "../Tesselation/TesselationShare.hlsl"
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL

HLSLPROGRAM
#pragma vertex VertTesselation
#pragma hull Hull
#pragma domain Domain
#pragma hull Hull
#pragma domain Domain
#include "LitData.hlsl"
#include "../Tesselation/TesselationShare.hlsl"
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL

HLSLPROGRAM
#pragma vertex VertTesselation
#pragma hull Hull
#pragma domain Domain
// TODO: Tesselation can't work with velocity for now...
#include "LitData.hlsl"
#include "../Tesselation/TesselationShare.hlsl"
#include "LitData.hlsl"
#include "../../ShaderPass/ShaderPassVelocity.hlsl"
ENDHLSL

HLSLPROGRAM
#pragma vertex VertTesselation
#pragma hull Hull
#pragma domain Domain
#pragma hull Hull
#pragma domain Domain
#include "../Tesselation/TesselationShare.hlsl"
#include "../../ShaderPass/ShaderPassDistortion.hlsl"
ENDHLSL

HLSLPROGRAM
#pragma vertex VertTesselation
#pragma hull Hull
#pragma domain Domain
#pragma hull Hull
#pragma domain Domain
#define SHADERPASS SHADERPASS_FORWARD
// TEMP until pragma work in include

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

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


#error Undefine_SHADERPASS
#endif
// Check if Alpha test is enabled. If it is, check if parallax is enabled on this material
#define NEED_TEXCOORD0 1 // defined(_ALPHATEST_ON)
#define NEED_TANGENT_TO_WORLD 1 // NEED_TEXCOORD0 && (defined(_HEIGHTMAP) && defined(_PER_PIXEL_DISPLACEMENT)) TEMP!!!: until we fix tesselation so it can access normalOS
// 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))
// When modifying this structure, update the tesselation code below
struct Attributes
{
float3 positionOS : POSITION;
#if NEED_TEXCOORD0
float2 uv0 : TEXCOORD0;
#endif
#if NEED_TANGENT_TO_WORLD
float3 normalOS : NORMAL;
float4 tangentOS : TANGENT;
#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)
#ifdef TESSELATION_ON
// Copy paste of above struct with POSITION rename to INTERNALTESSPOS (internal of unity shader compiler)
struct AttributesTesselation
{
float3 positionOS : INTERNALTESSPOS;
#if NEED_TEXCOORD0
float2 uv0 : TEXCOORD0;
// Tesselation require normal
#if defined(TESSELLATION_ON) || REQUIRE_TANGENT_TO_WORLD
#define ATTRIBUTES_NEED_NORMAL
#if NEED_TANGENT_TO_WORLD
float3 normalOS : NORMAL;
float4 tangentOS : TANGENT;
#endif
};
AttributesTesselation AttributesToAttributesTesselation(Attributes input)
{
AttributesTesselation output;
output.positionOS = input.positionOS;
#if NEED_TEXCOORD0
output.uv0 = input.uv0;
#endif
#if NEED_TANGENT_TO_WORLD
output.normalOS = input.normalOS;
output.tangentOS = input.tangentOS;
#if REQUIRE_TANGENT_TO_WORLD
#define ATTRIBUTES_NEED_TANGENT
return output;
}
// 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
Attributes AttributesTesselationToAttributes(AttributesTesselation input)
{
Attributes output;
output.positionOS = input.positionOS;
#if NEED_TEXCOORD0
output.uv0 = input.uv0;
#endif
#if NEED_TANGENT_TO_WORLD
output.normalOS = input.normalOS;
output.tangentOS = input.tangentOS;
#if REQUIRE_UV_FOR_TESSELATION || REQUIRE_TANGENT_TO_WORLD || defined(_ALPHATEST_ON)
#define ATTRIBUTES_NEED_TEXCOORD0
#ifdef LAYERED_LIT_SHADER
#define ATTRIBUTES_NEED_TEXCOORD1
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3)
#define ATTRIBUTES_NEED_TEXCOORD2
#endif
#if defined(_REQUIRE_UV3)
#define ATTRIBUTES_NEED_TEXCOORD3
#endif
#endif
return output;
}
AttributesTesselation InterpolateWithBary(AttributesTesselation input0, AttributesTesselation input1, AttributesTesselation input2, float3 baryWeight)
{
AttributesTesselation ouput;
TESSELATION_INTERPOLATE_BARY(positionOS, baryWeight);
#if NEED_TEXCOORD0
TESSELATION_INTERPOLATE_BARY(uv0, baryWeight);
#endif
#if NEED_TANGENT_TO_WORLD
TESSELATION_INTERPOLATE_BARY(normalOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(tangentOS, baryWeight);
// Varying - Use for pixel shader
// This second set of define allow to say which varyings will be output in the vertex (no more tesselation)
#if REQUIRE_TANGENT_TO_WORLD
#define VARYINGS_NEED_TANGENT_TO_WORLD
return ouput;
}
#endif // TESSELATION_ON
struct Varyings
{
float4 positionCS;
#if NEED_TEXCOORD0
float2 texCoord0;
#if REQUIRE_TANGENT_TO_WORLD || defined(_ALPHATEST_ON)
#define VARYINGS_NEED_TEXCOORD0
#ifdef LAYERED_LIT_SHADER
#define VARYINGS_NEED_TEXCOORD1
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3)
#define VARYINGS_NEED_TEXCOORD2
#endif
#if defined(_REQUIRE_UV3)
#define VARYINGS_NEED_TEXCOORD3
#endif
#endif
#if NEED_TANGENT_TO_WORLD
float3 positionWS;
float3 tangentToWorld[3];
#endif
};
struct PackedVaryings
{
float4 positionCS : SV_Position;
#if NEED_TANGENT_TO_WORLD
float4 interpolators[4] : TEXCOORD0;
#elif NEED_TEXCOORD0
float4 interpolators[1] : TEXCOORD0;
#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;
#if NEED_TANGENT_TO_WORLD
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;
#elif NEED_TEXCOORD0
output.interpolators[0] = float4(input.texCoord0, 0.0, 0.0);
#endif
return output;
}
FragInputs UnpackVaryings(PackedVaryings input)
{
FragInputs output;
ZERO_INITIALIZE(FragInputs, output);
output.unPositionSS = input.positionCS; // input.positionCS is SV_Position
#if NEED_TANGENT_TO_WORLD
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);
#elif NEED_TEXCOORD0
output.texCoord0.xy = input.interpolators[0].xy;
#endif
return output;
}
PackedVaryings Vert(Attributes input)
{
Varyings output;
float3 positionWS = TransformObjectToWorld(input.positionOS);
output.positionCS = TransformWorldToHClip(positionWS);
#if NEED_TEXCOORD0
output.texCoord0 = input.uv0;
#endif
#if NEED_TANGENT_TO_WORLD
output.positionWS = positionWS;
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"

173
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))
// 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))
struct Attributes
{
float3 positionOS : POSITION;
float2 uv0 : TEXCOORD0;
#if NEED_TANGENT_TO_WORLD
float3 normalOS : NORMAL;
float4 tangentOS : TANGENT;
#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)
#ifdef TESSELATION_ON
// Copy paste of above struct with POSITION rename to INTERNALTESSPOS (internal of unity shader compiler)
struct AttributesTesselation
{
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_NEED_NORMAL
};
AttributesTesselation AttributesToAttributesTesselation(Attributes input)
{
AttributesTesselation 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_NEED_TANGENT
return output;
}
// 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
Attributes AttributesTesselationToAttributes(AttributesTesselation input)
{
Attributes output;
output.positionOS = input.positionOS;
output.uv0 = input.uv0;
#if NEED_TANGENT_TO_WORLD
output.normalOS = input.normalOS;
output.tangentOS = input.tangentOS;
#if REQUIRE_UV_FOR_TESSELATION || REQUIRE_TANGENT_TO_WORLD || defined(_ALPHATEST_ON) || defined(_DISTORTION_ON)
#define ATTRIBUTES_NEED_TEXCOORD0
#ifdef LAYERED_LIT_SHADER
#define ATTRIBUTES_NEED_TEXCOORD1
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3)
#define ATTRIBUTES_NEED_TEXCOORD2
#endif
#if defined(_REQUIRE_UV3)
#define ATTRIBUTES_NEED_TEXCOORD3
#endif
#endif
return output;
}
AttributesTesselation InterpolateWithBary(AttributesTesselation input0, AttributesTesselation input1, AttributesTesselation input2, float3 baryWeight)
{
AttributesTesselation ouput;
TESSELATION_INTERPOLATE_BARY(positionOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(uv0, baryWeight);
#if NEED_TANGENT_TO_WORLD
TESSELATION_INTERPOLATE_BARY(normalOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(tangentOS, baryWeight);
// Varying - Use for pixel shader
// This second set of define allow to say which varyings will be output in the vertex (no more tesselation)
#if REQUIRE_TANGENT_TO_WORLD
#define VARYINGS_NEED_TANGENT_TO_WORLD
return ouput;
}
#endif // TESSELATION_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;
#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];
#endif
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 VARYINGS_NEED_TEXCOORD0
#ifdef LAYERED_LIT_SHADER
#define VARYINGS_NEED_TEXCOORD1
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3)
#define VARYINGS_NEED_TEXCOORD2
#endif
#if defined(_REQUIRE_UV3)
#define VARYINGS_NEED_TEXCOORD3
#endif
#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);
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);
}
// This include will define the various Attributes/Varyings structure
#include "../../ShaderPass/VaryingMesh.hlsl"

91
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
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;
};
#define ATTRIBUTES_NEED_TEXCOORD0
#define ATTRIBUTES_NEED_TEXCOORD1
#define ATTRIBUTES_NEED_TEXCOORD2
struct PackedVaryings
{
float4 positionCS : SV_Position;
float4 interpolators[1] : TEXCOORD0;
};
#define VARYINGS_NEED_TEXCOORD0
#define VARYINGS_NEED_TEXCOORD1
// 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; // input.positionCS is SV_Position
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);
}
// This include will define the various Attributes/Varyings structure
#include "../../ShaderPass/VaryingMesh.hlsl"

252
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 TESSELATION_ON
// Copy paste of above struct with POSITION rename to INTERNALTESSPOS (internal of unity shader compiler)
struct AttributesTesselation
{
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;
};
AttributesTesselation AttributesToAttributesTesselation(Attributes input)
{
AttributesTesselation 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 AttributesTesselationToAttributes(AttributesTesselation 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;
}
AttributesTesselation InterpolateWithBary(AttributesTesselation input0, AttributesTesselation input1, AttributesTesselation input2, float3 baryWeight)
{
AttributesTesselation ouput;
TESSELATION_INTERPOLATE_BARY(positionOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(normalOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(uv0, baryWeight);
TESSELATION_INTERPOLATE_BARY(uv1, baryWeight);
#if WANT_UV2
TESSELATION_INTERPOLATE_BARY(uv2, baryWeight);
#endif
#if WANT_UV3
TESSELATION_INTERPOLATE_BARY(uv3, baryWeight);
#endif
TESSELATION_INTERPOLATE_BARY(tangentOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(color, baryWeight);
return ouput;
}
#endif // TESSELATION_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
#if SHADER_STAGE_FRAGMENT
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMATIC;
#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].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;
// This first set of define allow to say which attributes will be use by the mesh in the vertex and domain shader (for tesselation)
#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;
#endif
#if WANT_UV3
output.interpolators[5].zw = input.texCoord3.xy;
#endif
#endif
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];
// Attributes
#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
#if WANT_UV2
output.texCoord2 = input.interpolators[5].xy;
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3) || defined(DYNAMICLIGHTMAP_ON) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL)
#define ATTRIBUTES_NEED_TEXCOORD2
#if WANT_UV3
output.texCoord3 = input.interpolators[5].zw;
#if defined(_REQUIRE_UV3) || (SHADERPASS == SHADERPASS_DEBUG_VIEW_MATERIAL)
#define ATTRIBUTES_NEED_TEXCOORD3
#if SHADER_STAGE_FRAGMENT
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
output.isFrontFace = IS_FRONT_VFACE(input.cullFace, true, false);
#endif
// 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
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);
output.texCoord0 = input.uv0;
output.texCoord1 = input.uv1;
#if WANT_UV2
output.texCoord2 = input.uv2;
#ifdef ATTRIBUTES_NEED_TEXCOORD3
#define VARYINGS_NEED_TEXCOORD3
#define VARYINGS_NEED_COLOR
#if WANT_UV3
output.texCoord3 = input.uv3;
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
#define VARYINGS_NEED_CULLFACE
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);
}
// This include will define the various Attributes/Varyings structure
#include "../../ShaderPass/VaryingMesh.hlsl"

215
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: 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.
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
};
// 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)) */
#ifdef TESSELATION_ON
// Copy paste of above struct with POSITION rename to INTERNALTESSPOS (internal of unity shader compiler)
struct AttributesTesselation
{
float3 positionOS : INTERNALTESSPOS;
float3 previousPositionOS : NORMAL;
#if NEED_TEXCOORD0
float2 uv0 : TEXCOORD0;
#endif
#if NEED_TANGENT_TO_WORLD
// float3 normalOS : NORMAL;
float4 tangentOS : TANGENT;
#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)
AttributesTesselation AttributesToAttributesTesselation(Attributes input)
{
AttributesTesselation output;
output.positionOS = input.positionOS;
output.previousPositionOS = input.previousPositionOS;
#if NEED_TEXCOORD0
output.uv0 = input.uv0;
// Tesselation require normal
#if defined(TESSELLATION_ON) || REQUIRE_TANGENT_TO_WORLD
// #define ATTRIBUTES_NEED_NORMAL
#if NEED_TANGENT_TO_WORLD
// output.normalOS = input.normalOS;
output.tangentOS = input.tangentOS;
#if REQUIRE_TANGENT_TO_WORLD
#define ATTRIBUTES_NEED_TANGENT
return output;
}
// 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
Attributes AttributesTesselationToAttributes(AttributesTesselation input)
{
Attributes output;
output.positionOS = input.positionOS;
output.previousPositionOS = input.previousPositionOS;
#if NEED_TEXCOORD0
output.uv0 = input.uv0;
#endif
#if NEED_TANGENT_TO_WORLD
// output.normalOS = input.normalOS;
output.tangentOS = input.tangentOS;
#if defined(_ALPHATEST_ON)
#define ATTRIBUTES_NEED_TEXCOORD0
#ifdef LAYERED_LIT_SHADER
#define ATTRIBUTES_NEED_TEXCOORD1
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3)
#define ATTRIBUTES_NEED_TEXCOORD2
#endif
#if defined(_REQUIRE_UV3)
#define ATTRIBUTES_NEED_TEXCOORD3
#endif
#endif
return output;
}
AttributesTesselation InterpolateWithBary(AttributesTesselation input0, AttributesTesselation input1, AttributesTesselation input2, float3 baryWeight)
{
AttributesTesselation ouput;
// 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
TESSELATION_INTERPOLATE_BARY(positionOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(previousPositionOS, baryWeight);
#if NEED_TEXCOORD0
TESSELATION_INTERPOLATE_BARY(uv0, baryWeight);
#endif
#if NEED_TANGENT_TO_WORLD
// TESSELATION_INTERPOLATE_BARY(normalOS, baryWeight);
TESSELATION_INTERPOLATE_BARY(tangentOS, baryWeight);
#if REQUIRE_TANGENT_TO_WORLD
#define VARYINGS_NEED_TANGENT_TO_WORLD
return ouput;
}
#endif // TESSELATION_ON
struct Varyings
{
float4 positionCS;
float3 positionWS;
// Note: Z component is not use
float4 transferPositionCS;
float4 transferPreviousPositionCS;
#if NEED_TEXCOORD0
float2 texCoord0;
#if REQUIRE_TANGENT_TO_WORLD || defined(_ALPHATEST_ON)
#define VARYINGS_NEED_TEXCOORD0
#ifdef LAYERED_LIT_SHADER
#define VARYINGS_NEED_TEXCOORD1
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3)
#define VARYINGS_NEED_TEXCOORD2
#endif
#if defined(_REQUIRE_UV3)
#define VARYINGS_NEED_TEXCOORD3
#endif
#endif
#if NEED_TANGENT_TO_WORLD
float3 tangentToWorld[3];
#endif
};
struct PackedVaryings
{
float4 positionCS : SV_Position;
#if NEED_TANGENT_TO_WORLD
float4 interpolators[5] : TEXCOORD0;
#elif NEED_TEXCOORD0
float4 interpolators[3] : TEXCOORD0;
#else
float4 interpolators[3] : TEXCOORD0;
#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[1] = float4(input.transferPositionCS.xyw, 0.0);
output.interpolators[2] = float4(input.transferPreviousPositionCS.xyw, 0.0);
#if NEED_TANGENT_TO_WORLD
output.interpolators[0].w = input.texCoord0.x;
output.interpolators[1].w = input.texCoord0.y;
output.interpolators[3].xyz = input.tangentToWorld[0];
output.interpolators[4].xyz = input.tangentToWorld[1];
output.interpolators[2].w = input.tangentToWorld[2].x;
output.interpolators[3].w = input.tangentToWorld[2].y;
output.interpolators[4].w = input.tangentToWorld[2].z;
#elif NEED_TEXCOORD0
output.interpolators[0].w = input.texCoord0.x;
output.interpolators[1].w = input.texCoord0.y;
#endif
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;
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"

8
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.cs.hlsl


#ifndef UNLIT_CS_HLSL
#define UNLIT_CS_HLSL
//
// UnityEngine.Experimental.ScriptableRenderLoop.Unlit.SurfaceData: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.Unlit.SurfaceData: static fields
// UnityEngine.Experimental.ScriptableRenderLoop.Unlit.BSDFData: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.Unlit.BSDFData: static fields
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.Unlit.SurfaceData
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Unlit.SurfaceData
// PackingRules = Exact
struct SurfaceData
{

// Generated from UnityEngine.Experimental.ScriptableRenderLoop.Unlit.BSDFData
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Unlit.BSDFData
// PackingRules = Exact
struct BSDFData
{

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


_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
_EmissiveIntensity("EmissiveIntensity", Float) = 0
[ToggleOff] _DistortionOnly("Distortion Only", Float) = 0.0
[ToggleOff] _DistortionDepthTest("Distortion Only", Float) = 0.0
_DistortionVectorMap("DistortionVectorMap", 2D) = "black" {}
[ToggleOff] _DistortionEnable("Enable Distortion", Float) = 0.0
[ToggleOff] _DistortionOnly("Distortion Only", Float) = 0.0
[ToggleOff] _DistortionDepthTest("Distortion Depth Test Enable", Float) = 0.0
[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5

[HideInInspector] _BlendMode ("__blendmode", Float) = 0.0
[HideInInspector] _SrcBlend ("__src", Float) = 1.0
[HideInInspector] _DstBlend ("__dst", Float) = 0.0
[HideInInspector] _ZWrite ("__zw", Float) = 1.0
[HideInInspector] _BlendMode("__blendmode", Float) = 0.0
[HideInInspector] _SrcBlend("__src", Float) = 1.0
[HideInInspector] _DstBlend("__dst", Float) = 0.0
[HideInInspector] _ZWrite("__zw", Float) = 1.0
[HideInInspector] _ZTestMode("_ZTestMode", Int) = 8
[Enum(None, 0, DoubleSided, 1)] _DoubleSidedMode("Double sided mode", Float) = 0
}

#pragma target 5.0
#pragma only_renderers d3d11 ps4// TEMP: unitl we go futher in dev
#pragma only_renderers d3d11 ps4 // TEMP: unitl we go futher in dev
//-------------------------------------------------------------------------------------
// Variant

#pragma shader_feature _DISTORTION_ON
#pragma shader_feature _ _DOUBLESIDED
#pragma shader_feature _EMISSIVE_COLOR_MAP
//-------------------------------------------------------------------------------------

#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/ShaderPass/FragInputs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
//-------------------------------------------------------------------------------------

#define SHADERPASS SHADERPASS_DEBUG_VIEW_MATERIAL
#include "../../Material/Material.hlsl"
#include "ShaderPass/UnlitSharePass.hlsl"
#include "UnlitSharePass.hlsl"
// ------------------------------------------------------------------
// forward opaque pass
// Material opaque that are always forward (i.e can't render in deferred) need to implement ForwardOnlyOpaque pass
// (Code is exactly the same as "Forward", it simply allow our system to filter objects correctly
// TODO: can we do this another way ? Like relying on QueueIndex ? But it will be require anyway for material with two forward pass like hair
Pass
{
Name "ForwardUnlit"
Tags { "LightMode" = "ForwardOnlyOpaque" }
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]
Cull [_CullMode]
HLSLPROGRAM
#define SHADERPASS SHADERPASS_FORWARD_UNLIT
#include "../../Material/Material.hlsl"
#include "ShaderPass/UnlitSharePass.hlsl"
#include "UnlitData.hlsl"
#include "../../ShaderPass/ShaderPassForwardUnlit.hlsl"
ENDHLSL
}
// ------------------------------------------------------------------
// forward pass

Tags { "LightMode" = "ForwardUnlit" }
Tags { "LightMode" = "Forward" }
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]

#define SHADERPASS SHADERPASS_FORWARD_UNLIT
#include "../../Material/Material.hlsl"
#include "ShaderPass/UnlitSharePass.hlsl"
#include "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 "../../Material/Material.hlsl"
#include "UnlitData.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;
};
#include "../../Material/Material.hlsl"
#include "ShaderPass/UnlitMetaPass.hlsl"
#include "UnlitData.hlsl"
#include "../../ShaderPass/ShaderPassLightTransport.hlsl"
struct PackedVaryings
{
float4 positionCS : SV_Position;
float4 interpolators[1] : TEXCOORD0;
};
ENDHLSL
}
// 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;
Pass
{
Name "Distortion" // Name is not used
Tags { "LightMode" = "DistortionVectors" } // This will be only for transparent object based on the RenderQueue index
return output;
}
Blend One One
ZTest [_ZTestMode]
ZWrite off
Cull [_CullMode]
FragInputs UnpackVaryings(PackedVaryings input)
{
FragInputs output;
ZERO_INITIALIZE(FragInputs, output);
HLSLPROGRAM
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 "../../ShaderPass/ShaderPassLightTransport.hlsl"
#define SHADERPASS SHADERPASS_DISTORTION
#include "../../Material/Material.hlsl"
#include "ShaderPass/UnlitSharePass.hlsl"
#include "UnlitData.hlsl"
#include "../../ShaderPass/ShaderPassDistortion.hlsl"
CustomEditor "Experimental.ScriptableRenderLoop.UnlitGUI"
CustomEditor "Experimental.Rendering.HDPipeline.UnlitGUI"
}

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


builtinData.velocity = float2(0.0, 0.0);
#ifdef _DISTORTION_ON
float3 distortion = SAMPLE_TEXTURE2D(_DistortionVectorMap, sampler_DistortionVectorMap, input.texCoord0).rgb;
builtinData.distortion = distortion.rg;
builtinData.distortionBlur = distortion.b;
#else
#endif

2
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl


#ifndef SHADERCONFIG_CS_HLSL
#define SHADERCONFIG_CS_HLSL
//
// UnityEngine.Experimental.ScriptableRenderLoop.ShaderOptions: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.ShaderOptions: static fields
//
#define SHADEROPTIONS_VELOCITY_IN_GBUFFER (0)
#define SHADEROPTIONS_PACK_GBUFFER_IN_U16 (0)

2
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl


#ifndef SHADERPASS_CS_HLSL
#define SHADERPASS_CS_HLSL
//
// UnityEngine.Experimental.ScriptableRenderLoop.ShaderPass: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.ShaderPass: static fields
//
#define SHADERPASS_GBUFFER (0)
#define SHADERPASS_FORWARD (1)

26
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
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
{
VaryingsToPS output;
output.vmesh = VertMeshTesselation(input.vmesh);
return PackVaryingsToPS(output);
}
#include "TessellationShare.hlsl"
#endif // TESSELLATION_ON
float4 Frag(PackedVaryings packedInput) : SV_Target
float4 Frag(PackedVaryingsToPS packedInput) : SV_Target
FragInputs input = UnpackVaryings(packedInput);
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);

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


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

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

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


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

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


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

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

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


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

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


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

{
FragInputs input = UnpackVaryings(packedInput);
FragInputs input = UnpackVaryingsMeshToFragInputs(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.vmesh.positionCS = TransformWorldToHClip(positionWS);
output.vmesh.texCoord0 = inputMesh.uv0;
output.vmesh.texCoord1 = inputMesh.uv1;
return PackVaryingsToPS(output);
}
float4 Frag(PackedVaryingsToPS packedInput) : SV_Target
FragInputs input = UnpackVaryings(packedInput);
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);

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


#error SHADERPASS_is_not_correctly_define
#endif
float4 Frag(PackedVaryings packedInput) : SV_Target
// Available semantic start from TEXCOORD4
struct AttributesPass
{
float3 previousPositionOS : NORMAL; // Contain previous transform position (in case of skinning for example)
// 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!
};
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;
};
// Available interpolator start from TEXCOORD8
struct PackedVaryingsPassToPS
{
// 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);
return output;
}
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);
return output;
}
#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)
FragInputs input = UnpackVaryings(packedInput);
VaryingsPassToDS ouput;
TESSELLATION_INTERPOLATE_BARY(positionCS, baryCoords);
TESSELLATION_INTERPOLATE_BARY(previousPositionCS, baryCoords);
return ouput;
}
#endif // TESSELLATION_ON
#ifdef TESSELLATION_ON
#define VaryingsPassType VaryingsPassToDS
#else
#define VaryingsPassType VaryingsPassToPS
#endif
// We will use custom attributes for this pass
#define VARYINGS_NEED_PASS
#include "VertMesh.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh,
AttributesPass inputPass)
{
VaryingsType varyingsType;
varyingsType.vmesh = VertMesh(inputMesh);
// 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.
varyingsType.vpass.positionCS = mul(_NonJitteredVP, mul(unity_ObjectToWorld, float4(inputMesh.positionOS, 1.0)));
varyingsType.vpass.previousPositionCS = mul(_PreviousVP, mul(_PreviousM, _HasLastPositionData ? float4(inputPass.previousPositionOS, 1.0) : float4(inputMesh.positionOS, 1.0)));
return PackVaryingsType(varyingsType);
}
#ifdef TESSELLATION_ON
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
{
VaryingsToPS output;
output.vmesh = VertMeshTesselation(input.vmesh);
output.vpass.positionCS = input.vpass.positionCS;
output.vpass.previousPositionCS = input.vpass.previousPositionCS;
return PackVaryingsToPS(output);
}
#include "TessellationShare.hlsl"
#endif // TESSELLATION_ON
float4 Frag(PackedVaryingsToPS packedInput) : SV_Target
{
FragInputs input = UnpackVaryingsMeshToFragInputs(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);

6
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl


return glstate_matrix_inv_projection;
}
float GetOdddNegativeScale()
float GetOddNegativeScale()
{
return unity_WorldTransformParams.w;
}

float3x3 CreateTangentToWorld(float3 normal, float3 tangent, float tangentSign)
{
// For odd-negative scale transforms we need to flip the sign
float sign = tangentSign * GetOdddNegativeScale();
float3 bitangent = cross(normal, tangent) * sign;
float sgn = tangentSign * GetOddNegativeScale();
float3 bitangent = cross(normal, tangent) * sgn;
return float3x3(tangent, bitangent, normal);
}

6
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs


if (builtinParams.depthBuffer != BuiltinSkyParameters.invalidRTI)
{
cmd.SetGlobalTexture("_CameraDepthTexture", builtinParams.depthBuffer);
cmd.SetGlobalFloat("_DisableSkyOcclusionTest", 0.0f);
}
else
{
// For some reason, disabling the 'PERFORM_SKY_OCCLUSION_TEST' keyword has no effect.
cmd.SetGlobalFloat("_DisableSkyOcclusionTest", 1.0f);
}
cmd.DrawMesh(builtinParams.skyMesh, Matrix4x4.identity, m_ProceduralSkyMaterial);
builtinParams.renderContext.ExecuteCommandBuffer(cmd);

10
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/SkyProcedural.shader


HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 ps4// TEMP: unitl we go futher in dev
#pragma only_renderers d3d11 ps4 // TEMP: unitl we go futher in dev
#pragma vertex Vert
#pragma fragment Frag

float4x4 _InvViewProjMatrix;
float4x4 _ViewProjMatrix;
float _DisableSkyOcclusionTest;
#define IS_RENDERING_SKY
#include "AtmosphericScattering.hlsl"

float depthRaw = skyDepth;
float skyTexWeight = 1.0;
#endif
if (_DisableSkyOcclusionTest != 0.0)
{
depthRaw = skyDepth;
skyTexWeight = 1.0;
}
UpdatePositionInput(depthRaw, _InvViewProjMatrix, _ViewProjMatrix, posInput);

26
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/GGXConvolve.shader


HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 ps4// TEMP: unitl we go futher in dev
#pragma only_renderers d3d11 ps4 // TEMP: unitl we go futher in dev
#pragma multi_compile _ USE_MIS

TEXTURECUBE(_MainTex);
SAMPLERCUBE(sampler_MainTex);
TEXTURE2D(_GgxIblSamples);
#ifdef USE_MIS
TEXTURE2D(_MarginalRowDensities);
TEXTURE2D(_ConditionalDensities);

float _MaxLevel;
float _LastLevel;
float _InvOmegaP;
half4 Frag(Varyings input) : SV_Target

// Remove view-dependency from GGX, effectively making the BSDF isotropic.
float3 V = N;
float perceptualRoughness = mipmapLevelToPerceptualRoughness(_Level);
float perceptualRoughness = MipmapLevelToPerceptualRoughness(_Level);
uint sampleCount = GetIBLRuntimeFilterSampleCount(_Level);
#ifdef USE_MIS
float4 val = IntegrateLD_MIS(TEXTURECUBE_PARAM(_MainTex, sampler_MainTex),

1024,
false);
#else
uint sampleCount = 0;
switch (_Level)
{
case 1: sampleCount = 21; break;
case 2: sampleCount = 34; break;
case 3: sampleCount = 55; break;
case 4: sampleCount = 89; break;
case 5: sampleCount = 89; break;
case 6: sampleCount = 89; break; // UNITY_SPECCUBE_LOD_STEPS
}
_GgxIblSamples,
_MaxLevel,
_Level - 1,
_LastLevel,
true,
true);
#endif

67
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs


RenderTexture m_SkyboxConditionalCdfRT = null;
Material m_StandardSkyboxMaterial = null; // This is the Unity standard skybox material. Used to pass the correct cubemap to Enlighten.
Material m_GGXConvolveMaterial = null; // Apply GGX convolution to cubemap
ComputeShader m_BuildProbabilityTablesCS = null;
int m_ConditionalDensitiesKernel = -1;
int m_MarginalRowDensitiesKernel = -1;
IBLFilterGGX m_iblFilterGgx = null;
Vector4 m_CubemapScreenSize;
Matrix4x4[] m_faceCameraViewProjectionMatrix = new Matrix4x4[6];

if (m_Renderer != null)
m_Renderer.Build();
// Create unititialized. Lazy initialization is performed later.
m_iblFilterGgx = new IBLFilterGGX();
m_GGXConvolveMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/GGXConvolve");
m_BuildProbabilityTablesCS = Resources.Load<ComputeShader>("BuildProbabilityTables");
m_ConditionalDensitiesKernel = m_BuildProbabilityTablesCS.FindKernel("ComputeConditionalDensities");
m_MarginalRowDensitiesKernel = m_BuildProbabilityTablesCS.FindKernel("ComputeMarginalRowDensities");
m_CurrentUpdateTime = 0.0f;
}

Utilities.Destroy(m_StandardSkyboxMaterial);
Utilities.Destroy(m_GGXConvolveMaterial);
Utilities.Destroy(m_SkyboxCubemapRT);
Utilities.Destroy(m_SkyboxGGXCubemapRT);
Utilities.Destroy(m_SkyboxMarginalRowCdfRT);

}
}
private void BuildProbabilityTables(ScriptableRenderContext renderContext)
{
// Bind the input cubemap.
m_BuildProbabilityTablesCS.SetTexture(m_ConditionalDensitiesKernel, "envMap", m_SkyboxCubemapRT);
// Bind the outputs.
m_BuildProbabilityTablesCS.SetTexture(m_ConditionalDensitiesKernel, "marginalRowDensities", m_SkyboxMarginalRowCdfRT);
m_BuildProbabilityTablesCS.SetTexture(m_ConditionalDensitiesKernel, "conditionalDensities", m_SkyboxConditionalCdfRT);
m_BuildProbabilityTablesCS.SetTexture(m_MarginalRowDensitiesKernel, "marginalRowDensities", m_SkyboxMarginalRowCdfRT);
var cmd = new CommandBuffer() { name = "" };
cmd.DispatchCompute(m_BuildProbabilityTablesCS, m_ConditionalDensitiesKernel, (int)LightSamplingParameters.TextureHeight, 1, 1);
cmd.DispatchCompute(m_BuildProbabilityTablesCS, m_MarginalRowDensitiesKernel, 1, 1, 1);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
private void RenderCubemapGGXConvolution(ScriptableRenderContext renderContext, BuiltinSkyParameters builtinParams, SkyParameters skyParams, Texture input, RenderTexture target)
{
using (new Utilities.ProfilingSample("Sky Pass: GGX Convolution", renderContext))

return;
}
if (m_useMIS)
if (!m_iblFilterGgx.IsInitialized())
BuildProbabilityTables(renderContext);
m_iblFilterGgx.Initialize(renderContext);
}
// Copy the first mip.

if (m_useMIS)
{
m_GGXConvolveMaterial.EnableKeyword("USE_MIS");
m_GGXConvolveMaterial.SetTexture("_MarginalRowDensities", m_SkyboxMarginalRowCdfRT);
m_GGXConvolveMaterial.SetTexture("_ConditionalDensities", m_SkyboxConditionalCdfRT);
m_iblFilterGgx.FilterCubemapGgxMis(renderContext, mipCount, input, target, m_SkyboxConditionalCdfRT, m_SkyboxMarginalRowCdfRT, m_CubemapFaceMesh);
m_GGXConvolveMaterial.DisableKeyword("USE_MIS");
m_iblFilterGgx.FilterCubemapGgx(renderContext, mipCount, input, target, m_CubemapFaceMesh);
// Do the convolution on remaining mipmaps
float invOmegaP = (6.0f * input.width * input.width) / (4.0f * Mathf.PI); // Solid angle associated to a pixel of the cubemap;
m_GGXConvolveMaterial.SetTexture("_MainTex", input);
m_GGXConvolveMaterial.SetFloat("_MaxLevel", mipCount - 1);
m_GGXConvolveMaterial.SetFloat("_InvOmegaP", invOmegaP);
for (int mip = 1; mip < ((int)EnvConstants.SpecCubeLodStep + 1); ++mip)
{
MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
propertyBlock.SetFloat("_Level", mip);
for (int face = 0; face < 6; ++face)
{
Utilities.SetRenderTarget(renderContext, target, ClearFlag.ClearNone, mip, (CubemapFace)face);
var cmd = new CommandBuffer { name = "" };
cmd.DrawMesh(m_CubemapFaceMesh[face], Matrix4x4.identity, m_GGXConvolveMaterial, 0, 0, propertyBlock);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}
}
}

{
// Render sky into a cubemap - doesn't happen every frame, can be controlled
RenderSkyToCubemap(m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT);
// Note that m_SkyboxCubemapRT is created with auto-generate mipmap, it mean that here we have also our mipmap correctly box filtered for importance sampling.
// Convolve downsampled cubemap
RenderCubemapGGXConvolution(renderContext, m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT);

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs.hlsl


#ifndef SKYMANAGER_CS_HLSL
#define SKYMANAGER_CS_HLSL
//
// UnityEngine.Experimental.ScriptableRenderLoop.LightSamplingParameters: static fields
// UnityEngine.Experimental.Rendering.HDPipeline.LightSamplingParameters: static fields
//
#define LIGHTSAMPLINGPARAMETERS_TEXTURE_HEIGHT (256)
#define LIGHTSAMPLINGPARAMETERS_TEXTURE_WIDTH (512)

9
Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl


return INV_PI * D_GGXNoPI(NdotH, roughness);
}
float D_GGX_Inverse(float NdotH, float roughness)
{
float a2 = roughness * roughness;
float f = (NdotH * a2 - NdotH) * NdotH + 1.0;
float g = (f * f) / a2;
return PI * g;
}
// Ref: Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs, p. 19, 29.
float G_MaskingSmithGGX(float NdotV, float VdotH, float roughness)
{

14
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


return x * x * (3.0 - (2.0 * x));
}
const float3x3 k_identity3x3 = {1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0};
static const float3x3 k_identity3x3 = {1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0};
const float4x4 k_identity4x4 = {1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0 };
static const float4x4 k_identity4x4 = {1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0};
// Using pow often result to a warning like this
// "pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them"

1
Assets/ScriptableRenderLoop/ShaderLibrary/CommonMaterial.hlsl


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

139
Assets/ScriptableRenderLoop/ShaderLibrary/ImageBasedLighting.hlsl


// Util image based lighting
//-----------------------------------------------------------------------------
// Performs a *non-linear* remapping which improves the perceptual roughness distribution
// and adds reflection (contact) hardening. The *approximated* version.
float perceptualRoughnessToMipmapLevel(float perceptualRoughness)
// The *approximated* version of the non-linear remapping. It works by
// approximating the cone of the specular lobe, and then computing the MIP map level
// which (approximately) covers the footprint of the lobe with a single texel.
// Improves the perceptual roughness distribution.
float PerceptualRoughnessToMipmapLevel(float perceptualRoughness)
{
perceptualRoughness = perceptualRoughness * (1.7 - 0.7 * perceptualRoughness);

// Performs a *non-linear* remapping which improves the perceptual roughness distribution
// and adds reflection (contact) hardening. The *accurate* version.
// The *accurate* version of the non-linear remapping. It works by
// approximating the cone of the specular lobe, and then computing the MIP map level
// which (approximately) covers the footprint of the lobe with a single texel.
// Improves the perceptual roughness distribution and adds reflection (contact) hardening.
float perceptualRoughnessToMipmapLevel(float perceptualRoughness, float NdotR)
float PerceptualRoughnessToMipmapLevel(float perceptualRoughness, float NdotR)
{
float m = PerceptualRoughnessToRoughness(perceptualRoughness);

return perceptualRoughness * UNITY_SPECCUBE_LOD_STEPS;
}
// Performs *linear* remapping for runtime EnvMap filtering.
float mipmapLevelToPerceptualRoughness(float mipmapLevel)
// The inverse of the *approximated* version of perceptualRoughnessToMipmapLevel().
float MipmapLevelToPerceptualRoughness(float mipmapLevel)
return saturate(mipmapLevel / UNITY_SPECCUBE_LOD_STEPS);
float perceptualRoughness = saturate(mipmapLevel / UNITY_SPECCUBE_LOD_STEPS);
return saturate(1.7 / 1.4 - sqrt(2.89 - 2.8 * perceptualRoughness) / 1.4);
// Ref: See "Moving Frostbite to PBR" Listing 22
// This formulation is for GGX only (with smith joint visibility or regular)
float3 GetSpecularDominantDir(float3 N, float3 R, float roughness)
// Ref: "Moving Frostbite to PBR", p. 69.
float3 GetSpecularDominantDir(float3 N, float3 R, float roughness, float NdotV)
float lerpFactor = a * (sqrt(a) + roughness);
float s = sqrt(a);
#ifdef USE_FB_DSD
// This is the original formulation.
float lerpFactor = (s + roughness) * a;
#else
// TODO: tweak this further to achieve a closer match to the reference.
float lerpFactor = (s + roughness) * saturate(a * a + lerp(0.0, a, NdotV * NdotV));
#endif
// The result is not normalized as we fetch in a cubemap
return lerp(N, R, lerpFactor);
}

return acc / sampleCount;
}
uint GetIBLRuntimeFilterSampleCount(uint mipLevel)
{
uint sampleCount = 0;
switch (mipLevel)
{
case 1: sampleCount = 21; break;
case 2: sampleCount = 34; break;
case 3: sampleCount = 55; break;
case 4: sampleCount = 89; break;
case 5: sampleCount = 89; break;
case 6: sampleCount = 89; break; // UNITY_SPECCUBE_LOD_STEPS
}
return sampleCount;
}
float3 V,
float3 N,
float roughness,
float maxMipLevel,
float invOmegaP,
uint sampleCount, // Must be a Fibonacci number
bool prefilter)
TEXTURE2D(ggxIblSamples),
float3 V,
float3 N,
float roughness,
float index, // Current MIP level minus one
float lastMipLevel,
float invOmegaP,
uint sampleCount, // Must be a Fibonacci number
bool prefilter,
bool usePrecomputedSamples)
// Bias samples towards the mirror direction to reduce variance.
// This will have a side effect of making the reflection sharper.
// Ref: Stochastic Screen-Space Reflections, p. 67.
const float bias = 0.5 * roughness;
float2 u = Fibonacci2d(i, sampleCount);
float3 L;
float NdotL, NdotH, VdotH;
bool isValid;
if (usePrecomputedSamples)
{
float3 localL = LOAD_TEXTURE2D(ggxIblSamples, uint2(i, index)).xyz;
L = mul(localL, localToWorld);
NdotL = localL.z;
isValid = true;
}
else
{
float2 u = Fibonacci2d(i, sampleCount);
u.x = lerp(u.x, 0.0, bias);
// Bias samples towards the mirror direction to reduce variance.
// This will have a side effect of making the reflection sharper.
// Ref: Stochastic Screen-Space Reflections, p. 67.
const float bias = 0.2;
u.x = lerp(u.x, 0.0, bias);
SampleGGXDir(u, V, localToWorld, roughness, L, NdotL, NdotH, VdotH, true);
float3 L;
float NdotL, NdotH, VdotH;
SampleGGXDir(u, V, localToWorld, roughness, L, NdotL, NdotH, VdotH, true);
isValid = NdotL > 0.0;
}
float mipLevel;

// can be simplified:
// pdf = D * NdotH / (4 * LdotH) = D * 0.25;
//
// - OmegaS : Solid angle associated to a sample
// - OmegaP : Solid angle associated to a pixel of the cubemap
// - OmegaS : Solid angle associated with the sample
// - OmegaP : Solid angle associated with the texel of the cubemap
float omegaS;
if (usePrecomputedSamples)
{
omegaS = LOAD_TEXTURE2D(ggxIblSamples, uint2(i, index)).w;
}
else
{
float pdf = D_GGX(NdotH, roughness) * 0.25;
// TODO: check the accuracy of the sample's solid angle fit for GGX.
omegaS = rcp(sampleCount) / pdf;
}
float invPdf = D_GGX_Inverse(NdotH, roughness) * 4.0;
// TODO: check the accuracy of the sample's solid angle fit for GGX.
float omegaS = rcp(sampleCount) * invPdf;
}
if (isValid)
{
mipLevel = lerp(mipLevel, maxMipLevel, bias);
mipLevel = lerp(mipLevel, lastMipLevel, bias);
// TODO: There is a bug currently where autogenerate mipmap for the cubemap seems to
// clamp the mipLevel to 6. correct it! Then remove this clamp
}
if (NdotL > 0.0)
{
// *********************************************************************************
// Our goal is to use Monte-Carlo integration with importance sampling to evaluate
// X(V) = Integral{Radiance(L) * CBSDF(L, N, V) dL} / Integral{CBSDF(L, N, V) dL}.
// CBSDF = F * D * G * NdotL / (4 * NdotL * NdotV) = F * D * G / (4 * NdotV).

// (LdotH == NdotH) && (NdotV == 1) && (Weight == F * G).
// We use the approximation of Brian Karis from "Real Shading in Unreal Engine 4":
// Weight ≈ NdotL, which produces nearly identical results in practice.
// *********************************************************************************
lightInt += NdotL * val;
cbsdfInt += NdotL;

195
Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl


#define TESSELATION_INTERPOLATE_BARY(name, bary) ouput.name = input0.name * bary.x + input1.name * bary.y + input2.name * bary.z
#define TESSELLATION_INTERPOLATE_BARY(name, bary) ouput.name = input0.name * bary.x + input1.name * bary.y + input2.name * bary.z
// ---- utility functions
float UnityCalcDistanceTessFactor(float3 positionOS, float minDist, float maxDist, float tess, float4x4 objectToWorld, float3 cameraPosWS)
// TODO: Move in geomtry.hlsl
float3 ProjectPointOnPlane(float3 position, float3 planePosition, float3 planeNormal)
float3 positionWS = mul(objectToWorld, float4(positionOS, 1.0)).xyz;
float dist = distance(positionWS, cameraPosWS);
float f = clamp(1.0 - (dist - minDist) / (maxDist - minDist), 0.01, 1.0) * tess;
return f;
return position - (dot(position - planePosition, planeNormal) * planeNormal);
float4 UnityCalcTriEdgeTessFactors(float3 triVertexFactors)
// p0, p1, p2 triangle world position
// p0, p1, p2 triangle world vertex normal
float3 PhongTessellation(float3 positionWS, float3 p0, float3 p1, float3 p2, float3 n0, float3 n1, float3 n2, float3 baryCoords, float shape)
float4 tess;
tess.x = 0.5 * (triVertexFactors.y + triVertexFactors.z);
tess.y = 0.5 * (triVertexFactors.x + triVertexFactors.z);
tess.z = 0.5 * (triVertexFactors.x + triVertexFactors.y);
tess.w = (triVertexFactors.x + triVertexFactors.y + triVertexFactors.z) / 3.0f;
return tess;
float3 c0 = ProjectPointOnPlane(positionWS, p0, n0);
float3 c1 = ProjectPointOnPlane(positionWS, p1, n1);
float3 c2 = ProjectPointOnPlane(positionWS, p2, n2);
float3 phongPositionWS = baryCoords.x * c0 + baryCoords.y * c1 + baryCoords.z * c2;
return lerp(positionWS, phongPositionWS, shape);
/*
float UnityCalcEdgeTessFactor(float3 wpos0, float3 wpos1, float edgeLen)
// Reference: http://twvideo01.ubm-us.net/o1/vault/gdc10/slides/Bilodeau_Bill_Direct3D11TutorialTessellation.pdf
// Return true if the triangle must be culled
// backFaceCullEpsilon is the threshold of the dot product between view and normal ( < 0 mean we cull)
bool BackFaceCullTriangle(float3 p0, float3 p1, float3 p2, float backFaceCullEpsilon, float3 cameraPosWS)
// distance to edge center
float dist = distance(0.5 * (wpos0 + wpos1), _WorldSpaceCameraPos);
// length of the edge
float len = distance(wpos0, wpos1);
// edgeLen is approximate desired size in pixels
float f = max(len * _ScreenParams.y / (edgeLen * dist), 1.0);
return f;
float3 edge0 = p1 - p0;
float3 edge2 = p2 - p0;
float3 N = normalize(cross(edge0, edge2));
float3 midpoint = (p0 + p1 + p2) / 3.0;
float3 V = normalize(cameraPosWS - midpoint);
return (dot(V, N) < backFaceCullEpsilon) ? true : false;
float UnityDistanceFromPlane(float3 pos, float4 plane)
float2 GetScreenSpacePosition(float3 positionWS, float4x4 viewProjectionMatrix, float4 screenParams)
float d = dot(float4(pos, 1.0f), plane);
return d;
float4 positionCS = mul(viewProjectionMatrix, float4(positionWS, 1.0));
float2 positionSS = positionCS.xy / positionCS.w;
// TODO: Check if we need to invert y
return (positionSS * 0.5 + 0.5) * float2(screenParams.x, -screenParams.y);
}
// Compute both screen and distance based adaptation - return factor between 0 and 1
float3 GetScreenSpaceTessFactor(float3 p0, float3 p1, float3 p2, float4x4 viewProjectionMatrix, float4 screenParams, float triangleSize)
{
// Get screen space adaptive scale factor
float2 edgeScreenPosition0 = GetScreenSpacePosition(p0, viewProjectionMatrix, screenParams);
float2 edgeScreenPosition1 = GetScreenSpacePosition(p1, viewProjectionMatrix, screenParams);
float2 edgeScreenPosition2 = GetScreenSpacePosition(p2, viewProjectionMatrix, screenParams);
float EdgeScale = 1.0 / triangleSize; // Edge size in reality, but name is simpler
float3 tessFactor;
tessFactor.x = saturate(distance(edgeScreenPosition1, edgeScreenPosition2) * EdgeScale);
tessFactor.y = saturate(distance(edgeScreenPosition0, edgeScreenPosition2) * EdgeScale);
tessFactor.z = saturate(distance(edgeScreenPosition0, edgeScreenPosition1) * EdgeScale);
return tessFactor;
// Returns true if triangle with given 3 world positions is outside of camera's view frustum.
// cullEps is distance outside of frustum that is still considered to be inside (i.e. max displacement)
bool UnityWorldViewFrustumCull(float3 wpos0, float3 wpos1, float3 wpos2, float cullEps)
float3 GetDistanceBasedTessFactor(float3 p0, float3 p1, float3 p2, float3 cameraPosWS, float tessMinDist, float tessMaxDist)
float4 planeTest;
float3 edgePosition0 = 0.5 * (p1 + p2);
float3 edgePosition1 = 0.5 * (p0 + p2);
float3 edgePosition2 = 0.5 * (p0 + p1);
// left
planeTest.x = ((UnityDistanceFromPlane(wpos0, unity_CameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f) +
((UnityDistanceFromPlane(wpos1, unity_CameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f) +
((UnityDistanceFromPlane(wpos2, unity_CameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f);
// right
planeTest.y = ((UnityDistanceFromPlane(wpos0, unity_CameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f) +
((UnityDistanceFromPlane(wpos1, unity_CameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f) +
((UnityDistanceFromPlane(wpos2, unity_CameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f);
// top
planeTest.z = ((UnityDistanceFromPlane(wpos0, unity_CameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f) +
((UnityDistanceFromPlane(wpos1, unity_CameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f) +
((UnityDistanceFromPlane(wpos2, unity_CameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f);
// bottom
planeTest.w = ((UnityDistanceFromPlane(wpos0, unity_CameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f) +
((UnityDistanceFromPlane(wpos1, unity_CameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f) +
((UnityDistanceFromPlane(wpos2, unity_CameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f);
// TODO: Move to camera relative and change distance to length
float dist0 = distance(edgePosition0, cameraPosWS);
float dist1 = distance(edgePosition1, cameraPosWS);
float dist2 = distance(edgePosition2, cameraPosWS);
// The saturate will handle the produced NaN in case min == max
float fadeDist = tessMaxDist - tessMinDist;
float3 tessFactor;
tessFactor.x = saturate(1.0 - (dist0 - tessMinDist) / fadeDist);
tessFactor.y = saturate(1.0 - (dist1 - tessMinDist) / fadeDist);
tessFactor.z = saturate(1.0 - (dist2 - tessMinDist) / fadeDist);
// has to pass all 4 plane tests to be visible
return !all(planeTest);
return tessFactor;
*/
// ---- functions that compute tessellation factors
// Distance based tessellation:
// Tessellation level is "tess" before "minDist" from camera, and linearly decreases to 1
// up to "maxDist" from camera.
float4 UnityDistanceBasedTess(float3 positionOS0, float3 positionOS1, float3 positionOS2, float minDist, float maxDist, float tess, float4x4 objectToWorld, float3 cameraPosWS)
float4 CalcTriEdgeTessFactors(float3 triVertexFactors)
float3 f;
f.x = UnityCalcDistanceTessFactor(positionOS0, minDist, maxDist, tess, objectToWorld, cameraPosWS);
f.y = UnityCalcDistanceTessFactor(positionOS1, minDist, maxDist, tess, objectToWorld, cameraPosWS);
f.z = UnityCalcDistanceTessFactor(positionOS2, minDist, maxDist, tess, objectToWorld, cameraPosWS);
return UnityCalcTriEdgeTessFactors(f);
float4 tess;
tess.x = triVertexFactors.x;
tess.y = triVertexFactors.y;
tess.z = triVertexFactors.z;
tess.w = (triVertexFactors.x + triVertexFactors.y + triVertexFactors.z) / 3.0;
return tess;
/*
// Desired edge length based tessellation:
// Approximate resulting edge length in pixels is "edgeLength".
// Does not take viewing FOV into account, just flat out divides factor by distance.
float4 UnityEdgeLengthBasedTess(float4 v0, float4 v1, float4 v2, float edgeLength)
// TODO: Move in geomtry.hlsl
float DistanceFromPlane(float3 pos, float4 plane)
float3 pos0 = mul(unity_ObjectToWorld, v0).xyz;
float3 pos1 = mul(unity_ObjectToWorld, v1).xyz;
float3 pos2 = mul(unity_ObjectToWorld, v2).xyz;
float4 tess;
tess.x = UnityCalcEdgeTessFactor(pos1, pos2, edgeLength);
tess.y = UnityCalcEdgeTessFactor(pos2, pos0, edgeLength);
tess.z = UnityCalcEdgeTessFactor(pos0, pos1, edgeLength);
tess.w = (tess.x + tess.y + tess.z) / 3.0f;
return tess;
float d = dot(float4(pos, 1.0f), plane);
return d;
// Same as UnityEdgeLengthBasedTess, but also does patch frustum culling:
// patches outside of camera's view are culled before GPU tessellation. Saves some wasted work.
float4 UnityEdgeLengthBasedTessCull(float4 v0, float4 v1, float4 v2, float edgeLength, float maxDisplacement)
// Returns true if triangle with given 3 world positions is outside of camera's view frustum.
// cullEps is distance outside of frustum that is still considered to be inside (i.e. max displacement)
bool WorldViewFrustumCull(float3 p0, float3 p1, float3 p2, float cullEps, float4 cameraWorldClipPlanes[4])
float3 pos0 = mul(unity_ObjectToWorld, v0).xyz;
float3 pos1 = mul(unity_ObjectToWorld, v1).xyz;
float3 pos2 = mul(unity_ObjectToWorld, v2).xyz;
float4 tess;
if (UnityWorldViewFrustumCull(pos0, pos1, pos2, maxDisplacement))
{
tess = 0.0f;
}
else
{
tess.x = UnityCalcEdgeTessFactor(pos1, pos2, edgeLength);
tess.y = UnityCalcEdgeTessFactor(pos2, pos0, edgeLength);
tess.z = UnityCalcEdgeTessFactor(pos0, pos1, edgeLength);
tess.w = (tess.x + tess.y + tess.z) / 3.0f;
}
return tess;
float4 planeTest;
// left
planeTest.x = ((DistanceFromPlane(p0, cameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f) +
((DistanceFromPlane(p1, cameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f) +
((DistanceFromPlane(p2, cameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f);
// right
planeTest.y = ((DistanceFromPlane(p0, cameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f) +
((DistanceFromPlane(p1, cameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f) +
((DistanceFromPlane(p2, cameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f);
// top
planeTest.z = ((DistanceFromPlane(p0, cameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f) +
((DistanceFromPlane(p1, cameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f) +
((DistanceFromPlane(p2, cameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f);
// bottom
planeTest.w = ((DistanceFromPlane(p0, cameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f) +
((DistanceFromPlane(p1, cameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f) +
((DistanceFromPlane(p2, cameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f);
// has to pass all 4 plane tests to be visible
return !all(planeTest);
*/

2
Assets/ScriptableRenderLoop/common/TextureCache.cs


}
public abstract class TextureCache : Object
public abstract class TextureCache
{
protected int m_NumMipLevels;

2
README.md


## For Unity 5.6 beta users
* Unity 5.6 beta 1 and beta 2 should use an older revision of this project, [tagged unity-5.6.0b1](../../releases/tag/unity-5.6.0b1) (commit `acc230b` on 2016 Nov 23). "BasicRenderLoopScene" scene is the basic example, with the scriptable render loop defaulting to off; enable it by enabling the component on the camera. All the other scenes may or might not work. Use of Windows/DX11 is preferred.
* Unity 5.6 **beta 1, 2 and 3** should use an older revision of this project, [tagged unity-5.6.0b1](../../releases/tag/unity-5.6.0b1) (commit `acc230b` on 2016 Nov 23). "BasicRenderLoopScene" scene is the basic example, with the scriptable render loop defaulting to off; enable it by enabling the component on the camera. All the other scenes may or might not work. Use of Windows/DX11 is preferred.

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


float2 texCoord2;
float2 texCoord3;
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
float4 color; // vertex color
void ApplyDepthOffsetAttribute(float depthOffsetVS, inout FragInputs fragInput)
// FragInputs use dir vector that are normalized in the code even if not used
// so we initialize them to a valid != 0 to shutdown compiler warning
FragInputs InitializeFragInputs()
fragInput.positionCS.w += depthOffsetVS;
fragInput.previousPositionCS.w += depthOffsetVS;
FragInputs output;
ZERO_INITIALIZE(FragInputs, output);
output.tangentToWorld[0] = float3(0.0, 0.0, 1.0);
output.tangentToWorld[2] = float3(0.0, 0.0, 1.0);
return output;
}
void GetVaryingsDataDebug(uint paramId, FragInputs input, inout float3 result, inout bool needLinearToSRGB)

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

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


float4 TessellationEdge(float3 p0, float3 p1, float3 p2, float3 n0, float3 n1, float3 n2)
{
float maxDisplacement = ADD_ZERO_IDX(_HeightAmplitude);
#ifdef _LAYER_COUNT
maxDisplacement = max(maxDisplacement, _HeightAmplitude1);
#if _LAYER_COUNT >= 3
maxDisplacement = max(maxDisplacement, _HeightAmplitude2);
#endif
#if _LAYER_COUNT >= 4
maxDisplacement = max(maxDisplacement, _HeightAmplitude3);
#endif
#endif
bool frustumCulled = WorldViewFrustumCull(p0, p1, p2, maxDisplacement, (float4[4])unity_CameraWorldClipPlanes);
bool faceCull = false;
#if !(defined(_DOUBLESIDED) || defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR))
// TODO: Handle inverse culling (for mirror)!
if (_TessellationBackFaceCullEpsilon > -0.99) // Is backface culling enabled ?
{
faceCull = BackFaceCullTriangle(p0, p1, p2, _TessellationBackFaceCullEpsilon, _WorldSpaceCameraPos);
}
#endif
if (frustumCulled || faceCull)
{
// Settings factor to 0 will kill the triangle
return float4(0.0, 0.0, 0.0, 0.0);
}
float3 tessFactor = float3(1.0, 1.0, 1.0);
// Aaptive screen space tessellation
if (_TessellationFactorTriangleSize > 0.0)
{
// return a value between 0 and 1
tessFactor *= GetScreenSpaceTessFactor( p0, p1, p2, GetWorldToHClipMatrix(), _ScreenParams, _TessellationFactorTriangleSize);
}
// Distance based tessellation
if (_TessellationFactorMaxDistance > 0.0)
{
tessFactor *= GetDistanceBasedTessFactor(p0, p1, p2, _WorldSpaceCameraPos, _TessellationFactorMinDistance, _TessellationFactorMaxDistance);
}
tessFactor *= _TessellationFactor;
// TessFactor below 1.0 have no effect. At 0 it kill the triangle, so clamp it to 1.0
tessFactor.xyz = float3(max(1.0, tessFactor.x), max(1.0, tessFactor.y), max(1.0, tessFactor.z));
return CalcTriEdgeTessFactors(tessFactor);
}
float3 GetDisplacement(VaryingsMeshToDS input)
{
// This call will work for both LayeredLit and Lit shader
LayerTexCoord layerTexCoord;
GetLayerTexCoord(
#ifdef VARYINGS_DS_NEED_TEXCOORD0
input.texCoord0,
#else
float2(0.0, 0.0),
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD1
input.texCoord1,
#else
float2(0.0, 0.0),
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD2
input.texCoord2,
#else
float2(0.0, 0.0),
#endif
#ifdef VARYINGS_DS_NEED_TEXCOORD3
input.texCoord3,
#else
float2(0.0, 0.0),
#endif
input.positionWS,
#ifdef VARYINGS_DS_NEED_NORMAL
input.normalWS,
#else
float3(0.0, 0.0, 1.0),
#endif
layerTexCoord);
// TODO: For now just use Layer0, but we are suppose to apply the same heightmap blending than in the pixel shader
#ifdef _HEIGHTMAP
// TODO test mip lod to reduce texture cache miss
// TODO: Move to camera relative and change distance to length
//float dist = distance(input.positionWS, cameraPosWS);
// No ddx/ddy to calculate LOD, use camera distance instead
//float fadeDist = _TessellationFactorMaxDistance - _TessellationFactorMinDistance;
//float heightMapLod = saturate((dist - _TessellationFactorMinDistance) / min(fadeDist, 0.01)) * 6; // 6 is an arbitrary number here
float heightMapLod = 0.0;
float height = (SAMPLE_LAYER_TEXTURE2D_LOD(ADD_ZERO_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), ADD_ZERO_IDX(layerTexCoord.base), heightMapLod).r - ADD_ZERO_IDX(_HeightCenter)) * ADD_ZERO_IDX(_HeightAmplitude);
#else
float height = 0.0;
#endif
#ifdef VARYINGS_DS_NEED_NORMAL
return height * input.normalWS;
#else
return float3(0.0, 0.0, 0.0);
#endif
}

9
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass.meta


fileFormatVersion: 2
guid: 83421d7ac8db22148903e8ecee502314
folderAsset: yes
timeCreated: 1484323639
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

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


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

86
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]);
float3 p0 = varying0.vmesh.positionWS;
float3 p1 = varying1.vmesh.positionWS;
float3 p2 = varying2.vmesh.positionWS;
#ifdef VARYINGS_DS_NEED_NORMAL
float3 n0 = varying0.vmesh.normalWS;
float3 n1 = varying1.vmesh.normalWS;
float3 n2 = varying2.vmesh.normalWS;
#else
float3 n0 = float3(0.0, 0.0, 0.0);
float3 n1 = float3(0.0, 0.0, 0.0);
float3 n2 = float3(0.0, 0.0, 0.0);
#endif
float4 tf = TessellationEdge(p0, p1, p2, n0, n1, n2);
TessellationFactors output;
output.edge[0] = tf.x;
output.edge[1] = tf.y;
output.edge[2] = tf.z;
output.inside = tf.w;
return output;
}
[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")]
PackedVaryingsToPS 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 = InterpolateWithBaryCoordsToDS(varying0, varying1, varying2, baryCoords);
// We have Phong tessellation in all case where we don't have displacement only
#ifndef _TESSELLATION_DISPLACEMENT
float3 p0 = varying0.vmesh.positionWS;
float3 p1 = varying1.vmesh.positionWS;
float3 p2 = varying2.vmesh.positionWS;
#ifdef VARYINGS_DS_NEED_NORMAL
float3 n0 = varying0.vmesh.normalWS;
float3 n1 = varying1.vmesh.normalWS;
float3 n2 = varying2.vmesh.normalWS;
#else
float3 n0 = float3(0.0, 0.0, 0.0);
float3 n1 = float3(0.0, 0.0, 0.0);
float3 n2 = float3(0.0, 0.0, 0.0);
#endif
varying.vmesh.positionWS = PhongTessellation( varying.vmesh.positionWS,
p0, p1, p2, n0, n1, n2,
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 = input.positionWS;
#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 UnpackVaryingsMeshToFragInputs(PackedVaryingsMeshToPS input)
{
FragInputs output = InitializeFragInputs();
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 VARYINGS_NEED_POSITION_WS
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
#if defined(VARYINGS_NEED_TANGENT_TO_WORLD) || defined(ATTRIBUTES_NEED_NORMAL)
#define VARYINGS_DS_NEED_NORMAL
#endif
#if defined(VARYINGS_NEED_TANGENT_TO_WORLD) || defined(ATTRIBUTES_NEED_TANGENT)
#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)
#define 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(VaryingsMeshToDS 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)
{
VaryingsMeshToDS 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

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


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

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


struct VaryingsToPS
{
VaryingsMeshToPS vmesh;
#ifdef VARYINGS_NEED_PASS
VaryingsPassToPS vpass;
#endif
};
struct PackedVaryingsToPS
{
PackedVaryingsMeshToPS vmesh;
#ifdef VARYINGS_NEED_PASS
PackedVaryingsPassToPS vpass;
#endif
};
PackedVaryingsToPS PackVaryingsToPS(VaryingsToPS input)
{
PackedVaryingsToPS output;
output.vmesh = PackVaryingsMeshToPS(input.vmesh);
#ifdef VARYINGS_NEED_PASS
output.vpass = PackVaryingsPassToPS(input.vpass);
#endif
return output;
}
#ifdef TESSELLATION_ON
struct VaryingsToDS
{
VaryingsMeshToDS vmesh;
#ifdef VARYINGS_NEED_PASS
VaryingsPassToDS vpass;
#endif
};
struct PackedVaryingsToDS
{
PackedVaryingsMeshToDS vmesh;
#ifdef VARYINGS_NEED_PASS
PackedVaryingsPassToDS vpass;
#endif
};
PackedVaryingsToDS PackVaryingsToDS(VaryingsToDS input)
{
PackedVaryingsToDS output;
output.vmesh = PackVaryingsMeshToDS(input.vmesh);
#ifdef VARYINGS_NEED_PASS
output.vpass = PackVaryingsPassToDS(input.vpass);
#endif
return output;
}
VaryingsToDS UnpackVaryingsToDS(PackedVaryingsToDS input)
{
VaryingsToDS output;
output.vmesh = UnpackVaryingsMeshToDS(input.vmesh);
#ifdef VARYINGS_NEED_PASS
output.vpass = UnpackVaryingsPassToDS(input.vpass);
#endif
return output;
}
VaryingsToDS InterpolateWithBaryCoordsToDS(VaryingsToDS input0, VaryingsToDS input1, VaryingsToDS input2, float3 baryCoords)
{
VaryingsToDS output;
output.vmesh = InterpolateWithBaryCoordsMeshToDS(input0.vmesh, input1.vmesh, input2.vmesh, baryCoords);
#ifdef VARYINGS_NEED_PASS
output.vpass = InterpolateWithBaryCoordsPassToDS(input0.vpass, input1.vpass, input2.vpass, baryCoords);
#endif
return output;
}
#endif // TESSELLATION_ON
#ifdef TESSELLATION_ON
#define VaryingsType VaryingsToDS
#define VaryingsMeshType VaryingsMeshToDS
#define PackedVaryingsType PackedVaryingsToDS
#define PackVaryingsType PackVaryingsToDS
#else
#define VaryingsType VaryingsToPS
#define VaryingsMeshType VaryingsMeshToPS
#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)
VaryingsMeshType VertMesh(AttributesMesh input)
{
VaryingsMeshType 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(VARYINGS_NEED_TANGENT_TO_WORLD) || defined(VARYINGS_DS_NEED_NORMAL)
output.normalWS = TransformObjectToWorldNormal(input.normalOS);
#endif
#if defined(VARYINGS_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)
#ifdef VARYINGS_NEED_POSITION_WS
output.positionWS = positionWS;
#endif
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
VaryingsMeshToPS VertMeshTesselation(VaryingsMeshToDS input)
{
VaryingsMeshToPS output;
#ifdef VARYINGS_NEED_POSITION_WS
output.positionWS = input.positionWS;
#endif
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.texCoord0;
#endif
#ifdef VARYINGS_NEED_TEXCOORD1
output.texCoord1 = input.texCoord1;
#endif
#ifdef VARYINGS_NEED_TEXCOORD2
output.texCoord2 = input.texCoord2;
#endif
#ifdef VARYINGS_NEED_TEXCOORD3
output.texCoord3 = input.texCoord3;
#endif
#ifdef VARYINGS_NEED_COLOR
output.color = input.color;
#endif
return output;
}
#endif // TESSELLATION_ON

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


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

49
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/ComputeGgxIblSampleData.compute


// Precomputes data for IntegrateLD(). See that function for a detailed description.
#include "Common.hlsl"
#include "ImageBasedLighting.hlsl"
#define MAX_IBL_SAMPLE_CNT 89
RWTexture2D<float4> output; // [MAX_SAMPLE_CNT x UNITY_SPECCUBE_LOD_STEPS]
#pragma kernel ComputeGgxIblSampleData
[numthreads(MAX_IBL_SAMPLE_CNT, UNITY_SPECCUBE_LOD_STEPS, 1)]
void ComputeGgxIblSampleData(uint3 groupThreadId : SV_GroupThreadID)
{
uint sampleIndex = groupThreadId.x;
uint mipLevel = groupThreadId.y + 1;
uint sampleCount = GetIBLRuntimeFilterSampleCount(mipLevel);
if (sampleIndex >= sampleCount)
{
output[groupThreadId.xy] = float4(0, 0, 0, 0);
return;
}
float perceptualRoughness = MipmapLevelToPerceptualRoughness(mipLevel);
float roughness = PerceptualRoughnessToRoughness(perceptualRoughness);
float bias = 0.5 * roughness;
float2 u = Fibonacci2d(sampleIndex, sampleCount);
u.x = lerp(u.x, 0, bias);
float3 localL;
float NdotL, NdotH, VdotH;
SampleGGXDir(u, float3(0, 0, 1), k_identity3x3, roughness, localL, NdotL, NdotH, VdotH, true);
if (NdotL <= 0)
{
// We are not supposed to generate wasteful samples.
output[groupThreadId.xy] = float4(0, 0, 0, 0);
return;
}
float pdf = D_GGX(NdotH, roughness) * 0.25;
float omegaS = rcp(sampleCount * pdf);
output[groupThreadId.xy] = float4(localL, omegaS);
}

9
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/ComputeGgxIblSampleData.compute.meta


fileFormatVersion: 2
guid: 764a24bb47ef5ba4781d9ae82ca07445
timeCreated: 1484572881
licenseType: Pro
ComputeShaderImporter:
currentAPIMask: 4
userData:
assetBundleName:
assetBundleVariant:

134
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/RuntimeFilterIBL.cs


using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
using System;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class IBLFilterGGX
{
RenderTexture m_GgxIblSampleData = null;
const int k_GgxIblMaxSampleCount = 89; // Width
const int k_GgxIblMipCountMinusOne = 6; // Height (UNITY_SPECCUBE_LOD_STEPS)
ComputeShader m_ComputeGgxIblSampleDataCS = null;
int m_ComputeIblGgxSampleDataKernel = -1;
ComputeShader m_BuildProbabilityTablesCS = null;
int m_ConditionalDensitiesKernel = -1;
int m_MarginalRowDensitiesKernel = -1;
Material m_GgxConvolveMaterial = null; // Convolves a cubemap with GGX
public bool IsInitialized()
{
return m_GgxIblSampleData != null;
}
public void Initialize(ScriptableRenderContext context)
{
if (!m_ComputeGgxIblSampleDataCS)
{
m_ComputeGgxIblSampleDataCS = Resources.Load<ComputeShader>("ComputeGgxIblSampleData");
m_ComputeIblGgxSampleDataKernel = m_ComputeGgxIblSampleDataCS.FindKernel("ComputeGgxIblSampleData");
}
if (!m_BuildProbabilityTablesCS)
{
m_BuildProbabilityTablesCS = Resources.Load<ComputeShader>("BuildProbabilityTables");
m_ConditionalDensitiesKernel = m_BuildProbabilityTablesCS.FindKernel("ComputeConditionalDensities");
m_MarginalRowDensitiesKernel = m_BuildProbabilityTablesCS.FindKernel("ComputeMarginalRowDensities");
}
if (!m_GgxConvolveMaterial)
{
m_GgxConvolveMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/GGXConvolve");
}
if (!m_GgxIblSampleData)
{
m_GgxIblSampleData = new RenderTexture(k_GgxIblMaxSampleCount, k_GgxIblMipCountMinusOne, 1, RenderTextureFormat.ARGBFloat);
m_GgxIblSampleData.dimension = TextureDimension.Tex2D;
m_GgxIblSampleData.useMipMap = false;
m_GgxIblSampleData.autoGenerateMips = false;
m_GgxIblSampleData.enableRandomWrite = true;
m_GgxIblSampleData.filterMode = FilterMode.Point;
m_GgxIblSampleData.Create();
m_ComputeGgxIblSampleDataCS.SetTexture(m_ComputeIblGgxSampleDataKernel, "output", m_GgxIblSampleData);
var cmd = new CommandBuffer() { name = "Compute GGX IBL Sample Data" };
cmd.DispatchCompute(m_ComputeGgxIblSampleDataCS, m_ComputeIblGgxSampleDataKernel, 1, 1, 1);
context.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}
void FilterCubemapGgxCommon(ScriptableRenderContext context, int mipCount,
Texture source, RenderTexture target,
Mesh[] cubemapFaceMesh)
{
// Solid angle associated with a texel of the cubemap.
float invOmegaP = (6.0f * source.width * source.width) / (4.0f * Mathf.PI);
m_GgxConvolveMaterial.SetTexture("_MainTex", source);
m_GgxConvolveMaterial.SetTexture("_GgxIblSamples", m_GgxIblSampleData);
m_GgxConvolveMaterial.SetFloat("_LastLevel", mipCount - 1);
m_GgxConvolveMaterial.SetFloat("_InvOmegaP", invOmegaP);
for (int mip = 1; mip < ((int)EnvConstants.SpecCubeLodStep + 1); ++mip)
{
MaterialPropertyBlock props = new MaterialPropertyBlock();
props.SetFloat("_Level", mip);
for (int face = 0; face < 6; ++face)
{
Utilities.SetRenderTarget(context, target, ClearFlag.ClearNone, mip, (CubemapFace)face);
var cmd = new CommandBuffer { name = "" };
cmd.DrawMesh(cubemapFaceMesh[face], Matrix4x4.identity, m_GgxConvolveMaterial, 0, 0, props);
context.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}
}
// Filters MIP map levels (other than 0) with GGX using BRDF importance sampling.
public void FilterCubemapGgx(ScriptableRenderContext context, int mipCount,
Texture source, RenderTexture target,
Mesh[] cubemapFaceMesh)
{
m_GgxConvolveMaterial.DisableKeyword("USE_MIS");
FilterCubemapGgxCommon(context, mipCount, source, target, cubemapFaceMesh);
}
// Filters MIP map levels (other than 0) with GGX using multiple importance sampling.
public void FilterCubemapGgxMis(ScriptableRenderContext context, int mipCount,
Texture source, RenderTexture target,
RenderTexture conditionalCdf, RenderTexture marginalRowCdf,
Mesh[] cubemapFaceMesh)
{
// Bind the input cubemap.
m_BuildProbabilityTablesCS.SetTexture(m_ConditionalDensitiesKernel, "envMap", source);
// Bind the outputs.
m_BuildProbabilityTablesCS.SetTexture(m_ConditionalDensitiesKernel, "conditionalDensities", conditionalCdf);
m_BuildProbabilityTablesCS.SetTexture(m_ConditionalDensitiesKernel, "marginalRowDensities", marginalRowCdf);
m_BuildProbabilityTablesCS.SetTexture(m_MarginalRowDensitiesKernel, "marginalRowDensities", marginalRowCdf);
int numRows = conditionalCdf.height;
var cmd = new CommandBuffer() { name = "Build Probability Tables" };
cmd.DispatchCompute(m_BuildProbabilityTablesCS, m_ConditionalDensitiesKernel, numRows, 1, 1);
cmd.DispatchCompute(m_BuildProbabilityTablesCS, m_MarginalRowDensitiesKernel, 1, 1, 1);
context.ExecuteCommandBuffer(cmd);
cmd.Dispose();
m_GgxConvolveMaterial.EnableKeyword("USE_MIS");
m_GgxConvolveMaterial.SetTexture("_ConditionalDensities", conditionalCdf);
m_GgxConvolveMaterial.SetTexture("_MarginalRowDensities", marginalRowCdf);
FilterCubemapGgxCommon(context, mipCount, source, target, cubemapFaceMesh);
}
}
}

12
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/RuntimeFilterIBL.cs.meta


fileFormatVersion: 2
guid: 827056f7b26e8a64883735043af76431
timeCreated: 1484572874
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/TestScenes/HDTest/GlobalIlluminationTest/LightingData.asset
文件差异内容过多而无法显示
查看文件

8
Assets/TestScenes/HDTest/GlobalIlluminationTest/LightingData.asset.meta


fileFormatVersion: 2
guid: 3d51fc2c60f333c44b613049001dfba8
timeCreated: 1484352329
licenseType: Pro
NativeFormatImporter:
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"

9
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/ShaderPass/UnlitMetaPass.hlsl.meta


fileFormatVersion: 2
guid: 34b6e92ecac8a054085e28dc783b1a80
timeCreated: 1484323639
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

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"

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


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

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/Tesselation.meta


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

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

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

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

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

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

/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/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

正在加载...
取消
保存