浏览代码

Merge branch 'master' of https://github.com/Unity-Technologies/ScriptableRenderLoop

# Conflicts:
#	Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitData.hlsl
#	Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitDebugPass.hlsl
/main
Julien Ignace 8 年前
当前提交
2d47017c
共有 30 个文件被更改,包括 531 次插入163 次删除
  1. 6
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/Resources/DebugViewMaterialGBuffer.shader
  2. 60
      Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs
  3. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset.meta
  4. 181
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  5. 28
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/LayeredLit/LayeredLit.shader
  6. 29
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.shader
  7. 25
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitData.hlsl
  8. 16
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/Unlit.shader
  9. 11
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/UnlitData.hlsl
  10. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass/ShaderPassDebugViewMaterial.hlsl
  11. 2
      Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl
  12. 21
      Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl
  13. 31
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs
  14. 27
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.hlsl
  15. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.hlsl.meta
  16. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.meta
  17. 60
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl
  18. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl.meta
  19. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky.meta
  20. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources.meta
  21. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/SkyHDRI.shader.meta
  22. 72
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/SkyHDRI.shader
  23. 15
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.hlsl
  24. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.hlsl.meta
  25. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitDebugPass.hlsl.meta
  26. 31
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitDebugPass.hlsl
  27. 0
      /Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/UnlitSharePass.hlsl.meta
  28. 0
      /Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/UnlitSharePass.hlsl

6
Assets/ScriptableRenderLoop/HDRenderLoop/Debug/Resources/DebugViewMaterialGBuffer.shader


#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Material/Material.hlsl"

float3 result = float3(-666.0, 0.0, 0.0);
bool needLinearToSRGB = false;
if (_DebugViewMaterial == DEBUGVIEW_GBUFFER_DEPTH)
if (_DebugViewMaterial == DEBUGVIEWGBUFFER_DEPTH)
else if (_DebugViewMaterial == DEBUGVIEW_GBUFFER_BAKEDIFFUSELIGHTING)
else if (_DebugViewMaterial == DEBUGVIEWGBUFFER_BAKE_DIFFUSE_LIGHTING)
{
result = bakeDiffuseLighting;
}

60
Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs


public readonly GUIContent exposure = new GUIContent("Exposure");
public readonly GUIContent useForwardRenderingOnly = new GUIContent("Use Forward Rendering Only");
public readonly GUIContent useDepthPrepass = new GUIContent("Use Depth Prepass");
public readonly GUIContent skyParameters = new GUIContent("Sky Parameters");
public readonly GUIContent skyExposure = new GUIContent("Sky Exposure");
public readonly GUIContent skyRotation = new GUIContent("Sky Rotation");
public readonly GUIContent skyMultiplier = new GUIContent("Sky Multiplier");
}
private static Styles s_Styles = null;

