浏览代码

Merge pull request #2 from Unity-Technologies/ShaderLibrary

Merge Shaderlibrary
/main
GitHub 8 年前
当前提交
87679324
共有 87 个文件被更改,包括 2981 次插入296 次删除
  1. 4
      Assets/ScriptableRenderLoop/fptl/Internal-DeferredReflections.shader
  2. 381
      Assets/TestScenes/ForwardRenderLoop/ForwardRenderLoop.unity
  3. 32
      Assets/TestScenes/ForwardRenderLoop/Materials/gray.mat
  4. 3
      ProjectSettings/ProjectVersion.txt
  5. 14
      ProjectSettings/UnityConnectSettings.asset
  6. 13
      Assets/HDRenderLoop.asset
  7. 8
      Assets/HDRenderLoop.asset.meta
  8. 9
      Assets/ScriptableRenderLoop/HDRenderLoop.meta
  9. 9
      Assets/ScriptableRenderLoop/ShaderLibrary.meta
  10. 12
      Assets/ScriptableRenderLoop/common/SkyboxHelper.cs.meta
  11. 12
      Assets/ScriptableRenderLoop/common/TextureSettings.cs.meta
  12. 9
      Assets/ScriptableRenderLoop/fptl/FinalPass.shader.meta
  13. 9
      Assets/TestScenes/HDTest.meta
  14. 13
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset
  15. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset.meta
  16. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs.meta
  17. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders.meta
  18. 596
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  19. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting.meta
  20. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material.meta
  21. 224
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl
  22. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl.meta
  23. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl.meta
  24. 30
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/CommonMaterial.hlsl
  25. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/CommonMaterial.hlsl.meta
  26. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/DisneyGGX.hlsl.meta
  27. 140
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/DisneyGGX.hlsl
  28. 68
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl
  29. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.shader.meta
  30. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl.meta
  31. 53
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LightDefinition.cs
  32. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LightDefinition.cs.meta
  33. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/PostProcess.meta
  34. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/PostProcess/FinalPass.shader.meta
  35. 48
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/PostProcess/FinalPass.shader
  36. 104
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.shader
  37. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl.meta
  38. 41
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingForward.hlsl
  39. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingForward.hlsl.meta
  40. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.hlsl.meta
  41. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.shader.meta
  42. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl
  43. 0
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.hlsl
  44. 82
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.shader
  45. 138
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl
  46. 9
      Assets/ScriptableRenderLoop/ShaderLibrary/API.meta
  47. 8
      Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl.meta
  48. 3
      Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11_1.hlsl
  49. 8
      Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11_1.hlsl.meta
  50. 9
      Assets/ScriptableRenderLoop/ShaderLibrary/API/Validate.hlsl.meta
  51. 5
      Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl
  52. 13
      Assets/ScriptableRenderLoop/ShaderLibrary/API/Validate.hlsl
  53. 109
      Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl
  54. 8
      Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl.meta
  55. 203
      Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl
  56. 8
      Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl.meta
  57. 8
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl.meta
  58. 6
      Assets/ScriptableRenderLoop/ShaderLibrary/GeometricTools.hlsl
  59. 8
      Assets/ScriptableRenderLoop/ShaderLibrary/GeometricTools.hlsl.meta
  60. 85
      Assets/ScriptableRenderLoop/ShaderLibrary/Packing.hlsl
  61. 8
      Assets/ScriptableRenderLoop/ShaderLibrary/Packing.hlsl.meta
  62. 6
      Assets/ScriptableRenderLoop/ShaderLibrary/QuaternionMath.hlsl
  63. 8
      Assets/ScriptableRenderLoop/ShaderLibrary/QuaternionMath.hlsl.meta
  64. 6
      Assets/ScriptableRenderLoop/ShaderLibrary/SHMath.hlsl
  65. 8
      Assets/ScriptableRenderLoop/ShaderLibrary/SHMath.hlsl.meta
  66. 6
      Assets/ScriptableRenderLoop/ShaderLibrary/Sampling.hlsl
  67. 8
      Assets/ScriptableRenderLoop/ShaderLibrary/Sampling.hlsl.meta
  68. 82
      Assets/ScriptableRenderLoop/ShaderLibrary/Filtering.hlsl
  69. 8
      Assets/ScriptableRenderLoop/ShaderLibrary/Filtering.hlsl.meta
  70. 38
      Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl
  71. 8
      Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl.meta
  72. 9
      Assets/ScriptableRenderLoop/ShaderLibrary/Postprocress.meta
  73. 175
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
  74. 160
      Assets/TestScenes/HDTest/Material/test.mat
  75. 8
      Assets/TestScenes/HDTest/Material/test.mat.meta
  76. 9
      Assets/TestScenes/HDTest/Material.meta
  77. 9
      Assets/TestScenes/ForwardRenderLoop/ForwardRenderLoop.meta
  78. 11
      ProjectSettings/UnityAdsSettings.asset

4
Assets/ScriptableRenderLoop/fptl/Internal-DeferredReflections.shader


sampleDir = worldNormalRefl;
Unity_GlossyEnvironmentData g;
g.perceptualRoughness = SmoothnessToPerceptualRoughness(data.smoothness);
g.roughness = SmoothnessToPerceptualRoughness(data.smoothness);
g.reflUVW = sampleDir;
half3 env0 = Unity_GlossyEnvironment(UNITY_PASS_TEXCUBEARRAY(_reflCubeTextures), lgtDat.iSliceIndex, float4(lgtDat.fLightIntensity, lgtDat.fDecodeExp, 0.0, 0.0), g);

// TODO: remove pow, store cubemap mips differently
half perceptualRoughness = pow(glossIn.perceptualRoughness, 3.0/4.0);
#else
half perceptualRoughness = glossIn.perceptualRoughness; // MM: switched to this
half perceptualRoughness = glossIn.roughness; // MM: switched to this
#endif
//perceptualRoughness = sqrt(sqrt(2/(64.0+2))); // spec power to the square root of real roughness

381
Assets/TestScenes/ForwardRenderLoop/ForwardRenderLoop.unity


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
SceneSettings:
OcclusionCullingSettings:
m_PVSData:
m_PVSObjectsArray: []
m_PVSPortalsArray: []
serializedVersion: 2
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0

m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: de937cf09e81b4862bae4a2fb6c7f459, type: 2}
m_IsPrefabParent: 0
--- !u!1 &550164696
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 550164699}
- component: {fileID: 550164698}
- component: {fileID: 550164697}
m_Layer: 0
m_Name: Spotlight (10)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &550164697
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 550164696}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7a68c43fe1f2a47cfa234b5eeaa98012, type: 3}
m_Name:
m_EditorClassIdentifier:
shadowResolution: 976
innerSpotPercent: 77
--- !u!108 &550164698
Light:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 550164696}
m_Enabled: 1
serializedVersion: 7
m_Type: 0
m_Color: {r: 0.8455882, g: 0.42901167, b: 0.42901167, a: 1}
m_Intensity: 1.5
m_Range: 80
m_SpotAngle: 76
m_CookieSize: 10
m_Shadows:
m_Type: 1
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 1.75
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967039
m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &550164699
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 550164696}
m_LocalRotation: {x: -0.08570645, y: -0.6503448, z: 0.71963257, w: 0.22767335}
m_LocalPosition: {x: 18.1, y: 4.89, z: 2.7}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 116.25299, y: -251.91699, z: -83.630005}
--- !u!1 &756999128
GameObject:
m_ObjectHideFlags: 0

serializedVersion: 7
m_Type: 2
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 2.41
m_Range: 8.37
m_Intensity: 8
m_Range: 20
m_SpotAngle: 67.2
m_CookieSize: 10
m_Shadows:

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 756999128}
m_LocalRotation: {x: -0.03901584, y: -0.61546946, z: 0.78589, w: 0.045300227}
m_LocalPosition: {x: 16.31, y: 4.21, z: 9.9}
m_LocalPosition: {x: -1.75, y: 1.47, z: 1.33}
m_RootOrder: 17
m_RootOrder: 16
--- !u!1001 &841426484
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 400012, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_LocalPosition.x
value: 9.662517
objectReference: {fileID: 0}
- target: {fileID: 400012, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_LocalPosition.y
value: 12.61
objectReference: {fileID: 0}
- target: {fileID: 400012, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_LocalPosition.z
value: 6.806114
objectReference: {fileID: 0}
- target: {fileID: 400012, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 400012, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 400012, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 400012, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 400012, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2300032, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 87c86082ee14fbd4b8426a8794f2060d, type: 2}
- target: {fileID: 2300036, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 87c86082ee14fbd4b8426a8794f2060d, type: 2}
- target: {fileID: 2300052, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 87c86082ee14fbd4b8426a8794f2060d, type: 2}
- target: {fileID: 2300040, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 87c86082ee14fbd4b8426a8794f2060d, type: 2}
- target: {fileID: 2300056, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 87c86082ee14fbd4b8426a8794f2060d, type: 2}
- target: {fileID: 2300048, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 87c86082ee14fbd4b8426a8794f2060d, type: 2}
- target: {fileID: 2300044, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 87c86082ee14fbd4b8426a8794f2060d, type: 2}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
m_IsPrefabParent: 0
--- !u!1 &942239534
GameObject:
m_ObjectHideFlags: 0

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1064871612
GameObject:

m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 2100000, guid: b4d74419a10f9614aaf2624ff3c83e80, type: 2}
- {fileID: 2100000, guid: 87c86082ee14fbd4b8426a8794f2060d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1064871612}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 18.6, y: -1.87, z: 20.3}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_RootOrder: 15
m_RootOrder: 14
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1090653688
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1100543299
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 12
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1256381297
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_RootOrder: 7
--- !u!1 &1403765353
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1403765356}
- component: {fileID: 1403765355}
- component: {fileID: 1403765354}
m_Layer: 0
m_Name: Spotlight (9)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1403765354
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1403765353}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7a68c43fe1f2a47cfa234b5eeaa98012, type: 3}
m_Name:
m_EditorClassIdentifier:
shadowResolution: 955
innerSpotPercent: 66.4
--- !u!108 &1403765355
Light:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1403765353}
m_Enabled: 1
serializedVersion: 7
m_Type: 0
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 1.05
m_Range: 37.2
m_SpotAngle: 67.2
m_CookieSize: 10
m_Shadows:
m_Type: 1
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 1.75
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967039
m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &1403765356
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1403765353}
m_LocalRotation: {x: -0.03901584, y: -0.61546946, z: 0.78589, w: 0.045300227}
m_LocalPosition: {x: 28.35, y: 5.85, z: 8.73}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 105.47699, y: -205.932, z: -26.46399}
--- !u!1 &1409545155
GameObject:
m_ObjectHideFlags: 0

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1409545155}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 26.23, y: 0.5, z: 11}
m_LocalPosition: {x: 26.23, y: 6.95, z: 11}
m_RootOrder: 16
m_RootOrder: 15
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1469174313
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 11
m_RootOrder: 10
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1506796422
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1.0394905, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 14
m_RootOrder: 13
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1597621866
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1713034008
GameObject:

m_Script: {fileID: 11500000, guid: 92bb16b4ee20841929b24d6bd771738d, type: 3}
m_Name:
m_EditorClassIdentifier:
m_RenderLoop: {fileID: 11400000, guid: 873753be6b0da44d58b061c5ec3d12bc, type: 2}
m_RenderLoop: {fileID: 11400000, guid: 2400b74f5ce370c4481e5dc417d03703, type: 2}
--- !u!1 &1758207072
GameObject:
m_ObjectHideFlags: 0

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 9
m_RootOrder: 8
--- !u!1 &1810843056
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1810843059}
- component: {fileID: 1810843058}
- component: {fileID: 1810843057}
m_Layer: 0
m_Name: Spotlight (12)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1810843057
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1810843056}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7a68c43fe1f2a47cfa234b5eeaa98012, type: 3}
m_Name:
m_EditorClassIdentifier:
shadowResolution: 955
innerSpotPercent: 66.4
--- !u!108 &1810843058
Light:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1810843056}
m_Enabled: 1
serializedVersion: 7
m_Type: 1
m_Color: {r: 0.87586504, g: 0.99264705, b: 0.7809797, a: 1}
m_Intensity: 0.65
m_Range: 37.2
m_SpotAngle: 67.2
m_CookieSize: 10
m_Shadows:
m_Type: 1
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 1.75
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967039
m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &1810843059
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1810843056}
m_LocalRotation: {x: -0.26871026, y: -0.31149626, z: 0.87299806, w: 0.2619911}
m_LocalPosition: {x: 28.75, y: 9.26, z: 7.88}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 18
m_LocalEulerAnglesHint: {x: 23.738, y: -43.674004, z: 136.89601}
--- !u!1 &1818419755
GameObject:
m_ObjectHideFlags: 0

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 10
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1946201409
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2054101900
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 0.78171986, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2136471011
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 13
m_RootOrder: 12
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

32
Assets/TestScenes/ForwardRenderLoop/Materials/gray.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: gray
m_Shader: {fileID: 4800000, guid: 908b379d4818cd64184b95a21123d909, type: 3}
m_Shader: {fileID: 4800000, guid: c846f5368b257ca49aa135748a1700e2, type: 3}
m_ShaderKeywords: S_RECEIVE_SHADOWS S_SPECULAR_METALLIC
m_LightmapFlags: 5
m_CustomRenderQueue: -1

name: _DetailNormalMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DiffuseMap
second:
m_Texture: {fileID: 2800000, guid: 32c4b9c8ddc1c5d49ac7d10122540447, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:

m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _NormalMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _OcclusionMap
second:
m_Texture: {fileID: 0}

m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _SmoothnessMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _SpecGlossMap
second:
m_Texture: {fileID: 0}

name: _SpecMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: g_tOverrideLightmap
second:
m_Texture: {fileID: 0}

name: _Parallax
second: 0.02
- first:
name: _Smoothness
second: 0.5
- first:
name: _SmoothnessTextureChannel
second: 0
- first:

- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
- first:
name: _DiffuseColor
second: {r: 0.71323526, g: 0.19404197, b: 0.19404197, a: 1}
- first:
name: _EmissionColor
second: {r: 0, g: 0, b: 0, a: 1}

3
ProjectSettings/ProjectVersion.txt


m_EditorVersion: 5.4.0b19
m_StandardAssetsVersion: 0
m_EditorVersion: 5.5.0b4

14
ProjectSettings/UnityConnectSettings.asset


--- !u!310 &1
UnityConnectSettings:
m_ObjectHideFlags: 0
m_Enabled: 0
m_TestMode: 0
m_TestEventUrl:
m_TestConfigUrl:
CrashReportingSettings:
m_EventUrl: https://perf-events.cloud.unity3d.com/api/events/crashes
m_Enabled: 0
UnityPurchasingSettings:
m_Enabled: 0
m_TestMode: 0

m_TestMode: 0
m_TestEventUrl:
m_TestConfigUrl:
UnityAdsSettings:
m_Enabled: 0
m_InitializeOnStartup: 1
m_TestMode: 0
m_EnabledPlatforms: 4294967295
m_IosGameId:
m_AndroidGameId:

13
Assets/HDRenderLoop.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 558064ecdbf6b6742892d699acb39aed, type: 3}
m_Name: HDRenderLoop
m_EditorClassIdentifier:

8
Assets/HDRenderLoop.asset.meta


fileFormatVersion: 2
guid: a760b5cf201f0f5478077e4ee5df8236
timeCreated: 1474961622
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop.meta


fileFormatVersion: 2
guid: efe43be6d4923e441a2d4b20b3783b7f
folderAsset: yes
timeCreated: 1474540060
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/ShaderLibrary.meta


fileFormatVersion: 2
guid: 534c3b565c7ef4248a10594dbdf4faf1
folderAsset: yes
timeCreated: 1472130065
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

12
Assets/ScriptableRenderLoop/common/SkyboxHelper.cs.meta


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

12
Assets/ScriptableRenderLoop/common/TextureSettings.cs.meta


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

9
Assets/ScriptableRenderLoop/fptl/FinalPass.shader.meta


fileFormatVersion: 2
guid: 5590f54ad211f594da4e687b698f2258
timeCreated: 1474297133
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

9
Assets/TestScenes/HDTest.meta


fileFormatVersion: 2
guid: 8276fd7131b21b74f995f26f7712cf65
folderAsset: yes
timeCreated: 1474299364
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

13
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 558064ecdbf6b6742892d699acb39aed, type: 3}
m_Name: HDRenderLoop
m_EditorClassIdentifier:

8
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset.meta


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

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


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

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders.meta


fileFormatVersion: 2
guid: fafbb144d7f66074785b7727293d89c5
folderAsset: yes
timeCreated: 1474297943
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

596
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


