浏览代码

HDRenderLoop Rename DisneyGGX to Li and convert to whitesapce convention

/main
sebastienlagarde 8 年前
当前提交
acd11ee0
共有 40 个文件被更改,包括 1909 次插入1902 次删除
  1. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset
  2. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset.meta
  3. 706
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  4. 174
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoopInspector.cs
  5. 192
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/GBufferDebug.shader
  6. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl
  7. 128
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.shader
  8. 46
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingForward.hlsl
  9. 28
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.hlsl
  10. 98
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl
  11. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit.hlsl
  12. 192
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.hlsl
  13. 222
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/PostProcess/FinalPass.shader
  14. 180
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl
  15. 254
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Unlit.shader
  16. 208
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.cs
  17. 256
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateLit.hlsl
  18. 2
      Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl
  19. 2
      Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11_1.hlsl
  20. 8
      Assets/ScriptableRenderLoop/ShaderLibrary/API/Validate.hlsl
  21. 79
      Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl
  22. 138
      Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl
  23. 32
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
  24. 28
      Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl
  25. 12
      Assets/ScriptableRenderLoop/ShaderLibrary/Filtering.hlsl
  26. 134
      Assets/ScriptableRenderLoop/ShaderLibrary/Packing.hlsl
  27. 30
      Assets/ScriptableRenderLoop/ShaderLibrary/QuaternionMath.hlsl
  28. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.cs.meta
  29. 284
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.shader
  30. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.shader.meta
  31. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.hlsl.meta
  32. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateLit.hlsl.meta
  33. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/DisneyGGX.hlsl.meta
  34. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.shader.meta
  35. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl.meta
  36. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.cs.meta
  37. 284
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.shader
  38. 0
      /Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.hlsl
  39. 0
      /Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.cs
  40. 0
      /Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateLit.hlsl

2
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset


m_Script: {fileID: 11500000, guid: 558064ecdbf6b6742892d699acb39aed, type: 3}
m_Name: HDRenderLoop
m_EditorClassIdentifier:
enableTonemap: 0
exposure: 0

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


fileFormatVersion: 2
guid: 2400b74f5ce370c4481e5dc417d03703
timeCreated: 1474923798
timeCreated: 1475845998
licenseType: Pro
NativeFormatImporter:
userData:

706
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