const float k_MaxExposure = 32.0f;
void FillWithProperties(Type type, GUIContent[] debugViewMaterialStrings, int[] debugViewMaterialValues, bool isBSDFData, ref int index)
string GetSubNameSpaceName(Type type)
{
return type.Namespace.Substring(type.Namespace.LastIndexOf((".")) + 1) + "/";
}
void FillWithProperties(Type type, GUIContent[] debugViewMaterialStrings, int[] debugViewMaterialValues, bool isBSDFData, string strSubNameSpace, ref int index)
{
var attributes = type.GetCustomAttributes(true);
// Get attribute to get the start number of the value for the enum

}
var fields = type.GetFields();
var subNamespace = type.Namespace.Substring(type.Namespace.LastIndexOf((".")) + 1);
var localIndex = 0;
foreach (var field in fields)

}
}
fieldName = (isBSDFData ? "Engine/" : "") + subNamespace + "/" + fieldName;
fieldName = (isBSDFData ? "Engine/" : "") + strSubNameSpace + fieldName;
debugViewMaterialStrings[index] = new GUIContent(fieldName);
debugViewMaterialValues[index] = attr.paramDefinesStart + (int)localIndex;

}
void FillWithPropertiesEnum(Type type, GUIContent[] debugViewMaterialStrings, int[] debugViewMaterialValues, bool isBSDFData, ref int index)
void FillWithPropertiesEnum(Type type, GUIContent[] debugViewMaterialStrings, int[] debugViewMaterialValues, string prefix, bool isBSDFData, ref int index)
{
var names = Enum.GetNames(type);

var valueName = (isBSDFData ? "Engine/" : "") + names[localIndex];
var valueName = (isBSDFData ? "Engine/" : "" + prefix) + names[localIndex];
debugViewMaterialStrings[index] = new GUIContent(valueName);
debugViewMaterialValues[index] = (int)value;

if (!styles.isDebugViewMaterialInit)
{
var varyingNames = Enum.GetNames(typeof(HDRenderLoop.DebugViewVaryingMode));
var gbufferNames = Enum.GetNames(typeof(HDRenderLoop.DebugViewGbufferMode));
var varyingNames = Enum.GetNames(typeof(Attributes.DebugViewVarying));
var gbufferNames = Enum.GetNames(typeof(Attributes.DebugViewGbuffer));
+ typeof(Builtin.BuiltinData).GetFields().Length
+ typeof(Builtin.BuiltinData).GetFields().Length * 2 // BuildtinData are duplicated for each material
+ typeof(Lit.SurfaceData).GetFields().Length
+ typeof(Lit.BSDFData).GetFields().Length
+ typeof(Unlit.SurfaceData).GetFields().Length

styles.debugViewMaterialValues[0] = 0;
index++;
FillWithPropertiesEnum(typeof(HDRenderLoop.DebugViewVaryingMode), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, ref index);
FillWithProperties(typeof(Builtin.BuiltinData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, ref index);
FillWithProperties(typeof(Lit.SurfaceData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, ref index);
FillWithProperties(typeof(Unlit.SurfaceData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, ref index);
FillWithPropertiesEnum(typeof(Attributes.DebugViewVarying), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, GetSubNameSpaceName(typeof(Attributes.DebugViewVarying)), false, ref index);
FillWithProperties(typeof(Builtin.BuiltinData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, GetSubNameSpaceName(typeof(Lit.SurfaceData)), ref index);
FillWithProperties(typeof(Lit.SurfaceData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, GetSubNameSpaceName(typeof(Lit.SurfaceData)), ref index);
FillWithProperties(typeof(Builtin.BuiltinData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, GetSubNameSpaceName(typeof(Unlit.SurfaceData)), ref index);
FillWithProperties(typeof(Unlit.SurfaceData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, GetSubNameSpaceName(typeof(Unlit.SurfaceData)), ref index);
FillWithPropertiesEnum(typeof(HDRenderLoop.DebugViewGbufferMode), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, true, ref index);
FillWithProperties(typeof(Lit.BSDFData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, true, ref index);
FillWithProperties(typeof(Unlit.BSDFData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, true, ref index);
FillWithPropertiesEnum(typeof(Attributes.DebugViewGbuffer), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, "", true, ref index);
FillWithProperties(typeof(Lit.BSDFData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, true, "", ref index);
FillWithProperties(typeof(Unlit.BSDFData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, true, "", ref index);
styles.isDebugViewMaterialInit = true;
}

debugParameters.displayOpaqueObjects = EditorGUILayout.Toggle(styles.displayOpaqueObjects, debugParameters.displayOpaqueObjects);
debugParameters.displayTransparentObjects = EditorGUILayout.Toggle(styles.displayTransparentObjects, debugParameters.displayTransparentObjects);
debugParameters.useForwardRenderingOnly = EditorGUILayout.Toggle(styles.useForwardRenderingOnly, debugParameters.useForwardRenderingOnly);
debugParameters.useDepthPrepass = EditorGUILayout.Toggle(styles.useDepthPrepass, debugParameters.useDepthPrepass);
if (EditorGUI.EndChangeCheck())
{
EditorUtility.SetDirty(renderLoop); // Repaint
}
EditorGUI.indentLevel--;
var skyParameters = renderLoop.skyParameters;
EditorGUILayout.LabelField(styles.skyParameters);
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
skyParameters.skyHDRI = (Cubemap)EditorGUILayout.ObjectField("Cubemap", skyParameters.skyHDRI, typeof(Cubemap), false);
skyParameters.exposure = Mathf.Max(Mathf.Min(EditorGUILayout.FloatField(styles.skyExposure, skyParameters.exposure), 32), -32);
skyParameters.multiplier = Mathf.Max(EditorGUILayout.FloatField(styles.skyMultiplier, skyParameters.multiplier), 0);
skyParameters.rotation = Mathf.Max(Mathf.Min(EditorGUILayout.FloatField(styles.skyRotation, skyParameters.rotation), 360), 0);
if (EditorGUI.EndChangeCheck())
{
EditorUtility.SetDirty(renderLoop); // Repaint

2
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset.meta


fileFormatVersion: 2
guid: 2400b74f5ce370c4481e5dc417d03703
timeCreated: 1478912125
timeCreated: 1479240578
licenseType: Pro
NativeFormatImporter:
userData:

181
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


{
private const string k_HDRenderLoopPath = "Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset";
// Must be in sync with DebugViewMaterial.hlsl
public enum DebugViewVaryingMode
public class SkyParameters
TexCoord0 = 1,
TexCoord1 = 2,
TexCoord2 = 3,
VertexTangentWS = 4,
VertexBitangentWS = 5,
VertexNormalWS = 6,
VertexColor = 7,
public Cubemap skyHDRI;
public float rotation;
public float exposure;
public float multiplier;
// Must be in sync with DebugViewMaterial.hlsl
public enum DebugViewGbufferMode
[SerializeField]
private SkyParameters m_SkyParameters = new SkyParameters();
public SkyParameters skyParameters
Depth = 10,
BakeDiffuseLighting = 11,
get { return m_SkyParameters; }
}
public class DebugParameters

public bool displayTransparentObjects = true;
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 enableTonemap = true;
public float exposure = 0;

[SerializeField]
TextureSettings m_TextureSettings = TextureSettings.Default;
Material m_SkyboxMaterial;
Material m_SkyHDRIMaterial;
Material m_DeferredMaterial;
Material m_FinalPassMaterial;

s_envLightList = new ComputeBuffer(MaxLights, System.Runtime.InteropServices.Marshal.SizeOf(typeof(EnvLightData)));
s_punctualShadowList = new ComputeBuffer(MaxShadows, System.Runtime.InteropServices.Marshal.SizeOf(typeof(PunctualShadowData)));
// TODO: We need to have an API to send our sky information to Enlighten. For now use a workaround through skybox/cubemap material...
m_SkyboxMaterial = CreateEngineMaterial("Skybox/Cubemap");
RenderSettings.skybox = m_SkyboxMaterial; // Setup this material as the default to be use in RenderSettings
RenderSettings.ambientIntensity = 1.0f; // fix this to 1, this parameter should not exist!
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox; // Force skybox for our HDRI
RenderSettings.reflectionIntensity = 1.0f;
m_SkyHDRIMaterial = CreateEngineMaterial("Hidden/HDRenderLoop/SkyHDRI");
m_DeferredMaterial = CreateEngineMaterial("Hidden/HDRenderLoop/Deferred");
m_FinalPassMaterial = CreateEngineMaterial("Hidden/HDRenderLoop/FinalPass");

s_areaLightList.Release();
s_envLightList.Release();
s_punctualShadowList.Release();
if (m_SkyboxMaterial) DestroyImmediate(m_SkyboxMaterial);
if (m_SkyHDRIMaterial) DestroyImmediate(m_SkyHDRIMaterial);
if (m_DeferredMaterial) DestroyImmediate(m_DeferredMaterial);
if (m_FinalPassMaterial) DestroyImmediate(m_FinalPassMaterial);

// END TEMP
}
// TODO: Create an opaque and transparent list!
void RenderOpaqueNoLightingRenderList(CullResults cull, Camera camera, RenderLoop renderLoop, string passName)
{
if (!debugParameters.displayOpaqueObjects)
return;
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName))
{
rendererConfiguration = 0,
sorting = { sortOptions = SortOptions.SortByMaterialThenMesh }
};
settings.inputFilter.SetQueuesOpaque();
renderLoop.DrawRenderers(ref settings);
}
DrawRendererSettings settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName));
settings.sorting.sortOptions = SortOptions.SortByMaterialThenMesh;
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName))
{
rendererConfiguration = RendererConfiguration.PerObjectLightProbe | RendererConfiguration.PerObjectReflectionProbes | RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbeProxyVolume,
sorting = { sortOptions = SortOptions.SortByMaterialThenMesh }
};
settings.rendererConfiguration = RendererConfiguration.PerObjectLightProbe | RendererConfiguration.PerObjectReflectionProbes | RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbeProxyVolume;
renderLoop.DrawRenderers(ref settings);
}
void RenderTransparentNoLightingRenderList(CullResults cull, Camera camera, RenderLoop renderLoop, string passName)
{
if (!debugParameters.displayTransparentObjects)
return;
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName))
{
rendererConfiguration = 0,
sorting = { sortOptions = SortOptions.BackToFront }
};
settings.inputFilter.SetQueuesTransparent();
void RenderTransparentRenderList(CullResults cull, Camera camera, RenderLoop renderLoop, string passName)
void RenderTransparentRenderList(CullResults cull, Camera camera, RenderLoop renderLoop, string passName)
{
if (!debugParameters.displayTransparentObjects)
return;

renderLoop.DrawRenderers(ref settings);
}
void RenderDepthPrepass(CullResults cull, Camera camera, RenderLoop renderLoop)
{
// If we are forward only we will do a depth prepass
// TODO: Depth prepass should be enabled based on light loop settings. LightLoop define if they need a depth prepass + forward only...
if (!debugParameters.useDepthPrepass)
return;
// TODO: Must do opaque then alpha masked for performance!
// TODO: front to back for opaque and by materal for opaque tested when we split in two
var cmd = new CommandBuffer { name = "Depth Prepass" };
cmd.SetRenderTarget(new RenderTargetIdentifier(s_CameraDepthBuffer));
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
RenderOpaqueNoLightingRenderList(cull, camera, renderLoop, "DepthOnly");
}
void RenderGBuffer(CullResults cull, Camera camera, RenderLoop renderLoop)
{
if (debugParameters.useForwardRenderingOnly)

// render opaque objects into GBuffer
RenderOpaqueRenderList(cull, camera, renderLoop, "GBuffer");
}
// This pass is use in case of forward opaque and deferred rendering. We need to render forward objects before tile lighting pass
void RenderForwardOpaqueDepth(CullResults cull, Camera camera, RenderLoop renderLoop)
{
// If we have render a depth prepass, no need for this pass
if (debugParameters.useDepthPrepass)
return;
// TODO: Use the render queue index to only send the forward opaque!
var cmd = new CommandBuffer { name = "Depth Prepass" };
cmd.SetRenderTarget(new RenderTargetIdentifier(s_CameraDepthBuffer));
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
RenderOpaqueNoLightingRenderList(cull, camera, renderLoop, "DepthOnly");
}
void RenderDebugViewMaterial(CullResults cull, Camera camera, RenderLoop renderLoop)

cmd.Dispose();
}
void RenderSky(Camera camera, RenderLoop renderLoop)
{
/*
// Render sky into a cubemap - doesn't happen every frame, can be control
// TODO: do a render to texture here
// Downsample the cubemap and provide it to Enlighten
// TODO: currently workaround is to set the cubemap in a Skybox/cubemap material
//m_SkyboxMaterial.SetTexture(cubemap);
// Render the sky itself
Vector3[] vertData = new Vector3[4];
vertData[0] = new Vector3(-1.0f, -1.0f, 0.0f);
vertData[1] = new Vector3(1.0f, -1.0f, 0.0f);
vertData[2] = new Vector3(1.0f, 1.0f, 0.0f);
vertData[3] = new Vector3(-1.0f, 1.0f, 0.0f);
Vector3[] eyeVectorData = new Vector3[4];
// camera.worldToCameraMatrix, camera.projectionMatrix
// Get view vector vased on the frustrum, i.e (invert transform frustrum get position etc...)
eyeVectorData[0] =
eyeVectorData[1] =
eyeVectorData[2] =
eyeVectorData[3] =
// Write out the mesh
var triangles = new int[4];
for (int i = 0; i < 4; i++)
{
triangles[i] = i;
}
Mesh mesh = new Mesh
{
vertices = vertData,
normals = eyeVectorData,
triangles = triangles
};
m_SkyHDRIMaterial.SetTexture("_Cubemap", skyParameters.skyHDRI);
m_SkyHDRIMaterial.SetVector("_SkyParam", new Vector4(skyParameters.exposure, skyParameters.multiplier, skyParameters.rotation, 0.0f));
var cmd = new CommandBuffer { name = "Skybox" };
cmd.DrawMesh(mesh, Matrix4x4.identity, m_SkyHDRIMaterial);
renderloop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
*/
}
void RenderForward(CullResults cullResults, Camera camera, RenderLoop renderLoop)
{
// Bind material data

renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
RenderOpaqueRenderList(cullResults, camera, renderLoop, "ForwardUnlit");
RenderTransparentRenderList(cullResults, camera, renderLoop, "ForwardUnlit");
RenderOpaqueNoLightingRenderList(cullResults, camera, renderLoop, "ForwardUnlit");
RenderTransparentNoLightingRenderList(cullResults, camera, renderLoop, "ForwardUnlit");
}
void RenderVelocity(CullResults cullResults, Camera camera, RenderLoop renderLoop)

renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
RenderOpaqueRenderList(cullResults, camera, renderLoop, "MotionVectors");
RenderOpaqueNoLightingRenderList(cullResults, camera, renderLoop, "MotionVectors");
#pragma warning restore 162, 429
}

cmd.Dispose();
// Only transparent object can render distortion vectors
RenderTransparentRenderList(cullResults, camera, renderLoop, "DistortionVectors");
RenderTransparentNoLightingRenderList(cullResults, camera, renderLoop, "DistortionVectors");
}

InitAndClearBuffer(camera, renderLoop);
RenderDepthPrepass(cullResults, camera, renderLoop);
// For tile lighting with forward opaque
//RenderForwardOpaqueDepth(cullResults, camera, renderLoop);
if (debugParameters.debugViewMaterial != 0)
{

RenderDeferredLighting(camera, renderLoop);
RenderForward(cullResults, camera, renderLoop);
RenderSky(camera, renderLoop);
RenderForward(cullResults, camera, renderLoop); // Note: We want to render forward opaque before RenderSky, then RenderTransparent - can only do that once we have material.SetPass feature...
RenderVelocity(cullResults, camera, renderLoop);
RenderVelocity(cullResults, camera, renderLoop); // 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 ?
// TODO: Check with VFX team.
// Rendering distortion here have off course lot of artifact.

28
Assets/ScriptableRenderLoop/HDRenderLoop/Material/LayeredLit/LayeredLit.shader


#include "common.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.hlsl"
//-------------------------------------------------------------------------------------
// variable declaration

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

{
Name "ShadowCaster"
Tags{ "LightMode" = "ShadowCaster" }
Cull[_CullMode]
ZWrite On ZTest LEqual
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
#define SHADERPASS SHADERPASS_DEPTH_ONLY
#define LAYERED_LIT_SHADER
#include "../../Material/Material.hlsl"
#include "../Lit/LitData.hlsl"
#include "../Lit/LitDepthPass.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL
}
Pass
{
Name "DepthOnly"
Tags{ "LightMode" = "DepthOnly" }
Cull[_CullMode]

29
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.shader


#include "common.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass/ShaderPass.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass/ShaderPass.cs.hlsl"
//-------------------------------------------------------------------------------------
// variable declaration

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

{
Name "ShadowCaster"
Tags{ "LightMode" = "ShadowCaster" }
Cull[_CullMode]
ZWrite On ZTest LEqual
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
#define SHADERPASS SHADERPASS_DEPTH_ONLY
#include "../../Material/Material.hlsl"
#include "LitData.hlsl"
#include "LitDepthPass.hlsl"
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl"
ENDHLSL
}
Pass
{
Name "DepthOnly"
Tags{ "LightMode" = "DepthOnly" }
Cull[_CullMode]

25
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitData.hlsl


//-------------------------------------------------------------------------------------
// FragInput
// This structure gather all possible varying/interpolator for this shader.
//-------------------------------------------------------------------------------------
struct FragInput
{
float4 unPositionSS; // This is the position return by VPOS (That is name positionCS in PackedVarying), only xy is use
float3 positionWS;
float2 texCoord0;
float2 texCoord1;
float2 texCoord2;
float3 tangentToWorld[3];
float4 vertexColor;
// For velocity
// Note: Z component is not use
float4 positionCS; // This is the clip spae position. Warning, do not confuse with the value of positionCS in PackedVarying which is VPOS and store in unPositionSS
float4 previousPositionCS;
// For two sided lighting
bool isFrontFace;
};
//-------------------------------------------------------------------------------------
// Fill SurfaceData/Builtin data function

// Mask Values : Layer 1, 2, 3 are r, g, b
float3 maskValues = float3(0.0, 0.0, 0.0);
#if defined(_LAYER_MASK_MAP)
maskValues = SAMPLE_TEXTURE2D(_LayerMaskMap, sampler_LayerMaskMap, input.texCoord0).rgb;
#endif

16
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/Unlit.shader


#include "common.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.hlsl"
//-------------------------------------------------------------------------------------
// variable declaration

#define SHADERPASS SHADERPASS_DEBUG_VIEW_MATERIAL
#include "../../Material/Material.hlsl"
#include "UnlitData.hlsl"
#include "UnlitShare.hlsl"
void GetVaryingsDataDebug(uint paramId, FragInput input, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEW_VARYING_TEXCOORD0:
result = float3(input.texCoord0 * 0.5 + 0.5, 0.0);
break;
}
}
#include "UnlitSharePass.hlsl"
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl"

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

11
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/UnlitData.hlsl


//-------------------------------------------------------------------------------------
// FragInput
// This structure gather all possible varying/interpolator for this shader.
//-------------------------------------------------------------------------------------
struct FragInput
{
float4 unPositionSS;
float2 texCoord0;
float2 texCoord1;
};
//-------------------------------------------------------------------------------------
// Fill SurfaceData/Builtin data function

2
Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass/ShaderPassDebugViewMaterial.hlsl


BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);
float3 result = float3(1.0, 1.0, 0.0);
float3 result = float3(1.0, 0.0, 1.0);
bool needLinearToSRGB = false;
GetVaryingsDataDebug(_DebugViewMaterial, input, result, needLinearToSRGB);

2
Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl


#define UNITY_UV_STARTS_AT_TOP 1
#define UNITY_REVERSED_Z 1
#define UNITY_NEAR_CLIP_VALUE (1.0)
// This value will not go through any matrix projection convertion
#define UNITY_RAW_FAR_CLIP_VALUE (0.0)
#define FRONT_FACE_SEMATIC SV_IsFrontFace
#define FRONT_FACE_TYPE bool
#define IS_FRONT_VFACE(VAL, FRONT, BACK) ((VAL) ? (FRONT) : (BACK))

21
Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl


#ifndef UNITY_COMMON_LIGHTING_INCLUDED
#define UNITY_COMMON_LIGHTING_INCLUDED
// These clamping function to max of floating point 16 bit are use to prevent INF in code in case of extreme value
float ClampToFloat16Max(float value)
{
return min(value, 65504.0);
}
float2 ClampToFloat16Max(float2 value)
{
return min(value, 65504.0);
}
float3 ClampToFloat16Max(float3 value)
{
return min(value, 65504.0);
}
float4 ClampToFloat16Max(float4 value)
{
return min(value, 65504.0);
}
// Ligthing convention
// Light direction is oriented backward (-Z). i.e in shader code, light direction is -lightData.forward

31
Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs


using UnityEngine;
namespace UnityEngine.Experimental.ScriptableRenderLoop
{
namespace Attributes
{
// 0 is reserved!
[GenerateHLSL]
public enum DebugViewVarying
{
Texcoord0 = 1,
Texcoord1,
Texcoord2,
Texcoord3,
VertexTangentWS,
VertexBitangentWS,
VertexNormalWS,
VertexColor,
VertexColorAlpha,
};
// Number must be contiguous
[GenerateHLSL]
public enum DebugViewGbuffer
{
Depth = DebugViewVarying.VertexColor + 1,
BakeDiffuseLighting,
}
}
} // namespace UnityEngine.Experimental.ScriptableRenderLoop

27
Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs. Please don't edit by hand.
//
#ifndef DEBUGVIEWMATERIAL_CS_HLSL
#define DEBUGVIEWMATERIAL_CS_HLSL
//
// UnityEngine.Experimental.ScriptableRenderLoop.Attributes.DebugViewVarying: static fields
//
#define DEBUGVIEWVARYING_TEXCOORD0 (1)
#define DEBUGVIEWVARYING_TEXCOORD1 (2)
#define DEBUGVIEWVARYING_TEXCOORD2 (3)
#define DEBUGVIEWVARYING_TEXCOORD3 (4)
#define DEBUGVIEWVARYING_VERTEX_TANGENT_WS (5)
#define DEBUGVIEWVARYING_VERTEX_BITANGENT_WS (6)
#define DEBUGVIEWVARYING_VERTEX_NORMAL_WS (7)
#define DEBUGVIEWVARYING_VERTEX_COLOR (8)
#define DEBUGVIEWVARYING_VERTEX_COLOR_ALPHA (9)
//
// UnityEngine.Experimental.ScriptableRenderLoop.Attributes.DebugViewGbuffer: static fields
//
#define DEBUGVIEWGBUFFER_DEPTH (9)
#define DEBUGVIEWGBUFFER_BAKE_DIFFUSE_LIGHTING (10)
#endif

9
Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.hlsl.meta


fileFormatVersion: 2
guid: 972a0c56f0332c84f95914786d1f2f4b
timeCreated: 1479292942
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

12
Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.meta


fileFormatVersion: 2
guid: 4a6949840f48a7948a9610d89e539bf9
timeCreated: 1479292895
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

60
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl


//-------------------------------------------------------------------------------------
// FragInput
// This structure gather all possible varying/interpolator for this shader.
//-------------------------------------------------------------------------------------
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.hlsl"
struct FragInput
{
float4 unPositionSS; // This is the position return by VPOS (That is name positionCS in PackedVarying), only xy is use
float3 positionWS;
float2 texCoord0;
float2 texCoord1;
float2 texCoord2;
float2 texCoord3;
float3 tangentToWorld[3];
float4 vertexColor;
// For velocity
// Note: Z component is not use
float4 positionCS; // This is the clip spae position. Warning, do not confuse with the value of positionCS in PackedVarying which is VPOS and store in unPositionSS
float4 previousPositionCS;
// For two sided lighting
bool isFrontFace;
};
void GetVaryingsDataDebug(uint paramId, FragInput input, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEWVARYING_TEXCOORD0:
result = float3(input.texCoord0 * 0.5 + 0.5, 0.0);
break;
case DEBUGVIEWVARYING_TEXCOORD1:
result = float3(input.texCoord1 * 0.5 + 0.5, 0.0);
break;
case DEBUGVIEWVARYING_TEXCOORD2:
result = float3(input.texCoord2 * 0.5 + 0.5, 0.0);
break;
case DEBUGVIEWVARYING_TEXCOORD3:
result = float3(input.texCoord3 * 0.5 + 0.5, 0.0);
break;
case DEBUGVIEWVARYING_VERTEX_TANGENT_WS:
result = input.tangentToWorld[0].xyz * 0.5 + 0.5;
break;
case DEBUGVIEWVARYING_VERTEX_BITANGENT_WS:
result = input.tangentToWorld[1].xyz * 0.5 + 0.5;
break;
case DEBUGVIEWVARYING_VERTEX_NORMAL_WS:
result = input.tangentToWorld[2].xyz * 0.5 + 0.5;
break;
case DEBUGVIEWVARYING_VERTEX_COLOR:
result = input.vertexColor.rgb; needLinearToSRGB = true;
break;
case DEBUGVIEWVARYING_VERTEX_COLOR_ALPHA:
result = input.vertexColor.aaa;
break;
}
}

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


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

9
Assets/ScriptableRenderLoop/HDRenderLoop/Sky.meta


fileFormatVersion: 2
guid: d7469c05ebee66f4886264af0ab8bf2a
folderAsset: yes
timeCreated: 1479239906
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources.meta


fileFormatVersion: 2
guid: 4cdc45a9a65126a42aca158413a5b089
folderAsset: yes
timeCreated: 1479239906
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/SkyHDRI.shader.meta


fileFormatVersion: 2
guid: 0e7a148852dbc8f47a32e829517574ff
timeCreated: 1479239909
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

72
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/SkyHDRI.shader


Shader "Hidden/HDRenderLoop/SkyHDRI"
{
SubShader
{
Pass
{
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha // We will lerp only the values that are valid
HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma vertex Vert
#pragma fragment Frag
#include "Common.hlsl"
#include "CommonLighting.hlsl"
TEXTURECUBE(_Cubemap);
SAMPLERCUBE(sampler_Cubemap);
float4 _SkyParam; // x exposure, y multiplier, z rotation
struct Attributes
{
float3 positionCS : POSITION;
float3 eyeVector : NORMAL;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float3 eyeVector : TEXCOORD0;
};
Varyings Vert(Attributes input)
{
// TODO: implement SV_vertexID full screen quad
Varyings output;
output.positionCS = float4(input.positionCS.xy, UNITY_RAW_FAR_CLIP_VALUE
#if UNITY_REVERSED_Z
+ 0.000001
#else
- 0.000001
#endif
, 1.0);
output.eyeVector = input.eyeVector;
return output;
}
float4 Frag(Varyings input) : SV_Target
{
float3 dir = normalize(input.eyeVector);
// Rotate direction
float phi = _SkyParam.z * PI / 180.0; // Convert to radiant
float cosPhi, sinPhi;
sincos(phi, cosPhi, sinPhi);
float3 rotDirX = float3(cosPhi, 0, sinPhi);
float3 rotDirY = float3(sinPhi, 0, -cosPhi);
dir = float3(dot(rotDirX, dir), dir.y, dot(rotDirY, dir));
return ClampToFloat16Max(SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0) * exp2(_SkyParam.x) * _SkyParam.y);
}
ENDHLSL
}
}
Fallback Off
}