using UnityEngine;
using System.Collections;
using UnityEngine.Rendering;
using System.Collections.Generic;
using System;
using UnityEditor;
namespace UnityEngine.ScriptableRenderLoop
{
[ExecuteInEditMode]
// This HDRenderLoop assume linear lighting. Don't work with gamma.
public class HDRenderLoop : ScriptableRenderLoop
{
#if UNITY_EDITOR
[MenuItem("Renderloop/CreateHDRenderLoop")]
static void CreateHDRenderLoop()
{
var instance = ScriptableObject.CreateInstance<HDRenderLoop>();
UnityEditor.AssetDatabase.CreateAsset(instance, "Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset");
}
#endif
public class GBufferManager
{
public const int MaxGbuffer = 8;
public void SetBufferDescription(int index, string stringID, RenderTextureFormat inFormat, RenderTextureReadWrite inSRGBWrite)
{
IDs[index] = Shader.PropertyToID(stringID);
RTIDs[index] = new RenderTargetIdentifier(IDs[index]);
formats[index] = inFormat;
sRGBWrites[index] = inSRGBWrite;
}
public void InitGBuffers(CommandBuffer cmd)
{
for (int index = 0; index < gbufferCount; index++)
{
/* RTs[index] = */ cmd.GetTemporaryRT(IDs[index], -1, -1, 0, FilterMode.Point, formats[index], sRGBWrites[index]);
}
}
public RenderTargetIdentifier[] GetGBuffers(CommandBuffer cmd)
{
var colorMRTs = new RenderTargetIdentifier[gbufferCount];
for (int index = 0; index < gbufferCount; index++)
{
colorMRTs[index] = RTIDs[index];
}
return colorMRTs;
}
/*
public void BindBuffers(Material mat)
{
for (int index = 0; index < gbufferCount; index++)
{
mat.SetTexture(IDs[index], RTs[index]);
}
}
*/
public int gbufferCount { get; set; }
int[] IDs = new int[MaxGbuffer];
RenderTargetIdentifier[] RTIDs = new RenderTargetIdentifier[MaxGbuffer];
RenderTextureFormat[] formats = new RenderTextureFormat[MaxGbuffer];
RenderTextureReadWrite[] sRGBWrites = new RenderTextureReadWrite[MaxGbuffer];
}
public const int MaxLights = 32;
//[SerializeField]
//ShadowSettings m_ShadowSettings = ShadowSettings.Default;
//ShadowRenderPass m_ShadowPass;
Material m_DeferredMaterial;
Material m_FinalPassMaterial;
GBufferManager gbufferManager = new GBufferManager();
static private int s_CameraColorBuffer;
static private int s_CameraDepthBuffer;
static private ComputeBuffer s_punctualLightList;
void OnEnable()
{
Rebuild ();
}
void OnValidate()
{
Rebuild ();
}
void ClearComputeBuffers()
{
if (s_punctualLightList != null)
s_punctualLightList.Release();
}
void Rebuild()
{
ClearComputeBuffers();
gbufferManager.gbufferCount = 4;
gbufferManager.SetBufferDescription(0, "_CameraGBufferTexture0", RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB); // Store diffuse color => sRGB
gbufferManager.SetBufferDescription(1, "_CameraGBufferTexture1", RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
gbufferManager.SetBufferDescription(2, "_CameraGBufferTexture2", RenderTextureFormat.ARGB2101010, RenderTextureReadWrite.Linear); // Store normal => higher precision
gbufferManager.SetBufferDescription(3, "_CameraGBufferTexture3", RenderTextureFormat.RGB111110Float, RenderTextureReadWrite.Linear);
s_CameraColorBuffer = Shader.PropertyToID("_CameraColorTexture");
s_CameraDepthBuffer = Shader.PropertyToID("_CameraDepthTexture");
s_punctualLightList = new ComputeBuffer(MaxLights, System.Runtime.InteropServices.Marshal.SizeOf(typeof(PunctualLightData)));
Shader deferredMaterial = Shader.Find("Hidden/Unity/LightingDeferred") as Shader;
m_DeferredMaterial = new Material(deferredMaterial);
m_DeferredMaterial.hideFlags = HideFlags.HideAndDontSave;
Shader finalPassShader = Shader.Find("Hidden/Unity/FinalPass") as Shader;
m_FinalPassMaterial = new Material(finalPassShader);
m_FinalPassMaterial.hideFlags = HideFlags.HideAndDontSave;
// m_ShadowPass = new ShadowRenderPass (m_ShadowSettings);
}
void OnDisable()
{
s_punctualLightList.Release();
if (m_DeferredMaterial) DestroyImmediate(m_DeferredMaterial);
if (m_FinalPassMaterial) DestroyImmediate(m_FinalPassMaterial);
}
void InitAndClearBuffer(Camera camera, RenderLoop renderLoop)
{
// We clear only the depth buffer, no need to clear the various color buffer as we overwrite them.
// Clear depth/stencil and init buffers
{
var cmd = new CommandBuffer();
cmd.name = "InitGBuffers and clear Depth/Stencil";
// Init buffer
// With scriptable render loop we must allocate ourself depth and color buffer (We must be independent of backbuffer for now, hope to fix that later).
// Also we manage ourself the HDR format, here allocating fp16 directly.
// With scriptable render loop we can allocate temporary RT in a command buffer, they will not be release with ExecuteCommandBuffer
// These temporary surface are release automatically at the end of the scriptable renderloop if not release explicitly
cmd.GetTemporaryRT(s_CameraColorBuffer, -1, -1, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default);
cmd.GetTemporaryRT(s_CameraDepthBuffer, -1, -1, 24, FilterMode.Point, RenderTextureFormat.Depth);
gbufferManager.InitGBuffers(cmd);
cmd.SetRenderTarget(new RenderTargetIdentifier(s_CameraColorBuffer), new RenderTargetIdentifier(s_CameraDepthBuffer));
cmd.ClearRenderTarget(true, false, new Color(0, 0, 0, 0));
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
// TEMP: As we are in development and have not all the setup pass we still clear the color in emissive buffer and gbuffer, but this will be removed later.
// Clear HDR target
{
var cmd = new CommandBuffer();
cmd.name = "Clear HDR target";
cmd.SetRenderTarget(new RenderTargetIdentifier(s_CameraColorBuffer), new RenderTargetIdentifier(s_CameraDepthBuffer));
cmd.ClearRenderTarget(false, true, new Color(0, 0, 0, 0));
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
// Clear GBuffers
{
var cmd = new CommandBuffer();
cmd.name = "Clear GBuffer";
// Write into the Camera Depth buffer
cmd.SetRenderTarget(gbufferManager.GetGBuffers(cmd), new RenderTargetIdentifier(s_CameraDepthBuffer));
// Clear everything
// TODO: Clear is not required for color as we rewrite everything, will save performance.
cmd.ClearRenderTarget(false, true, new Color(0, 0, 0, 0));
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
// END TEMP
}
void RenderGBuffer(CullResults cull, Camera camera, RenderLoop renderLoop)
{
// setup GBuffer for rendering
var cmd = new CommandBuffer();
cmd.name = "GBuffer Pass";
cmd.SetRenderTarget(gbufferManager.GetGBuffers(cmd), new RenderTargetIdentifier(s_CameraDepthBuffer));
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
// render opaque objects into GBuffer
DrawRendererSettings settings = new DrawRendererSettings(cull, camera, new ShaderPassName("GBuffer"));
settings.sorting.sortOptions = SortOptions.SortByMaterialThenMesh;
settings.inputCullingOptions.SetQueuesOpaque();
renderLoop.DrawRenderers(ref settings);
}
Matrix4x4 GetViewProjectionMatrix(Camera camera)
{
// Calculate inverse projection matrix as this is not done by Unity
Matrix4x4 view = camera.worldToCameraMatrix;
Matrix4x4 proj = camera.projectionMatrix;
// The actual projection matrix used in shaders is actually massaged a bit to work across all platforms
// (different Z value ranges etc.)
Matrix4x4 gpuProj = GL.GetGPUProjectionMatrix(proj, false);
Matrix4x4 gpuVP = gpuProj * view;
return camera.projectionMatrix * camera.worldToCameraMatrix;
}
void RenderDeferredLighting(Camera camera, RenderLoop renderLoop)
{
Matrix4x4 invViewProj = GetViewProjectionMatrix(camera).inverse;
m_DeferredMaterial.SetMatrix("_InvViewProjMatrix", invViewProj);
Vector4 screenSize = new Vector4();
screenSize.x = camera.pixelWidth;
screenSize.y = camera.pixelHeight;
screenSize.z = 1.0f / camera.pixelWidth;
screenSize.w = 1.0f / camera.pixelHeight;
m_DeferredMaterial.SetVector("_ScreenSize", screenSize);
// gbufferManager.BindBuffers(m_DeferredMaterial);
// TODO: Bind depth textures
var cmd = new CommandBuffer();
cmd.name = "Deferred Ligthing Pass";
cmd.Blit(null, new RenderTargetIdentifier(s_CameraColorBuffer), m_DeferredMaterial, 0);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
void RenderForward(CullResults cullResults, Camera camera, RenderLoop renderLoop)
{
// setup GBuffer for rendering
var cmd = new CommandBuffer();
cmd.name = "Forward Pass";
cmd.SetRenderTarget(new RenderTargetIdentifier(s_CameraColorBuffer), new RenderTargetIdentifier(s_CameraDepthBuffer));
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
DrawRendererSettings settings = new DrawRendererSettings(cullResults, camera, new ShaderPassName("Forward"));
settings.rendererConfiguration = RendererConfiguration.ConfigureOneLightProbePerRenderer | RendererConfiguration.ConfigureReflectionProbesProbePerRenderer;
settings.sorting.sortOptions = SortOptions.SortByMaterialThenMesh;
renderLoop.DrawRenderers(ref settings);
}
void FinalPass(RenderLoop renderLoop)
{
CommandBuffer cmd = new CommandBuffer();
cmd.name = "FinalPass";
// Resolve our HDR texture to CameraTarget.
cmd.Blit(s_CameraColorBuffer, BuiltinRenderTextureType.CameraTarget, m_FinalPassMaterial, 0);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
//---------------------------------------------------------------------------------------------------------------------------------------------------
void UpdatePunctualLights(ActiveLight[] activeLights)
{
int punctualLightCount = 0;
List<PunctualLightData> lights = new List<PunctualLightData>();
for (int lightIndex = 0; lightIndex < Math.Min(activeLights.Length, MaxLights); lightIndex++)
{
ActiveLight light = activeLights[lightIndex];
if (light.lightType == LightType.Spot || light.lightType == LightType.Point)
{
PunctualLightData l = new PunctualLightData();
l.positionWS = light.light.transform.position;
l.invSqrAttenuationRadius = 1.0f / (light.range * light.range);
// Correct intensity calculation (Different from Unity)
float lightColorR = light.light.intensity * Mathf.GammaToLinearSpace(light.light.color.r);
float lightColorG = light.light.intensity * Mathf.GammaToLinearSpace(light.light.color.g);
float lightColorB = light.light.intensity * Mathf.GammaToLinearSpace(light.light.color.b);
l.color = new Vec3(lightColorR, lightColorG, lightColorB);
// Light direction is opposite to the forward direction...
l.forward = -light.light.transform.forward;
// CAUTION: For IES as we inverse forward maybe this will need rotation.
l.up = light.light.transform.up;
l.right = light.light.transform.right;
l.diffuseScale = 1.0f;
l.specularScale = 1.0f;
l.shadowDimmer = 1.0f;
if (light.lightType == LightType.Spot)
{
float spotAngle = light.light.spotAngle;
AdditionalLightData additionalLightData = light.light.GetComponent<AdditionalLightData>();
float innerConePercent = AdditionalLightData.GetInnerSpotPercent01(additionalLightData);
float cosSpotOuterHalfAngle = Mathf.Clamp(Mathf.Cos(spotAngle * 0.5f * Mathf.Deg2Rad), 0.0f, 1.0f);
float cosSpotInnerHalfAngle = Mathf.Clamp(Mathf.Cos(spotAngle * 0.5f * innerConePercent * Mathf.Deg2Rad), 0.0f, 1.0f); // inner cone
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;
l.angleOffset = 2.0f;
}
lights.Add(l);
punctualLightCount++;
}
}
s_punctualLightList.SetData(lights.ToArray());
Shader.SetGlobalBuffer("g_punctualLightList", s_punctualLightList);
Shader.SetGlobalInt("g_punctualLightCount", punctualLightCount);
}
void UpdateLightConstants(ActiveLight[] activeLights /*, ref ShadowOutput shadow */)
{
/*
int nNumLightsIncludingTooMany = 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 ];
for ( int nLight = 0; nLight < activeLights.Length; nLight++ )
{
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> ();
// 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 (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 );
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;
}
}
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" );
}
}
// 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 );
// 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 );
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)
{
var props = new MaterialPropertyBlock();
var cmd = new CommandBuffer();
cmd.SetRenderTarget(new RenderTargetIdentifier(kGBufferEmission), new RenderTargetIdentifier(kGBufferZ));
foreach (var cl in inputs.culledLights)
{
bool renderAsQuad = (cl.flags & VisibleLightFlags.IntersectsNearPlane) != 0 || (cl.flags & VisibleLightFlags.IntersectsFarPlane) != 0 || (cl.lightType == LightType.Directional);
Vector3 lightPos = cl.localToWorld.GetColumn(3);
float range = cl.range;
cmd.DisableShaderKeyword("POINT");
cmd.DisableShaderKeyword("POINT_COOKIE");
cmd.DisableShaderKeyword("SPOT");
cmd.DisableShaderKeyword("DIRECTIONAL");
cmd.DisableShaderKeyword("DIRECTIONAL_COOKIE");
//cmd.EnableShaderKeyword ("UNITY_HDR_ON");
switch (cl.lightType)
{
case LightType.Point:
cmd.EnableShaderKeyword("POINT");
break;
case LightType.Spot:
cmd.EnableShaderKeyword("SPOT");
break;
case LightType.Directional:
cmd.EnableShaderKeyword("DIRECTIONAL");
break;
}
props.SetFloat("_LightAsQuad", renderAsQuad ? 1 : 0);
props.SetVector("_LightPos", new Vector4(lightPos.x, lightPos.y, lightPos.z, 1.0f / (range * range)));
props.SetVector("_LightColor", cl.finalColor);
Debug.Log("Light color : " + cl.finalColor.ToString());
props.SetMatrix("_WorldToLight", cl.worldToLocal);
///@TODO: cleanup, remove this from Internal-PrePassLighting shader
//DeferredPrivate::s_LightMaterial->SetTexture (ShaderLab::Property ("_LightTextureB0"), builtintex::GetAttenuationTexture ());
if (renderAsQuad)
{
cmd.DrawMesh(m_QuadMesh, Matrix4x4.identity, m_DeferredMaterial, 0, 0, props);
}
else
{
var matrix = Matrix4x4.TRS(lightPos, Quaternion.identity, new Vector3(range, range, range));
cmd.DrawMesh(m_PointLightMesh, matrix, m_DeferredMaterial, 0, 0, props);
}
}
loop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
*/
public override void Render(Camera[] cameras, RenderLoop renderLoop)
{
// Set Frame constant buffer
// TODO...
foreach (var camera in cameras)
{
// Set camera constant buffer
// TODO...
CullResults cullResults;
CullingParameters cullingParams;
if (!CullResults.GetCullingParameters (camera, out cullingParams))
continue;
//m_ShadowPass.UpdateCullingParameters (ref cullingParams);
cullResults = CullResults.Cull (ref cullingParams, renderLoop);
//ShadowOutput shadows;
//m_ShadowPass.Render (renderLoop, cullResults, out shadows);
renderLoop.SetupCameraProperties (camera);
//UpdateLightConstants(cullResults.culledLights /*, ref shadows */);
UpdatePunctualLights(cullResults.culledLights);
InitAndClearBuffer(camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);
RenderDeferredLighting(camera, renderLoop);
RenderForward(cullResults, camera, renderLoop);
FinalPass(renderLoop);
renderLoop.Submit ();
}
// Post effects
}
#if UNITY_EDITOR
public override UnityEditor.SupportedRenderingFeatures GetSupportedRenderingFeatures()
{
var features = new UnityEditor.SupportedRenderingFeatures();
features.reflectionProbe = UnityEditor.SupportedRenderingFeatures.ReflectionProbe.Rotation;
return features;
}
#endif
}
}

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting.meta


fileFormatVersion: 2
guid: b8bec6e2ba5850349bc2827fbe25b071
folderAsset: yes
timeCreated: 1474297943
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

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


fileFormatVersion: 2
guid: b7bc5becc2cf7f14292d68bcd5fdeba6
folderAsset: yes
timeCreated: 1474297943
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

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


// UNITY_SHADER_NO_UPGRADE
// CAUTION:
// Currently the shaders compiler always include regualr Unity shaderVariables, so I get a conflict here were UNITY_SHADER_VARIABLES_INCLUDED is already define, this need to be fixed.
// As I haven't change the variables name yet, I simply don't define anything, and I put the transform function at the end of the file outside the guard header.
// This need to be fixed.
float4x4 glstate_matrix_inv_projection;
#ifndef UNITY_SHADER_VARIABLES_INCLUDED
#define UNITY_SHADER_VARIABLES_INCLUDED
#define UNITY_MATRIX_M unity_ObjectToWorld
// These are updated per eye in VR
#define UNITY_MATRIX_V unity_MatrixV
#define UNITY_MATRIX_P glstate_matrix_projection
#define UNITY_MATRIX_VP unity_MatrixVP
#ifdef UNITY_SINGLE_PASS_STEREO
#define UNITY_MATRIX_MVP mul(unity_MatrixVP, unity_ObjectToWorld)
#else
#define UNITY_MATRIX_MVP glstate_matrix_mvp
#endif
// These use the camera center position in VR
#define UNITY_MATRIX_MV glstate_matrix_modelview0
#define UNITY_MATRIX_T_MV glstate_matrix_transpose_modelview0
#define UNITY_MATRIX_IT_MV glstate_matrix_invtrans_modelview0
// ----------------------------------------------------------------------------
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
#ifndef UNITY_SINGLE_PASS_STEREO
float3 _WorldSpaceCameraPos;
#endif
// 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;
CBUFFER_END
CBUFFER_START(UnityPerCameraRare)
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;
#ifndef UNITY_SINGLE_PASS_STEREO
float4x4 unity_WorldToCamera;
float4x4 unity_CameraToWorld;
#endif
CBUFFER_END
// ----------------------------------------------------------------------------
CBUFFER_START(UnityPerDraw)
#ifndef UNITY_SINGLE_PASS_STEREO
float4x4 glstate_matrix_mvp;
#endif
// 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
CBUFFER_END
#ifdef UNITY_SINGLE_PASS_STEREO
CBUFFER_START(UnityPerEye)
float3 _WorldSpaceCameraPos;
float4x4 glstate_matrix_projection;
float4x4 unity_MatrixV;
float4x4 unity_MatrixVP;
float4x4 unity_WorldToCamera;
float4x4 unity_CameraToWorld;
CBUFFER_END
#endif
CBUFFER_START(UnityPerDrawRare)
float4x4 glstate_matrix_transpose_modelview0;
#ifdef UNITY_SINGLE_PASS_STEREO
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;
#endif
fixed4 glstate_lightmodel_ambient;
fixed4 unity_AmbientSky;
fixed4 unity_AmbientEquator;
fixed4 unity_AmbientGround;
fixed4 unity_IndirectSpecColor;
CBUFFER_END
// ----------------------------------------------------------------------------
#endif // UNITY_SHADER_VARIABLES_INCLUDED
float4x4 GetObjectToWorldMatrix()
{
return unity_ObjectToWorld;
}
float4x4 GetWorldToObjectMatrix()
{
return unity_WorldToObject;
}
// Transform to homogenous clip space
float4x4 GetWorldToHClipMatrix()
{
return unity_MatrixVP;
}
// Transform from clip space to homogenous world space
float4x4 GetClipToHWorldMatrix()
{
return glstate_matrix_inv_projection;
}
float4x4 GetObjectToWorldViewMatrix()
{
return glstate_matrix_modelview0;
}
float3 TransformObjectToWorld(float3 positionOS)
{
return mul(GetObjectToWorldMatrix(), float4(positionOS, 1.0));
}
float3 TransformObjectToView(float3 positionOS)
{
return mul(GetObjectToWorldViewMatrix(), float4(positionOS, 1.0));
}
float3 TransformObjectToWorldDir(float3 dirOS)
{
// Normalize to support uniform scaling
return normalize(mul((float3x3)GetObjectToWorldMatrix(), dirOS));
}
// Transforms normal from object to world space
float3 TransformObjectToWorldNormal(float3 normalOS)
{
#ifdef UNITY_ASSUME_UNIFORM_SCALING
return UnityObjectToWorldDir(normalOS);
#else
// 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
}
// Tranforms position from world space to homogenous space
float4 TransformWorldToHClip(float3 positionWS)
{
return mul(GetWorldToHClipMatrix(), float4(positionWS, 1.0));
}
float3x3 CreateTangentToWorld(float3 normal, float3 tangent, float tangentSign)
{
// For odd-negative scale transforms we need to flip the sign
float sign = tangentSign * unity_WorldTransformParams.w;
float3 binormal = cross(normal, tangent) * sign;
return float3x3(tangent, binormal, normal);
}
// Computes world space view direction, from object space position
float3 GetWorldSpaceNormalizeViewDir(float3 positionWS)
{
return normalize(_WorldSpaceCameraPos.xyz - positionWS);
}

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


fileFormatVersion: 2
guid: d1fb2d5b8f417ce40bac95e4fe4301b9
timeCreated: 1472205826
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

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


fileFormatVersion: 2
guid: 1dc16e70dd841de4396d41f9ae92c6f9
timeCreated: 1472140530
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

30
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/CommonMaterial.hlsl


#ifndef UNITY_COMMON_MATERIAL_INCLUDED
#define UNITY_COMMON_MATERIAL_INCLUDED
//-----------------------------------------------------------------------------
// Parametrization function helpers
//-----------------------------------------------------------------------------
float PerceptualRoughnessToRoughness(float perceptualRoughness)
{
return perceptualRoughness * perceptualRoughness;
}
float RoughnessToPerceptualRoughness(float roughness)
{
return sqrt(roughness);
}
// Smoothness is the user facing name
// it should be perceptualSmoothness but we don't want the user to have to deal with this name
float SmoothnessToRoughness(float smoothness)
{
return (1 - smoothness) * (1 - smoothness);
}
float SmoothnessToPerceptualRoughness(float smoothness)
{
return (1 - smoothness);
}
#endif // UNITY_COMMON_MATERIAL_INCLUDED

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


fileFormatVersion: 2
guid: 71aa77c8ecebcc942b7914328d88f7d1
timeCreated: 1474465931
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

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


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

140
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/DisneyGGX.hlsl


#ifndef UNITY_MATERIAL_DISNEYGGX_INCLUDED
#define UNITY_MATERIAL_DISNEYGGX_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 occlusion;
float3 specularColor;
float smoothness;
float3 normal; // normal in world space
// TODO: create a system surfaceData for thing like that + Transparent
// As we collect some lighting information (Lightmap, lightprobe/proxy volume)
// and emissive ahead (i.e in Gbuffer pass when doing deferred), we need to
// to have them in the SurfaceData structure.
float3 baked;
float3 emissiveColor; // Linear space
float emissiveIntensity;
};
struct BSDFData
{
float3 diffuseColor;
float occlusion;
float3 fresnel0;
float perceptualRoughness;
float3 normalWS;
float roughness;
// System
float3 bakedAndEmissive;
};
//-----------------------------------------------------------------------------
// conversion function for forward and deferred
//-----------------------------------------------------------------------------
BSDFData ConvertSurfaceDataToBSDFData(SurfaceData data)
{
BSDFData output;
output.diffuseColor = data.diffuseColor;
output.occlusion = data.occlusion;
output.fresnel0 = data.specularColor;
output.perceptualRoughness = SmoothnessToPerceptualRoughness(data.smoothness);
output.normalWS = data.normal;
output.roughness = PerceptualRoughnessToRoughness(output.perceptualRoughness);
output.bakedAndEmissive = data.baked + data.emissiveColor * data.emissiveIntensity;
return output;
}
#define GBUFFER_COUNT 4
// This will encode UnityStandardData into GBuffer
void EncodeIntoGBuffer(SurfaceData data, out float4 outGBuffer0, out float4 outGBuffer1, out float4 outGBuffer2, out float4 outGBuffer3)
{
// RT0: diffuse color (rgb), occlusion (a) - sRGB rendertarget
outGBuffer0 = float4(data.diffuseColor, data.occlusion);
// RT1: spec color (rgb), perceptual roughness (a) - sRGB rendertarget
outGBuffer1 = float4(data.specularColor, SmoothnessToPerceptualRoughness(data.smoothness));
// RT2: normal (rgb), --unused, very low precision-- (a)
outGBuffer2 = float4(PackNormalCartesian(data.normal), 1.0f);
// RT3: 11, 11, 10 float
outGBuffer3 = float4(data.baked + data.emissiveColor * data.emissiveIntensity, 0.0f);
}
// This decode the Gbuffer in a BSDFData struct
BSDFData DecodeFromGBuffer(float4 inGBuffer0, float4 inGBuffer1, float4 inGBuffer2, float4 inGBuffer3)
{
BSDFData bsdfData;
bsdfData.diffuseColor = inGBuffer0.rgb;
bsdfData.occlusion = inGBuffer0.a;
bsdfData.fresnel0 = inGBuffer1.rgb;
bsdfData.perceptualRoughness = inGBuffer1.a;
bsdfData.normalWS = UnpackNormalCartesian(inGBuffer2.rgb);
bsdfData.roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness);
bsdfData.bakedAndEmissive = inGBuffer3.rgb;
return bsdfData;
}
//-----------------------------------------------------------------------------
// EvaluateBSDF functions for each light type
//-----------------------------------------------------------------------------
void EvaluateBSDF_Punctual( float3 V, float3 positionWS, PunctualLightData light, BSDFData material,
out float4 diffuseLighting,
out float4 specularLighting)
{
float3 unL = light.positionWS - positionWS;
float3 L = normalize(unL);
// Always done, directional have it neutral
float attenuation = GetDistanceAttenuation(unL, light.invSqrAttenuationRadius);
// Always done, point and dir have it neutral
attenuation *= GetAngleAttenuation(L, light.forward, light.angleScale, light.angleOffset);
float illuminance = saturate(dot(material.normalWS, L)) * attenuation;
diffuseLighting = float4(0.0f, 0.0f, 0.0f, 1.0f);
specularLighting = float4(0.0f, 0.0f, 0.0f, 1.0f);
if (illuminance > 0.0f)
{
float NdotV = abs(dot(material.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(material.normalWS, H));
float NdotL = saturate(dot(material.normalWS, L));
float3 F = F_Schlick(material.fresnel0, LdotH);
float Vis = V_SmithJointGGX(NdotL, NdotV, material.roughness);
float D = D_GGX(NdotH, material.roughness);
specularLighting.rgb = F * Vis * D;
float disneyDiffuse = DisneyDiffuse(NdotV, NdotL, LdotH, material.perceptualRoughness);
diffuseLighting.rgb = material.diffuseColor * disneyDiffuse;
diffuseLighting.rgb *= light.color * illuminance;
specularLighting.rgb *= light.color * illuminance;
}
}
#endif // UNITY_MATERIAL_DISNEYGGX_INCLUDED

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


#ifndef UNITY_MATERIAL_INCLUDED
#define UNITY_MATERIAL_INCLUDED
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Packing.hlsl"
#include "Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl"
#include "Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LightDefinition.cs"
#include "CommonMaterial.hlsl"
// Here we include all the different lighting model supported by the renderloop based on define done in .shader
#ifdef UNITY_MATERIAL_DISNEYGXX
#include "DisneyGGX.hlsl"
#endif
//-----------------------------------------------------------------------------
// Define for GBuffer
//-----------------------------------------------------------------------------
#ifdef GBUFFER_COUNT
#if GBUFFER_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
#define DECLARE_GBUFFER_TEXTURE(NAME) \
Texture2D MERGE_NAME(NAME, 0); \
Texture2D MERGE_NAME(NAME, 1); \
Texture2D MERGE_NAME(NAME, 2);
#define FETCH_GBUFFER(NAME, TEX, UV) \
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_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
#define DECLARE_GBUFFER_TEXTURE(NAME) \
Texture2D MERGE_NAME(NAME, 0); \
Texture2D MERGE_NAME(NAME, 1); \
Texture2D MERGE_NAME(NAME, 2); \
Texture2D MERGE_NAME(NAME, 3);
#define FETCH_GBUFFER(NAME, TEX, UV) \
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))
#endif
#endif // #ifdef GBUFFER_COUNT
#endif // UNITY_MATERIAL_INCLUDED

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:

53
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LightDefinition.cs


// Note: This file is included both in C# code and in hlsl code, avoiding duplication
//-----------------------------------------------------------------------------
// structure definition
//-----------------------------------------------------------------------------
#if !__HLSL
namespace UnityEngine.ScriptableRenderLoop
{
#endif
// These structures share between C# and hlsl need to be align on float4, so we pad them.
struct PunctualLightData
{
public Vec3 positionWS;
public float invSqrAttenuationRadius;
public Vec3 color;
public float unused;
public Vec3 forward;
public float diffuseScale;
public Vec3 up;
public float specularScale;
public Vec3 right;
public float shadowDimmer;
public float angleScale;
public float angleOffset;
public Vec2 unused2;
};
struct AreaLightData
{
public Vec3 positionWS;
};
struct EnvLightData
{
public Vec3 positionWS;
};
struct PlanarLightData
{
public Vec3 positionWS;
};
#if !__HLSL
} // namespace UnityEngine.ScriptableRenderLoop
#endif

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


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

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/PostProcess.meta


fileFormatVersion: 2
guid: 8a352e0cb2a42fd4ba968b628ec4bc10
folderAsset: yes
timeCreated: 1474641822
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/PostProcess/FinalPass.shader.meta


fileFormatVersion: 2
guid: 59e008f014898b14cbdfb3195e16e5f5
timeCreated: 1474641824
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

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


// Final compositing pass, just does gamma correction for now.
Shader "Hidden/Unity/FinalPass"
{
Properties { _MainTex ("Texture", any) = "" {} }
SubShader {
Pass {
ZTest Always Cull Off ZWrite Off
CGPROGRAM
#pragma vertex Vert
#pragma fragment Frag
#pragma target 5.0
#include "../../../ShaderLibrary/Color.hlsl"
#include "../ShaderVariables.hlsl"
sampler2D _MainTex;
struct Attributes {
float3 vertex : 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;
}
float4 Frag(Varyings input) : SV_Target
{
float4 c = tex2D(_MainTex, input.texcoord);
// Gamma correction
return LinearToSRGB(c);
}
ENDCG
}
}
Fallback Off
}

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


Shader "Unity/DisneyGGX"
{
// TODO: Following set of parameters represent the parameters node inside the MaterialGraph.
// They are use to fill a SurfaceData. With a MaterialGraph these parameters will not be write here (?).
Properties
{
_DiffuseColor("Diffuse", Color) = (1,1,1,1)
_DiffuseMap("Diffuse", 2D) = "white" {}
_SpecColor("Specular", Color) = (0.04,0.04,0.04)
_SpecMap("Specular", 2D) = "white" {}
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
_SmoothnessMap("Smoothness", 2D) = "white" {}
_NormalMap("Normal Map", 2D) = "bump" {}
_OcclusionMap("Occlusion", 2D) = "white" {}
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
// Blending state
[HideInInspector] _Mode ("__mode", Float) = 0.0
[HideInInspector] _SrcBlend ("__src", Float) = 1.0
[HideInInspector] _DstBlend ("__dst", Float) = 0.0
[HideInInspector] _ZWrite ("__zw", Float) = 1.0
}
CGINCLUDE
ENDCG
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]
CGPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma vertex VertDefault
#pragma fragment FragForward
#include "TemplateDisneyGGX.hlsl"
float4 FragForward(PackedVaryings packedInput) : SV_Target
{
Varyings input = UnpackVaryings(packedInput);
float3 V = GetWorldSpaceNormalizeViewDir(input.positionWS);
float3 positionWS = input.positionWS;
SurfaceData surfaceData = GetSurfaceData(input);
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);
float4 diffuseLighting;
float4 specularLighting;
ForwardLighting(V, positionWS, bsdfData, diffuseLighting, specularLighting);
return float4(diffuseLighting.rgb + specularLighting.rgb, 1.0);
}
ENDCG
}
// ------------------------------------------------------------------
// Deferred pass
Pass
{
Name "GBuffer" // Name is not used
Tags { "LightMode" = "GBuffer" } // This will be only for opaque object based on the RenderQueue index
CGPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma vertex VertDefault
#pragma fragment FragDeferred
#include "TemplateDisneyGGX.hlsl"
void FragDeferred( PackedVaryings packedInput,
OUTPUT_GBUFFER(outGBuffer)
)
{
Varyings input = UnpackVaryings(packedInput);
SurfaceData surfaceData = GetSurfaceData(input);
ENCODE_INTO_GBUFFER(surfaceData, outGBuffer);
}
ENDCG
}
}
}

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