namespace UnityEngine.ScriptableRenderLoop
{
[ExecuteInEditMode]
[ExecuteInEditMode]
public class HDRenderLoop : ScriptableRenderLoop
{
private static string m_HDRenderLoopPath = "Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset";
public class HDRenderLoop : ScriptableRenderLoop
{
private static string m_HDRenderLoopPath = "Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset";
// Debugging
public enum MaterialDebugMode
{
None = 0,
DiffuseColor = 1,
Normal = 2,
Depth = 3,
AmbientOcclusion = 4,
SpecularColor = 5,
SpecularOcclustion = 6,
Smoothness = 7,
MaterialId = 8,
UV0 = 9,
Tangent = 10,
Bitangent = 11
}
// Debugging
public enum MaterialDebugMode
{
None = 0,
DiffuseColor = 1,
Normal = 2,
Depth = 3,
AmbientOcclusion = 4,
SpecularColor = 5,
SpecularOcclustion = 6,
Smoothness = 7,
MaterialId = 8,
UV0 = 9,
Tangent = 10,
Bitangent = 11
}
public enum GBufferDebugMode
{
None = 0,
DiffuseColor = 1,
Normal = 2,
Depth = 3,
BakedDiffuse = 4,
SpecularColor = 5,
SpecularOcclustion = 6,
Smoothness = 7,
MaterialId = 8,
}
public enum GBufferDebugMode
{
None = 0,
DiffuseColor = 1,
Normal = 2,
Depth = 3,
BakedDiffuse = 4,
SpecularColor = 5,
SpecularOcclustion = 6,
Smoothness = 7,
MaterialId = 8,
}
public class DebugParameters
{
// Material Debugging
public MaterialDebugMode materialDebugMode = MaterialDebugMode.None;
public GBufferDebugMode gBufferDebugMode = GBufferDebugMode.None;
public class DebugParameters
{
// Material Debugging
public MaterialDebugMode materialDebugMode = MaterialDebugMode.None;
public GBufferDebugMode gBufferDebugMode = GBufferDebugMode.None;
// Rendering debugging
public bool displayOpaqueObjects = true;
public bool displayTransparentObjects = true;
// Rendering debugging
public bool displayOpaqueObjects = true;
public bool displayTransparentObjects = true;
public bool enableTonemap = true;
public float exposure = 0;
}
public bool enableTonemap = true;
public float exposure = 0;
}
private DebugParameters m_DebugParameters = new DebugParameters();
public DebugParameters debugParameters
{
get { return m_DebugParameters; }
}
private DebugParameters m_DebugParameters = new DebugParameters();
public DebugParameters debugParameters
{
get { return m_DebugParameters; }
}
#if UNITY_EDITOR
[MenuItem("Renderloop/CreateHDRenderLoop")]
static void CreateHDRenderLoop()
{
var instance = ScriptableObject.CreateInstance<HDRenderLoop>();
UnityEditor.AssetDatabase.CreateAsset(instance, m_HDRenderLoopPath);
}
#endif
#if UNITY_EDITOR
[MenuItem("Renderloop/CreateHDRenderLoop")]
static void CreateHDRenderLoop()
{
var instance = ScriptableObject.CreateInstance<HDRenderLoop>();
UnityEditor.AssetDatabase.CreateAsset(instance, m_HDRenderLoopPath);
}
#endif
public class GBufferManager
{

public const int MaxLights = 32;
//[SerializeField]
//ShadowSettings m_ShadowSettings = ShadowSettings.Default;
//ShadowRenderPass m_ShadowPass;
//[SerializeField]
//ShadowSettings m_ShadowSettings = ShadowSettings.Default;
//ShadowRenderPass m_ShadowPass;
// Debug
Material m_GBufferDebugMaterial;
// Debug
Material m_GBufferDebugMaterial;
GBufferManager gbufferManager = new GBufferManager();

static private ComputeBuffer s_punctualLightList;
void OnEnable()
{
Rebuild ();
}
void OnEnable()
{
Rebuild ();
}
void OnValidate()
{
Rebuild ();
}
void OnValidate()
{
Rebuild ();
}
void ClearComputeBuffers()
{

Material CreateEngineMaterial(string shaderPath)
{
Material mat = new Material(Shader.Find(shaderPath) as Shader);
mat.hideFlags = HideFlags.HideAndDontSave;
return mat;
}
Material CreateEngineMaterial(string shaderPath)
{
Material mat = new Material(Shader.Find(shaderPath) as Shader);
mat.hideFlags = HideFlags.HideAndDontSave;
return mat;
}
public override void Rebuild()
{
public override void Rebuild()
{
ClearComputeBuffers();
gbufferManager.gbufferCount = 4;

s_punctualLightList = new ComputeBuffer(MaxLights, System.Runtime.InteropServices.Marshal.SizeOf(typeof(PunctualLightData)));
m_DeferredMaterial = CreateEngineMaterial("Hidden/Unity/LightingDeferred");
m_FinalPassMaterial = CreateEngineMaterial("Hidden/Unity/FinalPass");
m_DeferredMaterial = CreateEngineMaterial("Hidden/Unity/LightingDeferred");
m_FinalPassMaterial = CreateEngineMaterial("Hidden/Unity/FinalPass");
// Debug
m_GBufferDebugMaterial = CreateEngineMaterial("Hidden/Unity/GBufferDebug");
// Debug
m_GBufferDebugMaterial = CreateEngineMaterial("Hidden/Unity/GBufferDebug");
}
}
void OnDisable()
{

// END TEMP
}
void RenderOpaqueRenderList(CullResults cull, Camera camera, RenderLoop renderLoop, string passName)
{
if (!debugParameters.displayOpaqueObjects)
return;
void RenderOpaqueRenderList(CullResults cull, Camera camera, RenderLoop renderLoop, string passName)
{
if (!debugParameters.displayOpaqueObjects)
return;
DrawRendererSettings settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName));
settings.sorting.sortOptions = SortOptions.SortByMaterialThenMesh;
settings.inputCullingOptions.SetQueuesOpaque();
renderLoop.DrawRenderers(ref settings);
}
DrawRendererSettings settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName));
settings.sorting.sortOptions = SortOptions.SortByMaterialThenMesh;
settings.inputCullingOptions.SetQueuesOpaque();
renderLoop.DrawRenderers(ref settings);
}
void RenderTransparentRenderList(CullResults cull, Camera camera, RenderLoop renderLoop, string passName)
{
if (!debugParameters.displayTransparentObjects)
return;
void RenderTransparentRenderList(CullResults cull, Camera camera, RenderLoop renderLoop, string passName)
{
if (!debugParameters.displayTransparentObjects)
return;
DrawRendererSettings settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName));
settings.rendererConfiguration = RendererConfiguration.ConfigureOneLightProbePerRenderer | RendererConfiguration.ConfigureReflectionProbesProbePerRenderer;
settings.sorting.sortOptions = SortOptions.SortByMaterialThenMesh;
settings.inputCullingOptions.SetQueuesTransparent();
renderLoop.DrawRenderers(ref settings);
}
DrawRendererSettings settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName));
settings.rendererConfiguration = RendererConfiguration.ConfigureOneLightProbePerRenderer | RendererConfiguration.ConfigureReflectionProbesProbePerRenderer;
settings.sorting.sortOptions = SortOptions.SortByMaterialThenMesh;
settings.inputCullingOptions.SetQueuesTransparent();
renderLoop.DrawRenderers(ref settings);
}
{
// setup GBuffer for rendering
var cmd = new CommandBuffer();
cmd.name = "GBuffer Pass";
{
// setup GBuffer for rendering
var cmd = new CommandBuffer();
cmd.name = "GBuffer Pass";
cmd.Dispose();
cmd.Dispose();
// render opaque objects into GBuffer
RenderOpaqueRenderList(cull, camera, renderLoop, "GBuffer");
}
// render opaque objects into GBuffer
RenderOpaqueRenderList(cull, camera, renderLoop, "GBuffer");
}
void RenderMaterialDebug(CullResults cull, Camera camera, RenderLoop renderLoop)
{
// setup GBuffer for rendering
var cmd = new CommandBuffer();
cmd.name = "Material Debug Pass";
cmd.GetTemporaryRT(s_CameraColorBuffer, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
cmd.GetTemporaryRT(s_CameraDepthBuffer, camera.pixelWidth, camera.pixelHeight, 24, FilterMode.Point, RenderTextureFormat.Depth);
cmd.SetRenderTarget(new RenderTargetIdentifier(s_CameraColorBuffer), new RenderTargetIdentifier(s_CameraDepthBuffer));
cmd.ClearRenderTarget(true, true, new Color(0, 0, 0, 0));
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
void RenderMaterialDebug(CullResults cull, Camera camera, RenderLoop renderLoop)
{
// setup GBuffer for rendering
var cmd = new CommandBuffer();
cmd.name = "Material Debug Pass";
cmd.GetTemporaryRT(s_CameraColorBuffer, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
cmd.GetTemporaryRT(s_CameraDepthBuffer, camera.pixelWidth, camera.pixelHeight, 24, FilterMode.Point, RenderTextureFormat.Depth);
cmd.SetRenderTarget(new RenderTargetIdentifier(s_CameraColorBuffer), new RenderTargetIdentifier(s_CameraDepthBuffer));
cmd.ClearRenderTarget(true, true, new Color(0, 0, 0, 0));
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
Shader.SetGlobalInt("g_MaterialDebugMode", (int)debugParameters.materialDebugMode);
Shader.SetGlobalInt("g_MaterialDebugMode", (int)debugParameters.materialDebugMode);
RenderOpaqueRenderList(cull, camera, renderLoop, "Debug");
RenderTransparentRenderList(cull, camera, renderLoop, "Debug");
RenderOpaqueRenderList(cull, camera, renderLoop, "Debug");
RenderTransparentRenderList(cull, camera, renderLoop, "Debug");
cmd = new CommandBuffer();
cmd.name = "Blit Material Debug";
cmd.Blit(s_CameraColorBuffer, BuiltinRenderTextureType.CameraTarget);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
cmd = new CommandBuffer();
cmd.name = "Blit Material Debug";
cmd.Blit(s_CameraColorBuffer, BuiltinRenderTextureType.CameraTarget);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
void RenderGBufferDebug(Camera camera, RenderLoop renderLoop)
{
Matrix4x4 invViewProj = GetViewProjectionMatrix(camera).inverse;
m_GBufferDebugMaterial.SetMatrix("_InvViewProjMatrix", invViewProj);
void RenderGBufferDebug(Camera camera, RenderLoop renderLoop)
{
Matrix4x4 invViewProj = GetViewProjectionMatrix(camera).inverse;
m_GBufferDebugMaterial.SetMatrix("_InvViewProjMatrix", invViewProj);
Vector4 screenSize = ComputeScreenSize(camera);
m_GBufferDebugMaterial.SetVector("_ScreenSize", screenSize);
m_GBufferDebugMaterial.SetFloat("_DebugMode", (float)debugParameters.gBufferDebugMode);
Vector4 screenSize = ComputeScreenSize(camera);
m_GBufferDebugMaterial.SetVector("_ScreenSize", screenSize);
m_GBufferDebugMaterial.SetFloat("_DebugMode", (float)debugParameters.gBufferDebugMode);
// gbufferManager.BindBuffers(m_DeferredMaterial);
// TODO: Bind depth textures
var cmd = new CommandBuffer();
cmd.name = "GBuffer Debug Pass";
cmd.Blit(null, BuiltinRenderTextureType.CameraTarget, m_GBufferDebugMaterial, 0);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
// gbufferManager.BindBuffers(m_DeferredMaterial);
// TODO: Bind depth textures
var cmd = new CommandBuffer();
cmd.name = "GBuffer Debug Pass";
cmd.Blit(null, BuiltinRenderTextureType.CameraTarget, m_GBufferDebugMaterial, 0);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
Matrix4x4 GetViewProjectionMatrix(Camera camera)
{

return gpuVP;
}
Vector4 ComputeScreenSize(Camera camera)
{
Vector4 screenSize = new Vector4();
screenSize.x = camera.pixelWidth;
screenSize.y = camera.pixelHeight;
screenSize.z = 1.0f / camera.pixelWidth;
screenSize.w = 1.0f / camera.pixelHeight;
return screenSize;
}
Vector4 ComputeScreenSize(Camera camera)
{
Vector4 screenSize = new Vector4();
screenSize.x = camera.pixelWidth;
screenSize.y = camera.pixelHeight;
screenSize.z = 1.0f / camera.pixelWidth;
screenSize.w = 1.0f / camera.pixelHeight;
return screenSize;
}
void RenderDeferredLighting(Camera camera, RenderLoop renderLoop)
{

Vector4 screenSize = ComputeScreenSize(camera);
Vector4 screenSize = ComputeScreenSize(camera);
m_DeferredMaterial.SetVector("_ScreenSize", screenSize);
// gbufferManager.BindBuffers(m_DeferredMaterial);

renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
RenderTransparentRenderList(cullResults, camera, renderLoop, "Forward");
RenderTransparentRenderList(cullResults, camera, renderLoop, "Forward");
}
void FinalPass(RenderLoop renderLoop)

m_FinalPassMaterial.SetVector("_ToneMapCoeffs2", tonemapCoeff2);
m_FinalPassMaterial.SetFloat("_EnableToneMap", debugParameters.enableTonemap ? 1.0f : 0.0f);
m_FinalPassMaterial.SetFloat("_Exposure", debugParameters.exposure);
m_FinalPassMaterial.SetFloat("_Exposure", debugParameters.exposure);
CommandBuffer cmd = new CommandBuffer();
cmd.name = "FinalPass";

cmd.Dispose();
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------------------
void UpdatePunctualLights(ActiveLight[] activeLights)
{

l.specularScale = 1.0f;
l.shadowDimmer = 1.0f;
if (light.lightType == LightType.Spot)
{
if (light.lightType == LightType.Spot)
{
float spotAngle = light.light.spotAngle;
AdditionalLightData additionalLightData = light.light.GetComponent<AdditionalLightData>();
float innerConePercent = AdditionalLightData.GetInnerSpotPercent01(additionalLightData);

float val = Mathf.Max(0.001f, (cosSpotInnerHalfAngle - cosSpotOuterHalfAngle));
l.angleScale = 1.0f / val;
l.angleOffset = -cosSpotOuterHalfAngle * l.angleScale;
}
else
{
// 1.0f, 2.0f are neutral value allowing GetAngleAnttenuation in shader code to return 1.0
l.angleScale = 1.0f / val;
l.angleOffset = -cosSpotOuterHalfAngle * l.angleScale;
}
else
{
// 1.0f, 2.0f are neutral value allowing GetAngleAnttenuation in shader code to return 1.0
}
}
lights.Add(l);
punctualLightCount++;

Shader.SetGlobalInt("g_punctualLightCount", punctualLightCount);
}
void UpdateLightConstants(ActiveLight[] activeLights /*, ref ShadowOutput shadow */)
{
/*
int nNumLightsIncludingTooMany = 0;
void UpdateLightConstants(ActiveLight[] activeLights /*, ref ShadowOutput shadow */)
{
/*
int nNumLightsIncludingTooMany = 0;
int g_nNumLights = 0;
int g_nNumLights = 0;
Vector4[] g_vLightColor = new Vector4[ MAX_LIGHTS ];
Vector4[] g_vLightPosition_flInvRadius = new Vector4[ MAX_LIGHTS ];
Vector4[] g_vLightDirection = new Vector4[ MAX_LIGHTS ];
Vector4[] g_vLightShadowIndex_vLightParams = new Vector4[ MAX_LIGHTS ];
Vector4[] g_vLightFalloffParams = new Vector4[ MAX_LIGHTS ];
Vector4[] g_vSpotLightInnersuterConeCosines = new Vector4[ MAX_LIGHTS ];
Matrix4x4[] g_matWorldToShadow = new Matrix4x4[ MAX_LIGHTS * MAX_SHADOWMAP_PER_LIGHTS ];
Vector4[] g_vDirShadowSplitSpheres = new Vector4[ MAX_DIRECTIONAL_SPLIT ];
Vector4[] g_vLightColor = new Vector4[ MAX_LIGHTS ];
Vector4[] g_vLightPosition_flInvRadius = new Vector4[ MAX_LIGHTS ];
Vector4[] g_vLightDirection = new Vector4[ MAX_LIGHTS ];
Vector4[] g_vLightShadowIndex_vLightParams = new Vector4[ MAX_LIGHTS ];
Vector4[] g_vLightFalloffParams = new Vector4[ MAX_LIGHTS ];
Vector4[] g_vSpotLightInnersuterConeCosines = new Vector4[ MAX_LIGHTS ];
Matrix4x4[] g_matWorldToShadow = new Matrix4x4[ MAX_LIGHTS * MAX_SHADOWMAP_PER_LIGHTS ];
Vector4[] g_vDirShadowSplitSpheres = new Vector4[ MAX_DIRECTIONAL_SPLIT ];
for ( int nLight = 0; nLight < activeLights.Length; nLight++ )
{
for ( int nLight = 0; nLight < activeLights.Length; nLight++ )
{
nNumLightsIncludingTooMany++;
if ( nNumLightsIncludingTooMany > MAX_LIGHTS )
continue;
nNumLightsIncludingTooMany++;
if ( nNumLightsIncludingTooMany > MAX_LIGHTS )
continue;
ActiveLight light = activeLights [nLight];
LightType lightType = light.lightType;
Vector3 position = light.light.transform.position;
Vector3 lightDir = light.light.transform.forward.normalized;
AdditionalLightData additionalLightData = light.light.GetComponent<AdditionalLightData> ();
ActiveLight light = activeLights [nLight];
LightType lightType = light.lightType;
Vector3 position = light.light.transform.position;
Vector3 lightDir = light.light.transform.forward.normalized;
AdditionalLightData additionalLightData = light.light.GetComponent<AdditionalLightData> ();
// Setup shadow data arrays
bool hasShadows = shadow.GetShadowSliceCountLightIndex (nLight) != 0;
// Setup shadow data arrays
bool hasShadows = shadow.GetShadowSliceCountLightIndex (nLight) != 0;
if ( lightType == LightType.Directional )
{
g_vLightColor[ g_nNumLights ] = light.finalColor;
g_vLightPosition_flInvRadius[ g_nNumLights ] = new Vector4(
position.x - ( lightDir.x * DIRECTIONAL_LIGHT_PULLBACK_DISTANCE ),
position.y - ( lightDir.y * DIRECTIONAL_LIGHT_PULLBACK_DISTANCE ),
position.z - ( lightDir.z * DIRECTIONAL_LIGHT_PULLBACK_DISTANCE ),
-1.0f );
g_vLightDirection[ g_nNumLights ] = new Vector4( lightDir.x, lightDir.y, lightDir.z );
g_vLightShadowIndex_vLightParams[ g_nNumLights ] = new Vector4( 0, 0, 1, 1 );
g_vLightFalloffParams[ g_nNumLights ] = new Vector4( 0.0f, 0.0f, float.MaxValue, (float)lightType );
g_vSpotLightInnerOuterConeCosines[ g_nNumLights ] = new Vector4( 0.0f, -1.0f, 1.0f );
if ( lightType == LightType.Directional )
{
g_vLightColor[ g_nNumLights ] = light.finalColor;
g_vLightPosition_flInvRadius[ g_nNumLights ] = new Vector4(
position.x - ( lightDir.x * DIRECTIONAL_LIGHT_PULLBACK_DISTANCE ),
position.y - ( lightDir.y * DIRECTIONAL_LIGHT_PULLBACK_DISTANCE ),
position.z - ( lightDir.z * DIRECTIONAL_LIGHT_PULLBACK_DISTANCE ),
-1.0f );
g_vLightDirection[ g_nNumLights ] = new Vector4( lightDir.x, lightDir.y, lightDir.z );
g_vLightShadowIndex_vLightParams[ g_nNumLights ] = new Vector4( 0, 0, 1, 1 );
g_vLightFalloffParams[ g_nNumLights ] = new Vector4( 0.0f, 0.0f, float.MaxValue, (float)lightType );
g_vSpotLightInnerOuterConeCosines[ g_nNumLights ] = new Vector4( 0.0f, -1.0f, 1.0f );
if (hasShadows)
{
for (int s = 0; s < MAX_DIRECTIONAL_SPLIT; ++s)
{
g_vDirShadowSplitSpheres[s] = shadow.directionalShadowSplitSphereSqr[s];
}
}
}
else if ( lightType == LightType.Point )
{
g_vLightColor[ g_nNumLights ] = light.finalColor;
if (hasShadows)
{
for (int s = 0; s < MAX_DIRECTIONAL_SPLIT; ++s)
{
g_vDirShadowSplitSpheres[s] = shadow.directionalShadowSplitSphereSqr[s];
}
}
}
else if ( lightType == LightType.Point )
{
g_vLightColor[ g_nNumLights ] = light.finalColor;
g_vLightPosition_flInvRadius[ g_nNumLights ] = new Vector4( position.x, position.y, position.z, 1.0f / light.range );
g_vLightDirection[ g_nNumLights ] = new Vector4( 0.0f, 0.0f, 0.0f );
g_vLightShadowIndex_vLightParams[ g_nNumLights ] = new Vector4( 0, 0, 1, 1 );
g_vLightFalloffParams[ g_nNumLights ] = new Vector4( 1.0f, 0.0f, light.range * light.range, (float)lightType );
g_vSpotLightInnerOuterConeCosines[ g_nNumLights ] = new Vector4( 0.0f, -1.0f, 1.0f );
}
else if ( lightType == LightType.Spot )
{
g_vLightColor[ g_nNumLights ] = light.finalColor;
g_vLightPosition_flInvRadius[ g_nNumLights ] = new Vector4( position.x, position.y, position.z, 1.0f / light.range );
g_vLightDirection[ g_nNumLights ] = new Vector4( lightDir.x, lightDir.y, lightDir.z );
g_vLightShadowIndex_vLightParams[ g_nNumLights ] = new Vector4( 0, 0, 1, 1 );
g_vLightFalloffParams[ g_nNumLights ] = new Vector4( 1.0f, 0.0f, light.range * light.range, (float)lightType );
g_vLightPosition_flInvRadius[ g_nNumLights ] = new Vector4( position.x, position.y, position.z, 1.0f / light.range );
g_vLightDirection[ g_nNumLights ] = new Vector4( 0.0f, 0.0f, 0.0f );
g_vLightShadowIndex_vLightParams[ g_nNumLights ] = new Vector4( 0, 0, 1, 1 );
g_vLightFalloffParams[ g_nNumLights ] = new Vector4( 1.0f, 0.0f, light.range * light.range, (float)lightType );
g_vSpotLightInnerOuterConeCosines[ g_nNumLights ] = new Vector4( 0.0f, -1.0f, 1.0f );
}
else if ( lightType == LightType.Spot )
{
g_vLightColor[ g_nNumLights ] = light.finalColor;
g_vLightPosition_flInvRadius[ g_nNumLights ] = new Vector4( position.x, position.y, position.z, 1.0f / light.range );
g_vLightDirection[ g_nNumLights ] = new Vector4( lightDir.x, lightDir.y, lightDir.z );
g_vLightShadowIndex_vLightParams[ g_nNumLights ] = new Vector4( 0, 0, 1, 1 );
g_vLightFalloffParams[ g_nNumLights ] = new Vector4( 1.0f, 0.0f, light.range * light.range, (float)lightType );
float flInnerConePercent = AdditionalLightData.GetInnerSpotPercent01(additionalLightData);
float spotAngle = light.light.spotAngle;
float flPhiDot = Mathf.Clamp( Mathf.Cos( spotAngle * 0.5f * Mathf.Deg2Rad ), 0.0f, 1.0f ); // outer cone
float flThetaDot = Mathf.Clamp( Mathf.Cos( spotAngle * 0.5f * flInnerConePercent * Mathf.Deg2Rad ), 0.0f, 1.0f ); // inner cone
g_vSpotLightInnerOuterConeCosines[ g_nNumLights ] = new Vector4( flThetaDot, flPhiDot, 1.0f / Mathf.Max( 0.01f, flThetaDot - flPhiDot ) );
float flInnerConePercent = AdditionalLightData.GetInnerSpotPercent01(additionalLightData);
float spotAngle = light.light.spotAngle;
float flPhiDot = Mathf.Clamp( Mathf.Cos( spotAngle * 0.5f * Mathf.Deg2Rad ), 0.0f, 1.0f ); // outer cone
float flThetaDot = Mathf.Clamp( Mathf.Cos( spotAngle * 0.5f * flInnerConePercent * Mathf.Deg2Rad ), 0.0f, 1.0f ); // inner cone
g_vSpotLightInnerOuterConeCosines[ g_nNumLights ] = new Vector4( flThetaDot, flPhiDot, 1.0f / Mathf.Max( 0.01f, flThetaDot - flPhiDot ) );
}
}
if ( hasShadows )
{
// Enable shadows
g_vLightShadowIndex_vLightParams[ g_nNumLights ].x = 1;
for(int s=0; s < shadow.GetShadowSliceCountLightIndex (nLight); ++s)
{
int shadowSliceIndex = shadow.GetShadowSliceIndex (nLight, s);
g_matWorldToShadow [g_nNumLights * MAX_SHADOWMAP_PER_LIGHTS + s] = shadow.shadowSlices[shadowSliceIndex].shadowTransform.transpose;
}
}
if ( hasShadows )
{
// Enable shadows
g_vLightShadowIndex_vLightParams[ g_nNumLights ].x = 1;
for(int s=0; s < shadow.GetShadowSliceCountLightIndex (nLight); ++s)
{
int shadowSliceIndex = shadow.GetShadowSliceIndex (nLight, s);
g_matWorldToShadow [g_nNumLights * MAX_SHADOWMAP_PER_LIGHTS + s] = shadow.shadowSlices[shadowSliceIndex].shadowTransform.transpose;
}
}
g_nNumLights++;
}
g_nNumLights++;
}
// Warn if too many lights found
if ( nNumLightsIncludingTooMany > MAX_LIGHTS )
{
if ( nNumLightsIncludingTooMany > m_nWarnedTooManyLights )
{
Debug.LogError( "ERROR! Found " + nNumLightsIncludingTooMany + " runtime lights! Valve renderer supports up to " + MAX_LIGHTS +
" active runtime lights at a time!\nDisabling " + ( nNumLightsIncludingTooMany - MAX_LIGHTS ) + " runtime light" +
( ( nNumLightsIncludingTooMany - MAX_LIGHTS ) > 1 ? "s" : "" ) + "!\n" );
}
m_nWarnedTooManyLights = nNumLightsIncludingTooMany;
}
else
{
if ( m_nWarnedTooManyLights > 0 )
{
m_nWarnedTooManyLights = 0;
Debug.Log( "SUCCESS! Found " + nNumLightsIncludingTooMany + " runtime lights which is within the supported number of lights, " + MAX_LIGHTS + ".\n\n" );
}
}
// Warn if too many lights found
if ( nNumLightsIncludingTooMany > MAX_LIGHTS )
{
if ( nNumLightsIncludingTooMany > m_nWarnedTooManyLights )
{
Debug.LogError( "ERROR! Found " + nNumLightsIncludingTooMany + " runtime lights! Valve renderer supports up to " + MAX_LIGHTS +
" active runtime lights at a time!\nDisabling " + ( nNumLightsIncludingTooMany - MAX_LIGHTS ) + " runtime light" +
( ( nNumLightsIncludingTooMany - MAX_LIGHTS ) > 1 ? "s" : "" ) + "!\n" );
}
m_nWarnedTooManyLights = nNumLightsIncludingTooMany;
}
else
{
if ( m_nWarnedTooManyLights > 0 )
{
m_nWarnedTooManyLights = 0;
Debug.Log( "SUCCESS! Found " + nNumLightsIncludingTooMany + " runtime lights which is within the supported number of lights, " + MAX_LIGHTS + ".\n\n" );
}
}
// Send constants to shaders
Shader.SetGlobalInt( "g_nNumLights", g_nNumLights );
// Send constants to shaders
Shader.SetGlobalInt( "g_nNumLights", g_nNumLights );
// New method for Unity 5.4 to set arrays of constants
Shader.SetGlobalVectorArray( "g_vLightPosition_flInvRadius", g_vLightPosition_flInvRadius );
Shader.SetGlobalVectorArray( "g_vLightColor", g_vLightColor );
Shader.SetGlobalVectorArray( "g_vLightDirection", g_vLightDirection );
Shader.SetGlobalVectorArray( "g_vLightShadowIndex_vLightParams", g_vLightShadowIndex_vLightParams );
Shader.SetGlobalVectorArray( "g_vLightFalloffParams", g_vLightFalloffParams );
Shader.SetGlobalVectorArray( "g_vSpotLightInnerOuterConeCosines", g_vSpotLightInnerOuterConeCosines );
Shader.SetGlobalMatrixArray( "g_matWorldToShadow", g_matWorldToShadow );
Shader.SetGlobalVectorArray( "g_vDirShadowSplitSpheres", g_vDirShadowSplitSpheres );
// New method for Unity 5.4 to set arrays of constants
Shader.SetGlobalVectorArray( "g_vLightPosition_flInvRadius", g_vLightPosition_flInvRadius );
Shader.SetGlobalVectorArray( "g_vLightColor", g_vLightColor );
Shader.SetGlobalVectorArray( "g_vLightDirection", g_vLightDirection );
Shader.SetGlobalVectorArray( "g_vLightShadowIndex_vLightParams", g_vLightShadowIndex_vLightParams );
Shader.SetGlobalVectorArray( "g_vLightFalloffParams", g_vLightFalloffParams );
Shader.SetGlobalVectorArray( "g_vSpotLightInnerOuterConeCosines", g_vSpotLightInnerOuterConeCosines );
Shader.SetGlobalMatrixArray( "g_matWorldToShadow", g_matWorldToShadow );
Shader.SetGlobalVectorArray( "g_vDirShadowSplitSpheres", g_vDirShadowSplitSpheres );
// Time
#if ( UNITY_EDITOR )
{
Shader.SetGlobalFloat( "g_flTime", Time.realtimeSinceStartup );
//Debug.Log( "Time " + Time.realtimeSinceStartup );
}
#else
{
Shader.SetGlobalFloat( "g_flTime", Time.timeSinceLevelLoad );
//Debug.Log( "Time " + Time.timeSinceLevelLoad );
}
#endif
// Time
#if ( UNITY_EDITOR )
{
Shader.SetGlobalFloat( "g_flTime", Time.realtimeSinceStartup );
//Debug.Log( "Time " + Time.realtimeSinceStartup );
}
#else
{
Shader.SetGlobalFloat( "g_flTime", Time.timeSinceLevelLoad );
//Debug.Log( "Time " + Time.timeSinceLevelLoad );
}
#endif
// PCF 3x3 Shadows
float flTexelEpsilonX = 1.0f / m_ShadowSettings.shadowAtlasWidth;
float flTexelEpsilonY = 1.0f / m_ShadowSettings.shadowAtlasHeight;
Vector4 g_vShadow3x3PCFTerms0 = new Vector4( 20.0f / 267.0f, 33.0f / 267.0f, 55.0f / 267.0f, 0.0f );
Vector4 g_vShadow3x3PCFTerms1 = new Vector4( flTexelEpsilonX, flTexelEpsilonY, -flTexelEpsilonX, -flTexelEpsilonY );
Vector4 g_vShadow3x3PCFTerms2 = new Vector4( flTexelEpsilonX, flTexelEpsilonY, 0.0f, 0.0f );
Vector4 g_vShadow3x3PCFTerms3 = new Vector4( -flTexelEpsilonX, -flTexelEpsilonY, 0.0f, 0.0f );
// PCF 3x3 Shadows
float flTexelEpsilonX = 1.0f / m_ShadowSettings.shadowAtlasWidth;
float flTexelEpsilonY = 1.0f / m_ShadowSettings.shadowAtlasHeight;
Vector4 g_vShadow3x3PCFTerms0 = new Vector4( 20.0f / 267.0f, 33.0f / 267.0f, 55.0f / 267.0f, 0.0f );
Vector4 g_vShadow3x3PCFTerms1 = new Vector4( flTexelEpsilonX, flTexelEpsilonY, -flTexelEpsilonX, -flTexelEpsilonY );
Vector4 g_vShadow3x3PCFTerms2 = new Vector4( flTexelEpsilonX, flTexelEpsilonY, 0.0f, 0.0f );
Vector4 g_vShadow3x3PCFTerms3 = new Vector4( -flTexelEpsilonX, -flTexelEpsilonY, 0.0f, 0.0f );
Shader.SetGlobalVector( "g_vShadow3x3PCFTerms0", g_vShadow3x3PCFTerms0 );
Shader.SetGlobalVector( "g_vShadow3x3PCFTerms1", g_vShadow3x3PCFTerms1 );
Shader.SetGlobalVector( "g_vShadow3x3PCFTerms2", g_vShadow3x3PCFTerms2 );
Shader.SetGlobalVector( "g_vShadow3x3PCFTerms3", g_vShadow3x3PCFTerms3 );
*/
}
Shader.SetGlobalVector( "g_vShadow3x3PCFTerms0", g_vShadow3x3PCFTerms0 );
Shader.SetGlobalVector( "g_vShadow3x3PCFTerms1", g_vShadow3x3PCFTerms1 );
Shader.SetGlobalVector( "g_vShadow3x3PCFTerms2", g_vShadow3x3PCFTerms2 );
Shader.SetGlobalVector( "g_vShadow3x3PCFTerms3", g_vShadow3x3PCFTerms3 );
*/
}
/*
void RenderDeferredLighting(Camera camera, CullingInputs inputs, RenderLoop loop)

}
*/
public override void Render(Camera[] cameras, RenderLoop renderLoop)
{
// Set Frame constant buffer
public override void Render(Camera[] cameras, RenderLoop renderLoop)
{
// Set Frame constant buffer
foreach (var camera in cameras)
{
// Set camera constant buffer
foreach (var camera in cameras)
{
// Set camera constant buffer
CullResults cullResults;
CullingParameters cullingParams;
if (!CullResults.GetCullingParameters (camera, out cullingParams))
continue;
CullResults cullResults;
CullingParameters cullingParams;
if (!CullResults.GetCullingParameters (camera, out cullingParams))
continue;
//m_ShadowPass.UpdateCullingParameters (ref cullingParams);
//m_ShadowPass.UpdateCullingParameters (ref cullingParams);
cullResults = CullResults.Cull (ref cullingParams, renderLoop);
//ShadowOutput shadows;
//m_ShadowPass.Render (renderLoop, cullResults, out shadows);
cullResults = CullResults.Cull (ref cullingParams, renderLoop);
//ShadowOutput shadows;
//m_ShadowPass.Render (renderLoop, cullResults, out shadows);
renderLoop.SetupCameraProperties (camera);
renderLoop.SetupCameraProperties (camera);
//UpdateLightConstants(cullResults.culledLights /*, ref shadows */);
//UpdateLightConstants(cullResults.culledLights /*, ref shadows */);
bool needDebugRendering = debugParameters.materialDebugMode != MaterialDebugMode.None || debugParameters.gBufferDebugMode != GBufferDebugMode.None;
bool needDebugRendering = debugParameters.materialDebugMode != MaterialDebugMode.None || debugParameters.gBufferDebugMode != GBufferDebugMode.None;
if (!needDebugRendering)
{
UpdatePunctualLights(cullResults.culledLights);
if (!needDebugRendering)
{
UpdatePunctualLights(cullResults.culledLights);
InitAndClearBuffer(camera, renderLoop);
InitAndClearBuffer(camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);
RenderDeferredLighting(camera, renderLoop);
RenderDeferredLighting(camera, renderLoop);
RenderForward(cullResults, camera, renderLoop);
RenderForward(cullResults, camera, renderLoop);
FinalPass(renderLoop);
}
else
{
if(debugParameters.materialDebugMode != MaterialDebugMode.None)
{
RenderMaterialDebug(cullResults, camera, renderLoop);
}
else if (debugParameters.gBufferDebugMode != GBufferDebugMode.None)
{
InitAndClearBuffer(camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);
RenderGBufferDebug(camera, renderLoop);
}
}
FinalPass(renderLoop);
}
else
{
if(debugParameters.materialDebugMode != MaterialDebugMode.None)
{
RenderMaterialDebug(cullResults, camera, renderLoop);
}
else if (debugParameters.gBufferDebugMode != GBufferDebugMode.None)
{
InitAndClearBuffer(camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);
RenderGBufferDebug(camera, renderLoop);
}
}
renderLoop.Submit ();
}
renderLoop.Submit ();
}
// Post effects
}
// Post effects
}
#if UNITY_EDITOR
public override UnityEditor.SupportedRenderingFeatures GetSupportedRenderingFeatures()
{
var features = new UnityEditor.SupportedRenderingFeatures();
#if UNITY_EDITOR
public override UnityEditor.SupportedRenderingFeatures GetSupportedRenderingFeatures()
{
var features = new UnityEditor.SupportedRenderingFeatures();
features.reflectionProbe = UnityEditor.SupportedRenderingFeatures.ReflectionProbe.Rotation;
features.reflectionProbe = UnityEditor.SupportedRenderingFeatures.ReflectionProbe.Rotation;
return features;
}
#endif
}
return features;
}
#endif
}
}

174
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoopInspector.cs


namespace UnityEngine.ScriptableRenderLoop
{
[CustomEditor(typeof(HDRenderLoop))]
public class HDRenderLoopInspector : Editor
{
private class Styles
{
public readonly GUIContent debugParameters = new GUIContent("Debug Parameters");
public readonly GUIContent materialDebugMode = new GUIContent("Material Debug Mode", "Display various properties of Materials.");
public readonly GUIContent gBufferDebugMode = new GUIContent("GBuffer Debug Mode", "Display various properties of contained in the GBuffer.");
[CustomEditor(typeof(HDRenderLoop))]
public class HDRenderLoopInspector : Editor
{
private class Styles
{
public readonly GUIContent debugParameters = new GUIContent("Debug Parameters");
public readonly GUIContent materialDebugMode = new GUIContent("Material Debug Mode", "Display various properties of Materials.");
public readonly GUIContent gBufferDebugMode = new GUIContent("GBuffer Debug Mode", "Display various properties of contained in the GBuffer.");
public readonly GUIContent displayOpaqueObjects = new GUIContent("Display Opaque Objects", "Toggle opaque objects rendering on and off.");
public readonly GUIContent displayTransparentObjects = new GUIContent("Display Transparent Objects", "Toggle transparent objects rendering on and off.");
public readonly GUIContent enableTonemap = new GUIContent("Enable Tonemap");
public readonly GUIContent exposure = new GUIContent("Exposure");
public readonly GUIContent displayOpaqueObjects = new GUIContent("Display Opaque Objects", "Toggle opaque objects rendering on and off.");
public readonly GUIContent displayTransparentObjects = new GUIContent("Display Transparent Objects", "Toggle transparent objects rendering on and off.");
public readonly GUIContent enableTonemap = new GUIContent("Enable Tonemap");
public readonly GUIContent exposure = new GUIContent("Exposure");
public readonly GUIContent[] materialDebugStrings = { new GUIContent("None"),
new GUIContent("Diffuse Color"),
new GUIContent("Normal"),
new GUIContent("Depth"),
new GUIContent("Ambient Occlusion"),
new GUIContent("Specular Color"),
new GUIContent("Specular Occlusion"),
new GUIContent("Smoothness"),
new GUIContent("MaterialId"),
new GUIContent("UV0"),
new GUIContent("Tangent"),
new GUIContent("Bitangent")
};
public readonly int[] materialDebugValues = { (int)HDRenderLoop.MaterialDebugMode.None,
(int)HDRenderLoop.MaterialDebugMode.DiffuseColor,
(int)HDRenderLoop.MaterialDebugMode.Normal,
(int)HDRenderLoop.MaterialDebugMode.Depth,
(int)HDRenderLoop.MaterialDebugMode.AmbientOcclusion,
(int)HDRenderLoop.MaterialDebugMode.SpecularColor,
(int)HDRenderLoop.MaterialDebugMode.SpecularOcclustion,
(int)HDRenderLoop.MaterialDebugMode.Smoothness,
(int)HDRenderLoop.MaterialDebugMode.MaterialId,
(int)HDRenderLoop.MaterialDebugMode.UV0,
(int)HDRenderLoop.MaterialDebugMode.Tangent,
(int)HDRenderLoop.MaterialDebugMode.Bitangent
};
public readonly GUIContent[] gBufferDebugStrings = { new GUIContent("None"),
new GUIContent("Diffuse Color"),
new GUIContent("Normal"),
new GUIContent("Depth"),
new GUIContent("Baked Diffuse"),
new GUIContent("Specular Color"),
new GUIContent("Specular Occlusion"),
new GUIContent("Smoothness"),
new GUIContent("MaterialId")
};
public readonly int[] gBufferDebugValues = { (int)HDRenderLoop.GBufferDebugMode.None,
(int)HDRenderLoop.GBufferDebugMode.DiffuseColor,
(int)HDRenderLoop.GBufferDebugMode.Normal,
(int)HDRenderLoop.GBufferDebugMode.Depth,
(int)HDRenderLoop.GBufferDebugMode.BakedDiffuse,
(int)HDRenderLoop.GBufferDebugMode.SpecularColor,
(int)HDRenderLoop.GBufferDebugMode.SpecularOcclustion,
(int)HDRenderLoop.GBufferDebugMode.Smoothness,
(int)HDRenderLoop.GBufferDebugMode.MaterialId
};
}
public readonly GUIContent[] materialDebugStrings = { new GUIContent("None"),
new GUIContent("Diffuse Color"),
new GUIContent("Normal"),
new GUIContent("Depth"),
new GUIContent("Ambient Occlusion"),
new GUIContent("Specular Color"),
new GUIContent("Specular Occlusion"),
new GUIContent("Smoothness"),
new GUIContent("MaterialId"),
new GUIContent("UV0"),
new GUIContent("Tangent"),
new GUIContent("Bitangent")
};
public readonly int[] materialDebugValues = { (int)HDRenderLoop.MaterialDebugMode.None,
(int)HDRenderLoop.MaterialDebugMode.DiffuseColor,
(int)HDRenderLoop.MaterialDebugMode.Normal,
(int)HDRenderLoop.MaterialDebugMode.Depth,
(int)HDRenderLoop.MaterialDebugMode.AmbientOcclusion,
(int)HDRenderLoop.MaterialDebugMode.SpecularColor,
(int)HDRenderLoop.MaterialDebugMode.SpecularOcclustion,
(int)HDRenderLoop.MaterialDebugMode.Smoothness,
(int)HDRenderLoop.MaterialDebugMode.MaterialId,
(int)HDRenderLoop.MaterialDebugMode.UV0,
(int)HDRenderLoop.MaterialDebugMode.Tangent,
(int)HDRenderLoop.MaterialDebugMode.Bitangent
};
public readonly GUIContent[] gBufferDebugStrings = { new GUIContent("None"),
new GUIContent("Diffuse Color"),
new GUIContent("Normal"),
new GUIContent("Depth"),
new GUIContent("Baked Diffuse"),
new GUIContent("Specular Color"),
new GUIContent("Specular Occlusion"),
new GUIContent("Smoothness"),
new GUIContent("MaterialId")
};
public readonly int[] gBufferDebugValues = { (int)HDRenderLoop.GBufferDebugMode.None,
(int)HDRenderLoop.GBufferDebugMode.DiffuseColor,
(int)HDRenderLoop.GBufferDebugMode.Normal,
(int)HDRenderLoop.GBufferDebugMode.Depth,
(int)HDRenderLoop.GBufferDebugMode.BakedDiffuse,
(int)HDRenderLoop.GBufferDebugMode.SpecularColor,
(int)HDRenderLoop.GBufferDebugMode.SpecularOcclustion,
(int)HDRenderLoop.GBufferDebugMode.Smoothness,
(int)HDRenderLoop.GBufferDebugMode.MaterialId
};
}
private static Styles s_Styles = null;
private static Styles styles { get { if (s_Styles == null) s_Styles = new Styles(); return s_Styles; } }
private static Styles s_Styles = null;
private static Styles styles { get { if (s_Styles == null) s_Styles = new Styles(); return s_Styles; } }
const float kMaxExposure = 32.0f;
const float kMaxExposure = 32.0f;
public override void OnInspectorGUI()
{
HDRenderLoop renderLoop = target as HDRenderLoop;
if(renderLoop)
{
HDRenderLoop.DebugParameters debugParameters = renderLoop.debugParameters;
public override void OnInspectorGUI()
{
HDRenderLoop renderLoop = target as HDRenderLoop;
if(renderLoop)
{
HDRenderLoop.DebugParameters debugParameters = renderLoop.debugParameters;
EditorGUILayout.LabelField(styles.debugParameters);
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
EditorGUILayout.LabelField(styles.debugParameters);
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
debugParameters.gBufferDebugMode = (HDRenderLoop.GBufferDebugMode)EditorGUILayout.IntPopup(styles.gBufferDebugMode, (int)debugParameters.gBufferDebugMode, styles.gBufferDebugStrings, styles.gBufferDebugValues);
debugParameters.materialDebugMode = (HDRenderLoop.MaterialDebugMode)EditorGUILayout.IntPopup(styles.materialDebugMode, (int)debugParameters.materialDebugMode, styles.materialDebugStrings, styles.materialDebugValues);
debugParameters.gBufferDebugMode = (HDRenderLoop.GBufferDebugMode)EditorGUILayout.IntPopup(styles.gBufferDebugMode, (int)debugParameters.gBufferDebugMode, styles.gBufferDebugStrings, styles.gBufferDebugValues);
debugParameters.materialDebugMode = (HDRenderLoop.MaterialDebugMode)EditorGUILayout.IntPopup(styles.materialDebugMode, (int)debugParameters.materialDebugMode, styles.materialDebugStrings, styles.materialDebugValues);
EditorGUILayout.Space();
debugParameters.enableTonemap = EditorGUILayout.Toggle(styles.enableTonemap, debugParameters.enableTonemap);
debugParameters.exposure = Mathf.Max(Mathf.Min(EditorGUILayout.FloatField(styles.exposure, debugParameters.exposure), kMaxExposure), -kMaxExposure);
EditorGUILayout.Space();
debugParameters.enableTonemap = EditorGUILayout.Toggle(styles.enableTonemap, debugParameters.enableTonemap);
debugParameters.exposure = Mathf.Max(Mathf.Min(EditorGUILayout.FloatField(styles.exposure, debugParameters.exposure), kMaxExposure), -kMaxExposure);
EditorGUILayout.Space();
debugParameters.displayOpaqueObjects = EditorGUILayout.Toggle(styles.displayOpaqueObjects, debugParameters.displayOpaqueObjects);
debugParameters.displayTransparentObjects = EditorGUILayout.Toggle(styles.displayTransparentObjects, debugParameters.displayTransparentObjects);
EditorGUILayout.Space();
debugParameters.displayOpaqueObjects = EditorGUILayout.Toggle(styles.displayOpaqueObjects, debugParameters.displayOpaqueObjects);
debugParameters.displayTransparentObjects = EditorGUILayout.Toggle(styles.displayTransparentObjects, debugParameters.displayTransparentObjects);
if(EditorGUI.EndChangeCheck())
{
EditorUtility.SetDirty(renderLoop); // Repaint
}
EditorGUI.indentLevel--;
}
}
}
if(EditorGUI.EndChangeCheck())
{
EditorUtility.SetDirty(renderLoop); // Repaint
}
EditorGUI.indentLevel--;
}
}
}
}

192
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/GBufferDebug.shader


Shader "Hidden/Unity/GBufferDebug"
{
SubShader
{
SubShader
{
Pass
{
ZWrite Off
Blend One Zero
Pass
{
ZWrite Off
Blend One Zero
HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma vertex VertDeferred
#pragma fragment FragDeferred
#pragma vertex VertDeferred
#pragma fragment FragDeferred
// CAUTION: In case deferred lighting need to support various lighting model statically, we will require to do multicompile with different define like UNITY_MATERIAL_DISNEYGXX
#define UNITY_MATERIAL_DISNEYGGX // Need to be define before including Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl" // This include Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugCommon.hlsl"
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl"
// CAUTION: In case deferred lighting need to support various lighting model statically, we will require to do multicompile with different define like UNITY_MATERIAL_DISNEYGXX
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl" // This include Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugCommon.hlsl"
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl"
DECLARE_GBUFFER_TEXTURE(_CameraGBufferTexture);
DECLARE_GBUFFER_BAKE_LIGHTING(_CameraGBufferTexture);
Texture2D _CameraDepthTexture;
float4 _ScreenSize;
float _DebugMode;
float4x4 _InvViewProjMatrix;
DECLARE_GBUFFER_TEXTURE(_CameraGBufferTexture);
DECLARE_GBUFFER_BAKE_LIGHTING(_CameraGBufferTexture);
Texture2D _CameraDepthTexture;
float4 _ScreenSize;
float _DebugMode;
float4x4 _InvViewProjMatrix;
struct Attributes
{
float3 positionOS : POSITION;
};
struct Attributes
{
float3 positionOS : POSITION;
};
struct Varyings
{
float4 positionHS : SV_POSITION;
};
struct Varyings
{
float4 positionHS : SV_POSITION;
};
Varyings VertDeferred(Attributes input)
{
// TODO: implement SV_vertexID full screen quad
// Lights are draw as one fullscreen quad
Varyings output;
float3 positionWS = TransformObjectToWorld(input.positionOS);
output.positionHS = TransformWorldToHClip(positionWS);
Varyings VertDeferred(Attributes input)
{
// TODO: implement SV_vertexID full screen quad
// Lights are draw as one fullscreen quad
Varyings output;
float3 positionWS = TransformObjectToWorld(input.positionOS);
output.positionHS = TransformWorldToHClip(positionWS);
return output;
}
return output;
}
float4 FragDeferred(Varyings input) : SV_Target
{
Coordinate coord = GetCoordinate(input.positionHS.xy, _ScreenSize.zw);
float4 FragDeferred(Varyings input) : SV_Target
{
Coordinate coord = GetCoordinate(input.positionHS.xy, _ScreenSize.zw);
float depth = _CameraDepthTexture.Load(uint3(coord.unPositionSS, 0)).x;
float depth = _CameraDepthTexture.Load(uint3(coord.unPositionSS, 0)).x;
FETCH_GBUFFER(gbuffer, _CameraGBufferTexture, coord.unPositionSS);
BSDFData bsdfData = DECODE_FROM_GBUFFER(gbuffer);
FETCH_GBUFFER(gbuffer, _CameraGBufferTexture, coord.unPositionSS);
BSDFData bsdfData = DECODE_FROM_GBUFFER(gbuffer);
float3 result = float3(1.0, 1.0, 0.0);
bool outputIsLinear = false;
float3 result = float3(1.0, 1.0, 0.0);
bool outputIsLinear = false;
if (_DebugMode == GBufferDebugDiffuseColor)
{
result = bsdfData.diffuseColor;
}
else if (_DebugMode == GBufferDebugNormal)
{
result = bsdfData.normalWS * 0.5 + 0.5;
outputIsLinear = true;
}
else if (_DebugMode == GBufferDebugDepth)
{
float linearDepth = frac(LinearEyeDepth(depth, _ZBufferParams) * 0.1);
result = linearDepth.xxx;
outputIsLinear = true;
}
else if (_DebugMode == GBufferDebugBakedDiffuse)
{
FETCH_BAKE_LIGHTING_GBUFFER(gbuffer, _CameraGBufferTexture, coord.unPositionSS);
result = DECODE_BAKE_LIGHTING_FROM_GBUFFER(gbuffer);
outputIsLinear = true;
}
else if (_DebugMode == GBufferDebugSpecularColor)
{
result = bsdfData.fresnel0;
}
else if (_DebugMode == GBufferDebugSpecularOcclustion)
{
result = bsdfData.specularOcclusion.xxx;
outputIsLinear = true;
}
else if (_DebugMode == GBufferDebugSmoothness)
{
result = (1.0 - bsdfData.perceptualRoughness).xxx;
outputIsLinear = true;
}
else if (_DebugMode == GBufferDebugMaterialId)
{
result = bsdfData.materialId.xxx;
outputIsLinear = true;
}
if (outputIsLinear)
result = SRGBToLinear(max(0, result));
if (_DebugMode == GBufferDebugDiffuseColor)
{
result = bsdfData.diffuseColor;
}
else if (_DebugMode == GBufferDebugNormal)
{
result = bsdfData.normalWS * 0.5 + 0.5;
outputIsLinear = true;
}
else if (_DebugMode == GBufferDebugDepth)
{
float linearDepth = frac(LinearEyeDepth(depth, _ZBufferParams) * 0.1);
result = linearDepth.xxx;
outputIsLinear = true;
}
else if (_DebugMode == GBufferDebugBakedDiffuse)
{
FETCH_BAKE_LIGHTING_GBUFFER(gbuffer, _CameraGBufferTexture, coord.unPositionSS);
result = DECODE_BAKE_LIGHTING_FROM_GBUFFER(gbuffer);
outputIsLinear = true;
}
else if (_DebugMode == GBufferDebugSpecularColor)
{
result = bsdfData.fresnel0;
}
else if (_DebugMode == GBufferDebugSpecularOcclustion)
{
result = bsdfData.specularOcclusion.xxx;
outputIsLinear = true;
}
else if (_DebugMode == GBufferDebugSmoothness)
{
result = (1.0 - bsdfData.perceptualRoughness).xxx;
outputIsLinear = true;
}
else if (_DebugMode == GBufferDebugMaterialId)
{
result = bsdfData.materialId.xxx;
outputIsLinear = true;
}
if (outputIsLinear)
result = SRGBToLinear(max(0, result));
return float4(result, 1.0);
}
return float4(result, 1.0);
}
ENDHLSL
}
ENDHLSL
}
}
Fallback Off
}
Fallback Off
}

2
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl


#include "LightingForward.hlsl"
#endif // UNITY_LIGHTING_INCLUDED
#endif // UNITY_LIGHTING_INCLUDED

128
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.shader


Shader "Hidden/Unity/LightingDeferred"
{
Properties
{
_SrcBlend("", Float) = 1
_DstBlend("", Float) = 1
}
SubShader
{
Properties
{
_SrcBlend("", Float) = 1
_DstBlend("", Float) = 1
}
SubShader
{
Pass
{
ZWrite Off
Blend[_SrcBlend][_DstBlend]
Pass
{
ZWrite Off
Blend[_SrcBlend][_DstBlend]
HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma vertex VertDeferred
#pragma fragment FragDeferred
#pragma vertex VertDeferred
#pragma fragment FragDeferred
// CAUTION: In case deferred lighting need to support various lighting model statically, we will require to do multicompile with different define like UNITY_MATERIAL_DISNEYGXX
#define UNITY_MATERIAL_DISNEYGGX // Need to be define before including Material.hlsl
#include "Lighting.hlsl" // This include Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl"
// CAUTION: In case deferred lighting need to support various lighting model statically, we will require to do multicompile with different define like UNITY_MATERIAL_DISNEYGXX
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Lighting.hlsl" // This include Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl"
DECLARE_GBUFFER_TEXTURE(_CameraGBufferTexture);
DECLARE_GBUFFER_BAKE_LIGHTING(_CameraGBufferTexture);
DECLARE_GBUFFER_TEXTURE(_CameraGBufferTexture);
DECLARE_GBUFFER_BAKE_LIGHTING(_CameraGBufferTexture);
Texture2D _CameraDepthTexture;
float4 _ScreenSize;
Texture2D _CameraDepthTexture;
float4 _ScreenSize;
float4x4 _InvViewProjMatrix;
float4x4 _InvViewProjMatrix;
struct Attributes
{
float3 positionOS : POSITION;
};
struct Attributes
{
float3 positionOS : POSITION;
};
struct Varyings
{
float4 positionHS : SV_POSITION;
};
struct Varyings
{
float4 positionHS : SV_POSITION;
};
Varyings VertDeferred(Attributes input)
{
// TODO: implement SV_vertexID full screen quad
// Lights are draw as one fullscreen quad
Varyings output;
float3 positionWS = TransformObjectToWorld(input.positionOS);
output.positionHS = TransformWorldToHClip(positionWS);
Varyings VertDeferred(Attributes input)
{
// TODO: implement SV_vertexID full screen quad
// Lights are draw as one fullscreen quad
Varyings output;
float3 positionWS = TransformObjectToWorld(input.positionOS);
output.positionHS = TransformWorldToHClip(positionWS);
return output;
}
return output;
}
float4 FragDeferred(Varyings input) : SV_Target
{
Coordinate coord = GetCoordinate(input.positionHS.xy, _ScreenSize.zw);
float4 FragDeferred(Varyings input) : SV_Target
{
Coordinate coord = GetCoordinate(input.positionHS.xy, _ScreenSize.zw);
// No need to manage inverse depth, this is handled by the projection matrix
float depth = _CameraDepthTexture.Load(uint3(coord.unPositionSS, 0)).x;
float3 positionWS = UnprojectToWorld(depth, coord.positionSS, _InvViewProjMatrix);
float3 V = GetWorldSpaceNormalizeViewDir(positionWS);
// No need to manage inverse depth, this is handled by the projection matrix
float depth = _CameraDepthTexture.Load(uint3(coord.unPositionSS, 0)).x;
float3 positionWS = UnprojectToWorld(depth, coord.positionSS, _InvViewProjMatrix);
float3 V = GetWorldSpaceNormalizeViewDir(positionWS);
FETCH_GBUFFER(gbuffer, _CameraGBufferTexture, coord.unPositionSS);
BSDFData bsdfData = DECODE_FROM_GBUFFER(gbuffer);
FETCH_GBUFFER(gbuffer, _CameraGBufferTexture, coord.unPositionSS);
BSDFData bsdfData = DECODE_FROM_GBUFFER(gbuffer);
// NOTE: Currently calling the forward loop, same code... :)
float4 diffuseLighting;
float4 specularLighting;
ForwardLighting(V, positionWS, bsdfData, diffuseLighting, specularLighting);
// NOTE: Currently calling the forward loop, same code... :)
float4 diffuseLighting;
float4 specularLighting;
ForwardLighting(V, positionWS, bsdfData, diffuseLighting, specularLighting);
FETCH_BAKE_LIGHTING_GBUFFER(gbuffer, _CameraGBufferTexture, coord.unPositionSS);
diffuseLighting.rgb += DECODE_BAKE_LIGHTING_FROM_GBUFFER(gbuffer);
FETCH_BAKE_LIGHTING_GBUFFER(gbuffer, _CameraGBufferTexture, coord.unPositionSS);
diffuseLighting.rgb += DECODE_BAKE_LIGHTING_FROM_GBUFFER(gbuffer);
return float4(diffuseLighting.rgb + specularLighting.rgb, 1.0);
}
return float4(diffuseLighting.rgb + specularLighting.rgb, 1.0);
}
ENDHLSL
}
ENDHLSL
}
}
Fallback Off
}
Fallback Off
}

46
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingForward.hlsl


// TODO: Think about how to apply Disney diffuse preconvolve on indirect diffuse => must be done during GBuffer layout! Else emissive will be fucked...
// That's mean we need to read DFG texture during Gbuffer...
void ForwardLighting( float3 V, float3 positionWS, BSDFData bsdfData,
out float4 diffuseLighting,
out float4 specularLighting)
out float4 diffuseLighting,
out float4 specularLighting)
diffuseLighting = float4(0.0, 0.0, 0.0, 0.0);
specularLighting = float4(0.0, 0.0, 0.0, 0.0);
diffuseLighting = float4(0.0, 0.0, 0.0, 0.0);
specularLighting = float4(0.0, 0.0, 0.0, 0.0);
for (int i = 0; i < g_punctualLightCount; ++i)
{
float4 localDiffuseLighting;
float4 localSpecularLighting;
EvaluateBSDF_Punctual(V, positionWS, g_punctualLightList[i], bsdfData, localDiffuseLighting, localSpecularLighting);
diffuseLighting += localDiffuseLighting;
specularLighting += localSpecularLighting;
}
for (int i = 0; i < g_punctualLightCount; ++i)
{
float4 localDiffuseLighting;
float4 localSpecularLighting;
EvaluateBSDF_Punctual(V, positionWS, g_punctualLightList[i], bsdfData, localDiffuseLighting, localSpecularLighting);
diffuseLighting += localDiffuseLighting;
specularLighting += localSpecularLighting;
}
/*
for (int i = 0; i < 4; ++i)
{
float4 localDiffuseLighting;
float4 localSpecularLighting;
EvaluateBSDF_Area(V, positionWS, areaLightData[i], bsdfData, localDiffuseLighting, localSpecularLighting);
diffuseLighting += localDiffuseLighting;
specularLighting += localSpecularLighting;
}
*/
/*
for (int i = 0; i < 4; ++i)
{
float4 localDiffuseLighting;
float4 localSpecularLighting;
EvaluateBSDF_Area(V, positionWS, areaLightData[i], bsdfData, localDiffuseLighting, localSpecularLighting);
diffuseLighting += localDiffuseLighting;
specularLighting += localSpecularLighting;
}
*/
#endif // UNITY_LIGHTING_FORWARD_INCLUDED
#endif // UNITY_LIGHTING_FORWARD_INCLUDED

28
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.hlsl


struct BuiltinData
{
float opacity;
float opacity;
// These are lighting data.
// We would prefer to split lighting and material information but for performance reasons,
// those lighting information are fill
// at the same time than material information.
float3 bakeDiffuseLighting; // This is the result of sampling lightmap/lightprobe/proxyvolume
// These are lighting data.
// We would prefer to split lighting and material information but for performance reasons,
// those lighting information are fill
// at the same time than material information.
float3 bakeDiffuseLighting; // This is the result of sampling lightmap/lightprobe/proxyvolume
float3 emissiveColor;
float emissiveIntensity;
float3 emissiveColor;
float emissiveIntensity;
// These is required for motion blur and temporalAA
float2 velocity;
// These is required for motion blur and temporalAA
float2 velocity;
// Distortion
float2 distortion;
float distortionBlur; // Define the color buffer mipmap level to use
// Distortion
float2 distortion;
float distortionBlur; // Define the color buffer mipmap level to use
#endif // UNITY_BUILTIN_DATA_INCLUDED
#endif // UNITY_BUILTIN_DATA_INCLUDED

98
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl


float PerceptualRoughnessToRoughness(float perceptualRoughness)
{
return perceptualRoughness * perceptualRoughness;
return perceptualRoughness * perceptualRoughness;
return sqrt(roughness);
return sqrt(roughness);
return (1 - perceptualSmoothness) * (1 - perceptualSmoothness);
return (1 - perceptualSmoothness) * (1 - perceptualSmoothness);
return (1 - perceptualSmoothness);
return (1 - perceptualSmoothness);
}
// Encode/Decode velocity in a buffer (either forward of deferred)

// RT - 16:16 float
outBuffer = float4(velocity.xy, 0.0, 0.0);
// RT - 16:16 float
outBuffer = float4(velocity.xy, 0.0, 0.0);
return float2(inBuffer.xy);
return float2(inBuffer.xy);
}
// Encode/Decode into GBuffer - This is share so others material can use it.

// RT - 11:11:10f
outBuffer = float4(bakeDiffuseLighting.xyz, 0.0);
// RT - 11:11:10f
outBuffer = float4(bakeDiffuseLighting.xyz, 0.0);
return float3(inBuffer.xyz);
return float3(inBuffer.xyz);
}
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Here we include all the different lighting model supported by the renderloop based on define done in .shader
#ifdef UNITY_MATERIAL_DISNEYGGX
#include "DisneyGGX.hlsl"
#ifdef UNITY_MATERIAL_LIT
#include "Lit.hlsl"
#elif defined(UNITY_MATERIAL_UNLIT)
#include "Unlit.hlsl"
#endif