15
Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.hlsl


// CAUTION: 0 is a reserved numbers meaning there is no debug view mode
// All number below folow each others!
// Must be in sync with DebugViewVaryingMode
#define DEBUGVIEW_VARYING_TEXCOORD0 1
#define DEBUGVIEW_VARYING_TEXCOORD1 2
#define DEBUGVIEW_VARYING_TEXCOORD2 3
#define DEBUGVIEW_VARYING_VERTEXTANGENTWS 4
#define DEBUGVIEW_VARYING_VERTEXBITANGENTWS 5
#define DEBUGVIEW_VARYING_VERTEXNORMALWS 6
#define DEBUGVIEW_VARYING_VERTEXCOLOR 7
// These define are sepcific to GBuffer
#define DEBUGVIEW_GBUFFER_DEPTH 10
#define DEBUGVIEW_GBUFFER_BAKEDIFFUSELIGHTING 11

9
Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.hlsl.meta


fileFormatVersion: 2
guid: 9048292f91ac48d479ce668c5aabf122
timeCreated: 1476053153
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitDebugPass.hlsl.meta


fileFormatVersion: 2
guid: afea19c25b5e93847af6262c2c00401f
timeCreated: 1478601047
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

31
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitDebugPass.hlsl


#ifndef SHADERPASS
#error Undefine_SHADERPASS
#endif
void GetVaryingsDataDebug(uint paramId, FragInput input, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEW_VARYING_TEXCOORD0:
result = float3(input.texCoord0 * 0.5 + 0.5, 0.0);
break;
case DEBUGVIEW_VARYING_TEXCOORD1:
result = float3(input.texCoord1 * 0.5 + 0.5, 0.0);
break;
case DEBUGVIEW_VARYING_TEXCOORD2:
result = float3(input.texCoord2 * 0.5 + 0.5, 0.0);
break;
case DEBUGVIEW_VARYING_VERTEXTANGENTWS:
result = input.tangentToWorld[0].xyz * 0.5 + 0.5;
break;
case DEBUGVIEW_VARYING_VERTEXBITANGENTWS:
result = input.tangentToWorld[1].xyz * 0.5 + 0.5;
break;
case DEBUGVIEW_VARYING_VERTEXNORMALWS:
result = input.tangentToWorld[2].xyz * 0.5 + 0.5;
break;
case DEBUGVIEW_VARYING_VERTEXCOLOR:
result = input.vertexColor.rgb;
break;
}
}

/Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/UnlitShare.hlsl.meta → /Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/UnlitSharePass.hlsl.meta

/Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/UnlitShare.hlsl → /Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/UnlitSharePass.hlsl

正在加载...
取消
保存