fileFormatVersion: 2
guid: 5b115c7d70db5004ab39a1cfbead4db7
timeCreated: 1474359714
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

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


#ifndef UNITY_LIGHTING_FORWARD_INCLUDED
#define UNITY_LIGHTING_FORWARD_INCLUDED
//-----------------------------------------------------------------------------
// Simple forward loop architecture
//-----------------------------------------------------------------------------
StructuredBuffer<PunctualLightData> g_punctualLightList;
int g_punctualLightCount;
// 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 material,
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);
for (int i = 0; i < g_punctualLightCount; ++i)
{
float4 localDiffuseLighting;
float4 localSpecularLighting;
EvaluateBSDF_Punctual(V, positionWS, g_punctualLightList[i], material, localDiffuseLighting, localSpecularLighting);
diffuseLighting += localDiffuseLighting;
specularLighting += localSpecularLighting;
}
/*
for (int i = 0; i < 4; ++i)
{
float4 localDiffuseLighting;
float4 localSpecularLighting;
EvaluateBSDF_Area(V, positionWS, areaLightData[i], material, localDiffuseLighting, localSpecularLighting);
diffuseLighting += localDiffuseLighting;
specularLighting += localSpecularLighting;
}
*/
}
#endif // UNITY_LIGHTING_FORWARD_INCLUDED