#if GBUFFER_MATERIAL_COUNT == 3
#define OUTPUT_GBUFFER(NAME) \
out float4 MERGE_NAME(NAME, 0) : SV_Target0, \
out float4 MERGE_NAME(NAME, 1) : SV_Target1, \
out float4 MERGE_NAME(NAME, 2) : SV_Target2
out float4 MERGE_NAME(NAME, 0) : SV_Target0, \
out float4 MERGE_NAME(NAME, 1) : SV_Target1, \
out float4 MERGE_NAME(NAME, 2) : SV_Target2
Texture2D MERGE_NAME(NAME, 0); \
Texture2D MERGE_NAME(NAME, 1); \
Texture2D MERGE_NAME(NAME, 2);
Texture2D MERGE_NAME(NAME, 0); \
Texture2D MERGE_NAME(NAME, 1); \
Texture2D MERGE_NAME(NAME, 2);
float4 MERGE_NAME(NAME, 0) = MERGE_NAME(TEX, 0).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 1) = MERGE_NAME(TEX, 1).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 2) = MERGE_NAME(TEX, 2).Load(uint3(UV, 0));
float4 MERGE_NAME(NAME, 0) = MERGE_NAME(TEX, 0).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 1) = MERGE_NAME(TEX, 1).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 2) = MERGE_NAME(TEX, 2).Load(uint3(UV, 0));
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, NAME) EncodeIntoGBuffer(SURFACE_DATA, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2))
#define DECODE_FROM_GBUFFER(NAME) DecodeFromGBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2))

#elif GBUFFER_MATERIAL_COUNT == 4
#define OUTPUT_GBUFFER(NAME) \
out float4 MERGE_NAME(NAME, 0) : SV_Target0, \
out float4 MERGE_NAME(NAME, 1) : SV_Target1, \
out float4 MERGE_NAME(NAME, 2) : SV_Target2, \
out float4 MERGE_NAME(NAME, 3) : SV_Target3
out float4 MERGE_NAME(NAME, 0) : SV_Target0, \
out float4 MERGE_NAME(NAME, 1) : SV_Target1, \
out float4 MERGE_NAME(NAME, 2) : SV_Target2, \
out float4 MERGE_NAME(NAME, 3) : SV_Target3
Texture2D MERGE_NAME(NAME, 0); \
Texture2D MERGE_NAME(NAME, 1); \
Texture2D MERGE_NAME(NAME, 2); \
Texture2D MERGE_NAME(NAME, 3);
Texture2D MERGE_NAME(NAME, 0); \
Texture2D MERGE_NAME(NAME, 1); \
Texture2D MERGE_NAME(NAME, 2); \
Texture2D MERGE_NAME(NAME, 3);
float4 MERGE_NAME(NAME, 0) = MERGE_NAME(TEX, 0).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 1) = MERGE_NAME(TEX, 1).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 2) = MERGE_NAME(TEX, 2).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 3) = MERGE_NAME(TEX, 3).Load(uint3(UV, 0));
float4 MERGE_NAME(NAME, 0) = MERGE_NAME(TEX, 0).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 1) = MERGE_NAME(TEX, 1).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 2) = MERGE_NAME(TEX, 2).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 3) = MERGE_NAME(TEX, 3).Load(uint3(UV, 0));
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, NAME) EncodeIntoGBuffer(SURFACE_DATA, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3))
#define DECODE_FROM_GBUFFER(NAME) DecodeFromGBuffer(MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3))

#elif GBUFFER_MATERIAL_COUNT == 5
#define OUTPUT_GBUFFER(NAME) \
out float4 MERGE_NAME(NAME, 0) : SV_Target0, \
out float4 MERGE_NAME(NAME, 1) : SV_Target1, \
out float4 MERGE_NAME(NAME, 2) : SV_Target2, \
out float4 MERGE_NAME(NAME, 3) : SV_Target3, \
out float4 MERGE_NAME(NAME, 4) : SV_Target4
out float4 MERGE_NAME(NAME, 0) : SV_Target0, \
out float4 MERGE_NAME(NAME, 1) : SV_Target1, \
out float4 MERGE_NAME(NAME, 2) : SV_Target2, \
out float4 MERGE_NAME(NAME, 3) : SV_Target3, \
out float4 MERGE_NAME(NAME, 4) : SV_Target4
Texture2D MERGE_NAME(NAME, 0); \
Texture2D MERGE_NAME(NAME, 1); \
Texture2D MERGE_NAME(NAME, 2); \
Texture2D MERGE_NAME(NAME, 3); \
Texture2D MERGE_NAME(NAME, 4);
Texture2D MERGE_NAME(NAME, 0); \
Texture2D MERGE_NAME(NAME, 1); \
Texture2D MERGE_NAME(NAME, 2); \
Texture2D MERGE_NAME(NAME, 3); \
Texture2D MERGE_NAME(NAME, 4);
float4 MERGE_NAME(NAME, 0) = MERGE_NAME(TEX, 0).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 1) = MERGE_NAME(TEX, 1).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 2) = MERGE_NAME(TEX, 2).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 3) = MERGE_NAME(TEX, 3).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 4) = MERGE_NAME(TEX, 4).Load(uint3(UV, 0));
float4 MERGE_NAME(NAME, 0) = MERGE_NAME(TEX, 0).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 1) = MERGE_NAME(TEX, 1).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 2) = MERGE_NAME(TEX, 2).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 3) = MERGE_NAME(TEX, 3).Load(uint3(UV, 0)); \
float4 MERGE_NAME(NAME, 4) = MERGE_NAME(TEX, 4).Load(uint3(UV, 0));
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, NAME) EncodeIntoGBuffer(SURFACE_DATA, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), MERGE_NAME(NAME, 4))
#define DECODE_FROM_GBUFFER(NAME) DecodeFromGBuffer(MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), MERGE_NAME(NAME, 4))

#define DECODE_VELOCITY_BUFFER(NAME) DecodeVelocity(GBUFFER_VELOCITY_NAME(NAME))
#endif
#endif // UNITY_MATERIAL_INCLUDED
#endif // UNITY_MATERIAL_INCLUDED

12
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit.hlsl


struct SurfaceData
{
float3 color;
float3 color;
float3 color;
float3 color;
};
//-----------------------------------------------------------------------------

BSDFData ConvertSurfaceDataToBSDFData(SurfaceData data)
{
BSDFData output;
output.color = data.color;
BSDFData output;
output.color = data.color;
return output;
return output;
}
//-----------------------------------------------------------------------------

#endif // UNITY_UNLIT_INCLUDED
#endif // UNITY_UNLIT_INCLUDED

192
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.hlsl


#ifndef UNITY_MATERIAL_DISNEYGGX_INCLUDED
#define UNITY_MATERIAL_DISNEYGGX_INCLUDED
#ifndef UNITY_MATERIAL_LIT_INCLUDED
#define UNITY_MATERIAL_LIT_INCLUDED
//-----------------------------------------------------------------------------
// SurfaceData and BSDFData

// Main structure that store the user data (i.e user input of master node in material graph)
struct SurfaceData
{
float3 diffuseColor;
float ambientOcclusion;
float3 diffuseColor;
float ambientOcclusion;
float3 specularColor;
float specularOcclusion;
float3 specularColor;
float specularOcclusion;
float3 normalWS;
float perceptualSmoothness;
float materialId;
float3 normalWS;
float perceptualSmoothness;
float materialId;
// MaterialID SSS - When enable, we only need one channel for specColor, so one is free to store information.
float subSurfaceRadius;
// MaterialID SSS - When enable, we only need one channel for specColor, so one is free to store information.
float subSurfaceRadius;
// MaterialID Clear coat
// MaterialID Clear coat
// float coatCoverage;
// float coatRoughness;
};

float3 diffuseColor;
float matData0;
float3 diffuseColor;
float matData0;
float3 fresnel0;
float specularOcclusion;
//float matData1;
float3 fresnel0;
float specularOcclusion;
//float matData1;
float3 normalWS;
float perceptualRoughness;
float materialId;
float3 normalWS;
float perceptualRoughness;
float materialId;
float roughness;
float roughness;
};
//-----------------------------------------------------------------------------

BSDFData ConvertSurfaceDataToBSDFData(SurfaceData input)
{
BSDFData output;
BSDFData output;
output.diffuseColor = input.diffuseColor;
output.matData0 = input.subSurfaceRadius; // TEMP
output.diffuseColor = input.diffuseColor;
output.matData0 = input.subSurfaceRadius; // TEMP
output.fresnel0 = input.specularColor;
output.specularOcclusion = input.specularOcclusion;
//output.matData1 = input.matData1;
output.fresnel0 = input.specularColor;
output.specularOcclusion = input.specularOcclusion;
//output.matData1 = input.matData1;
output.normalWS = input.normalWS;
output.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(input.perceptualSmoothness);
output.materialId = input.materialId;
output.normalWS = input.normalWS;
output.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(input.perceptualSmoothness);
output.materialId = input.materialId;
output.roughness = PerceptualRoughnessToRoughness(output.perceptualRoughness);
return output;
output.roughness = PerceptualRoughnessToRoughness(output.perceptualRoughness);
return output;
}
//-----------------------------------------------------------------------------

float PackMaterialId(int materialId)
{
return float(materialId) / 3.0;
return float(materialId) / 3.0;
return int(round(f * 3.0));
return int(round(f * 3.0));
}
//-----------------------------------------------------------------------------

float3 GetBakedDiffuseLigthing(SurfaceData surfaceData, BuiltinData builtinData)
{
return builtinData.bakeDiffuseLighting * surfaceData.ambientOcclusion * surfaceData.diffuseColor + builtinData.emissiveColor * builtinData.emissiveIntensity;
return builtinData.bakeDiffuseLighting * surfaceData.ambientOcclusion * surfaceData.diffuseColor + builtinData.emissiveColor * builtinData.emissiveIntensity;
}
//-----------------------------------------------------------------------------

// Encode SurfaceData (BSDF parameters) into GBuffer
void EncodeIntoGBuffer( SurfaceData surfaceData,
out float4 outGBuffer0,
out float4 outGBuffer1,
out float4 outGBuffer2)
out float4 outGBuffer0,
out float4 outGBuffer1,
out float4 outGBuffer2)
// RT0 - 8:8:8:8 sRGB
outGBuffer0 = float4(surfaceData.diffuseColor, surfaceData.subSurfaceRadius);
// RT0 - 8:8:8:8 sRGB
outGBuffer0 = float4(surfaceData.diffuseColor, surfaceData.subSurfaceRadius);
// RT1 - 8:8:8:8:
outGBuffer1 = float4(surfaceData.specularColor, surfaceData.specularOcclusion /*, surfaceData.matData1 */);
// RT1 - 8:8:8:8:
outGBuffer1 = float4(surfaceData.specularColor, surfaceData.specularOcclusion /*, surfaceData.matData1 */);
// RT2 - 10:10:10:2
// Encode normal on 20bit with oct compression
float2 octNormal = PackNormalOctEncode(surfaceData.normalWS);
// We store perceptualRoughness instead of roughness because it save a sqrt ALU when decoding
// (as we want both perceptualRoughness and roughness for the lighting due to Disney Diffuse model)
outGBuffer2 = float4(octNormal * 0.5 + 0.5, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness), PackMaterialId(surfaceData.materialId));
// RT2 - 10:10:10:2
// Encode normal on 20bit with oct compression
float2 octNormal = PackNormalOctEncode(surfaceData.normalWS);
// We store perceptualRoughness instead of roughness because it save a sqrt ALU when decoding
// (as we want both perceptualRoughness and roughness for the lighting due to Disney Diffuse model)
outGBuffer2 = float4(octNormal * 0.5 + 0.5, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness), PackMaterialId(surfaceData.materialId));
float4 inGBuffer1,
float4 inGBuffer2)
float4 inGBuffer1,
float4 inGBuffer2)
BSDFData bsdfData;
bsdfData.diffuseColor = inGBuffer0.rgb;
bsdfData.matData0 = inGBuffer0.a;
BSDFData bsdfData;
bsdfData.diffuseColor = inGBuffer0.rgb;
bsdfData.matData0 = inGBuffer0.a;
bsdfData.fresnel0 = inGBuffer1.rgb;
bsdfData.specularOcclusion = inGBuffer1.a;
// bsdfData.matData1 = ?;
bsdfData.fresnel0 = inGBuffer1.rgb;
bsdfData.specularOcclusion = inGBuffer1.a;
// bsdfData.matData1 = ?;
bsdfData.normalWS = UnpackNormalOctEncode(float2(inGBuffer2.r * 2.0 - 1.0, inGBuffer2.g * 2 - 1));
bsdfData.perceptualRoughness = inGBuffer2.b;
bsdfData.materialId = UnpackMaterialId(inGBuffer2.a);
bsdfData.normalWS = UnpackNormalOctEncode(float2(inGBuffer2.r * 2.0 - 1.0, inGBuffer2.g * 2 - 1));
bsdfData.perceptualRoughness = inGBuffer2.b;
bsdfData.materialId = UnpackMaterialId(inGBuffer2.a);
bsdfData.roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness);
bsdfData.roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness);
return bsdfData;
return bsdfData;
}
//-----------------------------------------------------------------------------

void EvaluateBSDF_Punctual( float3 V, float3 positionWS, PunctualLightData lightData, BSDFData bsdfData,
out float4 diffuseLighting,
out float4 specularLighting)
out float4 diffuseLighting,
out float4 specularLighting)
// All punctual light type in the same formula, attenuation is neutral depends on light type.
// light.positionWS is the normalize light direction in case of directional light and invSqrAttenuationRadius is 0
// mean dot(unL, unL) = 1 and mean GetDistanceAttenuation() will return 1
// For point light and directional GetAngleAttenuation() return 1
// All punctual light type in the same formula, attenuation is neutral depends on light type.
// light.positionWS is the normalize light direction in case of directional light and invSqrAttenuationRadius is 0
// mean dot(unL, unL) = 1 and mean GetDistanceAttenuation() will return 1
// For point light and directional GetAngleAttenuation() return 1
float3 unL = lightData.positionWS - positionWS * lightData.useDistanceAttenuation;
float3 L = normalize(unL);
float3 unL = lightData.positionWS - positionWS * lightData.useDistanceAttenuation;
float3 L = normalize(unL);
float attenuation = GetDistanceAttenuation(unL, lightData.invSqrAttenuationRadius);
attenuation *= GetAngleAttenuation(L, lightData.forward, lightData.angleScale, lightData.angleOffset);
float illuminance = saturate(dot(bsdfData.normalWS, L)) * attenuation;
float attenuation = GetDistanceAttenuation(unL, lightData.invSqrAttenuationRadius);
attenuation *= GetAngleAttenuation(L, lightData.forward, lightData.angleScale, lightData.angleOffset);
float illuminance = saturate(dot(bsdfData.normalWS, L)) * attenuation;
diffuseLighting = float4(0.0, 0.0, 0.0, 1.0);
specularLighting = float4(0.0, 0.0, 0.0, 1.0);
diffuseLighting = float4(0.0, 0.0, 0.0, 1.0);
specularLighting = float4(0.0, 0.0, 0.0, 1.0);
if (illuminance > 0.0f)
{
float NdotV = abs(dot(bsdfData.normalWS, V)) + 1e-5f; // TODO: check Eric idea about doing that when writting into the GBuffer (with our forward decal)
float3 H = normalize(V + L);
float LdotH = saturate(dot(L, H));
float NdotH = saturate(dot(bsdfData.normalWS, H));
float NdotL = saturate(dot(bsdfData.normalWS, L));
float3 F = F_Schlick(bsdfData.fresnel0, LdotH);
float Vis = V_SmithJointGGX(NdotL, NdotV, bsdfData.roughness);
float D = D_GGX(NdotH, bsdfData.roughness);
specularLighting.rgb = F * Vis * D;
#ifdef DIFFUSE_LAMBERT_BRDF
float diffuseTerm = Lambert();
#else
float diffuseTerm = DisneyDiffuse(NdotV, NdotL, LdotH, bsdfData.perceptualRoughness);
#endif
diffuseLighting.rgb = bsdfData.diffuseColor * diffuseTerm;
if (illuminance > 0.0f)
{
float NdotV = abs(dot(bsdfData.normalWS, V)) + 1e-5f; // TODO: check Eric idea about doing that when writting into the GBuffer (with our forward decal)
float3 H = normalize(V + L);
float LdotH = saturate(dot(L, H));
float NdotH = saturate(dot(bsdfData.normalWS, H));
float NdotL = saturate(dot(bsdfData.normalWS, L));
float3 F = F_Schlick(bsdfData.fresnel0, LdotH);
float Vis = V_SmithJointGGX(NdotL, NdotV, bsdfData.roughness);
float D = D_GGX(NdotH, bsdfData.roughness);
specularLighting.rgb = F * Vis * D;
#ifdef DIFFUSE_LAMBERT_BRDF
float diffuseTerm = Lambert();
#else
float diffuseTerm = DisneyDiffuse(NdotV, NdotL, LdotH, bsdfData.perceptualRoughness);
#endif
diffuseLighting.rgb = bsdfData.diffuseColor * diffuseTerm;
diffuseLighting.rgb *= lightData.color * illuminance;
specularLighting.rgb *= lightData.color * illuminance;
}
diffuseLighting.rgb *= lightData.color * illuminance;
specularLighting.rgb *= lightData.color * illuminance;
}
#endif // UNITY_MATERIAL_DISNEYGGX_INCLUDED
#endif // UNITY_MATERIAL_LIT_INCLUDED

222
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/PostProcess/FinalPass.shader