8
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingForward.hlsl.meta


fileFormatVersion: 2
guid: 2520701347d8611488160514a8d9a1bd
timeCreated: 1474540155
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.hlsl.meta


fileFormatVersion: 2
guid: 8ab751a0da67569489f8852db5423571
timeCreated: 1474899794
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.shader.meta


fileFormatVersion: 2
guid: 338228fc9e979ca41bf09a981c10c69e
timeCreated: 1474899949
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

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


#ifndef UNITY_LIGHTING_INCLUDED
#define UNITY_LIGHTING_INCLUDED
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl"
#include "LightingForward.hlsl"
#endif // UNITY_LIGHTING_INCLUDED

0
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.hlsl

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


Shader "Hidden/Unity/LightingDeferred"
{
Properties
{
_SrcBlend("", Float) = 1
_DstBlend("", Float) = 1
}
SubShader
{
Pass
{
ZWrite Off
Blend[_SrcBlend][_DstBlend]
CGPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#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_DISNEYGXX // 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);
Texture2D _CameraDepthTexture;
float4 _ScreenSize;
float4x4 _InvViewProjMatrix;
struct Attributes
{
float3 positionOS : 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);
return output;
}
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);
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);
return float4(diffuseLighting.rgb + specularLighting.rgb, 1.0);
//return float4(positionWS.y / 10, 0, 0, 1.0);
}
ENDCG
}
}
Fallback Off
}