// Final compositing pass, just does gamma correction for now.
// Final compositing pass, just does gamma correction for now.
Properties
{
_MainTex ("Texture", any) = "" {}
Properties
{
_MainTex ("Texture", any) = "" {}
_ToneMapCoeffs1("Parameters for neutral tonemap", Vector) = (0.0, 0.0, 0.0, 0.0)
_ToneMapCoeffs2("Parameters for neutral tonemap", Vector) = (0.0, 0.0, 0.0, 0.0)
_Exposure("Exposure", Range(-32.0, 32.0)) = 0
[ToggleOff] _EnableToneMap("Enable Tone Map", Float) = 0
}
_ToneMapCoeffs1("Parameters for neutral tonemap", Vector) = (0.0, 0.0, 0.0, 0.0)
_ToneMapCoeffs2("Parameters for neutral tonemap", Vector) = (0.0, 0.0, 0.0, 0.0)
_Exposure("Exposure", Range(-32.0, 32.0)) = 0
[ToggleOff] _EnableToneMap("Enable Tone Map", Float) = 0
}
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
#pragma target 5.0
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
#pragma target 5.0
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl"
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl"
#include "../ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl"
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl"
#include "../ShaderVariables.hlsl"
sampler2D _MainTex;
float4 _ToneMapCoeffs1;
float4 _ToneMapCoeffs2;
sampler2D _MainTex;
float4 _ToneMapCoeffs1;
float4 _ToneMapCoeffs2;
#define InBlack _ToneMapCoeffs1.x
#define OutBlack _ToneMapCoeffs1.y
#define InWhite _ToneMapCoeffs1.z
#define OutWhite _ToneMapCoeffs1.w
#define WhiteLevel _ToneMapCoeffs2.z
#define WhiteClip _ToneMapCoeffs2.w
#define InBlack _ToneMapCoeffs1.x
#define OutBlack _ToneMapCoeffs1.y
#define InWhite _ToneMapCoeffs1.z
#define OutWhite _ToneMapCoeffs1.w
#define WhiteLevel _ToneMapCoeffs2.z
#define WhiteClip _ToneMapCoeffs2.w
float _Exposure;
float _EnableToneMap;
float _Exposure;
float _EnableToneMap;
struct Attributes {
float3 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct Attributes {
float3 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct Varyings {
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
struct Varyings {
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
Varyings Vert(Attributes input)
{
Varyings output;
output.vertex = TransformWorldToHClip(input.vertex);
output.texcoord = input.texcoord.xy;
return output;
}
Varyings Vert(Attributes input)
{
Varyings output;
output.vertex = TransformWorldToHClip(input.vertex);
output.texcoord = input.texcoord.xy;
return output;
}
float3 evalCurve(float3 x, float A, float B, float C, float D, float E, float F)
{
return ((x*(A*x + C*B) + D*E) / (x*(A*x + B) + D*F)) - E / F;
}
float3 evalCurve(float3 x, float A, float B, float C, float D, float E, float F)
{
return ((x*(A*x + C*B) + D*E) / (x*(A*x + B) + D*F)) - E / F;
}
float3 applyTonemapFilmicAD(float3 linearColor)
{
float blackRatio = InBlack / OutBlack;
float whiteRatio = InWhite / OutWhite;
float3 applyTonemapFilmicAD(float3 linearColor)
{
float blackRatio = InBlack / OutBlack;
float whiteRatio = InWhite / OutWhite;
// blend tunable coefficients
float B = lerp(0.57, 0.37, blackRatio);
float C = lerp(0.01, 0.24, whiteRatio);
float D = lerp(0.02, 0.20, blackRatio);
// blend tunable coefficients
float B = lerp(0.57, 0.37, blackRatio);
float C = lerp(0.01, 0.24, whiteRatio);
float D = lerp(0.02, 0.20, blackRatio);
// constants
float A = 0.2;
float E = 0.02;
float F = 0.30;
// constants
float A = 0.2;
float E = 0.02;
float F = 0.30;
// eval and correct for white point
float3 whiteScale = 1.0f / evalCurve(WhiteLevel, A, B, C, D, E, F);
float3 curr = evalCurve(linearColor * whiteScale, A, B, C, D, E, F);
// eval and correct for white point
float3 whiteScale = 1.0f / evalCurve(WhiteLevel, A, B, C, D, E, F);
float3 curr = evalCurve(linearColor * whiteScale, A, B, C, D, E, F);
return curr * whiteScale;
}
return curr * whiteScale;
}
float3 remapWhite(float3 inPixel, float whitePt)
{
// var breakout for readability
const float inBlack = 0;
const float outBlack = 0;
float inWhite = whitePt;
const float outWhite = 1;
float3 remapWhite(float3 inPixel, float whitePt)
{
// var breakout for readability
const float inBlack = 0;
const float outBlack = 0;
float inWhite = whitePt;
const float outWhite = 1;
// remap input range to output range
float3 outPixel = ((inPixel.rgb) - inBlack.xxx) / (inWhite.xxx - inBlack.xxx) * (outWhite.xxx - outBlack.xxx) + outBlack.xxx;
return (outPixel.rgb);
}
// remap input range to output range
float3 outPixel = ((inPixel.rgb) - inBlack.xxx) / (inWhite.xxx - inBlack.xxx) * (outWhite.xxx - outBlack.xxx) + outBlack.xxx;
return (outPixel.rgb);
}
float3 NeutralTonemap(float3 x)
{
float3 finalColor = applyTonemapFilmicAD(x); // curve (dynamic coeffs differ per level)
finalColor = remapWhite(finalColor, WhiteClip); // post-curve white point adjustment
finalColor = saturate(finalColor);
return finalColor;
}
float3 NeutralTonemap(float3 x)
{
float3 finalColor = applyTonemapFilmicAD(x); // curve (dynamic coeffs differ per level)
finalColor = remapWhite(finalColor, WhiteClip); // post-curve white point adjustment
finalColor = saturate(finalColor);
return finalColor;
}
float3 ApplyToneMap(float3 color)
{
if (_EnableToneMap > 0.0)
{
return NeutralTonemap(color);
}
else
{
return saturate(color);
}
}
float3 ApplyToneMap(float3 color)
{
if (_EnableToneMap > 0.0)
{
return NeutralTonemap(color);
}
else
{
return saturate(color);
}
}
float4 Frag(Varyings input) : SV_Target
{
float4 c = tex2D(_MainTex, input.texcoord);
// Gamma correction
float4 Frag(Varyings input) : SV_Target
{
float4 c = tex2D(_MainTex, input.texcoord);
// Gamma correction
// TODO: Currenlt in the editor there a an additional pass were the result is copyed in a render target RGBA8_sRGB.
// So we must not correct the sRGB here else it will be done two time.
// To fix!
// TODO: Currenlt in the editor there a an additional pass were the result is copyed in a render target RGBA8_sRGB.
// So we must not correct the sRGB here else it will be done two time.
// To fix!
c.rgb = ApplyToneMap(c.rgb * exp2(_Exposure));
c.rgb = ApplyToneMap(c.rgb * exp2(_Exposure));
// return LinearToSRGB(c);
return c;
// return LinearToSRGB(c);
return c;
}
ENDHLSL
}
ENDHLSL
}
}
Fallback Off
}
}
Fallback Off
}

180
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl


#define UNITY_MATRIX_VP unity_MatrixVP
#ifdef UNITY_SINGLE_PASS_STEREO
#define UNITY_MATRIX_MVP mul(unity_MatrixVP, unity_ObjectToWorld)
#define UNITY_MATRIX_MVP mul(unity_MatrixVP, unity_ObjectToWorld)
#define UNITY_MATRIX_MVP glstate_matrix_mvp
#define UNITY_MATRIX_MVP glstate_matrix_mvp
#endif
// These use the camera center position in VR

CBUFFER_START(UnityPerCamera)
// Time (t = time since current level load) values from Unity
float4 _Time; // (t/20, t, t*2, t*3)
float4 _SinTime; // sin(t/8), sin(t/4), sin(t/2), sin(t)
float4 _CosTime; // cos(t/8), cos(t/4), cos(t/2), cos(t)
float4 unity_DeltaTime; // dt, 1/dt, smoothdt, 1/smoothdt
// Time (t = time since current level load) values from Unity
float4 _Time; // (t/20, t, t*2, t*3)
float4 _SinTime; // sin(t/8), sin(t/4), sin(t/2), sin(t)
float4 _CosTime; // cos(t/8), cos(t/4), cos(t/2), cos(t)
float4 unity_DeltaTime; // dt, 1/dt, smoothdt, 1/smoothdt
float3 _WorldSpaceCameraPos;
float3 _WorldSpaceCameraPos;
// x = 1 or -1 (-1 if projection is flipped)
// y = near plane
// z = far plane
// w = 1/far plane
float4 _ProjectionParams;
// x = width
// y = height
// z = 1 + 1.0/width
// w = 1 + 1.0/height
float4 _ScreenParams;
// Values used to linearize the Z buffer (http://www.humus.name/temp/Linearize%20depth.txt)
// x = 1-far/near
// y = far/near
// z = x/far
// w = y/far
float4 _ZBufferParams;
// x = 1 or -1 (-1 if projection is flipped)
// y = near plane
// z = far plane
// w = 1/far plane
float4 _ProjectionParams;
// x = width
// y = height
// z = 1 + 1.0/width
// w = 1 + 1.0/height
float4 _ScreenParams;
// Values used to linearize the Z buffer (http://www.humus.name/temp/Linearize%20depth.txt)
// x = 1-far/near
// y = far/near
// z = x/far
// w = y/far
float4 _ZBufferParams;
// x = orthographic camera's width
// y = orthographic camera's height
// z = unused
// w = 1.0 if camera is ortho, 0.0 if perspective
float4 unity_OrthoParams;
// x = orthographic camera's width
// y = orthographic camera's height
// z = unused
// w = 1.0 if camera is ortho, 0.0 if perspective
float4 unity_OrthoParams;
float4 unity_CameraWorldClipPlanes[6];
float4 unity_CameraWorldClipPlanes[6];
// Projection matrices of the camera. Note that this might be different from projection matrix
// that is set right now, e.g. while rendering shadows the matrices below are still the projection
// of original camera.
float4x4 unity_CameraProjection;
float4x4 unity_CameraInvProjection;
// Projection matrices of the camera. Note that this might be different from projection matrix
// that is set right now, e.g. while rendering shadows the matrices below are still the projection
// of original camera.
float4x4 unity_CameraProjection;
float4x4 unity_CameraInvProjection;
float4x4 unity_WorldToCamera;
float4x4 unity_CameraToWorld;
float4x4 unity_WorldToCamera;
float4x4 unity_CameraToWorld;
#endif
CBUFFER_END

#ifndef UNITY_SINGLE_PASS_STEREO
float4x4 glstate_matrix_mvp;
float4x4 glstate_matrix_mvp;
// Use center position for stereo rendering
float4x4 glstate_matrix_modelview0;
float4x4 glstate_matrix_invtrans_modelview0;
// Use center position for stereo rendering
float4x4 glstate_matrix_modelview0;
float4x4 glstate_matrix_invtrans_modelview0;
float4x4 unity_ObjectToWorld;
float4x4 unity_WorldToObject;
float4 unity_LODFade; // x is the fade value ranging within [0,1]. y is x quantized into 16 levels
float4 unity_WorldTransformParams; // w is usually 1.0, or -1.0 for odd-negative scale transforms
float4x4 unity_ObjectToWorld;
float4x4 unity_WorldToObject;
float4 unity_LODFade; // x is the fade value ranging within [0,1]. y is x quantized into 16 levels
float4 unity_WorldTransformParams; // w is usually 1.0, or -1.0 for odd-negative scale transforms
float3 _WorldSpaceCameraPos;
float4x4 glstate_matrix_projection;
float4x4 unity_MatrixV;
float4x4 unity_MatrixVP;
float3 _WorldSpaceCameraPos;
float4x4 glstate_matrix_projection;
float4x4 unity_MatrixV;
float4x4 unity_MatrixVP;
float4x4 unity_WorldToCamera;
float4x4 unity_CameraToWorld;
float4x4 unity_WorldToCamera;
float4x4 unity_CameraToWorld;
float4x4 glstate_matrix_transpose_modelview0;
float4x4 glstate_matrix_transpose_modelview0;
float4x4 glstate_matrix_mvp;
float4x4 glstate_matrix_mvp;
#endif
CBUFFER_END

CBUFFER_START(UnityPerFrame)
#ifndef UNITY_SINGLE_PASS_STEREO
float4x4 glstate_matrix_projection;
float4x4 unity_MatrixV;
float4x4 unity_MatrixVP;
float4x4 glstate_matrix_projection;
float4x4 unity_MatrixV;
float4x4 unity_MatrixVP;
float4 glstate_lightmodel_ambient;
float4 unity_AmbientSky;
float4 unity_AmbientEquator;
float4 unity_AmbientGround;
float4 unity_IndirectSpecColor;
float4 glstate_lightmodel_ambient;
float4 unity_AmbientSky;
float4 unity_AmbientEquator;
float4 unity_AmbientGround;
float4 unity_IndirectSpecColor;
CBUFFER_END

float4x4 GetObjectToWorldMatrix()
{
return unity_ObjectToWorld;
return unity_ObjectToWorld;
return unity_WorldToObject;
return unity_WorldToObject;
return unity_MatrixVP;
return unity_MatrixVP;
return glstate_matrix_inv_projection;
return glstate_matrix_inv_projection;
return unity_WorldTransformParams.w;
return unity_WorldTransformParams.w;
return glstate_matrix_modelview0;
return glstate_matrix_modelview0;
return mul(GetObjectToWorldMatrix(), float4(positionOS, 1.0)).xyz;
return mul(GetObjectToWorldMatrix(), float4(positionOS, 1.0)).xyz;
return mul(GetObjectToWorldViewMatrix(), float4(positionOS, 1.0)).xyz;
return mul(GetObjectToWorldViewMatrix(), float4(positionOS, 1.0)).xyz;
// Normalize to support uniform scaling
return normalize(mul((float3x3)GetObjectToWorldMatrix(), dirOS));
// Normalize to support uniform scaling
return normalize(mul((float3x3)GetObjectToWorldMatrix(), dirOS));
}
// Transforms normal from object to world space

return UnityObjectToWorldDir(normalOS);
return UnityObjectToWorldDir(normalOS);
// Normal need to be multiply by inverse transpose
// mul(IT_M, norm) => mul(norm, I_M) => {dot(norm, I_M.col0), dot(norm, I_M.col1), dot(norm, I_M.col2)}
return normalize(mul(normalOS, (float3x3)GetWorldToObjectMatrix()));
// Normal need to be multiply by inverse transpose
// mul(IT_M, norm) => mul(norm, I_M) => {dot(norm, I_M.col0), dot(norm, I_M.col1), dot(norm, I_M.col2)}
return normalize(mul(normalOS, (float3x3)GetWorldToObjectMatrix()));
#endif
}

return mul(GetWorldToHClipMatrix(), float4(positionWS, 1.0));
return mul(GetWorldToHClipMatrix(), float4(positionWS, 1.0));
// For odd-negative scale transforms we need to flip the sign
float sign = tangentSign * GetOdddNegativeScale();
float3 bitangent = cross(normal, tangent) * sign;
return float3x3(tangent, bitangent, normal);
// For odd-negative scale transforms we need to flip the sign
float sign = tangentSign * GetOdddNegativeScale();
float3 bitangent = cross(normal, tangent) * sign;
return float3x3(tangent, bitangent, normal);
return normalize(_WorldSpaceCameraPos.xyz - positionWS);
return normalize(_WorldSpaceCameraPos.xyz - positionWS);
#endif // UNITY_SHADER_VARIABLES_INCLUDED
#endif // UNITY_SHADER_VARIABLES_INCLUDED

254
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Unlit.shader


Shader "Unity/Unlit"
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
_ColorMap("ColorMap", 2D) = "white" {}
Properties
{
_Color("Color", Color) = (1,1,1,1)
_ColorMap("ColorMap", 2D) = "white" {}
_EmissiveColor("EmissiveColor", Color) = (0, 0, 0)
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
_EmissiveIntensity("EmissiveIntensity", Float) = 0
_EmissiveColor("EmissiveColor", Color) = (0, 0, 0)
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
_EmissiveIntensity("EmissiveIntensity", Float) = 0
[ToggleOff] _DistortionOnly("Distortion Only", Float) = 0.0
[ToggleOff] _DistortionDepthTest("Distortion Only", Float) = 0.0
[ToggleOff] _DistortionOnly("Distortion Only", Float) = 0.0
[ToggleOff] _DistortionDepthTest("Distortion Only", Float) = 0.0
[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
// 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] _CullMode("__cullmode", Float) = 2.0
// 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] _CullMode("__cullmode", Float) = 2.0
[Enum(None, 0, DoubleSided)] _DoubleSidedMode("Double sided mode", Float) = 0
}
[Enum(None, 0, DoubleSided)] _DoubleSidedMode("Double sided mode", Float) = 0
}
HLSLINCLUDE
HLSLINCLUDE
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _EMISSIVE_COLOR_MAP
#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _EMISSIVE_COLOR_MAP
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl"
#define UNITY_MATERIAL_UNLIT
#include "Material/Material.hlsl"
#include "ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl"
#define UNITY_MATERIAL_UNLIT
#include "Material/Material.hlsl"
#include "ShaderVariables.hlsl"
float4 _Color;
sampler2D _ColorMap;
float4 _EmissiveColor;
sampler2D _EmissiveColorMap;
float _EmissiveIntensity;
float4 _Color;
sampler2D _ColorMap;
float4 _EmissiveColor;
sampler2D _EmissiveColorMap;
float _EmissiveIntensity;
ENDHLSL
ENDHLSL
SubShader
{
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
LOD 300
SubShader
{
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
LOD 300
// ------------------------------------------------------------------
// forward pass
Pass
{
Name "Forward" // Name is not used
Tags { "LightMode" = "ForwardUnlit" } // This will be only for transparent object based on the RenderQueue index
// ------------------------------------------------------------------
// forward pass
Pass
{
Name "Forward" // Name is not used
Tags { "LightMode" = "ForwardUnlit" } // This will be only for transparent object based on the RenderQueue index
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]
Cull [_CullMode]
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]
Cull [_CullMode]
HLSLPROGRAM
#pragma vertex VertDefault
#pragma fragment FragForward
HLSLPROGRAM
#pragma vertex VertDefault
#pragma fragment FragForward
// Forward
struct Attributes
{
float3 positionOS : POSITION;
float2 uv0 : TEXCOORD0;
};
// Forward
struct Attributes
{
float3 positionOS : POSITION;
float2 uv0 : TEXCOORD0;
};
struct Varyings
{
float4 positionHS;
float2 texCoord0;
};
struct Varyings
{
float4 positionHS;
float2 texCoord0;
};
struct PackedVaryings
{
float4 positionHS : SV_Position;
float4 interpolators[1] : TEXCOORD0;
};
struct PackedVaryings
{
float4 positionHS : SV_Position;
float4 interpolators[1] : TEXCOORD0;
};
// Function to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions
PackedVaryings PackVaryings(Varyings input)
{
PackedVaryings output;
output.positionHS = input.positionHS;
output.interpolators[0].xy = input.texCoord0.xy;
output.interpolators[0].zw = float2(0.0, 0.0);
// Function to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions
PackedVaryings PackVaryings(Varyings input)
{
PackedVaryings output;
output.positionHS = input.positionHS;
output.interpolators[0].xy = input.texCoord0.xy;
output.interpolators[0].zw = float2(0.0, 0.0);
return output;
}
return output;
}
Varyings UnpackVaryings(PackedVaryings input)
{
Varyings output;
output.positionHS = input.positionHS;
output.texCoord0.xy = input.interpolators[0].xy;
Varyings UnpackVaryings(PackedVaryings input)
{
Varyings output;
output.positionHS = input.positionHS;
output.texCoord0.xy = input.interpolators[0].xy;
return output;
}
return output;
}
PackedVaryings VertDefault(Attributes input)
{
Varyings output;
PackedVaryings VertDefault(Attributes input)
{
Varyings output;
float3 positionWS = TransformObjectToWorld(input.positionOS);
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix)
output.positionHS = TransformWorldToHClip(positionWS);
float3 positionWS = TransformObjectToWorld(input.positionOS);
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix)
output.positionHS = TransformWorldToHClip(positionWS);
output.texCoord0 = input.uv0;
output.texCoord0 = input.uv0;
return PackVaryings(output);
}
return PackVaryings(output);
}
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData)
{
surfaceData.color = tex2D(_ColorMap, input.texCoord0).rgb * _Color.rgb;
float alpha = tex2D(_ColorMap, input.texCoord0).a * _Color.rgb;
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData)
{
surfaceData.color = tex2D(_ColorMap, input.texCoord0).rgb * _Color.rgb;
float alpha = tex2D(_ColorMap, input.texCoord0).a * _Color.rgb;
#ifdef _ALPHATEST_ON
clip(alpha - _AlphaCutoff);
#endif
#ifdef _ALPHATEST_ON
clip(alpha - _AlphaCutoff);
#endif
builtinData.opacity = alpha;
builtinData.opacity = alpha;
// Builtin Data
builtinData.bakeDiffuseLighting = float3(0.0, 0.0, 0.0);
// Builtin Data
builtinData.bakeDiffuseLighting = float3(0.0, 0.0, 0.0);
#ifdef _EMISSIVE_COLOR_MAP
builtinData.emissiveColor = tex2D(_EmissiveColorMap, input.texCoord0).rgb * _EmissiveColor;
#else
builtinData.emissiveColor = _EmissiveColor;
#endif
#ifdef _EMISSIVE_COLOR_MAP
builtinData.emissiveColor = tex2D(_EmissiveColorMap, input.texCoord0).rgb * _EmissiveColor;
#else
builtinData.emissiveColor = _EmissiveColor;
#endif
builtinData.emissiveIntensity = _EmissiveIntensity;
builtinData.emissiveIntensity = _EmissiveIntensity;
builtinData.velocity = float2(0.0, 0.0);
builtinData.velocity = float2(0.0, 0.0);
builtinData.distortion = float2(0.0, 0.0);
builtinData.distortionBlur = 0.0;
}
builtinData.distortion = float2(0.0, 0.0);
builtinData.distortionBlur = 0.0;
}
#if SHADER_STAGE_FRAGMENT
#if SHADER_STAGE_FRAGMENT
float4 FragForward(PackedVaryings packedInput) : SV_Target
{
Varyings input = UnpackVaryings(packedInput);
float4 FragForward(PackedVaryings packedInput) : SV_Target
{
Varyings input = UnpackVaryings(packedInput);
SurfaceData surfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, surfaceData, builtinData);
SurfaceData surfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, surfaceData, builtinData);
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);
return float4(bsdfData.color, builtinData.opacity);
}
return float4(bsdfData.color, builtinData.opacity);
}
#endif
#endif
ENDHLSL
}
}
ENDHLSL
}
}
}

208
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.cs