138
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl


// GENERATED BY SHADER GRAPH
// No guard header!
#define UNITY_MATERIAL_DISNEYGXX // Need to be define before including Material.hlsl
#include "Lighting/Lighting.hlsl" // This include Material.hlsl
#include "ShaderVariables.hlsl"
// This files is generated by the ShaderGraph or written by hand
// Note for ShaderGraph:
// ShaderGraph should generate the vertex shader output to add the variable that may be required
// For example if we require view vector in shader graph, the output must contain positionWS and we calcualte the view vector with it.
// Still some input are mandatory depends on the type of loop. positionWS is mandatory in this current framework. So the ShaderGraph should always generate it.
//-------------------------------------------------------------------------------------
// variable declaration
//-------------------------------------------------------------------------------------
// Set of users variables
float4 _DiffuseColor;
float4 _SpecColor;
float _Smoothness;
sampler2D _DiffuseMap;
sampler2D _NormalMap;
// ... Others
//-------------------------------------------------------------------------------------
// Lighting architecture
//-------------------------------------------------------------------------------------
// TODO: Check if we will have different Varyings based on different pass, not sure about that...
// Forward
struct Attributes
{
float3 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 uv0 : TEXCOORD0;
float4 tangentOS : TANGENT;
};
struct Varyings
{
float4 positionHS;
float3 positionWS;
float2 texCoord0;
float4 tangentToWorld[3]; // [3x3:tangentToWorld | 1x3:viewDirForParallax]
};
struct PackedVaryings
{
float4 positionHS : SV_Position;
float4 interpolators[5] : 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].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;
}
Varyings UnpackVaryings(PackedVaryings input)
{
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];
return output;
}
// TODO: Here we will also have all the vertex deformation (GPU skinning, vertex animation, morph target...) or we will need to generate a compute shaders instead (better! but require work to deal with unpacking like fp16)
PackedVaryings VertDefault(Attributes input)
{
Varyings output;
output.positionWS = TransformObjectToWorld(input.positionOS);
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix)
output.positionHS = TransformWorldToHClip(output.positionWS);
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
output.texCoord0 = input.uv0;
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];
output.tangentToWorld[0].w = 0;
output.tangentToWorld[1].w = 0;
output.tangentToWorld[2].w = 0;
return PackVaryings(output);
}
//-------------------------------------------------------------------------------------
// Fill SurfaceData/Lighting data function
//-------------------------------------------------------------------------------------
SurfaceData GetSurfaceData(Varyings input)
{
SurfaceData data;
data.diffuseColor = tex2D(_DiffuseMap, input.texCoord0) * _DiffuseColor;
data.occlusion = 1.0;
data.specularColor = _SpecColor;
data.smoothness = _Smoothness;
data.normal = input.tangentToWorld[2].xyz;//UnpackNormalDXT5nm(tex2D(_NormalMap, input.texCoord0));
// 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)
data.baked = float3(0.0, 0.0, 0.0);
data.emissiveColor = float3(0.0, 0.0, 0.0);
data.emissiveIntensity = 0.0;
return data;
}

9
Assets/ScriptableRenderLoop/ShaderLibrary/API.meta


fileFormatVersion: 2
guid: 6fa64bbd0ffaf8843b041c6e42bb5f82
folderAsset: yes
timeCreated: 1472140530
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

8
Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl.meta


fileFormatVersion: 2
guid: 9c7140d7b956a4547bb71f8ed0dd9049
timeCreated: 1472140530
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

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


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

8
Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11_1.hlsl.meta


fileFormatVersion: 2
guid: 9aa86e448ea738047916ec3dbc6e9e33
timeCreated: 1474465931
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/ShaderLibrary/API/Validate.hlsl.meta


fileFormatVersion: 2
guid: 30ba55673585a6e4f9afd796eb8b170e
timeCreated: 1474895361
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

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


// This file assume SHADER_API_D3D11 is defined
#define UNITY_UV_STARTS_AT_TOP 1
#define UNITY_REVERSED_Z 1
#define UNITY_NEAR_CLIP_VALUE (1.0)

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


// Upgrade NOTE: replaced 'defined in' with 'defined (in)'
// Wait for a fix from Trunk
/*
#define REQUIRE_DEFINED(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)
*/

109
Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl


#ifndef UNITY_BSDF_INCLUDED
#define UNITY_BSDF_INCLUDED
#include "Common.hlsl"
//-----------------------------------------------------------------------------
// Fresnel term
//-----------------------------------------------------------------------------
float F_Schlick(float f0, float f90, float u)
{
float x = 1.0f - u;
float x5 = x * x;
x5 = x5 * x5 * x;
return (f90 - f0) * x5 + f0; // sub mul mul mul sub mad
}
float F_Schlick(float f0, float u)
{
return F_Schlick(f0, 1.0f, u);
}
float3 F_Schlick(float3 f0, float f90, float u)
{
float x = 1.0f - 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 u)
{
return F_Schlick(f0, float3(1.0f, 1.0f, 1.0f), u);
}
//-----------------------------------------------------------------------------
// Specular BRDF
//-----------------------------------------------------------------------------
// With analytical light (not image based light) we clamp the minimun roughness to avoid numerical instability.
#define UNITY_MIN_ROUGHNESS 0.002
float D_GGX(float NdotH, float roughness)
{
roughness = max(roughness, UNITY_MIN_ROUGHNESS);
float a2 = roughness * roughness;
float f = (NdotH * a2 - NdotH) * NdotH + 1.0f;
return INV_PI * a2 / (f * f);
}
// roughnessT -> roughness in tangent direction
// roughnessB -> roughness in bitangent direction
float D_GGX_Aniso(float NdotH, float TdotH, float BdotH, float roughnessT, float roughnessB)
{
// 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
float V_SmithJointGGX(float NdotL, float NdotV, float roughness)
{
#if 1
// 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;
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);
#else
// Approximation of the above formulation (simplify the sqrt, not mathematically correct but close enough)
half a = roughness;
half lambdaV = NdotL * (NdotV * (1 - a) + a);
half lambdaL = NdotV * (NdotL * (1 - a) + a);
return 0.5f / (lambdaV + lambdaL);
#endif
}
// TODO: V_ term for aniso GGX from farcry
//-----------------------------------------------------------------------------
// Diffuse BRDF - diffuseColor is expected to be multiply by the caller
//-----------------------------------------------------------------------------
float Lambert()
{
return INV_PI;
}
float DisneyDiffuse(float NdotV, float NdotL, float LdotH, float perceptualRoughness)
{
float fd90 = 0.5 + 2 * LdotH * LdotH * perceptualRoughness;
// Two schlick fresnel term
float lightScatter = F_Schlick(1.0f, fd90, NdotL);
float viewScatter = F_Schlick(1.0f, fd90, NdotV);
return INV_PI * lightScatter * viewScatter;
}
#endif // UNITY_BSDF_INCLUDED

8
Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl.meta


fileFormatVersion: 2
guid: 5eb5e8e99ae281342bae5c7b296b3ae3
timeCreated: 1472140530
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

203
Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl


#ifndef UNITY_COLOR_INCLUDED
#define UNITY_COLOR_INCLUDED
#include "Common.hlsl"
//-----------------------------------------------------------------------------
// Gamma space - Assume positive values
//-----------------------------------------------------------------------------
// Gamma20
float Gamma20ToLinear(float c)
{
return c * c;
}
float3 Gamma20ToLinear(float3 c)
{
return c.rgb * c.rgb;
}
float4 Gamma20ToLinear(float4 c)
{
return float4(Gamma20ToLinear(c.rgb), c.a);
}
float LinearToGamma20(float c)
{
return sqrt(c);
}
float3 LinearToGamma20(float3 c)
{
return sqrt(c.rgb);
}
float4 LinearToGamma20(float4 c)
{
return float4(LinearToGamma20(c.rgb), c.a);
}
// Gamma22
float Gamma22ToLinear(float c)
{
return pow(c, 2.2);
}
float3 Gamma22ToLinear(float3 c)
{
return pow(c.rgb, float3(2.2, 2.2, 2.2));
}
float4 Gamma22ToLinear(float4 c)
{
return float4(Gamma22ToLinear(c.rgb), c.a);
}
float LinearToGamma22(float c)
{
return pow(c, 0.454545454545455);
}
float3 LinearToGamma22(float3 c)
{
return pow(c.rgb, float3(0.454545454545455, 0.454545454545455, 0.454545454545455));
}
float4 LinearToGamma22(float4 c)
{
return float4(LinearToGamma22(c.rgb), c.a);
}
// sRGB
float3 SRGBToLinear(float3 c)
{
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;
}
float4 SRGBToLinear(float4 c)
{
return float4(SRGBToLinear(c.rgb), c.a);
}
float3 LinearToSRGB(float3 c)
{
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;
}
float4 LinearToSRGB(float4 c)
{
return float4(LinearToSRGB(c.rgb), c.a);
}
// TODO: Seb - To verify and refit!
// Ref: http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1
float3 FastSRGBToLinear(float3 c)
{
return c * (c * (c * 0.305306011 + 0.682171111) + 0.012522878);
}
float4 FastSRGBToLinear(float4 c)
{
return float4(FastSRGBToLinear(c.rgb), c.a);
}
float3 FastLinearToSRGB(float3 c)
{
return max(1.055 * pow(c, 0.416666667) - 0.055, 0.0);
}
float4 FastLinearToSRGB(float4 c)
{
return float4(FastLinearToSRGB(c.rgb), c.a);
}
//-----------------------------------------------------------------------------
// Color space
//-----------------------------------------------------------------------------
// Convert rgb to luminance
// 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));
}
// Ref: http://realtimecollisiondetection.net/blog/?p=15
float4 PackLogLuv(float3 vRGB)
{
// 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);
Xp_Y_XYZp = max(Xp_Y_XYZp, float3(1e-6, 1e-6, 1e-6));
vResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;
float Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;
vResult.w = frac(Le);
vResult.z = (Le - (floor(vResult.w*255.0f))/255.0f)/255.0f;
return vResult;
}
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);
float Le = vLogLuv.z * 255.0 + vLogLuv.w;
float3 Xp_Y_XYZp;
Xp_Y_XYZp.y = exp2((Le - 127.0) / 2.0);
Xp_Y_XYZp.z = Xp_Y_XYZp.y / vLogLuv.y;
Xp_Y_XYZp.x = vLogLuv.x * Xp_Y_XYZp.z;
float3 vRGB = mul(Xp_Y_XYZp, InverseM);
return max(vRGB, float3(0.0, 0.0, 0.0));
}
// TODO: check what is really use by the lightmap... should be hardcoded
// 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;
float4 rgbm = float4(rgb * kOneOverRGBMMaxRange, 1.0f);
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...
#define RGBMRANGE (8.0)
float4 packRGBM(float3 color)
{
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;
}
float3 unpackRGBM(float4 rgbm)
{
return RGBMRANGE * rgbm.rgb * rgbm.a;
}
#endif // UNITY_COLOR_INCLUDED