namespace UnityEditor
{
internal class DisneyGGXGUI : ShaderGUI
internal class LitGUI : ShaderGUI
public enum SurfaceType
{
Opaque,
Transparent
}
public enum SurfaceType
{
Opaque,
Transparent
}
public enum BlendMode
{
Lerp,

Displacement,
}
private static class Styles
{
private static class Styles
{
public static string OptionText = "Options";
public static string SurfaceTypeText = "Surface Type";
public static string BlendModeText = "Blend Mode";

MaterialProperty emissiveColorMode = null;
MaterialProperty baseColor = null;
MaterialProperty baseColorMap = null;
MaterialProperty mettalic = null;
MaterialProperty smoothness = null;
MaterialProperty baseColorMap = null;
MaterialProperty mettalic = null;
MaterialProperty smoothness = null;
MaterialProperty specularOcclusionMap = null;
MaterialProperty normalMap = null;
MaterialProperty specularOcclusionMap = null;
MaterialProperty normalMap = null;
MaterialProperty heightMap = null;
MaterialProperty heightScale = null;
MaterialProperty heightBias = null;
MaterialProperty heightMap = null;
MaterialProperty heightScale = null;
MaterialProperty heightBias = null;
MaterialProperty emissiveColor = null;
MaterialProperty emissiveColorMap = null;
MaterialProperty emissiveIntensity = null;
MaterialProperty emissiveColor = null;
MaterialProperty emissiveColorMap = null;
MaterialProperty emissiveIntensity = null;
MaterialEditor m_MaterialEditor;
MaterialEditor m_MaterialEditor;
public void FindProperties (MaterialProperty[] props)
{
public void FindProperties (MaterialProperty[] props)
{
surfaceType = FindProperty("_SurfaceType", props);
blendMode = FindProperty("_BlendMode", props);
alphaCutoff = FindProperty("_AlphaCutoff", props);

}
public override void OnGUI (MaterialEditor materialEditor, MaterialProperty[] props)
{
FindProperties (props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
m_MaterialEditor = materialEditor;
Material material = materialEditor.target as Material;
{
FindProperties (props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
m_MaterialEditor = materialEditor;
Material material = materialEditor.target as Material;
ShaderPropertiesGUI (material);
}
ShaderPropertiesGUI (material);
}
public void ShaderPropertiesGUI (Material material)
{
// Use default labelWidth
EditorGUIUtility.labelWidth = 0f;
public void ShaderPropertiesGUI (Material material)
{
// Use default labelWidth
EditorGUIUtility.labelWidth = 0f;
// Detect any changes to the material
EditorGUI.BeginChangeCheck();
{
// Detect any changes to the material
EditorGUI.BeginChangeCheck();
{
GUILayout.Label(Styles.OptionText, EditorStyles.boldLabel);
SurfaceTypePopup();
if ((SurfaceType)surfaceType.floatValue == SurfaceType.Transparent)

m_MaterialEditor.TexturePropertySingleLine(Styles.emissiveText, emissiveColorMap, emissiveColor);
}
m_MaterialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText);
}
}
if (EditorGUI.EndChangeCheck())
{
foreach (var obj in blendMode.targets)
MaterialChanged((Material)obj);
}
}
if (EditorGUI.EndChangeCheck())
{
foreach (var obj in blendMode.targets)
MaterialChanged((Material)obj);
}
}
public override void AssignNewShaderToMaterial (Material material, Shader oldShader, Shader newShader)
{
base.AssignNewShaderToMaterial(material, oldShader, newShader);
}
public override void AssignNewShaderToMaterial (Material material, Shader oldShader, Shader newShader)
{
base.AssignNewShaderToMaterial(material, oldShader, newShader);
}
void SurfaceTypePopup()
{
EditorGUI.showMixedValue = surfaceType.hasMixedValue;
var mode = (SurfaceType)surfaceType.floatValue;
void SurfaceTypePopup()
{
EditorGUI.showMixedValue = surfaceType.hasMixedValue;
var mode = (SurfaceType)surfaceType.floatValue;
EditorGUI.BeginChangeCheck();
EditorGUI.BeginChangeCheck();
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo("Surface Type");
surfaceType.floatValue = (float)mode;
}
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo("Surface Type");
surfaceType.floatValue = (float)mode;
}
EditorGUI.showMixedValue = false;
}
EditorGUI.showMixedValue = false;
}
void BlendModePopup()
{
EditorGUI.showMixedValue = blendMode.hasMixedValue;
var mode = (BlendMode)blendMode.floatValue;
void BlendModePopup()
{
EditorGUI.showMixedValue = blendMode.hasMixedValue;
var mode = (BlendMode)blendMode.floatValue;
EditorGUI.BeginChangeCheck();
mode = (BlendMode)EditorGUILayout.Popup(Styles.BlendModeText, (int)mode, Styles.blendModeNames);
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo("Blend Mode");
blendMode.floatValue = (float)mode;
}
EditorGUI.BeginChangeCheck();
mode = (BlendMode)EditorGUILayout.Popup(Styles.BlendModeText, (int)mode, Styles.blendModeNames);
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo("Blend Mode");
blendMode.floatValue = (float)mode;
}
EditorGUI.showMixedValue = false;
}
EditorGUI.showMixedValue = false;
}
{
{
// Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation
// (MaterialProperty value might come from renderer material property block)

SetKeyword(material, "_HEIGHTMAP_AS_DISPLACEMENT", (HeightmapMode)material.GetFloat("_HeightMapMode") == HeightmapMode.Displacement);
/*
// Setup lightmap emissive flags
MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags;
if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0)
{
flags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack;
if (!shouldEmissionBeEnabled)
flags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack;
// Setup lightmap emissive flags
MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags;
if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0)
{
flags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack;
if (!shouldEmissionBeEnabled)
flags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack;
material.globalIlluminationFlags = flags;
}
material.globalIlluminationFlags = flags;
}
}
}
static bool ShouldEmissionBeEnabled(Material mat, Color color)
{
static bool ShouldEmissionBeEnabled(Material mat, Color color)
{
}
}
bool HasValidEmissiveKeyword (Material material)
{
bool HasValidEmissiveKeyword (Material material)
{
// Material animation might be out of sync with the material keyword.
// So if the emission support is disabled on the material, but the property blocks have a value that requires it, then we need to show a warning.
// (note: (Renderer MaterialPropertyBlock applies its values to emissionColorForRendering))
bool hasEmissionKeyword = material.IsKeywordEnabled ("_EMISSION");
if (!hasEmissionKeyword && ShouldEmissionBeEnabled (material, emissionColorForRendering.colorValue))
return false;
else
return true;
// Material animation might be out of sync with the material keyword.
// So if the emission support is disabled on the material, but the property blocks have a value that requires it, then we need to show a warning.
// (note: (Renderer MaterialPropertyBlock applies its values to emissionColorForRendering))
bool hasEmissionKeyword = material.IsKeywordEnabled ("_EMISSION");
if (!hasEmissionKeyword && ShouldEmissionBeEnabled (material, emissionColorForRendering.colorValue))
return false;
else
return true;
}
}
{
{
}
}
{
if (state)
m.EnableKeyword (keyword);
else
m.DisableKeyword (keyword);
}
{
if (state)
m.EnableKeyword (keyword);
else
m.DisableKeyword (keyword);
}
}
} // namespace UnityEditor

256
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateLit.hlsl


// No guard header!
#define UNITY_MATERIAL_DISNEYGGX // Need to be define before including Material.hlsl
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Lighting/Lighting.hlsl" // This include Material.hlsl
#include "ShaderVariables.hlsl"

// Forward
struct Attributes
{
float3 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 uv0 : TEXCOORD0;
float4 tangentOS : TANGENT;
float3 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 uv0 : TEXCOORD0;
float4 tangentOS : TANGENT;
float4 positionHS;
float3 positionWS;
float2 texCoord0;
float4 tangentToWorld[3]; // [3x3:tangentToWorld | 1x3:viewDirForParallax]
float4 positionHS;
float3 positionWS;
float2 texCoord0;
float4 tangentToWorld[3]; // [3x3:tangentToWorld | 1x3:viewDirForParallax]
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
FRONT_FACE_TYPE cullFace;
#endif
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
FRONT_FACE_TYPE cullFace;
#endif
float4 positionHS : SV_Position;
float4 interpolators[5] : TEXCOORD0;
float4 positionHS : SV_Position;
float4 interpolators[5] : TEXCOORD0;
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMATIC;
#endif
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMATIC;
#endif
#endif
};

PackedVaryings output;
output.positionHS = input.positionHS;
output.interpolators[0].xyz = input.positionWS.xyz;
output.interpolators[0].w = input.texCoord0.x;
output.interpolators[1] = input.tangentToWorld[0];
output.interpolators[2] = input.tangentToWorld[1];
output.interpolators[3] = input.tangentToWorld[2];
output.interpolators[4].x = input.texCoord0.y;
output.interpolators[4].yzw = float3(0.0, 0.0, 0.0);
PackedVaryings output;
output.positionHS = input.positionHS;
output.interpolators[0].xyz = input.positionWS.xyz;
output.interpolators[0].w = input.texCoord0.x;
output.interpolators[1] = input.tangentToWorld[0];
output.interpolators[2] = input.tangentToWorld[1];
output.interpolators[3] = input.tangentToWorld[2];
output.interpolators[4].x = input.texCoord0.y;
output.interpolators[4].yzw = float3(0.0, 0.0, 0.0);
return output;
return output;
Varyings output;
output.positionHS = input.positionHS;
output.positionWS.xyz = input.interpolators[0].xyz;
output.texCoord0.x = input.interpolators[0].w;
output.texCoord0.y = input.interpolators[4].x;
output.tangentToWorld[0] = input.interpolators[1];
output.tangentToWorld[1] = input.interpolators[2];
output.tangentToWorld[2] = input.interpolators[3];
Varyings output;
output.positionHS = input.positionHS;
output.positionWS.xyz = input.interpolators[0].xyz;
output.texCoord0.x = input.interpolators[0].w;
output.texCoord0.y = input.interpolators[4].x;
output.tangentToWorld[0] = input.interpolators[1];
output.tangentToWorld[1] = input.interpolators[2];
output.tangentToWorld[2] = input.interpolators[3];
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
output.cullFace = input.cullFace;
#endif
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
output.cullFace = input.cullFace;
#endif
return output;
return output;
Varyings output;
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.positionHS = TransformWorldToHClip(output.positionWS);
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.positionHS = TransformWorldToHClip(output.positionWS);
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
output.texCoord0 = input.uv0;
output.texCoord0 = input.uv0;
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w);
output.tangentToWorld[0].xyz = tangentToWorld[0];
output.tangentToWorld[1].xyz = tangentToWorld[1];
output.tangentToWorld[2].xyz = tangentToWorld[2];
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w);
output.tangentToWorld[0].xyz = tangentToWorld[0];
output.tangentToWorld[1].xyz = tangentToWorld[1];
output.tangentToWorld[2].xyz = tangentToWorld[2];
output.tangentToWorld[0].w = 0;
output.tangentToWorld[1].w = 0;
output.tangentToWorld[2].w = 0;
output.tangentToWorld[0].w = 0;
output.tangentToWorld[1].w = 0;
output.tangentToWorld[2].w = 0;
return PackVaryings(output);
return PackVaryings(output);
}

float3 TransformTangentToWorld(float3 normalTS, float4 tangentToWorld[3])
{
// TODO check: do we need to normalize ?
return normalize(mul(normalTS, float3x3(tangentToWorld[0].xyz, tangentToWorld[1].xyz, tangentToWorld[2].xyz)));
// TODO check: do we need to normalize ?
return normalize(mul(normalTS, float3x3(tangentToWorld[0].xyz, tangentToWorld[1].xyz, tangentToWorld[2].xyz)));
}
#if SHADER_STAGE_FRAGMENT

float3 baseColor = tex2D(_BaseColorMap, input.texCoord0).rgb * _BaseColor.rgb;
float3 baseColor = tex2D(_BaseColorMap, input.texCoord0).rgb * _BaseColor.rgb;
float alpha = _BaseColor.a;
float alpha = _BaseColor.a;
float alpha = tex2D(_BaseColorMap, input.texCoord0).a * _BaseColor.a;
float alpha = tex2D(_BaseColorMap, input.texCoord0).a * _BaseColor.a;
clip(alpha - _AlphaCutoff);
clip(alpha - _AlphaCutoff);
builtinData.opacity = alpha;
builtinData.opacity = alpha;
// MaskMap is Mettalic, Ambient Occlusion, (Optional) - emissive Mask, Optional - Smoothness (in alpha)
// MaskMap is Mettalic, Ambient Occlusion, (Optional) - emissive Mask, Optional - Smoothness (in alpha)
float mettalic = tex2D(_MaskMap, input.texCoord0).r;
surfaceData.ambientOcclusion = tex2D(_MaskMap, input.texCoord0).g;
float mettalic = tex2D(_MaskMap, input.texCoord0).r;
surfaceData.ambientOcclusion = tex2D(_MaskMap, input.texCoord0).g;
float mettalic = 1.0;
surfaceData.ambientOcclusion = 1.0;
float mettalic = 1.0;
surfaceData.ambientOcclusion = 1.0;
mettalic *= _Mettalic;
mettalic *= _Mettalic;
surfaceData.diffuseColor = baseColor * (1.0 - mettalic);
float f0_dieletric = 0.04;
surfaceData.specularColor = lerp(float3(f0_dieletric, f0_dieletric, f0_dieletric), baseColor, mettalic);
surfaceData.diffuseColor = baseColor * (1.0 - mettalic);
float f0_dieletric = 0.04;
surfaceData.specularColor = lerp(float3(f0_dieletric, f0_dieletric, f0_dieletric), baseColor, mettalic);
surfaceData.perceptualSmoothness = tex2D(_BaseColorMap, input.texCoord0).a;
surfaceData.perceptualSmoothness = tex2D(_BaseColorMap, input.texCoord0).a;
surfaceData.perceptualSmoothness = tex2D(_MaskMap, input.texCoord0).a;
surfaceData.perceptualSmoothness = tex2D(_MaskMap, input.texCoord0).a;
surfaceData.perceptualSmoothness = 1.0;
surfaceData.perceptualSmoothness = 1.0;
surfaceData.perceptualSmoothness *= _Smoothness;
surfaceData.perceptualSmoothness *= _Smoothness;
// TODO: Do something. For now just take alpha channel
surfaceData.specularOcclusion = tex2D(_SpecularOcclusionMap, input.texCoord0).a;
// TODO: Do something. For now just take alpha channel
surfaceData.specularOcclusion = tex2D(_SpecularOcclusionMap, input.texCoord0).a;
// Horizon Occlusion for Normal Mapped Reflections: http://marmosetco.tumblr.com/post/81245981087
//surfaceData.specularOcclusion = saturate(1.0 + horizonFade * dot(r, input.tangentToWorld[2].xyz);
// smooth it
//surfaceData.specularOcclusion *= surfaceData.specularOcclusion;
surfaceData.specularOcclusion = 1.0;
// Horizon Occlusion for Normal Mapped Reflections: http://marmosetco.tumblr.com/post/81245981087
//surfaceData.specularOcclusion = saturate(1.0 + horizonFade * dot(r, input.tangentToWorld[2].xyz);
// smooth it
//surfaceData.specularOcclusion *= surfaceData.specularOcclusion;
surfaceData.specularOcclusion = 1.0;
// TODO: think about using BC5
float3 vertexNormalWS = input.tangentToWorld[2].xyz;
// TODO: think about using BC5
float3 vertexNormalWS = input.tangentToWorld[2].xyz;
#ifdef _NORMALMAP_TANGENT_SPACE
float3 normalTS = UnpackNormalDXT5nm(tex2D(_NormalMap, input.texCoord0));
surfaceData.normalWS = TransformTangentToWorld(normalTS, input.tangentToWorld);
#else // Object space (TODO: We need to apply the world rotation here!)
surfaceData.normalWS = tex2D(_NormalMap, input.texCoord0).rgb;
#endif
#ifdef _NORMALMAP_TANGENT_SPACE
float3 normalTS = UnpackNormalDXT5nm(tex2D(_NormalMap, input.texCoord0));
surfaceData.normalWS = TransformTangentToWorld(normalTS, input.tangentToWorld);
#else // Object space (TODO: We need to apply the world rotation here!)
surfaceData.normalWS = tex2D(_NormalMap, input.texCoord0).rgb;
#endif
surfaceData.normalWS = vertexNormalWS;
surfaceData.normalWS = vertexNormalWS;
#ifdef _DOUBLESIDED_LIGHTING_FLIP
float3 oppositeNormalWS = -surfaceData.normalWS;
#else
// Mirror the normal with the plane define by vertex normal
float3 oppositeNormalWS = reflect(surfaceData.normalWS, vertexNormalWS);
#ifdef _DOUBLESIDED_LIGHTING_FLIP
float3 oppositeNormalWS = -surfaceData.normalWS;
#else
// Mirror the normal with the plane define by vertex normal
float3 oppositeNormalWS = reflect(surfaceData.normalWS, vertexNormalWS);
// TODO : Test if GetOdddNegativeScale() is necessary here in case of normal map, as GetOdddNegativeScale is take into account in CreateTangentToWorld();
surfaceData.normalWS = IS_FRONT_VFACE(input.cullFace, GetOdddNegativeScale() >= 0.0 ? surfaceData.normalWS : oppositeNormalWS, -GetOdddNegativeScale() >= 0.0 ? surfaceData.normalWS : oppositeNormalWS);
// TODO : Test if GetOdddNegativeScale() is necessary here in case of normal map, as GetOdddNegativeScale is take into account in CreateTangentToWorld();
surfaceData.normalWS = IS_FRONT_VFACE(input.cullFace, GetOdddNegativeScale() >= 0.0 ? surfaceData.normalWS : oppositeNormalWS, -GetOdddNegativeScale() >= 0.0 ? surfaceData.normalWS : oppositeNormalWS);
surfaceData.materialId = 0;
surfaceData.materialId = 0;
surfaceData.subSurfaceRadius = 1.0; // tex2D(_SubSurfaceRadiusMap, input.texCoord0).r * _SubSurfaceRadius;
surfaceData.subSurfaceRadius = 1.0; // tex2D(_SubSurfaceRadiusMap, input.texCoord0).r * _SubSurfaceRadius;
// TODO
/*
float _SubSurfaceRadius;
sampler2D _SubSurfaceRadiusMap;
float _Thickness;
sampler2D _ThicknessMap;
// TODO
/*
float _SubSurfaceRadius;
sampler2D _SubSurfaceRadiusMap;
float _Thickness;
sampler2D _ThicknessMap;
float _CoatCoverage;
sampler2D _CoatCoverageMap;
float _CoatCoverage;
sampler2D _CoatCoverageMap;
float _CoatRoughness;
sampler2D _CoatRoughnessMap;
*/
float _CoatRoughness;
sampler2D _CoatRoughnessMap;
*/
// Builtin Data
// Builtin Data
// TODO: Sample lightmap/lightprobe/volume proxy
// This should also handle projective lightmap
// Note that data input above can be use to sample into lightmap (like normal)
builtinData.bakeDiffuseLighting = tex2D(_DiffuseLightingMap, input.texCoord0).rgb;
// TODO: Sample lightmap/lightprobe/volume proxy
// This should also handle projective lightmap
// Note that data input above can be use to sample into lightmap (like normal)
builtinData.bakeDiffuseLighting = tex2D(_DiffuseLightingMap, input.texCoord0).rgb;
// If we chose an emissive color, we have a dedicated texture for it and don't use MaskMap
// If we chose an emissive color, we have a dedicated texture for it and don't use MaskMap
#ifdef _EMISSIVE_COLOR_MAP
builtinData.emissiveColor = tex2D(_EmissiveColorMap, input.texCoord0).rgb * _EmissiveColor;
#else
builtinData.emissiveColor = _EmissiveColor;
#endif
#ifdef _EMISSIVE_COLOR_MAP
builtinData.emissiveColor = tex2D(_EmissiveColorMap, input.texCoord0).rgb * _EmissiveColor;
#else
builtinData.emissiveColor = _EmissiveColor;
#endif
builtinData.emissiveColor = baseColor * tex2D(_MaskMap, input.texCoord0).bbb;
builtinData.emissiveColor = baseColor * tex2D(_MaskMap, input.texCoord0).bbb;
builtinData.emissiveColor = float3(0.0, 0.0, 0.0);
builtinData.emissiveColor = float3(0.0, 0.0, 0.0);
builtinData.emissiveIntensity = _EmissiveIntensity;
builtinData.emissiveIntensity = _EmissiveIntensity;
builtinData.velocity = float2(0.0, 0.0);
builtinData.velocity = float2(0.0, 0.0);
builtinData.distortion = float2(0.0, 0.0);
builtinData.distortionBlur = 0.0;
builtinData.distortion = float2(0.0, 0.0);
builtinData.distortionBlur = 0.0;
#endif // #if SHADER_STAGE_FRAGMENT
#endif // #if SHADER_STAGE_FRAGMENT

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


#define IS_FRONT_VFACE(VAL, FRONT, BACK) ((VAL) ? (FRONT) : (BACK))
#define CBUFFER_START(name) cbuffer name {
#define CBUFFER_END };
#define CBUFFER_END };

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


// This file assume SHADER_API_D3D11 is defined
#define UNITY_UV_STARTS_AT_TOP 1
#define UNITY_UV_STARTS_AT_TOP 1

8
Assets/ScriptableRenderLoop/ShaderLibrary/API/Validate.hlsl


// Wait for a fix from Trunk #error not supported yet
/*
#define REQUIRE_DEFINED(X_) \
#ifndef X_ \
#error X_ must be defined (in) the platform include \
#endif X_ \
#ifndef X_ \
#error X_ must be defined (in) the platform include \
#endif X_ \
REQUIRE_DEFINED(UNITY_UV_STARTS_AT_TOP)
REQUIRE_DEFINED(UNITY_REVERSED_Z)

REQUIRE_DEFINED(CBUFFER_START)
REQUIRE_DEFINED(CBUFFER_END)
*/
*/

79
Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl


float F_Schlick(float f0, float f90, float u)
{
float x = 1.0 - u;
float x5 = x * x;
x5 = x5 * x5 * x;
float x = 1.0 - u;
float x5 = x * x;
x5 = x5 * x5 * x;
return (f90 - f0) * x5 + f0; // sub mul mul mul sub mad
}

float3 F_Schlick(float3 f0, float f90, float u)
{
float x = 1.0 - u;
float x5 = x * x;
x5 = x5 * x5 * x;
return (float3(f90, f90, f90) - f0) * x5 + f0; // sub mul mul mul sub mad
float x = 1.0 - u;
float x5 = x * x;
x5 = x5 * x5 * x;
return (float3(f90, f90, f90) - f0) * x5 + f0; // sub mul mul mul sub mad
}
float3 F_Schlick(float3 f0, float u)

float D_GGX(float NdotH, float roughness)
{
roughness = max(roughness, UNITY_MIN_ROUGHNESS);
roughness = max(roughness, UNITY_MIN_ROUGHNESS);
float f = (NdotH * a2 - NdotH) * NdotH + 1.0;
float f = (NdotH * a2 - NdotH) * NdotH + 1.0;
return INV_PI * a2 / (f * f);
}

{
// TODO: Do the clamp on the artists parameter
float f = TdotH * TdotH / (roughnessT * roughnessT) + BdotH * BdotH / (roughnessB * roughnessB) + NdotH * NdotH;
return INV_PI / (roughnessT * roughnessB * f * f);
// TODO: Do the clamp on the artists parameter
float f = TdotH * TdotH / (roughnessT * roughnessT) + BdotH * BdotH / (roughnessB * roughnessB) + NdotH * NdotH;
return INV_PI / (roughnessT * roughnessB * f * f);
}
// Ref: http://jcgt.org/published/0003/02/03/paper.pdf

// Original formulation:
// lambda_v = (-1 + sqrt(a2 * (1 - NdotL2) / NdotL2 + 1)) * 0.5f;
// lambda_l = (-1 + sqrt(a2 * (1 - NdotV2) / NdotV2 + 1)) * 0.5f;
// G = 1 / (1 + lambda_v + lambda_l);
// Original formulation:
// lambda_v = (-1 + sqrt(a2 * (1 - NdotL2) / NdotL2 + 1)) * 0.5f;
// lambda_l = (-1 + sqrt(a2 * (1 - NdotV2) / NdotV2 + 1)) * 0.5f;
// G = 1 / (1 + lambda_v + lambda_l);
// Reorder code to be more optimal
half a = roughness;
half a2 = a * a;
// Reorder code to be more optimal
half a = roughness;
half a2 = a * a;
half lambdaV = NdotL * sqrt((-NdotV * a2 + NdotV) * NdotV + a2);
half lambdaL = NdotV * sqrt((-NdotL * a2 + NdotL) * NdotL + a2);
half lambdaV = NdotL * sqrt((-NdotV * a2 + NdotV) * NdotV + a2);
half lambdaL = NdotV * sqrt((-NdotL * a2 + NdotL) * NdotL + a2);
// Simplify visibility term: (2.0f * NdotL * NdotV) / ((4.0f * NdotL * NdotV) * (lambda_v + lambda_l));
return 0.5f / (lambdaV + lambdaL);
// Simplify visibility term: (2.0f * NdotL * NdotV) / ((4.0f * NdotL * NdotV) * (lambda_v + lambda_l));
return 0.5f / (lambdaV + lambdaL);
half a = roughness;
half lambdaV = NdotL * (NdotV * (1 - a) + a);
half lambdaL = NdotV * (NdotL * (1 - a) + a);
half a = roughness;
half lambdaV = NdotL * (NdotV * (1 - a) + a);
half lambdaL = NdotV * (NdotL * (1 - a) + a);
return 0.5 / (lambdaV + lambdaL);
return 0.5 / (lambdaV + lambdaL);
#endif
}

float V_SmithJointGGXAniso(float NdotL, float NdotV, float roughnessT, float roughnessB)
float V_SmithJointGGX(float3 L, float3 V, float roughnessT, float roughnessB)
// TODO
return 1.0;
half aX = roughnessT;
half aX2 = aX * aX;
half aY = roughnessB;
half aY2 = aY * aY;
half lambdaV = L.z * sqrt(aX2 * V.x * V.x + aY2 * V.y * V.y + V.z * V.z);
half lambdaL = V.z * sqrt(aX2 * L.x * L.x + aY2 * L.y * L.y + L.z * L.z);
return 0.5f / (lambdaV + lambdaL);
}
//-----------------------------------------------------------------------------

float Lambert()
{
return INV_PI;
return INV_PI;
float fd90 = 0.5 + 2 * LdotH * LdotH * perceptualRoughness;
// Two schlick fresnel term
float lightScatter = F_Schlick(1.0, fd90, NdotL);
float viewScatter = F_Schlick(1.0, fd90, NdotV);
float fd90 = 0.5 + 2 * LdotH * LdotH * perceptualRoughness;
// Two schlick fresnel term
float lightScatter = F_Schlick(1.0, fd90, NdotL);
float viewScatter = F_Schlick(1.0, fd90, NdotV);
return INV_PI * lightScatter * viewScatter;
return INV_PI * lightScatter * viewScatter;
}
#endif // UNITY_BSDF_INCLUDED

138
Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl


// Gamma20
float Gamma20ToLinear(float c)
{
return c * c;
return c * c;
return c.rgb * c.rgb;
return c.rgb * c.rgb;
return float4(Gamma20ToLinear(c.rgb), c.a);
return float4(Gamma20ToLinear(c.rgb), c.a);
return sqrt(c);
return sqrt(c);
return sqrt(c.rgb);
return sqrt(c.rgb);
return float4(LinearToGamma20(c.rgb), c.a);
return float4(LinearToGamma20(c.rgb), c.a);
return pow(c, 2.2);
return pow(c, 2.2);
return pow(c.rgb, float3(2.2, 2.2, 2.2));
return pow(c.rgb, float3(2.2, 2.2, 2.2));
return float4(Gamma22ToLinear(c.rgb), c.a);
return float4(Gamma22ToLinear(c.rgb), c.a);
return pow(c, 0.454545454545455);
return pow(c, 0.454545454545455);
return pow(c.rgb, float3(0.454545454545455, 0.454545454545455, 0.454545454545455));
return pow(c.rgb, float3(0.454545454545455, 0.454545454545455, 0.454545454545455));
return float4(LinearToGamma22(c.rgb), c.a);
return float4(LinearToGamma22(c.rgb), c.a);
float3 linearRGBLo = c / 12.92;
float3 linearRGBHi = pow((c + 0.055) / 1.055, float3(2.4, 2.4, 2.4));
float3 linearRGB = (c <= 0.04045) ? linearRGBLo : linearRGBHi;
return linearRGB;
float3 linearRGBLo = c / 12.92;
float3 linearRGBHi = pow((c + 0.055) / 1.055, float3(2.4, 2.4, 2.4));
float3 linearRGB = (c <= 0.04045) ? linearRGBLo : linearRGBHi;
return linearRGB;
return float4(SRGBToLinear(c.rgb), c.a);
return float4(SRGBToLinear(c.rgb), c.a);
float3 sRGBLo = c * 12.92;
float3 sRGBHi = (pow(c, float3(1.0/2.4, 1.0/2.4, 1.0/2.4)) * 1.055) - 0.055;
float3 sRGB = (c <= 0.0031308) ? sRGBLo : sRGBHi;
return sRGB;
float3 sRGBLo = c * 12.92;
float3 sRGBHi = (pow(c, float3(1.0/2.4, 1.0/2.4, 1.0/2.4)) * 1.055) - 0.055;
float3 sRGB = (c <= 0.0031308) ? sRGBLo : sRGBHi;
return sRGB;
return float4(LinearToSRGB(c.rgb), c.a);
return float4(LinearToSRGB(c.rgb), c.a);
}
// TODO: Seb - To verify and refit!

return c * (c * (c * 0.305306011 + 0.682171111) + 0.012522878);
return c * (c * (c * 0.305306011 + 0.682171111) + 0.012522878);
return float4(FastSRGBToLinear(c.rgb), c.a);
return float4(FastSRGBToLinear(c.rgb), c.a);
return max(1.055 * pow(c, 0.416666667) - 0.055, 0.0);
return max(1.055 * pow(c, 0.416666667) - 0.055, 0.0);
return float4(FastLinearToSRGB(c.rgb), c.a);
return float4(FastLinearToSRGB(c.rgb), c.a);
}
//-----------------------------------------------------------------------------

// with rgb in linear space with sRGB primaries and D65 white point
float Luminance(float3 linearRgb)
{
return dot(linearRgb, float3(0.2126729f, 0.7151522f, 0.0721750f));
return dot(linearRgb, float3(0.2126729f, 0.7151522f, 0.0721750f));
// M matrix, for encoding
const float3x3 M = float3x3(
0.2209, 0.3390, 0.4184,
0.1138, 0.6780, 0.7319,
0.0102, 0.1130, 0.2969);
// M matrix, for encoding
const float3x3 M = float3x3(
0.2209, 0.3390, 0.4184,
0.1138, 0.6780, 0.7319,
0.0102, 0.1130, 0.2969);
float4 vResult;
float3 Xp_Y_XYZp = mul(vRGB, M);

float3 UnpackLogLuv(float4 vLogLuv)
{
// Inverse M matrix, for decoding
const float3x3 InverseM = float3x3(
6.0014, -2.7008, -1.7996,
-1.3320, 3.1029, -5.7721,
0.3008, -1.0882, 5.6268);
// Inverse M matrix, for decoding
const float3x3 InverseM = float3x3(
6.0014, -2.7008, -1.7996,
-1.3320, 3.1029, -5.7721,
0.3008, -1.0882, 5.6268);
float Le = vLogLuv.z * 255.0 + vLogLuv.w;
float3 Xp_Y_XYZp;

// This function must handle various crappy case of lightmap ?
float4 UnityEncodeRGBM (float3 rgb, float maxRGBM)
{
float kOneOverRGBMMaxRange = 1.0 / maxRGBM;
const float kMinMultiplier = 2.0 * 1e-2;
float kOneOverRGBMMaxRange = 1.0 / maxRGBM;
const float kMinMultiplier = 2.0 * 1e-2;
float4 rgbm = float4(rgb * kOneOverRGBMMaxRange, 1.0);
rgbm.a = max(max(rgbm.r, rgbm.g), max(rgbm.b, kMinMultiplier));
rgbm.a = ceil(rgbm.a * 255.0) / 255.0;
// Division-by-zero warning from d3d9, so make compiler happy.
rgbm.a = max(rgbm.a, kMinMultiplier);
rgbm.rgb /= rgbm.a;
return rgbm;
float4 rgbm = float4(rgb * kOneOverRGBMMaxRange, 1.0);
rgbm.a = max(max(rgbm.r, rgbm.g), max(rgbm.b, kMinMultiplier));
rgbm.a = ceil(rgbm.a * 255.0) / 255.0;
// Division-by-zero warning from d3d9, so make compiler happy.
rgbm.a = max(rgbm.a, kMinMultiplier);
rgbm.rgb /= rgbm.a;
return rgbm;
}
// Alternative...

float4 rgbm;
color *= (1.0 / RGBMRANGE);
rgbm.a = saturate( max( max( color.r, color.g ), max( color.b, 1e-6 ) ) );
rgbm.a = ceil( rgbm.a * 255.0 ) / 255.0;
rgbm.rgb = color / rgbm.a;
return rgbm;
float4 rgbm;
color *= (1.0 / RGBMRANGE);
rgbm.a = saturate( max( max( color.r, color.g ), max( color.b, 1e-6 ) ) );
rgbm.a = ceil( rgbm.a * 255.0 ) / 255.0;
rgbm.rgb = color / rgbm.a;
return rgbm;
return RGBMRANGE * rgbm.rgb * rgbm.a;
return RGBMRANGE * rgbm.rgb * rgbm.a;
}
// Ref: http://www.nvidia.com/object/real-time-ycocg-dxt-compression.html

float3 YCoCg;
YCoCg.x = dot(rgb, float3(0.25, 0.5, 0.25));
YCoCg.y = dot(rgb, float3(0.5, 0.0, -0.5)) + CHROMA_BIAS;
YCoCg.z = dot(rgb, float3(-0.25, 0.5, -0.25)) + CHROMA_BIAS;
float3 YCoCg;
YCoCg.x = dot(rgb, float3(0.25, 0.5, 0.25));
YCoCg.y = dot(rgb, float3(0.5, 0.0, -0.5)) + CHROMA_BIAS;
YCoCg.z = dot(rgb, float3(-0.25, 0.5, -0.25)) + CHROMA_BIAS;
return YCoCg;
return YCoCg;
float Y = YCoCg.x;
float Co = YCoCg.y - CHROMA_BIAS;
float Cg = YCoCg.z - CHROMA_BIAS;
float Y = YCoCg.x;
float Co = YCoCg.y - CHROMA_BIAS;
float Cg = YCoCg.z - CHROMA_BIAS;
float3 rgb;
rgb.r = Y + Co - Cg;
rgb.g = Y + Cg;
rgb.b = Y - Co - Cg;
float3 rgb;
rgb.r = Y + Co - Cg;
rgb.g = Y + Cg;
rgb.b = Y - Co - Cg;
return rgb;
return rgb;
#endif // UNITY_COLOR_INCLUDED
#endif // UNITY_COLOR_INCLUDED

32
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


struct Coordinate
{
// Normalize coordinates
float2 positionSS;
// Unormalize coordinates
int2 unPositionSS;
// Normalize coordinates
float2 positionSS;
// Unormalize coordinates
int2 unPositionSS;
};
// This function is use to provide an easy way to sample into a screen texture, either from a pixel or a compute shaders.

Coordinate GetCoordinate(float2 inPositionSS, float2 invScreenSize)
{
Coordinate coord;
coord.positionSS = inPositionSS;
// TODO: How to detect automatically that we are a compute shader ?
Coordinate coord;
coord.positionSS = inPositionSS;
// TODO: How to detect automatically that we are a compute shader ?
// In case of compute shader an extra half offset is added to the screenPos to shift the integer position to pixel center.
coord.positionSS.xy += float2(0.5, 0.5);
// In case of compute shader an extra half offset is added to the screenPos to shift the integer position to pixel center.
coord.positionSS.xy += float2(0.5, 0.5);
coord.positionSS *= invScreenSize;
coord.positionSS *= invScreenSize;
coord.unPositionSS = int2(inPositionSS);
coord.unPositionSS = int2(inPositionSS);
return coord;
return coord;
}
// screenPos is screen coordinate in [0..1] (return by Coordinate.positionSS)

{
float4 positionHS = float4(screenPos.xy * 2.0 - 1.0, depth, 1.0);
float4 hpositionWS = mul(invViewProjectionMatrix, positionHS);
float4 positionHS = float4(screenPos.xy * 2.0 - 1.0, depth, 1.0);
float4 hpositionWS = mul(invViewProjectionMatrix, positionHS);
return hpositionWS.xyz / hpositionWS.w;
return hpositionWS.xyz / hpositionWS.w;
}
// Z buffer to linear 0..1 depth

return 1.0 / (zBufferParam.z * depth + zBufferParam.w);
}
#endif // UNITY_COMMON_INCLUDED
#endif // UNITY_COMMON_INCLUDED

28
Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl


// Ref: Moving Frostbite to PBR
float SmoothDistanceAttenuation(float squaredDistance, float invSqrAttenuationRadius)
{
float factor = squaredDistance * invSqrAttenuationRadius;
float smoothFactor = saturate(1.0f - factor * factor);
return smoothFactor * smoothFactor;
float factor = squaredDistance * invSqrAttenuationRadius;
float smoothFactor = saturate(1.0f - factor * factor);
return smoothFactor * smoothFactor;
}
#define PUNCTUAL_LIGHT_THRESHOLD 0.01 // 1cm (in Unity 1 is 1m)

float sqrDist = dot(unL, unL);
float attenuation = 1.0f / (max(PUNCTUAL_LIGHT_THRESHOLD * PUNCTUAL_LIGHT_THRESHOLD, sqrDist));
// Non physically based hack to limit light influence to attenuationRadius.
attenuation *= SmoothDistanceAttenuation(sqrDist, invSqrAttenuationRadius);
float sqrDist = dot(unL, unL);
float attenuation = 1.0f / (max(PUNCTUAL_LIGHT_THRESHOLD * PUNCTUAL_LIGHT_THRESHOLD, sqrDist));
// Non physically based hack to limit light influence to attenuationRadius.
attenuation *= SmoothDistanceAttenuation(sqrDist, invSqrAttenuationRadius);
return attenuation;
return attenuation;
float cd = dot(lightDir, L);
float attenuation = saturate(cd * lightAngleScale + lightAngleOffset);
// smooth the transition
attenuation *= attenuation;
float cd = dot(lightDir, L);
float attenuation = saturate(cd * lightAngleScale + lightAngleOffset);
// smooth the transition
attenuation *= attenuation;
return attenuation;
return attenuation;
#endif // UNITY_COMMON_LIGHTING_INCLUDED
#endif // UNITY_COMMON_LIGHTING_INCLUDED

12
Assets/ScriptableRenderLoop/ShaderLibrary/Filtering.hlsl


float2 w2 = (1.0f / 6.0) * (-9.0 * f3 + 12.0 * f2 + 3.0 * f);
float2 w3 = (1.0f / 6.0) * (3.0 * f3 - 3.0 * f2);
// Otim by Vlad, to test
// float2 w0 = (1.0 / 2.0) * f * (-1.0 + f * (2.0 - f));
// float2 w1 = (1.0 / 6.0) * f2 * (-15.0 + 9.0 * f)) + 1.0;
// float2 w2 = (1.0 / 6.0) * f * (3.0 + f * (12.0 - f * 9.0));
// float2 w3 = (1.0 / 2.0) * f2 * (f - 1.0);
// Otim by Vlad, to test
// float2 w0 = (1.0 / 2.0) * f * (-1.0 + f * (2.0 - f));
// float2 w1 = (1.0 / 6.0) * f2 * (-15.0 + 9.0 * f)) + 1.0;
// float2 w2 = (1.0 / 6.0) * f * (3.0 + f * (12.0 - f * 9.0));
// float2 w3 = (1.0 / 2.0) * f2 * (f - 1.0);
// Work out weighting factors and sampling offsets that will let us use bilinear filtering to
// simultaneously evaluate the middle 2 samples from the 4x4 grid.

texture3D( samp, (qi+vec3(1.0,1.0,1.0))*oneOverUvMapSize ), qa.x ), qa.y ), qa.z );
}
*/
*/

134
Assets/ScriptableRenderLoop/ShaderLibrary/Packing.hlsl


float3 PackNormalCartesian(float3 n)
{
return n * 0.5 + 0.5;
return n * 0.5 + 0.5;
return normalize(n * 2.0 - 1.0);
return normalize(n * 2.0 - 1.0);
// TODO: use max3
return (n / max(abs(n.x), max(abs(n.y), abs(n.z)))) * 0.5 + 0.5;
// TODO: use max3
return (n / max(abs(n.x), max(abs(n.y), abs(n.z)))) * 0.5 + 0.5;
return normalize(n * 2.0 - 1.0);
return normalize(n * 2.0 - 1.0);
}
// Ref: http://jcgt.org/published/0003/02/01/paper.pdf

{
float l1norm = abs(n.x) + abs(n.y) + abs(n.z);
float2 res0 = n.xy * (1.0 / l1norm);
float l1norm = abs(n.x) + abs(n.y) + abs(n.z);
float2 res0 = n.xy * (1.0 / l1norm);
float2 val = 1.0 - abs(res0.yx);
return (n.zz < float2(0.0, 0.0) ? (res0 >= 0.0 ? val : -val) : res0);
float2 val = 1.0 - abs(res0.yx);
return (n.zz < float2(0.0, 0.0) ? (res0 >= 0.0 ? val : -val) : res0);
float3 n = float3(f.x, f.y, 1.0 - abs(f.x) - abs(f.y));
float3 n = float3(f.x, f.y, 1.0 - abs(f.x) - abs(f.y));
float2 val = 1.0 - abs(n.yx);
n.xy = (n.zz < float2(0.0, 0.0) ? (n.xy >= 0.0 ? val : -val) : n.xy);
float2 val = 1.0 - abs(n.yx);
n.xy = (n.zz < float2(0.0, 0.0) ? (n.xy >= 0.0 ? val : -val) : n.xy);
return normalize(n);
return normalize(n);
float3 normal;
normal.xy = packednormal.wy * 2.0 - 1.0;
normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
return normal;
float3 normal;
normal.xy = packednormal.wy * 2.0 - 1.0;
normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
return normal;
}
//-----------------------------------------------------------------------------

// This is GCN intrinsic
uint FindBiggestComponent(float4 q)
{
uint xyzIndex = CubeMapFaceID(q.x, q.y, q.z) * 0.5f;
uint wIndex = 3;
uint xyzIndex = CubeMapFaceID(q.x, q.y, q.z) * 0.5f;
uint wIndex = 3;
bool wBiggest = abs(q.w) > max3(abs(q.x), qbs(q.y), qbs(q.z));
bool wBiggest = abs(q.w) > max3(abs(q.x), qbs(q.y), qbs(q.z));
return wBiggest ? wIndex : xyzIndex;
return wBiggest ? wIndex : xyzIndex;
uint index = FindBiggestComponent(quat);
uint index = FindBiggestComponent(quat);
if (index == 0) quat = quat.yzwx;
if (index == 1) quat = quat.xzwy;
if (index == 2) quat = quat.xywz;
if (index == 0) quat = quat.yzwx;
if (index == 1) quat = quat.xzwy;
if (index == 2) quat = quat.xywz;
float4 packedQuat;
packedQuat.xyz = quat.xyz * sign(quat.w) * sqrt(0.5) + 0.5;
packedQuat.w = index / 3.0;
float4 packedQuat;
packedQuat.xyz = quat.xyz * sign(quat.w) * sqrt(0.5) + 0.5;
packedQuat.w = index / 3.0;
return packedQuat;
return packedQuat;
}
*/

uint index = (uint)(packedQuat.w * 3.0);
uint index = (uint)(packedQuat.w * 3.0);
float4 quat;
quat.xyz = packedQuat.xyz * sqrt(2.0) - (1.0 / sqrt(2.0));
quat.w = sqrt(1.0 - saturate(dot(quat.xyz, quat.xyz)));
float4 quat;
quat.xyz = packedQuat.xyz * sqrt(2.0) - (1.0 / sqrt(2.0));
quat.w = sqrt(1.0 - saturate(dot(quat.xyz, quat.xyz)));
if (index == 0) quat = quat.wxyz;
if (index == 1) quat = quat.xwyz;
if (index == 2) quat = quat.xywz;
if (index == 0) quat = quat.wxyz;
if (index == 1) quat = quat.xwyz;
if (index == 2) quat = quat.xywz;
return quat;
return quat;
}
//-----------------------------------------------------------------------------