8
Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl.meta


fileFormatVersion: 2
guid: 23284bbc36146a94995a8a08e61f4e73
timeCreated: 1472140529
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

8
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl.meta


fileFormatVersion: 2
guid: a57f9f83ea626ae45b402953fe637268
timeCreated: 1472140530
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

6
Assets/ScriptableRenderLoop/ShaderLibrary/GeometricTools.hlsl


#ifndef UNITY_GEOMETRICTOOLS_INCLUDED
#define UNITY_GEOMETRICTOOLS_INCLUDED
#include "Common.hlsl"
#endif // UNITY_GEOMETRICTOOLS_INCLUDED

8
Assets/ScriptableRenderLoop/ShaderLibrary/GeometricTools.hlsl.meta


fileFormatVersion: 2
guid: eebfba22df48acf4b978d98000cb10e6
timeCreated: 1472140530
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

85
Assets/ScriptableRenderLoop/ShaderLibrary/Packing.hlsl


#ifndef UNITY_PACKING_INCLUDED
#define UNITY_PACKING_INCLUDED
#include "Common.hlsl"
//-----------------------------------------------------------------------------
// Normal packing
//-----------------------------------------------------------------------------
float3 PackNormalCartesian(float3 n)
{
return n * 0.5 + 0.5;
}
float3 UnpackNormalCartesian(float3 n)
{
return normalize(n * 2.0 - 1.0);
}
float3 PackNormalMaxComponent(float3 n)
{
// TODO: use max3
return (n / max(abs(n.x), max(abs(n.y), abs(n.z)))) * 0.5 + 0.5;
}
float3 UnpackNormalMaxComponent(float3 n)
{
return normalize(n * 2.0 - 1.0);
}
// Ref: http://jcgt.org/published/0003/02/01/paper.pdf
// Encode with Oct, this function work with any size of output
// return float between [-1, 1]
float2 PackNormalOctEncode(float3 v)
{
float l1norm = abs(v.x) + abs(v.y) + abs(v.z);
float2 res0 = v.xy * (1.0f / l1norm);
float2 val = 1.0f - abs(res0.yx);
return (v.zz < float2(0.0f, 0.0f) ? (res0 >= 0.0f ? val : -val) : res0);
}
float3 UnpackNormalOctEncode(float x, float y)
{
float3 v = float3(x, y, 1.0f - abs(x) - abs(y));
float2 val = 1.0f - abs(v.yx);
v.xy = (v.zz < float2(0.0f, 0.0f) ? (v.xy >= 0.0f ? val : -val) : v.xy);
return normalize(v);
}
float3 UnpackNormalDXT5nm (float4 packednormal)
{
float3 normal;
normal.xy = packednormal.wy * 2 - 1;
normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
return normal;
}
//-----------------------------------------------------------------------------
// Byte packing
//-----------------------------------------------------------------------------
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 Unpack2Byte(float inputs)
{
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));
}
//-----------------------------------------------------------------------------
#endif // UNITY_PACKING_INCLUDED

8
Assets/ScriptableRenderLoop/ShaderLibrary/Packing.hlsl.meta


fileFormatVersion: 2
guid: ad629edbad34c1c45afea3021c1553c8
timeCreated: 1472140530
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

6
Assets/ScriptableRenderLoop/ShaderLibrary/QuaternionMath.hlsl


#ifndef UNITY_QUATERNIONMATH_INCLUDED
#define UNITY_QUATERNIONMATH_INCLUDED
#include "Common.hlsl"
#endif // UNITY_QUATERNIONMATH_INCLUDED

8
Assets/ScriptableRenderLoop/ShaderLibrary/QuaternionMath.hlsl.meta


fileFormatVersion: 2
guid: 28991169f6e68314ab20d6a0e4aeccec
timeCreated: 1472140530
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

6
Assets/ScriptableRenderLoop/ShaderLibrary/SHMath.hlsl


#ifndef UNITY_SHMATH_INCLUDED
#define UNITY_SHMATH_INCLUDED
#include "Common.hlsl"
#endif // UNITY_SHMATH_INCLUDED

8
Assets/ScriptableRenderLoop/ShaderLibrary/SHMath.hlsl.meta


fileFormatVersion: 2
guid: 6c7ed7ec061ae2243bb560c39b451a15
timeCreated: 1472140530
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

6
Assets/ScriptableRenderLoop/ShaderLibrary/Sampling.hlsl


#ifndef UNITY_SAMPLING_INCLUDED
#define UNITY_SAMPLING_INCLUDED
#include "Common.hlsl"
#endif // UNITY_SAMPLING_INCLUDED

8
Assets/ScriptableRenderLoop/ShaderLibrary/Sampling.hlsl.meta


fileFormatVersion: 2
guid: f4c850bea2c5d45449ba8e228333c82c
timeCreated: 1472140530
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

82
Assets/ScriptableRenderLoop/ShaderLibrary/Filtering.hlsl


// Ref: https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1 from MJP
// Samples a texture with Catmull-Rom filtering, using 9 texture fetches instead of 16.
// See http://vec3.ca/bicubic-filtering-in-fewer-taps/ for more details
float4 SampleTextureCatmullRom(Texture2D<float4> tex, SamplerState linearSampler, float2 uv, float2 texSize)
{
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding
// down the sample location to get the exact center of our "starting" texel. The starting texel will be at
// location [1, 1] in the grid, where [0, 0] is the top left corner.
float2 samplePos = uv * texSize;
float2 texPos1 = floor(samplePos - 0.5f) + 0.5f;
// Compute the fractional offset from our starting texel to our original sample location, which we'll
// feed into the Catmull-Rom spline function to get our filter weights.
float2 f = samplePos - texPos1;
float2 f2 = f * f;
float2 f3 = f2 * f;
// Compute the Catmull-Rom weights using the fractional offset that we calculated earlier.
// These equations are pre-expanded based on our knowledge of where the texels will be located,
// which lets us avoid having to evaluate a piece-wise function.
float2 w0 = (1.0f / 6.0f) * (-3.0f * f3 + 6.0f * f2 - 3.0f * f);
float2 w1 = (1.0f / 6.0f) * (9.0f * f3 - 15.0f * f2 + 6.0f);
float2 w2 = (1.0f / 6.0f) * (-9.0f * f3 + 12.0f * f2 + 3.0f * f);
float2 w3 = (1.0f / 6.0f) * (3.0f * f3 - 3.0f * 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);
// 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.
float2 w12 = w1 + w2;
float2 offset12 = w2 / (w1 + w2);
// Compute the final UV coordinates we'll use for sampling the texture
float2 texPos0 = texPos1 - 1;
float2 texPos3 = texPos1 + 2;
float2 texPos12 = texPos1 + offset12;
texPos0 /= texSize;
texPos3 /= texSize;
texPos12 /= texSize;
float4 result = 0.0f;
result += tex.SampleLevel(linearSampler, float2(texPos0.x, texPos0.y), 0.0f) * w0.x * w0.y;
result += tex.SampleLevel(linearSampler, float2(texPos12.x, texPos0.y), 0.0f) * w12.x * w0.y;
result += tex.SampleLevel(linearSampler, float2(texPos3.x, texPos0.y), 0.0f) * w3.x * w0.y;
result += tex.SampleLevel(linearSampler, float2(texPos0.x, texPos12.y), 0.0f) * w0.x * w12.y;
result += tex.SampleLevel(linearSampler, float2(texPos12.x, texPos12.y), 0.0f) * w12.x * w12.y;
result += tex.SampleLevel(linearSampler, float2(texPos3.x, texPos12.y), 0.0f) * w3.x * w12.y;
result += tex.SampleLevel(linearSampler, float2(texPos0.x, texPos3.y), 0.0f) * w0.x * w3.y;
result += tex.SampleLevel(linearSampler, float2(texPos12.x, texPos3.y), 0.0f) * w12.x * w3.y;
result += tex.SampleLevel(linearSampler, float2(texPos3.x, texPos3.y), 0.0f) * w3.x * w3.y;
return result;
}
/*
// manual tri-linearly interpolated texture fetch
// not really needed: used hard-wired texture interpolation
vec4 manualTexture3D( sampler3D samp, vec3 p ){
vec3 qa = p*uvMapSize + vec3(0.5);
vec3 qi = floor(qa);
qa -= qi;
qi -= vec3(0.5);
return
mix( mix( mix( texture3D( samp, (qi+vec3(0.0,0.0,0.0))*oneOverUvMapSize ),
texture3D( samp, (qi+vec3(1.0,0.0,0.0))*oneOverUvMapSize ), qa.x ),
mix( texture3D( samp, (qi+vec3(0.0,1.0,0.0))*oneOverUvMapSize ),
texture3D( samp, (qi+vec3(1.0,1.0,0.0))*oneOverUvMapSize ), qa.x ), qa.y ),
mix( mix( texture3D( samp, (qi+vec3(0.0,0.0,1.0))*oneOverUvMapSize ),
texture3D( samp, (qi+vec3(1.0,0.0,1.0))*oneOverUvMapSize ), qa.x ),
mix( texture3D( samp, (qi+vec3(0.0,1.0,1.0))*oneOverUvMapSize ),
texture3D( samp, (qi+vec3(1.0,1.0,1.0))*oneOverUvMapSize ), qa.x ), qa.y ), qa.z );
}
*/