float Pack2Byte(float2 inputs)
{
float2 temp = inputs * float2(255.0, 255.0);
temp.x *= 256.0;
temp = round(temp);
float combined = temp.x + temp.y;
return combined * (1.0 / 65535.0);
float2 temp = inputs * float2(255.0, 255.0);
temp.x *= 256.0;
temp = round(temp);
float combined = temp.x + temp.y;
return combined * (1.0 / 65535.0);
float temp = round(inputs * 65535.0);
float ipart;
float fpart = modf(temp / 256.0, ipart);
float2 result = float2(ipart, round(256.0 * fpart));
return result * (1.0 / float2(255.0, 255.0));
float temp = round(inputs * 65535.0);
float ipart;
float fpart = modf(temp / 256.0, ipart);
float2 result = float2(ipart, round(256.0 * fpart));
return result * (1.0 / float2(255.0, 255.0));
}
// Encode a float in [0..1] and an int in [0..maxi - 1] as a float [0..1] to be store in log2(precision) bit

//...
float PackFloatInt(float f, int i, float maxi, float precision)
{
// Constant
float precisionMinusOne = precision - 1.0;
float t1 = ((precision / maxi) - 1.0) / precisionMinusOne;
float t2 = (precision / maxi) / precisionMinusOne;
// Constant
float precisionMinusOne = precision - 1.0;
float t1 = ((precision / maxi) - 1.0) / precisionMinusOne;
float t2 = (precision / maxi) / precisionMinusOne;
return t1 * f + t2 * float(i);
return t1 * f + t2 * float(i);
// Constant
float precisionMinusOne = precision - 1.0;
float t1 = ((precision / maxi) - 1.0) / precisionMinusOne;
float t2 = (precision / maxi) / precisionMinusOne;
// Constant
float precisionMinusOne = precision - 1.0;
float t1 = ((precision / maxi) - 1.0) / precisionMinusOne;
float t2 = (precision / maxi) / precisionMinusOne;
// extract integer part
i = int(val / t2);
// Now that we have i, solve formula in PackFloatInt for f
//f = (val - t2 * float(i)) / t1 => convert in mads form
f = (-t2 * float(i) + val) / t1;
// extract integer part
i = int(val / t2);
// Now that we have i, solve formula in PackFloatInt for f
//f = (val - t2 * float(i)) / t1 => convert in mads form
f = (-t2 * float(i) + val) / t1;
return PackFloatInt(f, i, maxi, 255.0);
return PackFloatInt(f, i, maxi, 255.0);
UnpackFloatInt(val, maxi, 255.0, f, i);
UnpackFloatInt(val, maxi, 255.0, f, i);
return PackFloatInt(f, i, maxi, 1024.0);
return PackFloatInt(f, i, maxi, 1024.0);
UnpackFloatInt(val, maxi, 1024.0, f, i);
UnpackFloatInt(val, maxi, 1024.0, f, i);
return PackFloatInt(f, i, maxi, 65536.0);
return PackFloatInt(f, i, maxi, 65536.0);
UnpackFloatInt(val, maxi, 65536.0, f, i);
UnpackFloatInt(val, maxi, 65536.0, f, i);
}
#endif // UNITY_PACKING_INCLUDED

30
Assets/ScriptableRenderLoop/ShaderLibrary/QuaternionMath.hlsl


float4 TangentSpaceToQuat(float3 tagent, float3 bitangent, float3 normal)
{
float4 quat;
quat.x = normal.y - bitangent.z;
quat.y = tangent.z - normal.x;
quat.z = bitangent.x - tangent.y;
quat.w = 1.0 + tangent.x + bitangent.y + normal.z;
float4 quat;
quat.x = normal.y - bitangent.z;
quat.y = tangent.z - normal.x;
quat.z = bitangent.x - tangent.y;
quat.w = 1.0 + tangent.x + bitangent.y + normal.z;
return normalize(quat);
return normalize(quat);
tangent = float3(1.0, 0.0, 0.0)
+ float3(-2.0, 2.0, 2.0) * quat.y * quat.yxw
+ float3(-2.0, -2.0, 2.0) * quat.z * quaternion.zwx;
tangent = float3(1.0, 0.0, 0.0)
+ float3(-2.0, 2.0, 2.0) * quat.y * quat.yxw
+ float3(-2.0, -2.0, 2.0) * quat.z * quaternion.zwx;
bitangent = float3(0.0, 1.0, 0.0)
+ float3(2.0, -2.0, 2.0) * quat.z * quat.wzy
+ float3(2.0, -2.0, -2.0) * quat.x * quaternion.yxw;
bitangent = float3(0.0, 1.0, 0.0)
+ float3(2.0, -2.0, 2.0) * quat.z * quat.wzy
+ float3(2.0, -2.0, -2.0) * quat.x * quaternion.yxw;
normal = float3(0.0, 0.0, 1.0)
+ float3(2.0, 2.0, -2.0) * quat.x * quat.zwx
+ float3(-2.0, 2.0, -2.0) * quat.y * quaternion.wzy;
normal = float3(0.0, 0.0, 1.0)
+ float3(2.0, 2.0, -2.0) * quat.x * quat.zwx
+ float3(-2.0, 2.0, -2.0) * quat.y * quaternion.wzy;
}
#endif // UNITY_QUATERNIONMATH_INCLUDED

12
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.cs.meta


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

284
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.shader


Shader "Unity/Lit"
{
Properties
{
// Following set of parameters represent the parameters node inside the MaterialGraph.
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist.
// Reminder. Color here are in linear but the UI (color picker) do the conversion sRGB to linear
_BaseColor("BaseColor", Color) = (1,1,1,1)
_BaseColorMap("BaseColorMap", 2D) = "white" {}
_Mettalic("Mettalic", Range(0.0, 1.0)) = 0
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
_MaskMap("MaskMap", 2D) = "white" {}
_SpecularOcclusionMap("SpecularOcclusion", 2D) = "white" {}
_NormalMap("NormalMap", 2D) = "bump" {}
[Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace("NormalMap space", Float) = 0
_HeightMap("HeightMap", 2D) = "black" {}
_HeightScale("Height Scale", Float) = 1
_HeightBias("Height Bias", Float) = 0
[Enum(Parallax, 0, Displacement, 1)] _HeightMapMode("Heightmap usage", Float) = 0
_SubSurfaceRadius("SubSurfaceRadius", Range(0.0, 1.0)) = 0
_SubSurfaceRadiusMap("SubSurfaceRadiusMap", 2D) = "white" {}
//_Thickness("Thickness", Range(0.0, 1.0)) = 0
//_ThicknessMap("ThicknessMap", 2D) = "white" {}
//_SubSurfaceProfile("SubSurfaceProfile", Float) = 0
//_CoatCoverage("CoatCoverage", Range(0.0, 1.0)) = 0
//_CoatCoverageMap("CoatCoverageMapMap", 2D) = "white" {}
//_CoatRoughness("CoatRoughness", Range(0.0, 1.0)) = 0
//_CoatRoughnessMap("CoatRoughnessMap", 2D) = "white" {}
// _DistortionVectorMap("DistortionVectorMap", 2D) = "white" {}
// _DistortionBlur("DistortionBlur", Range(0.0, 1.0)) = 0
// Following options are for the GUI inspector and different from the input parameters above
// These option below will cause different compilation flag.
_DiffuseLightingMap("DiffuseLightingMap", 2D) = "black" {}
_EmissiveColor("EmissiveColor", Color) = (0, 0, 0)
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
_EmissiveIntensity("EmissiveIntensity", Float) = 0
[ToggleOff] _DistortionOnly("Distortion Only", Float) = 0.0
[ToggleOff] _DistortionDepthTest("Distortion Only", Float) = 0.0
[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
// 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] _CullMode("__cullmode", Float) = 2.0
// Material Id
[HideInInspector] _MaterialId("_MaterialId", FLoat) = 0
[Enum(Mask Alpha, 0, BaseColor Alpha, 1)] _SmoothnessTextureChannel("Smoothness texture channel", Float) = 1
[Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1
[Enum(None, 0, DoubleSided, 1, DoubleSidedLigthingFlip, 2, DoubleSidedLigthingMirror, 3)] _DoubleSidedMode("Double sided mode", Float) = 0
}
HLSLINCLUDE
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _ _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
#pragma shader_feature _NORMALMAP
#pragma shader_feature _NORMALMAP_TANGENT_SPACE
#pragma shader_feature _MASKMAP
#pragma shader_feature _SPECULAROCCLUSIONMAP
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _EMISSIVE_COLOR
#pragma shader_feature _EMISSIVE_COLOR_MAP
#pragma shader_feature _HEIGHTMAP
#pragma shader_feature _HEIGHTMAP_AS_DISPLACEMENT
#include "TemplateLit.hlsl"
ENDHLSL
SubShader
{
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
LOD 300
// ------------------------------------------------------------------
// Deferred pass
Pass
{
Name "GBuffer" // Name is not used
Tags { "LightMode" = "GBuffer" } // This will be only for opaque object based on the RenderQueue index
Cull [_CullMode]
HLSLPROGRAM
#pragma vertex VertDefault
#pragma fragment FragDeferred
#if SHADER_STAGE_FRAGMENT
void FragDeferred( PackedVaryings packedInput,
OUTPUT_GBUFFER(outGBuffer)
#ifdef VELOCITY_IN_GBUFFER
, OUTPUT_GBUFFER_VELOCITY(outGBuffer)
#endif
, OUTPUT_GBUFFER_BAKE_LIGHTING(outGBuffer)
)
{
Varyings input = UnpackVaryings(packedInput);
SurfaceData surfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, surfaceData, builtinData);
ENCODE_INTO_GBUFFER(surfaceData, outGBuffer);
#ifdef VELOCITY_IN_GBUFFER
ENCODE_VELOCITY_INTO_GBUFFER(builtinData.velocity, outGBuffer);
#endif
ENCODE_BAKE_LIGHTING_INTO_GBUFFER(GetBakedDiffuseLigthing(surfaceData, builtinData), outGBuffer);
}
#endif
ENDHLSL
}
// ------------------------------------------------------------------
// Debug pass
Pass
{
Name "Debug"
Tags { "LightMode" = "Debug" }
Cull[_CullMode]
HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma vertex VertDefault
#pragma fragment FragDebug
int g_MaterialDebugMode;
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugCommon.hlsl"
#if SHADER_STAGE_FRAGMENT
float4 FragDebug( PackedVaryings packedInput ) : SV_Target
{
Varyings input = UnpackVaryings(packedInput);
SurfaceData surfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, surfaceData, builtinData);
float3 result = float3(1.0, 1.0, 0.0);
bool outputIsLinear = false;
if(g_MaterialDebugMode == MaterialDebugDiffuseColor)
{
result = surfaceData.diffuseColor;
}
else if (g_MaterialDebugMode == MaterialDebugNormal)
{
result = surfaceData.normalWS * 0.5 + 0.5;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugDepth)
{
float linearDepth = frac(LinearEyeDepth(input.positionHS.z, _ZBufferParams) * 0.1);
result = linearDepth.xxx;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugAO)
{
result = surfaceData.ambientOcclusion.xxx;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugSpecularColor)
{
result = surfaceData.specularColor;
}
else if (g_MaterialDebugMode == MaterialDebugSpecularOcclusion)
{
result = surfaceData.specularOcclusion.xxx;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugSmoothness)
{
result = surfaceData.perceptualSmoothness.xxx;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugMaterialId)
{
result = surfaceData.materialId.xxx;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugUV0)
{
result = float3(input.texCoord0, 0.0);
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugTangent)
{
result = input.tangentToWorld[0].xyz * 0.5 + 0.5;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugBitangent)
{
result = input.tangentToWorld[1].xyz * 0.5 + 0.5;
outputIsLinear = true;
}
// For now, the final blit in the backbuffer performs an sRGB write
// So in the meantime we apply the inverse transform to linear data to compensate.
if(outputIsLinear)
result = SRGBToLinear(max(0, result));
return float4(result, 0.0);
}
#endif
ENDHLSL
}
// ------------------------------------------------------------------
// forward pass
Pass
{
Name "Forward" // Name is not used
Tags { "LightMode" = "Forward" } // This will be only for transparent object based on the RenderQueue index
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]
Cull [_CullMode]
HLSLPROGRAM
#pragma vertex VertDefault
#pragma fragment FragForward
#if SHADER_STAGE_FRAGMENT
float4 FragForward(PackedVaryings packedInput) : SV_Target
{
Varyings input = UnpackVaryings(packedInput);
float3 V = GetWorldSpaceNormalizeViewDir(input.positionWS);
float3 positionWS = input.positionWS;
SurfaceData surfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, surfaceData, builtinData);
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);
float4 diffuseLighting;
float4 specularLighting;
ForwardLighting(V, positionWS, bsdfData, diffuseLighting, specularLighting);
diffuseLighting.rgb += GetBakedDiffuseLigthing(surfaceData, builtinData);
return float4(diffuseLighting.rgb + specularLighting.rgb, builtinData.opacity);
}
#endif
ENDHLSL
}
}
CustomEditor "LitGUI"
}

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.shader.meta


fileFormatVersion: 2
guid: e7e3743f30ad81a4ba2d0528f52d026b
timeCreated: 1475845772
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

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


fileFormatVersion: 2
guid: 103bcc6c90ed7124f8474d354c0171ba
timeCreated: 1475845771
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateLit.hlsl.meta


fileFormatVersion: 2
guid: f69e98902bfd77a48ab69e05b54c09a5
timeCreated: 1475845771
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

8
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/DisneyGGX.hlsl.meta


fileFormatVersion: 2
guid: 3d0985c9290aa0847969ac858555e87a
timeCreated: 1474465931
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.shader.meta


fileFormatVersion: 2
guid: e1a84346ee54f9f4993c2f05c59805a0
timeCreated: 1474456127
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

8
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl.meta


fileFormatVersion: 2
guid: bc4a80ef70e37814e94ea45fc03abdaa
timeCreated: 1474456127
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

12
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.cs.meta


fileFormatVersion: 2
guid: 5a4257d1b13e9cf4d877271cc4ef55ec
timeCreated: 1475450550
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

284
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.shader


Shader "Unity/DisneyGGX"
{
Properties
{
// Following set of parameters represent the parameters node inside the MaterialGraph.
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist.
// Reminder. Color here are in linear but the UI (color picker) do the conversion sRGB to linear
_BaseColor("BaseColor", Color) = (1,1,1,1)
_BaseColorMap("BaseColorMap", 2D) = "white" {}
_Mettalic("Mettalic", Range(0.0, 1.0)) = 0
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
_MaskMap("MaskMap", 2D) = "white" {}
_SpecularOcclusionMap("SpecularOcclusion", 2D) = "white" {}
_NormalMap("NormalMap", 2D) = "bump" {}
[Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace("NormalMap space", Float) = 0
_HeightMap("HeightMap", 2D) = "black" {}
_HeightScale("Height Scale", Float) = 1
_HeightBias("Height Bias", Float) = 0
[Enum(Parallax, 0, Displacement, 1)] _HeightMapMode("Heightmap usage", Float) = 0
_SubSurfaceRadius("SubSurfaceRadius", Range(0.0, 1.0)) = 0
_SubSurfaceRadiusMap("SubSurfaceRadiusMap", 2D) = "white" {}
//_Thickness("Thickness", Range(0.0, 1.0)) = 0
//_ThicknessMap("ThicknessMap", 2D) = "white" {}
//_SubSurfaceProfile("SubSurfaceProfile", Float) = 0
//_CoatCoverage("CoatCoverage", Range(0.0, 1.0)) = 0
//_CoatCoverageMap("CoatCoverageMapMap", 2D) = "white" {}
//_CoatRoughness("CoatRoughness", Range(0.0, 1.0)) = 0
//_CoatRoughnessMap("CoatRoughnessMap", 2D) = "white" {}
// _DistortionVectorMap("DistortionVectorMap", 2D) = "white" {}
// _DistortionBlur("DistortionBlur", Range(0.0, 1.0)) = 0
// Following options are for the GUI inspector and different from the input parameters above
// These option below will cause different compilation flag.
_DiffuseLightingMap("DiffuseLightingMap", 2D) = "black" {}
_EmissiveColor("EmissiveColor", Color) = (0, 0, 0)
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
_EmissiveIntensity("EmissiveIntensity", Float) = 0
[ToggleOff] _DistortionOnly("Distortion Only", Float) = 0.0
[ToggleOff] _DistortionDepthTest("Distortion Only", Float) = 0.0
[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
// 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] _CullMode("__cullmode", Float) = 2.0
// Material Id
[HideInInspector] _MaterialId("_MaterialId", FLoat) = 0
[Enum(Mask Alpha, 0, BaseColor Alpha, 1)] _SmoothnessTextureChannel("Smoothness texture channel", Float) = 1
[Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1
[Enum(None, 0, DoubleSided, 1, DoubleSidedLigthingFlip, 2, DoubleSidedLigthingMirror, 3)] _DoubleSidedMode("Double sided mode", Float) = 0
}
HLSLINCLUDE
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _ _DOUBLESIDED_LIGHTING_FLIP _DOUBLESIDED_LIGHTING_MIRROR
#pragma shader_feature _NORMALMAP
#pragma shader_feature _NORMALMAP_TANGENT_SPACE
#pragma shader_feature _MASKMAP
#pragma shader_feature _SPECULAROCCLUSIONMAP
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _EMISSIVE_COLOR
#pragma shader_feature _EMISSIVE_COLOR_MAP
#pragma shader_feature _HEIGHTMAP
#pragma shader_feature _HEIGHTMAP_AS_DISPLACEMENT
#include "TemplateDisneyGGX.hlsl"
ENDHLSL
SubShader
{
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
LOD 300
// ------------------------------------------------------------------
// forward pass
Pass
{
Name "Forward" // Name is not used
Tags { "LightMode" = "Forward" } // This will be only for transparent object based on the RenderQueue index
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]
Cull [_CullMode]
HLSLPROGRAM
#pragma vertex VertDefault
#pragma fragment FragForward
#if SHADER_STAGE_FRAGMENT
float4 FragForward(PackedVaryings packedInput) : SV_Target
{
Varyings input = UnpackVaryings(packedInput);
float3 V = GetWorldSpaceNormalizeViewDir(input.positionWS);
float3 positionWS = input.positionWS;
SurfaceData surfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, surfaceData, builtinData);
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);
float4 diffuseLighting;
float4 specularLighting;
ForwardLighting(V, positionWS, bsdfData, diffuseLighting, specularLighting);
diffuseLighting.rgb += GetBakedDiffuseLigthing(surfaceData, builtinData);
return float4(diffuseLighting.rgb + specularLighting.rgb, builtinData.opacity);
}
#endif
ENDHLSL
}
// ------------------------------------------------------------------
// Deferred pass
Pass
{
Name "GBuffer" // Name is not used
Tags { "LightMode" = "GBuffer" } // This will be only for opaque object based on the RenderQueue index
Cull [_CullMode]
HLSLPROGRAM
#pragma vertex VertDefault
#pragma fragment FragDeferred
#if SHADER_STAGE_FRAGMENT
void FragDeferred( PackedVaryings packedInput,
OUTPUT_GBUFFER(outGBuffer)
#ifdef VELOCITY_IN_GBUFFER
, OUTPUT_GBUFFER_VELOCITY(outGBuffer)
#endif
, OUTPUT_GBUFFER_BAKE_LIGHTING(outGBuffer)
)
{
Varyings input = UnpackVaryings(packedInput);
SurfaceData surfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, surfaceData, builtinData);
ENCODE_INTO_GBUFFER(surfaceData, outGBuffer);
#ifdef VELOCITY_IN_GBUFFER
ENCODE_VELOCITY_INTO_GBUFFER(builtinData.velocity, outGBuffer);
#endif
ENCODE_BAKE_LIGHTING_INTO_GBUFFER(GetBakedDiffuseLigthing(surfaceData, builtinData), outGBuffer);
}
#endif
ENDHLSL
}
// ------------------------------------------------------------------
// Debug pass
Pass
{
Name "Debug"
Tags { "LightMode" = "Debug" }
Cull[_CullMode]
HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma vertex VertDefault
#pragma fragment FragDebug
int g_MaterialDebugMode;
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugCommon.hlsl"
#if SHADER_STAGE_FRAGMENT
float4 FragDebug( PackedVaryings packedInput ) : SV_Target
{
Varyings input = UnpackVaryings(packedInput);
SurfaceData surfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, surfaceData, builtinData);
float3 result = float3(1.0, 1.0, 0.0);
bool outputIsLinear = false;
if(g_MaterialDebugMode == MaterialDebugDiffuseColor)
{
result = surfaceData.diffuseColor;
}
else if (g_MaterialDebugMode == MaterialDebugNormal)
{
result = surfaceData.normalWS * 0.5 + 0.5;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugDepth)
{
float linearDepth = frac(LinearEyeDepth(input.positionHS.z, _ZBufferParams) * 0.1);
result = linearDepth.xxx;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugAO)
{
result = surfaceData.ambientOcclusion.xxx;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugSpecularColor)
{
result = surfaceData.specularColor;
}
else if (g_MaterialDebugMode == MaterialDebugSpecularOcclusion)
{
result = surfaceData.specularOcclusion.xxx;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugSmoothness)
{
result = surfaceData.perceptualSmoothness.xxx;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugMaterialId)
{
result = surfaceData.materialId.xxx;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugUV0)
{
result = float3(input.texCoord0, 0.0);
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugTangent)
{
result = input.tangentToWorld[0].xyz * 0.5 + 0.5;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugBitangent)
{
result = input.tangentToWorld[1].xyz * 0.5 + 0.5;
outputIsLinear = true;
}
// For now, the final blit in the backbuffer performs an sRGB write
// So in the meantime we apply the inverse transform to linear data to compensate.
if(outputIsLinear)
result = SRGBToLinear(max(0, result));
return float4(result, 0.0);
}
#endif
ENDHLSL
}
}
CustomEditor "DisneyGGXGUI"
}

/Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/DisneyGGX.hlsl → /Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.hlsl

/Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.cs → /Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.cs

/Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl → /Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateLit.hlsl

正在加载...
取消
保存