8
Assets/ScriptableRenderLoop/ShaderLibrary/Filtering.hlsl.meta


fileFormatVersion: 2
guid: dac42c6a533d53b41b931e02431564fa
timeCreated: 1474355143
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

38
Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl


#ifndef UNITY_COMMON_LIGHTING_INCLUDED
#define UNITY_COMMON_LIGHTING_INCLUDED
//-----------------------------------------------------------------------------
// Attenuation functions
//-----------------------------------------------------------------------------
// 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;
}
#define PUNCTUAL_LIGHT_THRESHOLD 0.01 // 1cm (in Unity 1 is 1m)
float GetDistanceAttenuation(float3 unL, float 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;
}
float GetAngleAttenuation(float3 L, float3 lightDir, float lightAngleScale, float lightAngleOffset)
{
float cd = dot(lightDir, L);
float attenuation = saturate(cd * lightAngleScale + lightAngleOffset);
// smooth the transition
attenuation *= attenuation;
return attenuation;
}
#endif // UNITY_COMMON_LIGHTING_INCLUDED

8
Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl.meta


fileFormatVersion: 2
guid: 93bbf250faa37d446990b9501e7fb7e8
timeCreated: 1474465931
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/ShaderLibrary/Postprocress.meta


fileFormatVersion: 2
guid: d90c5a99d7855ad46b792d749ce7ca6f
folderAsset: yes
timeCreated: 1472140530
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

175
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


#ifndef UNITY_COMMON_INCLUDED
#define UNITY_COMMON_INCLUDED
// Convention:
// space at the end of the variable name
// WS: world space
// VS: view space
// OS: object space
// HS: Homogenous clip space
// CS: clips space
// Example: NormalWS
// normalized / unormalized vector
// normalized direction are almost everywhere, we tag unormalized vector with un.
// Example: unL for unormalized light vector
// use capital letter for regular vector, vector are always pointing outward the current pixel position (ready for lighting equation)
// capital letter mean the vector is normalize, unless we put un in front of it.
// V: View vector (no eye vector)
// L: Light vector
// N: Normal vector
// H: Half vector
// Input/Outputs structs in PascalCase and prefixed by entry type
// struct AttributesDefault
// struct VaryingsDefault
// use input/output as variable name when using these structures
// Entry program name
// VertDefault
// FragDefault / FragForward / FragDeferred
// constant floating number written as 1.0 (not 1, not 1.0f, not 1.0h)
// uniform have g_ as prefix (still lowercaseThenCamelCase)
// Structure definition that are share between C# and hlsl.
// These structures need to be align on float4 to respectect various packing rules from sahder language.
// This mean that these structure need to be padded.
// Do not use "in", only "out" or "inout" as califier, not "inline" keyword either, useless.
// The lighting code assume that 1 Unity unit (1uu) == 1 meters. This is very important regarding physically based light unit and inverse square attenuation
// When declaring "out" argument of function, they are always last
// Include language header
#if defined(SHADER_API_D3D11)
#include "API/D3D11.hlsl"
#elif defined(SHADER_API_XBOXONE)
#include "API/D3D11_1.hlsl"
#else
#error unsupported shader api
#endif
#include "API/Validate.hlsl"
// ----------------------------------------------------------------------------
// Common define allowing to include shared file between C# and hlsl
// ----------------------------------------------------------------------------
#define __HLSL 1
#define public
#define Vec2 float2
#define Vec3 float3
#define Vec4 float4
#define Mat44 float4x4
// ----------------------------------------------------------------------------
// Common math definition and fastmath function
// ----------------------------------------------------------------------------
#define PI 3.14159265359f
#define TWO_PI 6.28318530718f
#define FOUR_PI 12.56637061436f
#define INV_PI 0.31830988618f
#define INV_TWO_PI 0.15915494309f
#define INV_FOUR_PI 0.07957747155f
#define HALF_PI 1.57079632679f
#define INV_HALF_PI 0.636619772367f
#define MERGE_NAME(X, Y) X##Y
// Ref: https://seblagarde.wordpress.com/2014/12/01/inverse-trigonometric-functions-gpu-optimization-for-amd-gcn-architecture/
float FastACos(float inX)
{
float x = abs(inX);
float res = -0.156583f * x + HALF_PI;
res *= sqrt(1.0f - x);
return (inX >= 0) ? res : PI - res;
}
// Same cost as Acos + 1 FR
// Same error
// input [-1, 1] and output [-PI/2, PI/2]
float FastASin(float x)
{
return HALF_PI - FastACos(x);
}
// max absolute error 1.3x10^-3
// Eberly's odd polynomial degree 5 - respect bounds
// 4 VGPR, 14 FR (10 FR, 1 QR), 2 scalar
// input [0, infinity] and output [0, PI/2]
float FastATanPos(float x)
{
float t0 = (x < 1.0f) ? x : 1.0f / x;
float t1 = t0 * t0;
float poly = 0.0872929f;
poly = -0.301895f + poly * t1;
poly = 1.0f + poly * t1;
poly = poly * t0;
return (x < 1.0f) ? poly : HALF_PI - poly;
}
// 4 VGPR, 16 FR (12 FR, 1 QR), 2 scalar
// input [-infinity, infinity] and output [-PI/2, PI/2]
float FastATan(float x)
{
float t0 = FastATanPos(abs(x));
return (x < 0.0f) ? -t0: t0;
}
// ----------------------------------------------------------------------------
// World position reconstruction / transformation
// ----------------------------------------------------------------------------
struct Coordinate
{
// 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.
// This allow to easily share code.
// If a compute shader call this function inPositionSS is an interger usually calculate like: uint2 inPositionSS = groupId.xy * BLOCK_SIZE + groupThreadId.xy
// else it is current unormalized screen coordinate like return by VPOS
Coordinate GetCoordinate(float2 inPositionSS, float2 invScreenSize)
{
Coordinate coord;
coord.positionSS = inPositionSS;
// TODO: How to detect automatically that we are a compute shader ?
#if 0
// 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.5f, 0.5f);
#endif
coord.positionSS *= invScreenSize;
coord.unPositionSS = int2(inPositionSS);
return coord;
}
// screenPos is screen coordinate in [0..1] (return by Coordinate.positionSS)
// depth must be the depth from the raw depth buffer. This allow to handle all kind of depth automatically with the inverse view projection matrix.
// For information. In Unity Depth is always in range 0..1 (even on OpenGL) but can be reversed.
float3 UnprojectToWorld(float depth, float2 screenPos, float4x4 invViewProjectionMatrix)
{
// CAUTION: The camera projection we get with Unity don't include the reverse stuff and the depth need to be remap manually to -1..1
// We should simplify the process and have a way to do Camera.Projection matrix that return the projection martix use to project depth.
#if UNITY_REVERSED_Z
depth = 1.0 - depth;
#endif
depth = depth * 2.0 - 1.0;
float4 positionHS = float4(screenPos.xy * 2.0 - 1.0, depth, 1.0);
float4 hpositionWS = mul(invViewProjectionMatrix, positionHS);
return hpositionWS.xyz / hpositionWS.w;
}
#endif // UNITY_COMMON_INCLUDED

160
Assets/TestScenes/HDTest/Material/test.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: test
m_Shader: {fileID: 4800000, guid: e1a84346ee54f9f4993c2f05c59805a0, type: 3}
m_ShaderKeywords: _EMISSION
m_LightmapFlags: 1
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _BumpMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailAlbedoMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailMask
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailNormalMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DiffuseMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _EmissionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MetallicGlossMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _NormalMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _OcclusionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _ParallaxMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _SmoothnessMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _SpecMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _BumpScale
second: 1
- first:
name: _Cutoff
second: 0.5
- first:
name: _DetailNormalMapScale
second: 1
- first:
name: _DstBlend
second: 0
- first:
name: _GlossMapScale
second: 1
- first:
name: _Glossiness
second: 0.5
- first:
name: _GlossyReflections
second: 1
- first:
name: _Metallic
second: 0
- first:
name: _Mode
second: 0
- first:
name: _OcclusionStrength
second: 1
- first:
name: _Parallax
second: 0.02
- first:
name: _Smoothness
second: 0.5
- first:
name: _SmoothnessTextureChannel
second: 0
- first:
name: _SpecularHighlights
second: 1
- first:
name: _SrcBlend
second: 1
- first:
name: _UVSec
second: 0
- first:
name: _ZWrite
second: 1
m_Colors:
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
- first:
name: _DiffuseColor
second: {r: 1, g: 1, b: 1, a: 1}
- first:
name: _EmissionColor
second: {r: 0, g: 0, b: 0, a: 1}
- first:
name: _SpecColor
second: {r: 0.04, g: 0.04, b: 0.04, a: 1}

8
Assets/TestScenes/HDTest/Material/test.mat.meta


fileFormatVersion: 2
guid: 87c86082ee14fbd4b8426a8794f2060d
timeCreated: 1474299392
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/TestScenes/HDTest/Material.meta


fileFormatVersion: 2
guid: c66c964aecf301a43b3bdfdd3d39069e
folderAsset: yes
timeCreated: 1474299385
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/TestScenes/ForwardRenderLoop/ForwardRenderLoop.meta


fileFormatVersion: 2
guid: e7f1798d6eb03b34d85b33709157ad8e
folderAsset: yes
timeCreated: 1471266423
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

11
ProjectSettings/UnityAdsSettings.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!292 &1
UnityAdsSettings:
m_ObjectHideFlags: 0
m_Enabled: 0
m_InitializeOnStartup: 1
m_TestMode: 0
m_EnabledPlatforms: 4294967295
m_IosGameId:
m_AndroidGameId:
正在加载...
取消
保存