浏览代码

Merge branch 'master' into feature/SSR

# Conflicts:
#	ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/BuildPlayer/HDRPVariantStripper.cs
#	ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
#	ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
/main
Frédéric Vauchelles 6 年前
当前提交
4d7f78f1
共有 950 个文件被更改,包括 1882 次插入2022 次删除
  1. 6
      .gitattributes
  2. 6
      .gitignore
  3. 14
      .gitmodules
  4. 16
      README.md
  5. 161
      build.py
  6. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/BuildPlayer/HDRPCustomBuildProcessor.cs
  7. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/HDBaseEditor.cs
  8. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/HDEditorCLI.cs
  9. 6
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/VisualEnvironmentEditor.cs
  10. 6
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/SkySettingsEditor.cs
  11. 9
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/BakingSkyEditor.cs
  12. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/AtmosphericScattering/LinearFogEditor.cs
  13. 6
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/AtmosphericScattering/AtmosphericScatteringEditor.cs
  14. 3
      com.unity.render-pipelines.high-definition/HDRP/Editor/com.unity.render-pipelines.high-definition.Editor.asmdef
  15. 98
      com.unity.render-pipelines.high-definition/HDRP/Editor/EditorRenderPipelineResources/ReflectionProbesPreview.shader
  16. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/HDShaderIncludePaths.cs
  17. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/BaseUI.cs
  18. 9
      com.unity.render-pipelines.high-definition/HDRP/Editor/HDRenderPipelineMenuItems.cs
  19. 6
      com.unity.render-pipelines.high-definition/HDRP/Editor/Shadows/HDShadowSettingsEditor.cs
  20. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/Shadows/ContactShadowsEditor.cs
  21. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/Camera/SerializedHDCamera.cs
  22. 105
      com.unity.render-pipelines.high-definition/HDRP/Editor/Camera/HDCameraUI.cs
  23. 26
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Volumetric/Texture3DCreationEditor.cs
  24. 8
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs
  25. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/SerializedReflectionProxyVolumeComponent.cs
  26. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/SerializedProxyVolume.cs
  27. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/SerializedInfluenceVolume.cs
  28. 11
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/ReflectionProxyVolumeComponentUI.cs
  29. 20
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/ProxyVolumeUI.cs
  30. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/ProxyVolumeEditor.cs
  31. 3
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/InfluenceVolumeUI.cs
  32. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/InfluenceVolumeUI.Handles.cs
  33. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/InfluenceVolumeUI.Gizmos.cs
  34. 40
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/InfluenceVolumeUI.Drawers.cs
  35. 6
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/SerializedPlanarReflectionProbe.cs
  36. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/SerializedHDReflectionProbe.cs
  37. 3
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/ScreenSpaceRefractionEditor.cs
  38. 3
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/ScreenSpaceLightingEditor.cs
  39. 3
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/PlanarReflectionProbeUI.cs
  40. 138
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/PlanarReflectionProbeUI.Handles.cs
  41. 132
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/PlanarReflectionProbeUI.Drawers.cs
  42. 12
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/PlanarReflectionProbeEditor.cs
  43. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDScreenSpaceReflectionEditor.cs
  44. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeUI.cs
  45. 123
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeUI.Drawers.cs
  46. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditorUtility.cs
  47. 9
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditor.cs
  48. 3
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditor.Preview.cs
  49. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditor.Handles.cs
  50. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDCubemapInspector.cs
  51. 16
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/EditorReflectionSystemGUI.cs
  52. 18
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/EditorReflectionSystem.cs
  53. 96
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs
  54. 3
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/ShadowInitParametersUI.cs
  55. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/SerializedShadowInitParameters.cs
  56. 6
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/SerializedRenderPipelineSettings.cs
  57. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/SerializedLightLoopSettings.cs
  58. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/SerializedHDRenderPipelineAsset.cs
  59. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/SerializedGlobalLightLoopSettings.cs
  60. 22
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/SerializedGlobalDecalSettings.cs
  61. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/SerializedFrameSettings.cs
  62. 53
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/RenderPipelineSettingsUI.cs
  63. 10
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/LightLoopSettingsUI.cs
  64. 34
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/HDRenderPipelineUI.cs
  65. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/HDRenderPipelineEditor.cs
  66. 17
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/GlobalLightLoopSettingsUI.cs
  67. 33
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/GlobalDecalSettingsUI.cs
  68. 82
      com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/FrameSettingsUI.cs
  69. 49
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Unlit/UnlitsToHDUnlitUpgrader.cs
  70. 1
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Unlit/UnlitUI.cs
  71. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Unlit/BaseUnlitUI.cs
  72. 57
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/StackLitUI.cs
  73. 11
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/BaseMaterialUI.cs
  74. 50
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/StandardsToHDLitMaterialUpgrader.cs
  75. 13
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/LitUI.cs
  76. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/BaseLitUI.cs
  77. 5
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/LayeredLit/LayeredLitUI.cs
  78. 6
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/DiffusionProfile/DiffusionProfileSettingsEditor.cs
  79. 19
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalUI.cs
  80. 34
      com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalProjectorComponentEditor.cs
  81. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/AssetPostProcessors/NormalMapVarianceTexturePostprocessor.cs
  82. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightingConvexHullUtils.hlsl
  83. 30
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/ShadowContext.hlsl
  84. 6
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoopSettings.cs
  85. 5
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/Deferred.compute
  86. 12
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/builddispatchindirect.compute
  87. 10
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/cleardispatchindirect.compute
  88. 4
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightCullUtils.hlsl
  89. 12
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/ClusteredUtils.hlsl
  90. 70
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/Shadow.hlsl
  91. 36
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs.hlsl
  92. 250
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/lightlistbuild-bigtile.compute
  93. 530
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/lightlistbuild-clustered.compute
  94. 524
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/lightlistbuild.compute
  95. 60
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/materialflags.compute
  96. 638
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/scrbound.compute
  97. 3
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/GlobalLightLoopSettings.cs
  98. 8
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Lighting.hlsl
  99. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/Volumes/ShapeType.cs
  100. 2
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/Volumes/ReflectionProxyVolumeComponent.cs

6
.gitattributes


ShaderGraph/**/*.png filter=lfs diff=lfs merge=lfs -text
ShaderGraph/**/*.gif filter=lfs diff=lfs merge=lfs -text
com.unity.shadergraph/**/*.png filter=lfs diff=lfs merge=lfs -text
com.unity.shadergraph/**/*.gif filter=lfs diff=lfs merge=lfs -text
TestProjects/ShaderGraph/**/*.png filter=lfs diff=lfs merge=lfs -text
TestProjects/LWRP/**/*.tif filter=lfs diff=lfs merge=lfs -text

6
.gitignore


artifacts/**
build/**
DataSource/*
Library/*
**/Library/**
obj/*
Temp/*
.vs

.npmrc
ShaderGraph/DebugOutput.meta
ShaderGraph/DebugOutput/**
ShaderGraph/Testing/IntegrationTests/.Failed
ShaderGraph/Testing/IntegrationTests/.Failed
TestProjects/GraphicsTests/Temp/
TestProjects/LWRP/GraphicsTests/Temp/

14
.gitmodules


url = https://github.com/Unity-Technologies/PostProcessing
branch = v2
[submodule "Tests/UTF_Core"]
path = Tests/UTF_Core
path = TestProjects/GraphicsTests/Assets/Tests/UTF_Core
branch = master
path = Tests/UTF_Tests_HDRP
path = TestProjects/GraphicsTests/Assets/Tests/UTF_Tests_HDRP
url = https://github.com/Unity-Technologies/UTF_Tests_HDRP.git
branch = master
[submodule "TestProjects/GraphicsTests/Assets/Tests/UTF_Core"]
path = TestProjects/GraphicsTests/Assets/Tests/UTF_Core
url = https://github.com/Unity-Technologies/UTF_Core.git
[submodule "TestProjects/GraphicsTests/Assets/Tests/UTF_Tests_HDRP"]
path = TestProjects/GraphicsTests/Assets/Tests/UTF_Tests_HDRP
url = https://github.com/Unity-Technologies/UTF_Tests_HDRP.git

16
README.md


# Unity Scriptable Render Pipeline
The Scriptable Render Pipeline (SRP) is a new Unity feature in active development. SRP has been designed to give artists and developers the tools they need to create modern, high-fidelity graphics in Unity. Including a built-in Lightweight Render Pipeline for use on all platforms, and a High Definition Render Pipeline (HDRP) for use on compute shader compatible platforms. We hope to release both of these versions in beta with Unity version 2018.1.
The Scriptable Render Pipeline (SRP) is a new Unity feature in active development. SRP has been designed to give artists and developers the tools they need to create modern, high-fidelity graphics in Unity. Including a built-in Lightweight Render Pipeline for use on all platforms, and a High Definition Render Pipeline (HDRP) for use on compute shader compatible platforms. These features are available in Unity 2018.1+.
We are committed to an open and transparent development process, and as such you are welcome to take a look around if you are really curious, but we cannot provide support for this feature yet.
We are committed to an open and transparent development process, and as such you are welcome to take a look around if you are really curious.
This feature is currently a work in progress. We cannot promise that features will work as expected in their current state. Some features may change or be removed before we move to a full release.
This feature is currently in preview. Some features may change or be removed before we move to a full release.
[Lightweight Pipeline Blogpost](https://blogs.unity3d.com/2018/02/21/the-lightweight-render-pipeline-optimizing-real-time-performance/)

__Note: The Master branch is our current development branch and may not work on the latest publicly available version of Unity. You should always use the latest release tag and latest Unity beta version for testing purposes.__
To use the latest version of the SRP, follow the instructions below:
This repository consists of a folder that needs to be placed in the Assets\ folder of your Unity project. We recommend creating a new project to test SRP. Do not clone this repo into an existing project unless you want to break it, or unless you are updating to a newer version of the SRP repo. Your project's `packages.json` file (in either `UnityPackageManager/` or `Packages/`) does not have a dependency on any of the packages in this repository or the contained submodules.
This repository consists of a folder that should be cloned outside the Assets\ folder of your Unity project. We recommend creating a new project to test SRP. Do not clone this repo into an existing project unless you want to break it, or unless you are updating to a newer version of the SRP repo.
After cloning you will need to edit your project's `packages.json` file (in either `UnityPackageManager/` or `Packages/`) to point to the SRP submodules you wish to use. See: https://github.com/Unity-Technologies/ScriptableRenderPipeline/blob/build/automation/TestProjects/GraphicsTests/Packages/manifest.json
This will link your project to the specific version of SRP you have cloned.
You can use the GitHub desktop app to clone the latest version of the SRP repo or you can use GitHub console commands.

3. Enter the following URL: https://github.com/Unity-Technologies/ScriptableRenderPipeline
4. Click the __Choose…__ button to navigate to your project’s Asset folder.
4. Click the __Choose…__ button to navigate to your project’s base folder.
5. Click the __Clone__ button.
After the repo has been cloned you will need to run the following console commands from the ScriptableRenderPipeline folder:

Enter the following commands in your console application of choice:
```
> cd <Path to your Unity project>/Assets
> cd <Path to your Unity project>
> git clone https://github.com/Unity-Technologies/ScriptableRenderPipeline
> cd ScriptableRenderPipeline
> git checkout Unity-2018.1.0b2 (or the latest tag)

161
build.py


#!/usr/bin/python -B
import os
import json
import platform
import shutil
import subprocess
import textwrap
sub_packages = {}
sub_package_folders = {}
publish_order = []
("com.unity.render-pipelines.core", os.path.join("ScriptableRenderPipeline", "Core")),
("com.unity.render-pipelines.high-definition", os.path.join("ScriptableRenderPipeline", "HDRenderPipeline")),
("com.unity.render-pipelines.lightweight", os.path.join("ScriptableRenderPipeline", "LightweightPipeline"))
("com.unity.render-pipelines.core", os.path.join("com.unity.render-pipelines.core")),
("com.unity.render-pipelines.lightweight", os.path.join("com.unity.render-pipelines.lightweight")),
("com.unity.render-pipelines.high-definition", os.path.join("com.unity.render-pipelines.high-definition")),
("com.unity.shadergraph", os.path.join("com.unity.shadergraph")),
def prepare(logger):
file_path = os.path.join("./ScriptableRenderPipeline", "master-package.json")
if os.path.isfile(file_path):
logger.info("Found master package file: {}".format(file_path))
with open(file_path) as file:
try:
master_package = json.load(file)
except json.JSONDecodeError as e:
logger.critical(e)
exit(1)
potential_folders = master_package["subPackages"] if "subPackages" in master_package else []
for item in potential_folders:
file_path = os.path.join("./ScriptableRenderPipeline", item, "sub-package.json")
if os.path.isfile(file_path):
logger.info("Found sub-package file: {}".format(file_path))
with open(file_path) as file:
try:
sub_package = json.load(file)
sub_packages[sub_package["name"]] = sub_package
sub_package_folders[sub_package["name"]
] = os.path.join("./ScriptableRenderPipeline", item)
except json.JSONDecodeError as e:
logger.critical("Error: {}".format(e))
if not sub_packages:
logger.critical("Error: No sub-packages found.")
exit(1)
if "version" not in master_package:
logger.critical("Master package must contain a \"version\" field")
exit(1)
print("Propagating master package version to sub-packages")
for sub_package in sub_packages.values():
sub_package["version"] = master_package["version"]
if "unity" in master_package:
print("Propagating master package Unity version to sub-packages")
for sub_package in sub_packages.values():
sub_package["unity"] = master_package["unity"]
if "dependencies" in master_package and master_package["dependencies"]:
print("Propagating shared dependencies:")
for name, version in master_package["dependencies"].items():
logger.info(" {}@{}".format(name, version))
for sub_package in sub_packages.values():
if "dependencies" not in sub_package or not sub_package["dependencies"]:
sub_package["dependencies"] = {}
for name, version in master_package["dependencies"].items():
sub_package["dependencies"][name] = version
logger.info("Creating dependency tree:")
dependency_list = {}
dependency_tree = {}
for i, sub_package in enumerate(sub_packages.values()):
dependency_list[sub_package["name"]] = {}
for i, sub_package in enumerate(sub_packages.values()):
if "subDependencies" in sub_package and sub_package["subDependencies"]:
for dependency in sub_package["subDependencies"]:
dependency_list[dependency][sub_package["name"]
] = dependency_list[sub_package["name"]]
else:
dependency_tree[sub_package["name"]
] = dependency_list[sub_package["name"]]
if not dependency_tree:
logger.critical("Dependency tree is empty. You might have a circular reference.")
exit(1)
def print_dependency_tree(tree, indent):
for key, sub_tree in tree.items():
print(key, " " * indent)
print_dependency_tree(sub_tree, indent + 1)
print_dependency_tree(dependency_tree, 1)
logger.info("Creating publish order:")
visited = set()
def fill_publish_order(tree):
for key, sub_tree in tree.items():
if key not in visited:
publish_order.append(key)
fill_publish_order(sub_tree)
fill_publish_order(dependency_tree)
for name in publish_order:
logger.info(" {}".format(name))
print "Resolving dependencies between sub-packages:"
for sub_package in sub_packages.values():
if "dependencies" not in sub_package or not sub_package["dependencies"]:
sub_package["dependencies"] = {}
if "subDependencies" in sub_package and sub_package["subDependencies"]:
logger.info(" {}:".format(sub_package["name"]))
for sub_dependency in sub_package["subDependencies"]:
sub_package["dependencies"][sub_dependency] = master_package["version"]
logger.info(" {}@{}".format(sub_dependency,
sub_package["dependencies"][sub_dependency]))
del sub_package["subDependencies"]
logger.info("Writing package files:")
for name in publish_order:
sub_package = sub_packages[name]
package_path = os.path.join(sub_package_folders[name], "package.json")
logger.info(" {}:".format(package_path))
with open(package_path, 'w') as file:
json.dump(sub_package, file, indent=4, sort_keys=True)
import unity_package_build
for name in publish_order:
package_path = os.path.join(sub_package_folders[name])
unity_package_build.copy_file_to_project("LICENSE.md", ".", package_path, logger)
unity_package_build.copy_file_to_project("CHANGELOG.md", ".", package_path, logger)
def cleanup(logger):
logger.info("Reverting temporary file changes:")
files = []
for name in publish_order:
folder = sub_package_folders[name]
files.append(os.path.join(folder, "package.json"))
for file in files:
logger.info(" {}".format(file))
subprocess.call(["git", "checkout", file], cwd=".")
# Prepare an empty project for editor tests
def prepare_editor_test_project(repo_path, project_path, logger):
import unity_package_build
dest_path = os.path.join(project_path, "Assets", "ScriptableRenderLoop")
unity_package_build.copy_path_to_project("ImageTemplates", repo_path, dest_path, logger)
unity_package_build.copy_path_to_project("Tests", repo_path, dest_path, logger)
unity_package_build.copy_file_to_project("SRPMARKER", repo_path, dest_path, logger)
unity_package_build.copy_file_to_project("SRPMARKER.meta", repo_path, dest_path, logger)
unity_package_build.copy_file_to_project("ImageTemplates.meta", repo_path, dest_path, logger)
unity_package_build.copy_file_to_project("Tests.meta", repo_path, dest_path, logger)
def test_packages_list():
return [
"com.unity.render-pipelines.core",
"com.unity.render-pipelines.lightweight",
"com.unity.render-pipelines.high-definition",
"com.unity.shadergraph"
]
try:
import unity_package_build
build_log = unity_package_build.setup()

2
com.unity.render-pipelines.high-definition/HDRP/Editor/BuildPlayer/HDRPCustomBuildProcessor.cs


report.summary.platform == BuildTarget.PS4 ||
report.summary.platform == BuildTarget.Switch)
{
return ;
return;
}
string msg = "The platform " + report.summary.platform.ToString() + " is not supported with Hight Definition Render Pipeline";

2
com.unity.render-pipelines.high-definition/HDRP/Editor/HDBaseEditor.cs


using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline

2
com.unity.render-pipelines.high-definition/HDRP/Editor/HDEditorCLI.cs


var mat = AssetDatabase.LoadAssetAtPath<Material>(path);
if (HDEditorUtils.ResetMaterialKeywords(mat))
Console.WriteLine("[HDEditorCLI][ResetMaterialKeywords] " + path);
Console.WriteLine("[HDEditorCLI][ResetMaterialKeywords] " + path);
}
break;
}

6
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/VisualEnvironmentEditor.cs


using System;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

void UpdateSkyIntPopupData()
{
if(m_SkyClassNames == null)
if (m_SkyClassNames == null)
{
m_SkyClassNames = new List<GUIContent>();
m_SkyUniqueIDs = new List<int>();

PropertyField(m_FogType);
}
}
}
}

6
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/SkySettingsEditor.cs


using System.Collections;
using System.Collections;
using UnityEngine;
using UnityEditor;
using UnityEditor.Experimental.Rendering;

{
PropertyField(m_SkyExposure);
PropertyField(m_SkyMultiplier);
if(enableRotation)
if (enableRotation)
PropertyField(m_SkyRotation);
PropertyField(m_EnvUpdateMode);

}
}
}
}
}

9
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/BakingSkyEditor.cs


using System;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

{
m_VolumeProfile = serializedObject.FindProperty("m_Profile");
m_SkyUniqueID = serializedObject.FindProperty("m_BakingSkyUniqueID");
}
void UpdateSkyIntPopupData(bool reset = false)

m_SkyUniqueIDs.Add(0);
VolumeProfile profile = m_VolumeProfile.objectReferenceValue as VolumeProfile;
if(profile != null)
if (profile != null)
{
var skyTypesDict = SkyManager.skyTypesDict;

{
InitializeProperties();
if(m_VolumeProfile.objectReferenceValue == null)
if (m_VolumeProfile.objectReferenceValue == null)
if(volume != null)
if (volume != null)
{
bakingSky.profile = volume.sharedProfile;
}

4
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/AtmosphericScattering/LinearFogEditor.cs


using System.Collections;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

PropertyField(m_FogHeightEnd);
}
}
}
}

6
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/AtmosphericScattering/AtmosphericScatteringEditor.cs


using System.Collections;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

PropertyField(m_Density);
PropertyField(m_ColorMode);
EditorGUI.indentLevel++;
if(!m_ColorMode.value.hasMultipleDifferentValues && (FogColorMode)m_ColorMode.value.intValue == FogColorMode.ConstantColor)
if (!m_ColorMode.value.hasMultipleDifferentValues && (FogColorMode)m_ColorMode.value.intValue == FogColorMode.ConstantColor)
{
PropertyField(m_Color);
}

EditorGUI.indentLevel--;
}
}
}
}

3
com.unity.render-pipelines.high-definition/HDRP/Editor/com.unity.render-pipelines.high-definition.Editor.asmdef


"com.unity.render-pipelines.core.Editor",
"com.unity.render-pipelines.high-definition.Runtime",
"com.unity.postprocessing.Runtime",
"com.unity.postprocessing.Editor"
"com.unity.postprocessing.Editor",
"Unity.ShaderGraph.Editor"
],
"optionalUnityReferences": [],
"includePlatforms": [

98
com.unity.render-pipelines.high-definition/HDRP/Editor/EditorRenderPipelineResources/ReflectionProbesPreview.shader


Shader "Debug/ReflectionProbePreview"
Shader "Debug/ReflectionProbePreview"
Properties
{
_Cubemap("_Cubemap", Cube) = "white" {}
_CameraWorldPosition("_CameraWorldPosition", Vector) = (1,1,1,1)
_MipLevel("_MipLevel", Range(0.0,7.0)) = 0.0
_Exposure("_Exposure", Range(-10.0,10.0)) = 0.0
Properties
{
_Cubemap("_Cubemap", Cube) = "white" {}
_CameraWorldPosition("_CameraWorldPosition", Vector) = (1,1,1,1)
_MipLevel("_MipLevel", Range(0.0,7.0)) = 0.0
_Exposure("_Exposure", Range(-10.0,10.0)) = 0.0
}
}
SubShader
{
Tags{ "RenderPipeline" = "HDRenderPipeline" "RenderType" = "Opaque" "Queue" = "Transparent" }
ZWrite On
Cull Back
SubShader
{
Tags{ "RenderPipeline" = "HDRenderPipeline" "RenderType" = "Opaque" "Queue" = "Transparent" }
ZWrite On
Cull Back
Pass
{
Name "ForwardUnlit"
Tags{ "LightMode" = "Forward" }
Pass
{
Name "ForwardUnlit"
Tags{ "LightMode" = "Forward" }
HLSLPROGRAM
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag

struct appdata
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
};
struct appdata
{
float4 positionOS : POSITION;
float3 normalOS : NORMAL;
};
struct v2f
{
float4 positionCS : SV_POSITION;
float3 normalWS : NORMAL;
float3 positionWS : TEXCOORD0;
};
struct v2f
{
float4 positionCS : SV_POSITION;
float3 normalWS : NORMAL;
float3 positionWS : TEXCOORD0;
};
float3 _CameraWorldPosition;
float _MipLevel;
float _Exposure;
float3 _CameraWorldPosition;
float _MipLevel;
float _Exposure;
v2f vert(appdata v)
{
v2f o;
v2f vert(appdata v)
{
v2f o;
// Transform local to world before custom vertex code
o.positionWS = TransformObjectToWorld(v.positionOS.xyz);
o.positionWS = GetCameraRelativePositionWS(o.positionWS);

return o;
}
return o;
}
float4 frag(v2f i) : SV_Target
{
//float3 view = normalize(i.worldpos - _CameraWorldPosition);
float3 V = normalize(i.positionWS - GetPrimaryCameraPosition());
float3 R = reflect(V, i.normalWS);
float4 color = SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, R, _MipLevel).rgba;
float4 frag(v2f i) : SV_Target
{
//float3 view = normalize(i.worldpos - _CameraWorldPosition);
float3 V = normalize(i.positionWS - GetPrimaryCameraPosition());
float3 R = reflect(V, i.normalWS);
float4 color = SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, R, _MipLevel).rgba;
return float4(color);
}
ENDHLSL
}
}
return float4(color);
}
ENDHLSL
}
}
}

2
com.unity.render-pipelines.high-definition/HDRP/Editor/HDShaderIncludePaths.cs


using System.IO;
using System.IO;
using System.Linq;
using UnityEngine;

2
com.unity.render-pipelines.high-definition/HDRP/Editor/BaseUI.cs


using UnityEditor.AnimatedValues;
using UnityEditor.AnimatedValues;
using UnityEngine.Events;
namespace UnityEditor.Experimental.Rendering

9
com.unity.render-pipelines.high-definition/HDRP/Editor/HDRenderPipelineMenuItems.cs


using System;
using System;
using System.IO;
using UnityEditor.SceneManagement;
using UnityEngine;

camera.gameObject.AddComponent<HDAdditionalCameraData>();
}
}
static void CheckOutFile(bool VSCEnabled, UnityObject mat)
{
if (VSCEnabled)

{
if ((uint)profiles[j].transmissionMode == 2)
{
profiles[j].transmissionMode = (DiffusionProfile.TransmissionMode)0;
profiles[j].transmissionMode = (DiffusionProfile.TransmissionMode) 0;
}
}

}
}
else if (mat.shader.name == "HDRenderPipeline/LayeredLit" ||
mat.shader.name == "HDRenderPipeline/LayeredLitTessellation")
mat.shader.name == "HDRenderPipeline/LayeredLitTessellation")
{
/*
bool hasSubsurfaceProfile = false;

}
}
else if (mat.shader.name == "HDRenderPipeline/LayeredLit" ||
mat.shader.name == "HDRenderPipeline/LayeredLitTessellation")
mat.shader.name == "HDRenderPipeline/LayeredLitTessellation")
{
int numLayer = (int)mat.GetFloat("_LayerCount");

6
com.unity.render-pipelines.high-definition/HDRP/Editor/Shadows/HDShadowSettingsEditor.cs


using System.Collections;
using System.Collections;
using UnityEngine;
using UnityEditor;
using UnityEditor.Experimental.Rendering;

PropertyField(m_CascadeShadowSplits[i], CoreEditorUtils.GetContent(string.Format("Split {0}", i + 1)));
}
if(LightLoop.s_UseCascadeBorders)
if (LightLoop.s_UseCascadeBorders)
{
EditorGUILayout.Space();

}
}
}
}
}

4
com.unity.render-pipelines.high-definition/HDRP/Editor/Shadows/ContactShadowsEditor.cs


using System.Collections;
using System.Collections;
using UnityEngine;
using UnityEditor;
using UnityEditor.Experimental.Rendering;

}
}
}
}
}

2
com.unity.render-pipelines.high-definition/HDRP/Editor/Camera/SerializedHDCamera.cs


using UnityEngine;
using UnityEngine;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering

105
com.unity.render-pipelines.high-definition/HDRP/Editor/Camera/HDCameraUI.cs


using System;
using System;
using System.Reflection;
using UnityEditor.AnimatedValues;
using UnityEngine;

{
static HDCameraUI()
{
Inspector = new []
Inspector = new[]
{
SectionPrimarySettings,
// Not used for now

public static readonly CED.IDrawer[] Inspector = null;
public static readonly CED.IDrawer SectionPrimarySettings = CED.Group(
CED.Action(Drawer_FieldClearColorMode),
CED.Action(Drawer_FieldBackgroundColorHDR),
CED.Action(Drawer_FieldClearDepth),
CED.Action(Drawer_FieldCullingMask),
CED.Action(Drawer_FieldVolumeLayerMask),
CED.space,
CED.Action(Drawer_Projection),
CED.Action(Drawer_FieldClippingPlanes),
CED.space,
CED.Action(Drawer_CameraWarnings),
CED.Action(Drawer_FieldRenderingPath),
CED.space
);
CED.Action(Drawer_FieldClearColorMode),
CED.Action(Drawer_FieldBackgroundColorHDR),
CED.Action(Drawer_FieldClearDepth),
CED.Action(Drawer_FieldCullingMask),
CED.Action(Drawer_FieldVolumeLayerMask),
CED.space,
CED.Action(Drawer_Projection),
CED.Action(Drawer_FieldClippingPlanes),
CED.space,
CED.Action(Drawer_CameraWarnings),
CED.Action(Drawer_FieldRenderingPath),
CED.space
);
"Physical Settings",
(s, p, o) => s.isSectionExpandedPhysicalSettings,
FoldoutOption.Indent,
CED.Action(Drawer_FieldAperture),
CED.Action(Drawer_FieldShutterSpeed),
CED.Action(Drawer_FieldIso));
"Physical Settings",
(s, p, o) => s.isSectionExpandedPhysicalSettings,
FoldoutOption.Indent,
CED.Action(Drawer_FieldAperture),
CED.Action(Drawer_FieldShutterSpeed),
CED.Action(Drawer_FieldIso));
"Capture Settings",
(s, p, o) => s.isSectionExpandedCaptureSettings,
FoldoutOption.Indent,
CED.Action(Drawer_FieldOcclusionCulling),
CED.Action(Drawer_FieldNormalizedViewPort));
"Capture Settings",
(s, p, o) => s.isSectionExpandedCaptureSettings,
FoldoutOption.Indent,
CED.Action(Drawer_FieldOcclusionCulling),
CED.Action(Drawer_FieldNormalizedViewPort));
"Output Settings",
(s, p, o) => s.isSectionExpandedOutputSettings,
FoldoutOption.Indent,
"Output Settings",
(s, p, o) => s.isSectionExpandedOutputSettings,
FoldoutOption.Indent,
CED.Action(Drawer_SectionMultiDisplay),
CED.Action(Drawer_SectionMultiDisplay),
CED.Action(Drawer_FieldDepth),
CED.Action(Drawer_FieldRenderTarget));
CED.Action(Drawer_FieldDepth),
CED.Action(Drawer_FieldRenderTarget));
(s, d, o, i) => s.isSectionAvailableXRSettings,
FadeOption.None,
CED.FoldoutGroup(
"XR Settings",
(s, p, o) => s.isSectionExpandedXRSettings,
FoldoutOption.Indent,
CED.Action(Drawer_FieldVR),
CED.Action(Drawer_FieldTargetEye)));
(s, d, o, i) => s.isSectionAvailableXRSettings,
FadeOption.None,
CED.FoldoutGroup(
"XR Settings",
(s, p, o) => s.isSectionExpandedXRSettings,
FoldoutOption.Indent,
CED.Action(Drawer_FieldVR),
CED.Action(Drawer_FieldTargetEye)));
(s, d, o, i) => s.isSectionAvailableRenderLoopSettings,
FadeOption.None,
CED.Select(
(s, d, o) => s.frameSettingsUI,
(s, d, o) => d.frameSettings,
FrameSettingsUI.SectionRenderingPasses,
FrameSettingsUI.SectionRenderingSettings,
FrameSettingsUI.SectionLightingSettings),
CED.Select(
(s, d, o) => s.frameSettingsUI.lightLoopSettings,
(s, d, o) => d.frameSettings.lightLoopSettings,
LightLoopSettingsUI.SectionLightLoopSettings));
(s, d, o, i) => s.isSectionAvailableRenderLoopSettings,
FadeOption.None,
CED.Select(
(s, d, o) => s.frameSettingsUI,
(s, d, o) => d.frameSettings,
FrameSettingsUI.SectionRenderingPasses,
FrameSettingsUI.SectionRenderingSettings,
FrameSettingsUI.SectionLightingSettings),
CED.Select(
(s, d, o) => s.frameSettingsUI.lightLoopSettings,
(s, d, o) => d.frameSettings.lightLoopSettings,
LightLoopSettingsUI.SectionLightLoopSettings));
enum ProjectionType { Perspective, Orthographic };

UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
}
}
#endif
static readonly int[] k_TargetEyeValues = { (int)StereoTargetEyeMask.Both, (int)StereoTargetEyeMask.Left, (int)StereoTargetEyeMask.Right, (int)StereoTargetEyeMask.None };

26
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Volumetric/Texture3DCreationEditor.cs


private int numXTiles
{
get { return sourceTexture != null ? sourceTexture.width / tileSize : 0;}
get { return sourceTexture != null ? sourceTexture.width / tileSize : 0; }
get{ return sourceTexture != null ? sourceTexture.height / tileSize : 0; }
get { return sourceTexture != null ? sourceTexture.height / tileSize : 0; }
private bool validData
private bool validData
set{}
set {}
}
[MenuItem("Window/Render Pipeline/Create 3D Texture")]

private void OnGUI()
{
EditorGUILayout.BeginVertical(EditorStyles.miniButton);
GUILayout.Button(new GUIContent(" Create Texture3D Asset", ""), EditorStyles.centeredGreyMiniLabel);
GUILayout.Button(new GUIContent(" Create Texture3D Asset", ""), EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.HelpBox(String.Format("Volumetric system requires textures of size {0}x{0}x{0} so please ensure the source texture is at least this many pixels.", tileSize), MessageType.Info);
EditorGUILayout.HelpBox(String.Format("Volumetric system requires textures of size {0}x{0}x{0} so please ensure the source texture is at least this many pixels.", tileSize), MessageType.Info);
if(sourceTexture != null)
if (sourceTexture != null)
{
sourcePath = AssetDatabase.GetAssetPath(sourceTexture);
if (validData)

}
}
EditorGUILayout.EndVertical();
EditorGUILayout.EndVertical();
}
private void Generate3DTexture()

texture.anisoLevel = 0;
Color[] colorArray = new Color[0];
for(int i = numYTiles - 1; i >= 0; --i)
for (int i = numYTiles - 1; i >= 0; --i)
for(int j = 0; j < numXTiles; ++j)
for (int j = 0; j < numXTiles; ++j)
Color[] texColor = sourceTexture.GetPixels(j*tileSize, i*tileSize, tileSize, tileSize);
Color[] texColor = sourceTexture.GetPixels(j * tileSize, i * tileSize, tileSize, tileSize);
texture.SetPixels(colorArray);
texture.Apply();

8
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs


textureScroll = densityParams.FindPropertyRelative("textureScrollingSpeed");
textureTile = densityParams.FindPropertyRelative("textureTiling");
if (volumeTexture != null && volumeTexture.objectReferenceValue != null)
if (volumeTexture != null && volumeTexture.objectReferenceValue != null)
{
showTextureParams = true;
}

albedo.colorValue = EditorGUILayout.ColorField(albedoLabel, albedo.colorValue, true, false, false);
EditorGUILayout.PropertyField(meanFreePath, meanFreePathLabel);
EditorGUILayout.Space();
EditorGUILayout.PropertyField(volumeTexture, volumeTextureLabel);
EditorGUILayout.PropertyField(volumeTexture, volumeTextureLabel);
serializedObject.ApplyModifiedProperties ();
serializedObject.ApplyModifiedProperties();
}
}
}

2
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/SerializedReflectionProxyVolumeComponent.cs


using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{

2
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/SerializedProxyVolume.cs


using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{

2
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/SerializedInfluenceVolume.cs


using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{

11
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/ReflectionProxyVolumeComponentUI.cs


using UnityEngine.Events;
using UnityEngine.Events;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline

static ReflectionProxyVolumeComponentUI()
{
Inspector = CED.Select(
(s, d, o) => s.proxyVolume,
(s, d, o) => d.proxyVolume,
ProxyVolumeUI.SectionShape
);
(s, d, o) => s.proxyVolume,
(s, d, o) => d.proxyVolume,
ProxyVolumeUI.SectionShape
);
}
public ProxyVolumeUI proxyVolume = new ProxyVolumeUI();

{
}
public override void Reset(SerializedReflectionProxyVolumeComponent data, UnityAction repaint)

20
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/ProxyVolumeUI.cs


using System;
using System;
using UnityEditor.AnimatedValues;
using UnityEditor.IMGUI.Controls;
using UnityEngine;

static ProxyVolumeUI()
{
SectionShape = CED.Group(
CED.Action(Drawer_FieldShapeType),
CED.FadeGroup(
(s, d, o, i) => s.IsSectionExpanded_Shape((ShapeType)i),
FadeOption.Indent,
SectionShapeBox,
SectionShapeSphere
)
);
CED.Action(Drawer_FieldShapeType),
CED.FadeGroup(
(s, d, o, i) => s.IsSectionExpanded_Shape((ShapeType)i),
FadeOption.Indent,
SectionShapeBox,
SectionShapeSphere
)
);
}
public BoxBoundsHandle boxProjectionHandle = new BoxBoundsHandle();

: base(k_ShapeCount)
{
}
public override void Update()

public static void DrawHandles_EditNone(Transform transform, ProxyVolume proxyVolume, ProxyVolumeUI ui, Object sourceAsset)
{
}
static void Handles_EditBase_Sphere(Transform transform, ProxyVolume proxyVolume, ProxyVolumeUI s, Object sourceAsset)

2
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/ProxyVolumeEditor.cs


using System.Linq;
using System.Linq;
using UnityEngine;
using UnityEngine.Experimental.Rendering.HDPipeline;

3
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/InfluenceVolumeUI.cs


using System;
using System;
using UnityEditor.AnimatedValues;
using UnityEditor.IMGUI.Controls;
using UnityEngine;

public InfluenceVolumeUI()
: base(k_ShapeCount + 1)
{
}
public override void Update()

4
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/InfluenceVolumeUI.Handles.cs


ref size);
d.boxBaseOffset = center;
d.boxBaseSize = size;
break;
break;
}
case ShapeType.Sphere:
{

ref radius);
d.sphereBaseOffset = center;
d.sphereBaseRadius = radius;
break;
break;
}
}
Handles.matrix = mat;

2
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/InfluenceVolumeUI.Gizmos.cs


using System;
using System;
using UnityEngine;
using UnityEngine.Experimental.Rendering.HDPipeline;

40
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/Volume/InfluenceVolumeUI.Drawers.cs


static InfluenceVolumeUI()
{
SectionShape = CED.Group(
CED.Action(Drawer_FieldShapeType),
CED.FadeGroup(
(s, d, o, i) => s.IsSectionExpanded_Shape((ShapeType)i),
FadeOption.Indent,
SectionShapeBox,
SectionShapeSphere
)
);
SectionFoldoutShape = CED.Group(
CED.FoldoutGroup(
"Influence Volume",
(s, d, o) => s.isSectionExpandedShape,
FoldoutOption.Indent,
FadeOption.None,
FadeOption.Indent,
)
)
);
)
);
SectionFoldoutShape = CED.Group(
CED.FoldoutGroup(
"Influence Volume",
(s, d, o) => s.isSectionExpandedShape,
FoldoutOption.Indent,
CED.Action(Drawer_FieldShapeType),
CED.FadeGroup(
(s, d, o, i) => s.IsSectionExpanded_Shape((ShapeType)i),
FadeOption.None,
SectionShapeBox,
SectionShapeSphere
)
)
);
}
static void Drawer_FieldShapeType(InfluenceVolumeUI s, SerializedInfluenceVolume d, Editor o)

EditorGUILayout.Space();
_.DrawVector6Slider(
_.GetContent("Influence Fade"),
d.boxInfluencePositiveFade, d.boxInfluenceNegativeFade,
_.GetContent("Influence Fade"),
d.boxInfluencePositiveFade, d.boxInfluenceNegativeFade,
minFadeDistance, maxFadeDistance);
EditorGUILayout.Space();

6
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/SerializedPlanarReflectionProbe.cs


using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Rendering;

}
reflectionProxyVolume = objs.Count > 0
? new SerializedReflectionProxyVolumeComponent(new SerializedObject(objs.ToArray()))
: null;
? new SerializedReflectionProxyVolumeComponent(new SerializedObject(objs.ToArray()))
: null;
}
public void Update()

2
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/SerializedHDReflectionProbe.cs


using UnityEngine;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
namespace UnityEditor.Experimental.Rendering

3
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/ScreenSpaceRefractionEditor.cs


[VolumeComponentEditor(typeof(ScreenSpaceRefraction))]
public class ScreenSpaceRefractionEditor : ScreenSpaceLightingEditor
{
}
}

3
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/ScreenSpaceLightingEditor.cs


protected virtual void OnProxyInspectorGUI()
{
}
protected virtual void OnCommonInspectorGUI()

}
}
}
}

3
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/PlanarReflectionProbeUI.cs


using System;
using System;
using UnityEditor.AnimatedValues;
using UnityEngine.Events;
using UnityEngine.Experimental.Rendering.HDPipeline;

public PlanarReflectionProbeUI()
: base(k_AnimBoolTotal)
{
}
public AnimBool IsSectionExpandedReflectionProbeMode(ReflectionProbeMode mode)

138
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/PlanarReflectionProbeUI.Handles.cs


using System;
using System;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Experimental.Rendering;

InfluenceVolumeUI.DrawHandles_EditInfluenceNormal(s.influenceVolume, d.influenceVolume, o, mat, d);
break;
case EditMirrorPosition:
{
EditorGUI.BeginChangeCheck();
var m = Handles.matrix;
Handles.matrix = mat;
var p = Handles.PositionHandle(d.captureMirrorPlaneLocalPosition, d.transform.rotation);
if (EditorGUI.EndChangeCheck())
EditorGUI.BeginChangeCheck();
var m = Handles.matrix;
Handles.matrix = mat;
var p = Handles.PositionHandle(d.captureMirrorPlaneLocalPosition, d.transform.rotation);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(d, "Translate Mirror Plane");
d.captureMirrorPlaneLocalPosition = p;
EditorUtility.SetDirty(d);
}
Handles.matrix = m;
break;
Undo.RecordObject(d, "Translate Mirror Plane");
d.captureMirrorPlaneLocalPosition = p;
EditorUtility.SetDirty(d);
Handles.matrix = m;
break;
}
{
EditorGUI.BeginChangeCheck();
var m = Handles.matrix;
Handles.matrix = mat;
var q = Quaternion.LookRotation(d.captureMirrorPlaneLocalNormal, Vector3.up);
q = Handles.RotationHandle(q, d.captureMirrorPlaneLocalPosition);
if (EditorGUI.EndChangeCheck())
EditorGUI.BeginChangeCheck();
var m = Handles.matrix;
Handles.matrix = mat;
var q = Quaternion.LookRotation(d.captureMirrorPlaneLocalNormal, Vector3.up);
q = Handles.RotationHandle(q, d.captureMirrorPlaneLocalPosition);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(d, "Rotate Mirror Plane");
d.captureMirrorPlaneLocalNormal = q * Vector3.forward;
EditorUtility.SetDirty(d);
}
Handles.matrix = m;
break;
Undo.RecordObject(d, "Rotate Mirror Plane");
d.captureMirrorPlaneLocalNormal = q * Vector3.forward;
EditorUtility.SetDirty(d);
Handles.matrix = m;
break;
}
{
EditorGUI.BeginChangeCheck();
var m = Handles.matrix;
Handles.matrix = mat;
var p = Handles.PositionHandle(d.captureLocalPosition, d.transform.rotation);
if (EditorGUI.EndChangeCheck())
EditorGUI.BeginChangeCheck();
var m = Handles.matrix;
Handles.matrix = mat;
var p = Handles.PositionHandle(d.captureLocalPosition, d.transform.rotation);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(d, "Translate Capture Position");
d.captureLocalPosition = p;
EditorUtility.SetDirty(d);
}
Handles.matrix = m;
break;
Undo.RecordObject(d, "Translate Capture Position");
d.captureLocalPosition = p;
EditorUtility.SetDirty(d);
Handles.matrix = m;
break;
}
}
if (d.useMirrorPlane)

Handles.color = k_GizmoMirrorPlaneCamera;
Handles.ArrowHandleCap(
0,
d.captureMirrorPlaneLocalPosition,
0,
d.captureMirrorPlaneLocalPosition,
);
);
Handles.matrix = m;
}

{
case EditBaseShape:
InfluenceVolumeUI.DrawGizmos(
s.influenceVolume,
d.influenceVolume,
mat,
InfluenceVolumeUI.HandleType.Base,
InfluenceVolumeUI.HandleType.All);
s.influenceVolume,
d.influenceVolume,
mat,
InfluenceVolumeUI.HandleType.Base,
InfluenceVolumeUI.HandleType.All);
s.influenceVolume,
d.influenceVolume,
mat,
InfluenceVolumeUI.HandleType.Influence,
InfluenceVolumeUI.HandleType.All);
s.influenceVolume,
d.influenceVolume,
mat,
InfluenceVolumeUI.HandleType.Influence,
InfluenceVolumeUI.HandleType.All);
s.influenceVolume,
d.influenceVolume,
mat,
InfluenceVolumeUI.HandleType.InfluenceNormal,
InfluenceVolumeUI.HandleType.All);
break;
default:
{
var showedHandles = s.influenceVolume.showInfluenceHandles
? InfluenceVolumeUI.HandleType.All
: InfluenceVolumeUI.HandleType.Base;
InfluenceVolumeUI.DrawGizmos(
InfluenceVolumeUI.HandleType.InfluenceNormal,
InfluenceVolumeUI.HandleType.All);
InfluenceVolumeUI.HandleType.None,
showedHandles);
default:
{
var showedHandles = s.influenceVolume.showInfluenceHandles
? InfluenceVolumeUI.HandleType.All
: InfluenceVolumeUI.HandleType.Base;
InfluenceVolumeUI.DrawGizmos(
s.influenceVolume,
d.influenceVolume,
mat,
InfluenceVolumeUI.HandleType.None,
showedHandles);
break;
}
}
}
if (d.proxyVolumeReference != null)

var c = Gizmos.color;
var m = Gizmos.matrix;
Gizmos.matrix = Matrix4x4.TRS(
d.captureMirrorPlanePosition,
Quaternion.LookRotation(d.captureMirrorPlaneNormal, Vector3.up),
Vector3.one);
d.captureMirrorPlanePosition,
Quaternion.LookRotation(d.captureMirrorPlaneNormal, Vector3.up),
Vector3.one);
Gizmos.color = k_GizmoMirrorPlaneCamera;
Gizmos.DrawCube(Vector3.zero, new Vector3(1, 1, 0));

132
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/PlanarReflectionProbeUI.Drawers.cs


using System;
using System;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Experimental.Rendering.HDPipeline;

public static readonly CED.IDrawer SectionBakeButton = CED.Action(Drawer_SectionBakeButton);
public static readonly CED.IDrawer SectionFoldoutInfluenceSettings = CED.FoldoutGroup(
"Influence Settings",
(s, d, o) => s.isSectionExpandedInfluenceSettings,
FoldoutOption.Indent,
CED.Action(Drawer_SectionInfluenceSettings)
);
"Influence Settings",
(s, d, o) => s.isSectionExpandedInfluenceSettings,
FoldoutOption.Indent,
CED.Action(Drawer_SectionInfluenceSettings)
);
public static readonly CED.IDrawer SectionFoldoutCaptureSettings;

static PlanarReflectionProbeUI()
{
SectionFoldoutCaptureSettings = CED.FoldoutGroup(
"Capture Settings",
(s, d, o) => s.isSectionExpandedCaptureSettings,
FoldoutOption.Indent,
CED.Action(Drawer_SectionCaptureSettings),
CED.FadeGroup(
(s, d, o, i) =>
"Capture Settings",
(s, d, o) => s.isSectionExpandedCaptureSettings,
FoldoutOption.Indent,
CED.Action(Drawer_SectionCaptureSettings),
CED.FadeGroup(
(s, d, o, i) =>
{
switch (i)
switch (i)
{
default:
case 0: return s.isSectionExpandedCaptureMirrorSettings;
case 1: return s.isSectionExpandedCaptureStaticSettings;
}
},
FadeOption.None,
SectionCaptureMirrorSettings,
SectionCaptureStaticSettings)
);
default:
case 0: return s.isSectionExpandedCaptureMirrorSettings;
case 1: return s.isSectionExpandedCaptureStaticSettings;
}
},
FadeOption.None,
SectionCaptureMirrorSettings,
SectionCaptureStaticSettings)
);
CED.Action(Drawer_FieldCaptureType),
CED.FadeGroup(
(s, d, o, i) => s.IsSectionExpandedReflectionProbeMode((ReflectionProbeMode)i),
FadeOption.Indent,
SectionProbeModeBakedSettings,
SectionProbeModeRealtimeSettings,
SectionProbeModeCustomSettings
)
);
CED.Action(Drawer_FieldCaptureType),
CED.FadeGroup(
(s, d, o, i) => s.IsSectionExpandedReflectionProbeMode((ReflectionProbeMode)i),
FadeOption.Indent,
SectionProbeModeBakedSettings,
SectionProbeModeRealtimeSettings,
SectionProbeModeCustomSettings
)
);
SectionProbeModeSettings,
CED.space,
CED.Action((s, d, o) => EditorGUILayout.LabelField(_.GetContent("Proxy Volume"), EditorStyles.boldLabel)),
CED.Action(Drawer_FieldProxyVolumeReference),
CED.space,
CED.Action(Drawer_Toolbar),
CED.space,
CED.Select(
(s, d, o) => s.influenceVolume,
(s, d, o) => d.influenceVolume,
InfluenceVolumeUI.SectionFoldoutShape
),
CED.Action(Drawer_DifferentShapeError),
SectionFoldoutInfluenceSettings,
SectionFoldoutCaptureSettings,
CED.Select(
(s, d, o) => s.frameSettings,
(s, d, o) => d.frameSettings,
FrameSettingsUI.Inspector
),
CED.space,
CED.Action(Drawer_SectionBakeButton)
);
SectionProbeModeSettings,
CED.space,
CED.Action((s, d, o) => EditorGUILayout.LabelField(_.GetContent("Proxy Volume"), EditorStyles.boldLabel)),
CED.Action(Drawer_FieldProxyVolumeReference),
CED.space,
CED.Action(Drawer_Toolbar),
CED.space,
CED.Select(
(s, d, o) => s.influenceVolume,
(s, d, o) => d.influenceVolume,
InfluenceVolumeUI.SectionFoldoutShape
),
CED.Action(Drawer_DifferentShapeError),
SectionFoldoutInfluenceSettings,
SectionFoldoutCaptureSettings,
CED.Select(
(s, d, o) => s.frameSettings,
(s, d, o) => d.frameSettings,
FrameSettingsUI.Inspector
),
CED.space,
CED.Action(Drawer_SectionBakeButton)
);
}
const EditMode.SceneViewEditMode EditBaseShape = EditMode.SceneViewEditMode.ReflectionProbeBox;

"Proxy volume and influence volume have different shape types, this is not supported.",
MessageType.Error,
true
);
);
}
}

static void Drawer_SectionInfluenceSettings(PlanarReflectionProbeUI s, SerializedPlanarReflectionProbe d, Editor o)
{
EditorGUILayout.PropertyField(d.weight, _.GetContent("Weight"));
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(d.multiplier, _.GetContent("Multiplier"));

static Func<Bounds> GetBoundsGetter(Editor o)
{
return () =>
{
var bounds = new Bounds();
foreach (Component targetObject in o.targets)
var rp = targetObject.transform;
var b = rp.position;
bounds.Encapsulate(b);
}
return bounds;
};
var bounds = new Bounds();
foreach (Component targetObject in o.targets)
{
var rp = targetObject.transform;
var b = rp.position;
bounds.Encapsulate(b);
}
return bounds;
};
}
}
}

12
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/PlanarReflectionProbeEditor.cs


using System;
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor.Callbacks;

public override GUIContent GetPreviewTitle()
{
return _.GetContent("Planar Reflection");
return _.GetContent("Planar Reflection");
}
public override void OnPreviewGUI(Rect r, GUIStyle background)

var row = i / rowSize;
var col = i % rowSize;
var itemRect = new Rect(
r.x + size.x * row + ((row > 0) ? (row - 1) * space.x : 0),
r.y + size.y * col + ((col > 0) ? (col - 1) * space.y : 0),
size.x,
size.y);
r.x + size.x * row + ((row > 0) ? (row - 1) * space.x : 0),
r.y + size.y * col + ((col > 0) ? (col - 1) * space.y : 0),
size.x,
size.y);
if (m_PreviewedTextures[i] != null)
EditorGUI.DrawPreviewTexture(itemRect, m_PreviewedTextures[i], CameraEditorUtils.GUITextureBlit2SRGBMaterial, ScaleMode.ScaleToFit, 0, 1);

2
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDScreenSpaceReflectionEditor.cs


PropertyField(m_DeferredProjectionModel, CoreEditorUtils.GetContent("Projection Model"));
}
}
}
}

2
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeUI.cs


using System;
using System;
using UnityEditor.AnimatedValues;
using UnityEditor.IMGUI.Controls;
using UnityEditorInternal;

123
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeUI.Drawers.cs


using System;
using System;
using System.Reflection;
using UnityEditor.Experimental.Rendering.HDPipeline;
using UnityEditorInternal;

public static readonly CED.IDrawer SectionPrimarySettings = CED.Group(
CED.Action(Drawer_ReflectionProbeMode),
CED.FadeGroup((s, p, o, i) => s.IsSectionExpandedMode((ReflectionProbeMode)i),
FadeOption.Indent,
CED.noop, // Baked
CED.Action(Drawer_ModeSettingsRealtime), // Realtime
CED.Action(Drawer_ModeSettingsCustom) // Custom
),
CED.space,
CED.Action(Drawer_InfluenceShape),
//CED.Action(Drawer_IntensityMultiplier),
CED.space,
CED.Action(Drawer_Toolbar),
CED.space,
CED.Action((s, d, o) => EditorGUILayout.PropertyField(d.proxyVolumeComponent, _.GetContent("Proxy Volume")))
);
CED.Action(Drawer_ReflectionProbeMode),
CED.FadeGroup((s, p, o, i) => s.IsSectionExpandedMode((ReflectionProbeMode)i),
FadeOption.Indent,
CED.noop, // Baked
CED.Action(Drawer_ModeSettingsRealtime), // Realtime
CED.Action(Drawer_ModeSettingsCustom) // Custom
),
CED.space,
CED.Action(Drawer_InfluenceShape),
//CED.Action(Drawer_IntensityMultiplier),
CED.space,
CED.Action(Drawer_Toolbar),
CED.space,
CED.Action((s, d, o) => EditorGUILayout.PropertyField(d.proxyVolumeComponent, _.GetContent("Proxy Volume")))
);
"Influence volume settings",
(s, p, o) => s.isSectionExpandedInfluenceVolume,
FoldoutOption.Indent,
CED.FadeGroup(
(s, p, o, i) => s.IsSectionExpandedShape((ShapeType)i),
FadeOption.None,
CED.Action(Drawer_InfluenceBoxSettings), // Box
CED.Action(Drawer_InfluenceSphereSettings) // Sphere
)/*,
CED.Action(Drawer_UseSeparateProjectionVolume)*/
);
public static readonly CED.IDrawer SectionSeparateProjectionVolumeSettings = CED.FadeGroup(
(s, p, o, i) => s.isSectionExpandedSeparateProjection,
FadeOption.None,
CED.FoldoutGroup(
"Reprojection volume settings",
(s, p, o) => s.isSectionExpandedSeparateProjection,
"Influence volume settings",
(s, p, o) => s.isSectionExpandedInfluenceVolume,
CED.Action(Drawer_ProjectionBoxSettings), // Box
CED.Action(Drawer_ProjectionSphereSettings) // Sphere
)
)
);
CED.Action(Drawer_InfluenceBoxSettings), // Box
CED.Action(Drawer_InfluenceSphereSettings) // Sphere
)/*,
CED.Action(Drawer_UseSeparateProjectionVolume)*/
);
public static readonly CED.IDrawer SectionSeparateProjectionVolumeSettings = CED.FadeGroup(
(s, p, o, i) => s.isSectionExpandedSeparateProjection,
FadeOption.None,
CED.FoldoutGroup(
"Reprojection volume settings",
(s, p, o) => s.isSectionExpandedSeparateProjection,
FoldoutOption.Indent,
CED.FadeGroup(
(s, p, o, i) => s.IsSectionExpandedShape((ShapeType)i),
FadeOption.None,
CED.Action(Drawer_ProjectionBoxSettings), // Box
CED.Action(Drawer_ProjectionSphereSettings) // Sphere
)
)
);
"Capture settings",
(s, p, o) => s.isSectionExpandedCaptureSettings,
FoldoutOption.Indent,
CED.Action(Drawer_CaptureSettings)
);
"Capture settings",
(s, p, o) => s.isSectionExpandedCaptureSettings,
FoldoutOption.Indent,
CED.Action(Drawer_CaptureSettings)
);
"Additional settings",
(s, p, o) => s.isSectionExpandedAdditional,
FoldoutOption.Indent,
CED.Action(Drawer_AdditionalSettings)
);
"Additional settings",
(s, p, o) => s.isSectionExpandedAdditional,
FoldoutOption.Indent,
CED.Action(Drawer_AdditionalSettings)
);
public static readonly CED.IDrawer ButtonBake = CED.Action(Drawer_BakeActions);

EditorGUILayout.PropertyField(p.boxProjection, CoreEditorUtils.GetContent("Sphere Projection|Sphere projection causes reflections to appear to change based on the object's position within the probe's sphere, while still using a single probe as the source of the reflection. This works well for reflections on objects that are moving through enclosed spaces such as corridors and rooms. Setting sphere projection to False and the cubemap reflection will be treated as coming from infinitely far away. Note that this feature can be globally disabled from Graphics Settings -> Tier Settings"));
}
#endregion
#region Projection Volume

{
EditorGUILayout.PropertyField(p.sphereReprojectionVolumeRadius);
}
#endregion
#region Field Drawers

"Proxy volume and influence volume have different shape types, this is not supported.",
MessageType.Error,
true
);
);
}
}

}
#endregion
#region Toolbar

static Func<Bounds> GetBoundsGetter(SerializedHDReflectionProbe p)
{
return () =>
{
var bounds = new Bounds();
foreach (var targetObject in p.so.targetObjects)
var rp = (ReflectionProbe)targetObject;
var b = rp.bounds;
bounds.Encapsulate(b);
}
return bounds;
};
var bounds = new Bounds();
foreach (var targetObject in p.so.targetObjects)
{
var rp = (ReflectionProbe)targetObject;
var b = rp.bounds;
bounds.Encapsulate(b);
}
return bounds;
};
}
static readonly KeyCode[] k_ShortCutKeys =

}
}
}
#endregion
#region Mode Specific Settings

EditorGUILayout.PropertyField(p.refreshMode, CoreEditorUtils.GetContent("Refresh Mode|Controls how this probe refreshes in the Player"));
EditorGUILayout.PropertyField(p.timeSlicingMode, CoreEditorUtils.GetContent("Time Slicing|If enabled this probe will update over several frames, to help reduce the impact on the frame rate"));
}
#endregion
static MethodInfo k_EditorGUI_ButtonWithDropdownList = typeof(EditorGUI).GetMethod("ButtonWithDropdownList", BindingFlags.Static | BindingFlags.NonPublic, null, CallingConventions.Any, new[] { typeof(GUIContent), typeof(string[]), typeof(GenericMenu.MenuFunction2), typeof(GUILayoutOption[]) }, new ParameterModifier[0]);

2
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditorUtility.cs


using System;
using System;
using System.IO;
using System.Linq;
using System.Reflection;

9
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditor.cs


static HDReflectionProbeEditor GetEditorFor(ReflectionProbe p)
{
HDReflectionProbeEditor e;
if (s_ReflectionProbeEditors.TryGetValue(p, out e)
&& e != null
if (s_ReflectionProbeEditors.TryGetValue(p, out e)
&& e != null
&& !e.Equals(null)
&& ArrayUtility.IndexOf(e.targets, p) != -1)
return e;

static void PerformOperations(HDReflectionProbeUI s, SerializedHDReflectionProbe p, HDReflectionProbeEditor o)
{
}
void HideAdditionalComponents(bool visible)

for (var i = 0 ; i < targets.Length; ++i)
for (var i = 0; i < targets.Length; ++i)
{
var target = targets[i];
var addData = adds[i];

}
}
}
static void InspectColorsGUI()
{

3
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditor.Preview.cs


using UnityEngine;
using UnityEngine;
namespace UnityEditor.Experimental.Rendering
{

var p = target as ReflectionProbe;
if (p != null && p.texture != null && targets.Length == 1)
m_CubemapEditor.DrawPreview(position);
}
bool ValidPreviewSetup()

4
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditor.Handles.cs


using System;
using System;
using UnityEditor.IMGUI.Controls;
using UnityEditorInternal;
using UnityEngine;

var e = GetEditorFor(reflectionProbe);
if (e == null || !e.sceneViewEditing)
return;
var reflectionData = reflectionProbe.GetComponent<HDAdditionalReflectionData>();
if (reflectionData != null)
HDReflectionProbeEditorUtility.ChangeVisibility(reflectionProbe, false);

4
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDCubemapInspector.cs


using UnityEngine;
using UnityEngine;
using UnityEditor;
using UnityEngine.Experimental.Rendering.HDPipeline;

m_ReflectiveMaterial.SetFloat("_MipLevel", mipLevelPreview);
}
if(m_PreviewUtility == null)
if (m_PreviewUtility == null)
InitPreview();
UpdateCamera();

16
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/EditorReflectionSystemGUI.cs


case ReflectionProbeMode.Custom:
{
if (ButtonWithDropdownList(
_.GetContent("Bake|Bakes Reflection Probe's cubemap, overwriting the existing cubemap texture asset (if any)."), k_BakeCustomOptionText,
data =>
_.GetContent("Bake|Bakes Reflection Probe's cubemap, overwriting the existing cubemap texture asset (if any)."), k_BakeCustomOptionText,
data =>
{
var mode = (int)data;

}
}
},
GUILayout.ExpandWidth(true)))
GUILayout.ExpandWidth(true)))
{
if (probe != null)
{

case ReflectionProbeMode.Baked:
{
GUI.enabled = probe != null && probe.enabled
|| planarProbe != null && planarProbe.enabled;
|| planarProbe != null && planarProbe.enabled;
_.GetContent("Bake"),
k_BakeButtonsText,
data =>
_.GetContent("Bake"),
k_BakeButtonsText,
data =>
GUILayout.ExpandWidth(true)))
GUILayout.ExpandWidth(true)))
{
if (probe != null)
{

18
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/EditorReflectionSystem.cs


using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

if (IsCollidingWithOtherProbes(path, probe, out collidingProbe))
{
if (!EditorUtility.DisplayDialog("Texture is used by other reflection probe",
string.Format("'{0}' path is used by the game object '{1}', do you really want to overwrite it?",
path, collidingProbe.name), "Yes", "No"))
string.Format("'{0}' path is used by the game object '{1}', do you really want to overwrite it?",
path, collidingProbe.name), "Yes", "No"))
{
return;
}

var scene = probe.gameObject.scene;
var directory = Path.Combine(Path.GetDirectoryName(scene.path), Path.GetFileNameWithoutExtension(scene.path));
var filename = string.Format("PlanarReflectionProbe-{0}.exr", 0);
return Path.Combine(directory, filename);
}

if (IsCollidingWithOtherProbes(path, probe, out collidingProbe))
{
if (!EditorUtility.DisplayDialog("Cubemap is used by other reflection probe",
string.Format("'{0}' path is used by the game object '{1}', do you really want to overwrite it?",
path, collidingProbe.name), "Yes", "No"))
string.Format("'{0}' path is used by the game object '{1}', do you really want to overwrite it?",
path, collidingProbe.name), "Yes", "No"))
{
return;
}

if (result == null)
{
result = EditorUtility.CreateGameObjectWithHideFlags(
"Reflection System Dictionary",
k_ReflectionSystemDictionaryHideFlags,
typeof(ReflectionSystemSceneDictionary))
"Reflection System Dictionary",
k_ReflectionSystemDictionaryHideFlags,
typeof(ReflectionSystemSceneDictionary))
.GetComponent<ReflectionSystemSceneDictionary>();
SceneManager.MoveGameObjectToScene(result.gameObject, scene);

96
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs


[CustomEditorForRenderPipeline(typeof(Light), typeof(HDRenderPipelineAsset))]
sealed partial class HDLightEditor : LightEditor
{
[MenuItem("CONTEXT/Light/Remove HD Light", false,0)]
[MenuItem("CONTEXT/Light/Remove HD Light", false, 0)]
GameObject go = ( (Light) menuCommand.context ).gameObject;
GameObject go = ((Light)menuCommand.context).gameObject;
Assert.IsNotNull(go);

m_SerializedAdditionalShadowData = new SerializedObject(shadowData);
using (var o = new PropertyFetcher<HDAdditionalLightData>(m_SerializedAdditionalLightData))
m_AdditionalLightData = new SerializedLightData
{
directionalIntensity = o.Find(x => x.directionalIntensity),
punctualIntensity = o.Find(x => x.punctualIntensity),
areaIntensity = o.Find(x => x.areaIntensity),
enableSpotReflector = o.Find(x => x.enableSpotReflector),
spotInnerPercent = o.Find(x => x.m_InnerSpotPercent),
lightDimmer = o.Find(x => x.lightDimmer),
volumetricDimmer = o.Find(x => x.volumetricDimmer),
fadeDistance = o.Find(x => x.fadeDistance),
affectDiffuse = o.Find(x => x.affectDiffuse),
affectSpecular = o.Find(x => x.affectSpecular),
nonLightmappedOnly = o.Find(x => x.nonLightmappedOnly),
lightTypeExtent = o.Find(x => x.lightTypeExtent),
spotLightShape = o.Find(x => x.spotLightShape),
shapeWidth = o.Find(x => x.shapeWidth),
shapeHeight = o.Find(x => x.shapeHeight),
aspectRatio = o.Find(x => x.aspectRatio),
shapeRadius = o.Find(x => x.shapeRadius),
maxSmoothness = o.Find(x => x.maxSmoothness),
applyRangeAttenuation = o.Find(x => x.applyRangeAttenuation),
m_AdditionalLightData = new SerializedLightData
{
directionalIntensity = o.Find(x => x.directionalIntensity),
punctualIntensity = o.Find(x => x.punctualIntensity),
areaIntensity = o.Find(x => x.areaIntensity),
enableSpotReflector = o.Find(x => x.enableSpotReflector),
spotInnerPercent = o.Find(x => x.m_InnerSpotPercent),
lightDimmer = o.Find(x => x.lightDimmer),
volumetricDimmer = o.Find(x => x.volumetricDimmer),
fadeDistance = o.Find(x => x.fadeDistance),
affectDiffuse = o.Find(x => x.affectDiffuse),
affectSpecular = o.Find(x => x.affectSpecular),
nonLightmappedOnly = o.Find(x => x.nonLightmappedOnly),
lightTypeExtent = o.Find(x => x.lightTypeExtent),
spotLightShape = o.Find(x => x.spotLightShape),
shapeWidth = o.Find(x => x.shapeWidth),
shapeHeight = o.Find(x => x.shapeHeight),
aspectRatio = o.Find(x => x.aspectRatio),
shapeRadius = o.Find(x => x.shapeRadius),
maxSmoothness = o.Find(x => x.maxSmoothness),
applyRangeAttenuation = o.Find(x => x.applyRangeAttenuation),
// Editor stuff
useOldInspector = o.Find(x => x.useOldInspector),
showFeatures = o.Find(x => x.featuresFoldout),
showAdditionalSettings = o.Find(x => x.showAdditionalSettings)
};
// Editor stuff
useOldInspector = o.Find(x => x.useOldInspector),
showFeatures = o.Find(x => x.featuresFoldout),
showAdditionalSettings = o.Find(x => x.showAdditionalSettings)
};
m_AdditionalShadowData = new SerializedShadowData
{
dimmer = o.Find(x => x.shadowDimmer),
fadeDistance = o.Find(x => x.shadowFadeDistance),
resolution = o.Find(x => x.shadowResolution),
m_AdditionalShadowData = new SerializedShadowData
{
dimmer = o.Find(x => x.shadowDimmer),
fadeDistance = o.Find(x => x.shadowFadeDistance),
resolution = o.Find(x => x.shadowResolution),
viewBiasMin = o.Find(x => x.viewBiasMin),
viewBiasMax = o.Find(x => x.viewBiasMax),
viewBiasScale = o.Find(x => x.viewBiasScale),
normalBiasMin = o.Find(x => x.normalBiasMin),
normalBiasMax = o.Find(x => x.normalBiasMax),
normalBiasScale = o.Find(x => x.normalBiasScale),
sampleBiasScale = o.Find(x => x.sampleBiasScale),
edgeLeakFixup = o.Find(x => x.edgeLeakFixup),
edgeToleranceNormal = o.Find(x => x.edgeToleranceNormal),
edgeTolerance = o.Find(x => x.edgeTolerance)
};
viewBiasMin = o.Find(x => x.viewBiasMin),
viewBiasMax = o.Find(x => x.viewBiasMax),
viewBiasScale = o.Find(x => x.viewBiasScale),
normalBiasMin = o.Find(x => x.normalBiasMin),
normalBiasMax = o.Find(x => x.normalBiasMax),
normalBiasScale = o.Find(x => x.normalBiasScale),
sampleBiasScale = o.Find(x => x.sampleBiasScale),
edgeLeakFixup = o.Find(x => x.edgeLeakFixup),
edgeToleranceNormal = o.Find(x => x.edgeToleranceNormal),
edgeTolerance = o.Find(x => x.edgeTolerance)
};
}
public override void OnInspectorGUI()

{
if (spotLightShape == SpotLightShape.Cone)
{
settings.intensity.floatValue = LightUtils.ConvertSpotLightIntensity(m_AdditionalLightData.punctualIntensity.floatValue, settings.spotAngle.floatValue * Mathf.Deg2Rad, true );
settings.intensity.floatValue = LightUtils.ConvertSpotLightIntensity(m_AdditionalLightData.punctualIntensity.floatValue, settings.spotAngle.floatValue * Mathf.Deg2Rad, true);
LightUtils.CalculateAnglesForPyramid( m_AdditionalLightData.aspectRatio.floatValue, settings.spotAngle.floatValue,
out angleA, out angleB);
LightUtils.CalculateAnglesForPyramid(m_AdditionalLightData.aspectRatio.floatValue, settings.spotAngle.floatValue,
out angleA, out angleB);
settings.intensity.floatValue = LightUtils.ConvertFrustrumLightIntensity(m_AdditionalLightData.punctualIntensity.floatValue, angleA, angleB );
settings.intensity.floatValue = LightUtils.ConvertFrustrumLightIntensity(m_AdditionalLightData.punctualIntensity.floatValue, angleA, angleB);
}
else // Box shape, fallback to punctual light.
{

3
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/ShadowInitParametersUI.cs


using UnityEditor.AnimatedValues;
using UnityEditor.AnimatedValues;
using UnityEngine.Events;
using UnityEngine.Experimental.Rendering.HDPipeline;

public ShadowInitParametersUI()
: base(0)
{
}
static void Drawer_FieldShadowSize(ShadowInitParametersUI s, SerializedShadowInitParameters d, Editor o)

2
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/SerializedShadowInitParameters.cs


using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering;
namespace UnityEditor.Experimental.Rendering
{

6
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/SerializedRenderPipelineSettings.cs


using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering
{

public SerializedGlobalLightLoopSettings lightLoopSettings;
public SerializedShadowInitParameters shadowInitParams;
public SerializedGlobalDecalSettings decalSettings;
public SerializedGlobalDecalSettings decalSettings;
public SerializedRenderPipelineSettings(SerializedProperty root)
{

lightLoopSettings = new SerializedGlobalLightLoopSettings(root.Find((RenderPipelineSettings s) => s.lightLoopSettings));
shadowInitParams = new SerializedShadowInitParameters(root.Find((RenderPipelineSettings s) => s.shadowInitParams));
decalSettings = new SerializedGlobalDecalSettings(root.Find((RenderPipelineSettings s) => s.decalSettings));
decalSettings = new SerializedGlobalDecalSettings(root.Find((RenderPipelineSettings s) => s.decalSettings));
}
}
}

2
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/SerializedLightLoopSettings.cs


using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering
{

4
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/SerializedHDRenderPipelineAsset.cs


using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering
{

public SerializedProperty renderPipelineResources;
public SerializedProperty diffusionProfileSettings;
public SerializedProperty allowShaderVariantStripping;

2
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/SerializedGlobalLightLoopSettings.cs


using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering
{

22
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/SerializedGlobalDecalSettings.cs


using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Experimental.Rendering.HDPipeline;
class SerializedGlobalDecalSettings
{
public SerializedProperty root;
class SerializedGlobalDecalSettings
{
public SerializedProperty root;
public SerializedProperty drawDistance;
public SerializedProperty atlasWidth;
public SerializedProperty drawDistance;
public SerializedProperty atlasWidth;
public SerializedGlobalDecalSettings(SerializedProperty root)
public SerializedGlobalDecalSettings(SerializedProperty root)
drawDistance = root.Find((GlobalDecalSettings s) => s.drawDistance);
atlasWidth = root.Find((GlobalDecalSettings s) => s.atlasWidth);
atlasHeight = root.Find((GlobalDecalSettings s) => s.atlasHeight);
drawDistance = root.Find((GlobalDecalSettings s) => s.drawDistance);
atlasWidth = root.Find((GlobalDecalSettings s) => s.atlasWidth);
atlasHeight = root.Find((GlobalDecalSettings s) => s.atlasHeight);
}
}
}

2
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/SerializedFrameSettings.cs


using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering
{

53
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/RenderPipelineSettingsUI.cs


using UnityEngine.Events;
using UnityEngine.Events;
namespace UnityEditor.Experimental.Rendering
{

static RenderPipelineSettingsUI()
{
Inspector = CED.Group(
SectionPrimarySettings,
CED.space,
CED.Select(
(s, d, o) => s.lightLoopSettings,
(s, d, o) => d.lightLoopSettings,
GlobalLightLoopSettingsUI.Inspector
),
CED.space,
CED.Select(
(s, d, o) => s.shadowInitParams,
(s, d, o) => d.shadowInitParams,
ShadowInitParametersUI.SectionAtlas
),
CED.space,
CED.Select(
(s, d, o) => s.decalSettings,
(s, d, o) => d.decalSettings,
GlobalDecalSettingsUI.Inspector
)
SectionPrimarySettings,
CED.space,
CED.Select(
(s, d, o) => s.lightLoopSettings,
(s, d, o) => d.lightLoopSettings,
GlobalLightLoopSettingsUI.Inspector
),
CED.space,
CED.Select(
(s, d, o) => s.shadowInitParams,
(s, d, o) => d.shadowInitParams,
ShadowInitParametersUI.SectionAtlas
),
CED.space,
CED.Select(
(s, d, o) => s.decalSettings,
(s, d, o) => d.decalSettings,
GlobalDecalSettingsUI.Inspector
)
);
);
CED.Action(Drawer_SectionPrimarySettings)
);
CED.Action(Drawer_SectionPrimarySettings)
);
GlobalDecalSettingsUI decalSettings = new GlobalDecalSettingsUI();
GlobalDecalSettingsUI decalSettings = new GlobalDecalSettingsUI();
}
public override void Reset(SerializedRenderPipelineSettings data, UnityAction repaint)

decalSettings.Reset(data.decalSettings, repaint);
decalSettings.Reset(data.decalSettings, repaint);
base.Reset(data, repaint);
}

shadowInitParams.Update();
decalSettings.Update();
decalSettings.Update();
base.Update();
}

10
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/LightLoopSettingsUI.cs


using UnityEditor.AnimatedValues;
using UnityEditor.AnimatedValues;
using UnityEngine;
namespace UnityEditor.Experimental.Rendering

class LightLoopSettingsUI : BaseUI<SerializedLightLoopSettings>
{
public static CED.IDrawer SectionLightLoopSettings = CED.FoldoutGroup(
"Light Loop Settings",
(s, p, o) => s.isSectionExpandedLightLoopSettings,
FoldoutOption.Indent,
CED.LabelWidth(250, CED.Action(Drawer_SectionLightLoopSettings)));
"Light Loop Settings",
(s, p, o) => s.isSectionExpandedLightLoopSettings,
FoldoutOption.Indent,
CED.LabelWidth(250, CED.Action(Drawer_SectionLightLoopSettings)));
public AnimBool isSectionExpandedLightLoopSettings { get { return m_AnimBools[0]; } }
public AnimBool isSectionExpandedEnableTileAndCluster { get { return m_AnimBools[1]; } }

34
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/HDRenderPipelineUI.cs


using UnityEngine.Events;
using UnityEngine.Events;
namespace UnityEditor.Experimental.Rendering
{

static HDRenderPipelineUI()
{
Inspector = CED.Group(
SectionPrimarySettings,
CED.space,
CED.Select(
(s, d, o) => s.renderPipelineSettings,
(s, d, o) => d.renderPipelineSettings,
RenderPipelineSettingsUI.Inspector
),
CED.space,
CED.Action(Drawer_TitleDefaultFrameSettings),
CED.Select(
(s, d, o) => s.defaultFrameSettings,
(s, d, o) => d.defaultFrameSettings,
FrameSettingsUI.Inspector
)
);
SectionPrimarySettings,
CED.space,
CED.Select(
(s, d, o) => s.renderPipelineSettings,
(s, d, o) => d.renderPipelineSettings,
RenderPipelineSettingsUI.Inspector
),
CED.space,
CED.Action(Drawer_TitleDefaultFrameSettings),
CED.Select(
(s, d, o) => s.defaultFrameSettings,
(s, d, o) => d.defaultFrameSettings,
FrameSettingsUI.Inspector
)
);
}
public static readonly CED.IDrawer Inspector;

public HDRenderPipelineUI()
: base(0)
{
}
public override void Reset(SerializedHDRenderPipelineAsset data, UnityAction repaint)

EditorGUILayout.PropertyField(d.renderPipelineResources, _.GetContent("Render Pipeline Resources|Set of resources that need to be loaded when creating stand alone"));
EditorGUILayout.PropertyField(d.diffusionProfileSettings, _.GetContent("Diffusion Profile Settings"));
EditorGUILayout.PropertyField(d.allowShaderVariantStripping, _.GetContent("Enable Shader Variant Stripping (experimental)"));
}
}
}

2
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/HDRenderPipelineEditor.cs


using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline

17
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/GlobalLightLoopSettingsUI.cs


using UnityEngine;
using UnityEngine;
namespace UnityEditor.Experimental.Rendering
{

static GlobalLightLoopSettingsUI()
{
Inspector = CED.Group(
SectionCookies,
CED.space,
SectionReflection,
CED.space,
SectionSky
);
SectionCookies,
CED.space,
SectionReflection,
CED.space,
SectionSky
);
}
public static readonly CED.IDrawer Inspector;

public GlobalLightLoopSettingsUI()
: base(0)
{
}
static void Drawer_SectionCookies(GlobalLightLoopSettingsUI s, SerializedGlobalLightLoopSettings d, Editor o)

++EditorGUI.indentLevel;
EditorGUILayout.PropertyField(d.skyReflectionSize, _.GetContent("Sky Reflection Size"));
EditorGUILayout.PropertyField(d.skyLightingOverrideLayerMask, _.GetContent("Sky Lighting Override Mask|This layer mask will define in which layers the sky system will look for sky settings volumes for lighting override"));
if(d.skyLightingOverrideLayerMask.intValue == -1)
if (d.skyLightingOverrideLayerMask.intValue == -1)
{
EditorGUILayout.HelpBox("Be careful, Sky Lighting Override Mask is set to Everything. This is most likely a mistake as it serves no purpose.", MessageType.Warning);
}

33
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/GlobalDecalSettingsUI.cs


using UnityEngine;
using UnityEngine;
using CED = CoreEditorDrawer<GlobalDecalSettingsUI, SerializedGlobalDecalSettings>;
using CED = CoreEditorDrawer<GlobalDecalSettingsUI, SerializedGlobalDecalSettings>;
class GlobalDecalSettingsUI : BaseUI<SerializedGlobalDecalSettings>
{
static GlobalDecalSettingsUI()
class GlobalDecalSettingsUI : BaseUI<SerializedGlobalDecalSettings>
{
static GlobalDecalSettingsUI()
}
}
public static readonly CED.IDrawer Inspector;
public static readonly CED.IDrawer SectionDecalSettings = CED.Action(Drawer_SectionDecalSettings);

{
}
}
static void Drawer_SectionDecalSettings(GlobalDecalSettingsUI s, SerializedGlobalDecalSettings d, Editor o)
{
EditorGUILayout.LabelField(_.GetContent("Decals"), EditorStyles.boldLabel);
++EditorGUI.indentLevel;
EditorGUILayout.PropertyField(d.drawDistance, _.GetContent("Draw Distance"));
EditorGUILayout.PropertyField(d.atlasWidth, _.GetContent("Atlas Width"));
static void Drawer_SectionDecalSettings(GlobalDecalSettingsUI s, SerializedGlobalDecalSettings d, Editor o)
{
EditorGUILayout.LabelField(_.GetContent("Decals"), EditorStyles.boldLabel);
++EditorGUI.indentLevel;
EditorGUILayout.PropertyField(d.drawDistance, _.GetContent("Draw Distance"));
EditorGUILayout.PropertyField(d.atlasWidth, _.GetContent("Atlas Width"));
--EditorGUI.indentLevel;
}
}
--EditorGUI.indentLevel;
}
}
}

82
com.unity.render-pipelines.high-definition/HDRP/Editor/RenderLoopSettings/FrameSettingsUI.cs


using UnityEditor.AnimatedValues;
using UnityEditor.AnimatedValues;
using UnityEngine.Events;
namespace UnityEditor.Experimental.Rendering

static FrameSettingsUI()
{
Inspector = CED.Group(
SectionRenderingPasses,
SectionRenderingSettings,
SectionXRSettings,
SectionLightingSettings,
CED.Select(
(s, d, o) => s.lightLoopSettings,
(s, d, o) => d.lightLoopSettings,
LightLoopSettingsUI.SectionLightLoopSettings
)
);
SectionRenderingPasses,
SectionRenderingSettings,
SectionXRSettings,
SectionLightingSettings,
CED.Select(
(s, d, o) => s.lightLoopSettings,
(s, d, o) => d.lightLoopSettings,
LightLoopSettingsUI.SectionLightLoopSettings
)
);
"Rendering Passes",
(s, p, o) => s.isSectionExpandedRenderingPasses,
FoldoutOption.Indent,
CED.LabelWidth(200, CED.Action(Drawer_SectionRenderingPasses))
);
"Rendering Passes",
(s, p, o) => s.isSectionExpandedRenderingPasses,
FoldoutOption.Indent,
CED.LabelWidth(200, CED.Action(Drawer_SectionRenderingPasses))
);
"Rendering Settings",
(s, p, o) => s.isSectionExpandedRenderingSettings,
FoldoutOption.Indent,
CED.LabelWidth(300,
CED.Action(Drawer_FieldForwardRenderingOnly),
CED.FadeGroup(
(s, d, o, i) => s.isSectionExpandedUseForwardOnly,
FadeOption.None,
CED.Action(Drawer_FieldUseDepthPrepassWithDefferedRendering)
),
CED.Action(Drawer_SectionOtherRenderingSettings)
)
);
"Rendering Settings",
(s, p, o) => s.isSectionExpandedRenderingSettings,
FoldoutOption.Indent,
CED.LabelWidth(300,
CED.Action(Drawer_FieldForwardRenderingOnly),
CED.FadeGroup(
(s, d, o, i) => s.isSectionExpandedUseForwardOnly,
FadeOption.None,
CED.Action(Drawer_FieldUseDepthPrepassWithDefferedRendering)
),
CED.Action(Drawer_SectionOtherRenderingSettings)
)
);
(s, d, o, i) => s.isSectionExpandedXRSupported,
FadeOption.None,
CED.FoldoutGroup(
"XR Settings",
(s, p, o) => s.isSectionExpandedXRSettings,
FoldoutOption.Indent,
CED.LabelWidth(200, CED.Action(Drawer_FieldStereoEnabled))));
(s, d, o, i) => s.isSectionExpandedXRSupported,
FadeOption.None,
CED.FoldoutGroup(
"XR Settings",
(s, p, o) => s.isSectionExpandedXRSettings,
FoldoutOption.Indent,
CED.LabelWidth(200, CED.Action(Drawer_FieldStereoEnabled))));
"Lighting Settings",
(s, p, o) => s.isSectionExpandedLightingSettings,
FoldoutOption.Indent,
CED.LabelWidth(250, CED.Action(Drawer_SectionLightingSettings)));
"Lighting Settings",
(s, p, o) => s.isSectionExpandedLightingSettings,
FoldoutOption.Indent,
CED.LabelWidth(250, CED.Action(Drawer_SectionLightingSettings)));
public AnimBool isSectionExpandedRenderingPasses { get { return m_AnimBools[0]; } }
public AnimBool isSectionExpandedLightingSettings { get { return m_AnimBools[1]; } }

public LightLoopSettingsUI lightLoopSettings = new LightLoopSettingsUI();
public FrameSettingsUI()
: base(7)
: base(7)
{
}

49
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Unlit/UnlitsToHDUnlitUpgrader.cs


using UnityEngine;
using UnityEngine;
public class UnlitsToHDUnlitUpgrader : MaterialUpgrader
{
string Unlit_Color = "Unlit/Color";
//string Unlit_Texture = "Unlit/Texture";
string Unlit_Transparent = "Unlit/Transparent";
string Unlit_Cutout = "Unlit/Transparent Cutout";
public class UnlitsToHDUnlitUpgrader : MaterialUpgrader
{
string Unlit_Color = "Unlit/Color";
//string Unlit_Texture = "Unlit/Texture";
string Unlit_Transparent = "Unlit/Transparent";
string Unlit_Cutout = "Unlit/Transparent Cutout";
public UnlitsToHDUnlitUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer = null)
public UnlitsToHDUnlitUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer = null)
if (sourceShaderName == Unlit_Color)
RenameColor("_Color", "_UnlitColor");
else // all other unlit have a texture
RenameTexture("_MainTex", "_UnlitColorMap");
if (sourceShaderName == Unlit_Color)
RenameColor("_Color", "_UnlitColor");
else // all other unlit have a texture
RenameTexture("_MainTex", "_UnlitColorMap");
if (sourceShaderName == Unlit_Cutout)
{
RenameFloat("_Cutoff", "_AlphaCutoff");
SetFloat("_AlphaCutoffEnable", 1f);
}
else
SetFloat("_AlphaCutoffEnable", 0f);
if (sourceShaderName == Unlit_Cutout)
{
RenameFloat("_Cutoff", "_AlphaCutoff");
SetFloat("_AlphaCutoffEnable", 1f);
}
else
SetFloat("_AlphaCutoffEnable", 0f);
SetFloat("_SurfaceType", (sourceShaderName == Unlit_Transparent)? 1f : 0f );
}
SetFloat("_SurfaceType", (sourceShaderName == Unlit_Transparent) ? 1f : 0f);
}
public override void Convert(Material srcMaterial, Material dstMaterial)
public override void Convert(Material srcMaterial, Material dstMaterial)
{
//dstMaterial.hideFlags = HideFlags.DontUnloadUnusedAsset;

}
}
}
}
}

1
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Unlit/UnlitUI.cs


protected override void VertexAnimationPropertiesGUI()
{
}
protected override bool ShouldEmissionBeEnabled(Material mat)

2
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Unlit/BaseUnlitUI.cs


material.SetInt("_DistortionBlurSrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DistortionBlurDstBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DistortionBlurBlendOp", (int)UnityEngine.Rendering.BlendOp.Max);
break;
break;
case 1: // Multiply
material.SetInt("_DistortionSrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);

57
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/StackLitUI.cs


new Property(this, "_CoatIor", "Coat IOR", "Index of refraction", false),
new Property(this, "_CoatThickness", "Coat Thickness", "Coat thickness", false),
new Property(this, "_CoatExtinction", "Coat Absorption", "Coat absorption tint (the thicker the coat, the more that color is removed)", false),
}, _ =>EnableCoat.BoolValue == true),
}, _ => EnableCoat.BoolValue == true),
new GroupProperty(this, "_Iridescence", "Iridescence", new BaseProperty[]
{

{
new DiffusionProfileProperty(this, k_DiffusionProfile, "Diffusion Profile", "A profile determines the shape of the SSS/transmission filter.", false),
new TextureProperty(this, k_SubsurfaceMaskMap, k_SubsurfaceMask, "Subsurface mask map (R)", "Determines the strength of the subsurface scattering effect.", false, false),
}, _ => EnableSSS.BoolValue == true ),
}, _ => EnableSSS.BoolValue == true),
new GroupProperty(this, "_Transmission", "Transmission", new BaseProperty[]
{

new Property(this, "_NormalCurvatureToRoughnessScale", "Normal Curvature To Roughness Scale", "Normal Curvature To Roughness Scale", false, _ => EnableNormalCurvatureToRoughness.BoolValue == true),
new Property(this, "_NormalCurvatureToRoughnessBias", "Normal Curvature To Roughness Bias", "Normal Curvature To Roughness Bias", false, _ => EnableNormalCurvatureToRoughness.BoolValue == true),
new Property(this, "_NormalCurvatureToRoughnessExponent", "Normal Curvature To Roughness Exponent", "Normal Curvature To Roughness Exponent", false, _ => EnableNormalCurvatureToRoughness.BoolValue == true),
}),
});
}

int channel = (int)material.GetFloat(channelPropertyName);
switch (channel)
{
case 0:
material.SetVector(channelMaskPropertyName, new Vector4(1.0f, 0.0f, 0.0f, 0.0f));
break;
case 1:
material.SetVector(channelMaskPropertyName, new Vector4(0.0f, 1.0f, 0.0f, 0.0f));
break;
case 2:
material.SetVector(channelMaskPropertyName, new Vector4(0.0f, 0.0f, 1.0f, 0.0f));
break;
case 3:
material.SetVector(channelMaskPropertyName, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
break;
case 0:
material.SetVector(channelMaskPropertyName, new Vector4(1.0f, 0.0f, 0.0f, 0.0f));
break;
case 1:
material.SetVector(channelMaskPropertyName, new Vector4(0.0f, 1.0f, 0.0f, 0.0f));
break;
case 2:
material.SetVector(channelMaskPropertyName, new Vector4(0.0f, 0.0f, 1.0f, 0.0f));
break;
case 3:
material.SetVector(channelMaskPropertyName, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
break;
}
}
else

if (doubleSidedEnable)
{
BaseLitGUI.DoubleSidedNormalMode doubleSidedNormalMode =
(BaseLitGUI.DoubleSidedNormalMode) material.GetFloat(k_DoubleSidedNormalMode);
(BaseLitGUI.DoubleSidedNormalMode)material.GetFloat(k_DoubleSidedNormalMode);
switch (doubleSidedNormalMode)
{
case BaseLitGUI.DoubleSidedNormalMode.Mirror: // Mirror mode (in tangent space)

// Check if we are using specific UVs.
TextureProperty.UVMapping[] uvIndices = new[]
{
(TextureProperty.UVMapping) material.GetFloat(k_BaseColorMapUV),
(TextureProperty.UVMapping) material.GetFloat(k_MetallicMapUV),
(TextureProperty.UVMapping) material.GetFloat(k_NormalMapUV),
(TextureProperty.UVMapping) material.GetFloat(k_SmoothnessAMapUV),
(TextureProperty.UVMapping) material.GetFloat(k_SmoothnessBMapUV),
(TextureProperty.UVMapping) material.GetFloat(k_AmbientOcclusionMapUV),
(TextureProperty.UVMapping) material.GetFloat(k_EmissiveColorMapUV),
(TextureProperty.UVMapping) material.GetFloat(k_SubsurfaceMaskMapUV),
(TextureProperty.UVMapping) material.GetFloat(k_ThicknessMapUV),
(TextureProperty.UVMapping) material.GetFloat(k_AnisotropyMapUV),
(TextureProperty.UVMapping) material.GetFloat(k_IridescenceThicknessMapUV),
(TextureProperty.UVMapping) material.GetFloat(k_CoatSmoothnessMapUV),
(TextureProperty.UVMapping) material.GetFloat(k_CoatNormalMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_BaseColorMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_MetallicMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_NormalMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_SmoothnessAMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_SmoothnessBMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_AmbientOcclusionMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_EmissiveColorMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_SubsurfaceMaskMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_ThicknessMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_AnisotropyMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_IridescenceThicknessMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_CoatSmoothnessMapUV),
(TextureProperty.UVMapping)material.GetFloat(k_CoatNormalMapUV),
};
// Set keyword for mapping

11
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/StackLit/BaseMaterialUI.cs


{
m_Options = options;
}
public ComboProperty(BaseMaterialGUI parent, string propertyName, string guiText, string[] options, int[] values, bool isMandatory = true, Func<object, bool> isVisible = null)
: base(parent, propertyName, guiText, isMandatory, isVisible)
{

using (var scope = new EditorGUI.ChangeCheckScope())
{
int profileID = (int) FloatValue;
int profileID = (int)FloatValue;
using (new EditorGUILayout.HorizontalScope())
{

internal override string ToShaderPropertiesStringInternal()
{
return string.Format("{0}(\"{1}\", 2D) = \"white\" {{}}\n" +
"{2}(\"{3}\", Float) = 0.0",
PropertyName, PropertyText,
ExtraPropertyName, ExtraPropertyName);
"{2}(\"{3}\", Float) = 0.0",
PropertyName, PropertyText,
ExtraPropertyName, ExtraPropertyName);
}
}

"[HideInInspector] {0}Range(\"{1} Range\", Vector) = (0, 1, 0, 0)\n",
m_ConstantPropertyName, constantName, PropertyName);
}
}
}
#endregion
}
}

50
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/StandardsToHDLitMaterialUpgrader.cs


using UnityEngine;
using UnityEngine;
public class StandardsToHDLitMaterialUpgrader : MaterialUpgrader
{
public class StandardsToHDLitMaterialUpgrader : MaterialUpgrader
{
public StandardsToHDLitMaterialUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer = null)
public StandardsToHDLitMaterialUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer = null)
{
RenameShader(sourceShaderName, destShaderName, finalizer);

// Metallic
bool hasMetallic = false;
Texture metallicMap = Texture2D.blackTexture;
if ( (srcMaterial.shader.name == Standard) || (srcMaterial.shader.name == Standard_Rough) )
if ((srcMaterial.shader.name == Standard) || (srcMaterial.shader.name == Standard_Rough))
{
hasMetallic = srcMaterial.GetTexture("_MetallicGlossMap") != null;
if (hasMetallic)

{
string smoothnessTextureChannel = "_MainTex";
if ( srcMaterial.GetFloat("_SmoothnessTextureChannel") == 0 )
if (srcMaterial.GetFloat("_SmoothnessTextureChannel") == 0)
smoothnessMap = (Texture2D) srcMaterial.GetTexture( smoothnessTextureChannel );
smoothnessMap = (Texture2D)srcMaterial.GetTexture(smoothnessTextureChannel);
if (smoothnessMap != null)
{
hasSmoothness = true;

// Build the mask map
if ( hasMetallic || hasOcclusion || hasDetailMask || hasSmoothness )
if (hasMetallic || hasOcclusion || hasDetailMask || hasSmoothness)
metallicMap, 0, // R: Metallic from red
occlusionMap, 1, // G: Occlusion from green
detailMaskMap, 3, // B: Detail Mask from alpha
smoothnessMap, (srcMaterial.shader.name == Standard_Rough)?-4:3 // A: Smoothness Texture from inverse greyscale for roughness setup, or alpha
);
metallicMap, 0, // R: Metallic from red
occlusionMap, 1, // G: Occlusion from green
detailMaskMap, 3, // B: Detail Mask from alpha
smoothnessMap, (srcMaterial.shader.name == Standard_Rough) ? -4 : 3 // A: Smoothness Texture from inverse greyscale for roughness setup, or alpha
);
maskMapPath = maskMapPath.Remove(maskMapPath.Length-4) + "_MaskMap.png";
maskMap = maskMapCombiner.Combine( maskMapPath );
maskMapPath = maskMapPath.Remove(maskMapPath.Length - 4) + "_MaskMap.png";
maskMap = maskMapCombiner.Combine(maskMapPath);
dstMaterial.SetTexture("_MaskMap", maskMap);
}

if (srcMaterial.shader.name == Standard_Spec)
{
// if there is a specular map, change the specular color to white
if (srcMaterial.GetTexture("_SpecGlossMap") != null ) dstMaterial.SetColor("_SpecularColor", Color.white);
if (srcMaterial.GetTexture("_SpecGlossMap") != null) dstMaterial.SetColor("_SpecularColor", Color.white);
}
// ---------- Height Map ----------

// ---------- Detail Map ----------
bool hasDetailAlbedo = srcMaterial.GetTexture("_DetailAlbedoMap") != null;
bool hasDetailNormal = srcMaterial.GetTexture("_DetailNormalMap") != null;
if ( hasDetailAlbedo || hasDetailNormal )
if (hasDetailAlbedo || hasDetailNormal)
TextureCombiner.GetTextureSafe(srcMaterial, "_DetailAlbedoMap", Color.grey), 4, // Albedo (overlay)
TextureCombiner.GetTextureSafe(srcMaterial, "_DetailNormalMap", Color.grey), 1, // Normal Y
TextureCombiner.midGrey, 1, // Smoothness
TextureCombiner.GetTextureSafe(srcMaterial, "_DetailNormalMap", Color.grey), 0 // Normal X
);
TextureCombiner.GetTextureSafe(srcMaterial, "_DetailAlbedoMap", Color.grey), 4, // Albedo (overlay)
TextureCombiner.GetTextureSafe(srcMaterial, "_DetailNormalMap", Color.grey), 1, // Normal Y
TextureCombiner.midGrey, 1, // Smoothness
TextureCombiner.GetTextureSafe(srcMaterial, "_DetailNormalMap", Color.grey), 0 // Normal X
);
detailMapPath = detailMapPath.Remove(detailMapPath.Length-4) + "_DetailMap.png";
detailMap = detailCombiner.Combine( detailMapPath );
detailMapPath = detailMapPath.Remove(detailMapPath.Length - 4) + "_DetailMap.png";
detailMap = detailCombiner.Combine(detailMapPath);
dstMaterial.SetTexture("_DetailMap", detailMap);
}

HDEditorUtils.ResetMaterialKeywords(dstMaterial);
}
}
}
}

13
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/LitUI.cs


}
}
}
protected void ShaderIridescenceInputGUI()
{
m_MaterialEditor.TexturePropertySingleLine(Styles.iridescenceMaskText, iridescenceMaskMap, iridescenceMask);

else
{
// Allow the user to set the constant value of thickness if no thickness map is provided.
m_MaterialEditor.TexturePropertySingleLine(Styles.iridescenceThicknessMapText, iridescenceThicknessMap, iridescenceThickness);
m_MaterialEditor.TexturePropertySingleLine(Styles.iridescenceThicknessMapText, iridescenceThicknessMap, iridescenceThickness);
}
}

protected override void UpdateDisplacement()
{
for(int i = 0; i < m_LayerCount; ++i)
for (int i = 0; i < m_LayerCount; ++i)
{
UpdateDisplacement(i);
}

else
{
HeightmapParametrization parametrization = (HeightmapParametrization)heightParametrization[layerIndex].floatValue;
if(parametrization == HeightmapParametrization.MinMax)
if (parametrization == HeightmapParametrization.MinMax)
{
float offset = heightOffset[layerIndex].floatValue;
float amplitude = (heightMax[layerIndex].floatValue - heightMin[layerIndex].floatValue);

m_MaterialEditor.ShaderProperty(metallic[layerIndex], Styles.metallicText);
}
if(maskMap[layerIndex].textureValue == null)
if (maskMap[layerIndex].textureValue == null)
{
m_MaterialEditor.ShaderProperty(smoothness[layerIndex], Styles.smoothnessText);
}

}
DisplacementMode displaceMode = (DisplacementMode)displacementMode.floatValue;
if(displaceMode != DisplacementMode.None || showHeightMap)
if (displaceMode != DisplacementMode.None || showHeightMap)
{
EditorGUI.BeginChangeCheck();
m_MaterialEditor.TexturePropertySingleLine(Styles.heightMapText, heightMap[layerIndex]);

else
{
m_MaterialEditor.ShaderProperty(heightParametrization[layerIndex], Styles.heightMapParametrization);
if(!heightParametrization[layerIndex].hasMixedValue)
if (!heightParametrization[layerIndex].hasMixedValue)
{
HeightmapParametrization parametrization = (HeightmapParametrization)heightParametrization[layerIndex].floatValue;
if (parametrization == HeightmapParametrization.MinMax)

4
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/BaseLitUI.cs


public static GUIContent supportDBufferText = new GUIContent("Enable Decal", "Allow to specify if the material can receive decal or not");
public static GUIContent enableGeometricSpecularAAText = new GUIContent("Enable geometric specular AA", "This reduce specular aliasing on highly dense mesh (Particularly useful when they don't use using normal map)");
public static GUIContent enableGeometricSpecularAAText = new GUIContent("Enable geometric specular AA", "This reduce specular aliasing on highly dense mesh (Particularly useful when they don't use normal map)");
public static GUIContent specularAAScreenSpaceVarianceText = new GUIContent("Screen space variance", "Allow to control the strength of the specular AA reduction. Higher mean more blurry result and less aliasing");
public static GUIContent specularAAThresholdText = new GUIContent("Threshold", "Allow to limit the effect of specular AA reduction. 0 mean don't apply reduction, higher value mean allow higher reduction");
}

EditorGUI.BeginChangeCheck();
m_MaterialEditor.ShaderProperty(displacementMode, StylesBaseLit.displacementModeText);
if(EditorGUI.EndChangeCheck())
if (EditorGUI.EndChangeCheck())
{
UpdateDisplacement();
}

5
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/LayeredLit/LayeredLitUI.cs


case ShaderUtil.ShaderPropertyType.TexEnv:
{
material.SetTexture(layerPropertyName, layerMaterial.GetTexture(propertyName));
if(!excludeUVMappingProperties)
if (!excludeUVMappingProperties)
{
material.SetTextureOffset(layerPropertyName, layerMaterial.GetTextureOffset(propertyName));
material.SetTextureScale(layerPropertyName, layerMaterial.GetTextureScale(propertyName));

return result;
}
void DoLayeringInputGUI()
{

CoreUtils.SetKeyword(material, "_HEIGHT_BASED_BLEND", useHeightBasedBlend);
bool useDensityModeEnable = false;
for (int i = 0; i < material.GetInt(kLayerCount); ++i )
for (int i = 0; i < material.GetInt(kLayerCount); ++i)
{
useDensityModeEnable |= material.GetFloat(kOpacityAsDensity + i) != 0.0f;
}

6
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/DiffusionProfile/DiffusionProfileSettingsEditor.cs


using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;

internal Profile()
{
profileRT = new RenderTexture(256, 256, 0, RenderTextureFormat.DefaultHDR);
transmittanceRT = new RenderTexture( 16, 256, 0, RenderTextureFormat.DefaultHDR);
transmittanceRT = new RenderTexture(16, 256, 0, RenderTextureFormat.DefaultHDR);
}
internal void Release()

var scatterDist1 = profile.scatterDistance1.colorValue;
var scatterDist2 = profile.scatterDistance2.colorValue;
float rMax = Mathf.Max(scatterDist1.r, scatterDist1.g, scatterDist1.b,
scatterDist2.r, scatterDist2.g, scatterDist2.b);
scatterDist2.r, scatterDist2.g, scatterDist2.b);
var stdDev1 = s * (Vector4)scatterDist1;
var stdDev2 = s * (Vector4)scatterDist2;
m_ProfileMaterial.SetVector(HDShaderIDs._StdDev1, stdDev1);

19
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalUI.cs


using System;
using System;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;

public static GUIContent baseColorText = new GUIContent("Base Color + Blend", "Albedo (RGB) and Blend Factor (A)");
public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map (BC7/BC5/DXT5(nm))");
public static GUIContent maskMapText = new GUIContent("Mask Map - M(R), AO(G), D(B), S(A)", "Mask map");
public static GUIContent maskMapText = new GUIContent("Mask Map - M(R), AO(G), D(B), S(A)", "Mask map");
public static GUIContent decalBlendText = new GUIContent("Decal Blend", "Whole decal blend");
}

protected MaterialProperty normalMap = new MaterialProperty();
protected const string kNormalMap = "_NormalMap";
protected MaterialProperty maskMap = new MaterialProperty();
protected const string kMaskMap = "_MaskMap";
protected MaterialProperty maskMap = new MaterialProperty();
protected const string kMaskMap = "_MaskMap";
protected MaterialEditor m_MaterialEditor;

{
baseColorMap = FindProperty(kBaseColorMap, props);
normalMap = FindProperty(kNormalMap, props);
maskMap = FindProperty(kMaskMap, props);
maskMap = FindProperty(kMaskMap, props);
// All Setup Keyword functions must be static. It allow to create script to automatically update the shaders with a script if code change
static public void SetupMaterialKeywordsAndPass(Material material)

CoreUtils.SetKeyword(material, "_MASKMAP", material.GetTexture(kMaskMap));
CoreUtils.SetKeyword(material, "_MASKMAP", material.GetTexture(kMaskMap));
}
protected void SetupMaterialKeywordsAndPassInternal(Material material)

public void ShaderPropertiesGUI(Material material)
{

m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapText, maskMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapText, maskMap);
}
if (EditorGUI.EndChangeCheck())

// We should always do this call at the end
m_MaterialEditor.serializedObject.ApplyModifiedProperties();
}
}
}

34
com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Decal/DecalProjectorComponentEditor.cs


using System;
using System;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;

private SerializedProperty m_UVScaleProperty;
private SerializedProperty m_UVBiasProperty;
public class DecalBoundsHandle : BoxBoundsHandle
public class DecalBoundsHandle : BoxBoundsHandle
{
protected override Bounds OnHandleChanged(HandleDirection handle, Bounds boundsOnClick, Bounds newBounds)
{

public Vector3 m_Translation;
public Vector3 m_Scale;
}
private DecalBoundsHandle m_Handle = new DecalBoundsHandle();
private void OnEnable()

m_MaterialEditor = (MaterialEditor)CreateEditor(m_DecalProjectorComponent.Mat);
m_DecalProjectorComponent.OnMaterialChange += OnMaterialChange;
m_DecalProjectorComponent.OnMaterialChange += OnMaterialChange;
m_MaterialProperty = serializedObject.FindProperty("m_Material");
m_DrawDistanceProperty = serializedObject.FindProperty("m_DrawDistance");
m_FadeScaleProperty = serializedObject.FindProperty("m_FadeScale");

private void OnDisable()
{
m_DecalProjectorComponent.OnMaterialChange -= OnMaterialChange;
}
private void OnDisable()
{
m_DecalProjectorComponent.OnMaterialChange -= OnMaterialChange;
}
public void OnMaterialChange()
{
// Update material editor with the new material
m_MaterialEditor = (MaterialEditor)CreateEditor(m_DecalProjectorComponent.Mat);
}
public void OnMaterialChange()
{
// Update material editor with the new material
m_MaterialEditor = (MaterialEditor)CreateEditor(m_DecalProjectorComponent.Mat);
}
void OnSceneGUI()
{

Handles.color = Color.white;
// decal mesh is centered at (0, -0.5, 0)
// zero out the local scale in the matrix so that handle code gives us back the actual scale
Handles.matrix = Matrix4x4.TRS(m_DecalProjectorComponent.transform.position, m_DecalProjectorComponent.transform.rotation, Vector3.one) * Matrix4x4.Translate(new Vector3(0.0f, -0.5f* m_DecalProjectorComponent.transform.localScale.y, 0.0f));
// pass in the scale
Handles.matrix = Matrix4x4.TRS(m_DecalProjectorComponent.transform.position, m_DecalProjectorComponent.transform.rotation, Vector3.one) * Matrix4x4.Translate(new Vector3(0.0f, -0.5f * m_DecalProjectorComponent.transform.localScale.y, 0.0f));
// pass in the scale
m_DecalProjectorComponent.transform.Translate(m_Handle.m_Translation);
m_DecalProjectorComponent.transform.Translate(m_Handle.m_Translation);
m_DecalProjectorComponent.transform.localScale = m_Handle.m_Scale;
Repaint();
}

}
}
public override void OnInspectorGUI()
{

4
com.unity.render-pipelines.high-definition/HDRP/Editor/AssetPostProcessors/NormalMapVarianceTexturePostprocessor.cs


textureImporter.convertToNormalmap = false;
textureImporter.textureCompression = TextureImporterCompression.CompressedHQ;
#pragma warning disable 618 // remove obsolete warning for this one
#pragma warning restore 618
textureImporter.sRGBTexture = false; // But we're setting the new property just in case it changes later...
}
}

{
int texelFootprint = 1 << m;
Vector3 averageNormal = GetAverageNormal(source, x * texelFootprint, y * texelFootprint,
texture.width, texture.height, texelFootprint);
texture.width, texture.height, texelFootprint);
// Store the normal length for the average normal.
int outputPosition = y * mipWidth + x;

2
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightingConvexHullUtils.hlsl


if (bIsSideQuad) { vA2 *= (iAbsSide == 0 ? scaleXY.x : scaleXY.y); vB2 *= (iAbsSide == 0 ? scaleXY.y : scaleXY.x); }
float3 vN = cross(vB2, 0.5 * (vA - vA2) - vC); // +/- normal
float3 vN = cross(vB2, 0.5 * (vA - vA2) - vC); // +/- normal
float3 v0 = vA + vB - vC; // vector from center to p0
p0 = center + v0; // center + vA is center of face when scaleXY is 1.0
n0 = dot(vN,v0) < 0.0 ? (-vN) : vN;

30
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/ShadowContext.hlsl


TEXTURE2D_ARRAY(_ShadowmapExp_PCF);
SAMPLER_CMP(sampler_ShadowmapExp_PCF);
StructuredBuffer<ShadowData> _ShadowDatasExp;
StructuredBuffer<int4> _ShadowPayloads;
StructuredBuffer<ShadowData> _ShadowDatasExp;
StructuredBuffer<int4> _ShadowPayloads;
ShadowContext sc;
sc.shadowDatas = _ShadowDatasExp;
sc.payloads = _ShadowPayloads;
sc.tex2DArray[0] = _ShadowmapExp_PCF;
sc.compSamplers[0] = sampler_ShadowmapExp_PCF;
ShadowContext sc;
sc.shadowDatas = _ShadowDatasExp;
sc.payloads = _ShadowPayloads;
sc.tex2DArray[0] = _ShadowmapExp_PCF;
sc.compSamplers[0] = sampler_ShadowmapExp_PCF;
sc.tex2DArray[1] = _ShadowmapExp_VSM_0;
sc.tex2DArray[2] = _ShadowmapExp_VSM_1;
sc.tex2DArray[3] = _ShadowmapExp_VSM_2;
sc.tex2DArray[1] = _ShadowmapExp_VSM_0;
sc.tex2DArray[2] = _ShadowmapExp_VSM_1;
sc.tex2DArray[3] = _ShadowmapExp_VSM_2;
sc.samplers[0] = sampler_ShadowmapExp_VSM_0;
sc.samplers[1] = sampler_ShadowmapExp_VSM_1;
sc.samplers[2] = sampler_ShadowmapExp_VSM_2;
sc.samplers[0] = sampler_ShadowmapExp_VSM_0;
sc.samplers[1] = sampler_ShadowmapExp_VSM_1;
sc.samplers[2] = sampler_ShadowmapExp_VSM_2;
return sc;
return sc;
#endif // LIGHTLOOP_SHADOW_CONTEXT_HLSL
#endif // LIGHTLOOP_SHADOW_CONTEXT_HLSL

6
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoopSettings.cs


// aggregateFrameSettings already contain the aggregation of RenderPipelineSettings and FrameSettings (regular and/or debug)
public static void InitializeLightLoopSettings(Camera camera, FrameSettings aggregateFrameSettings,
RenderPipelineSettings renderPipelineSettings, FrameSettings frameSettings,
ref LightLoopSettings aggregate)
RenderPipelineSettings renderPipelineSettings, FrameSettings frameSettings,
ref LightLoopSettings aggregate)
{
if (aggregate == null)
aggregate = new LightLoopSettings();

public static void RegisterDebug(LightLoopSettings lightLoopSettings, List<DebugUI.Widget> widgets)
{
widgets.AddRange(new []
widgets.AddRange(new[]
{
new DebugUI.Container
{

5
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/Deferred.compute


RWTexture2D<float4> specularLightingUAV;
CBUFFER_START(UnityDeferredCompute)
uint g_TileListOffset;
uint g_TileListOffset;
CBUFFER_END
#ifdef USE_INDIRECT

{
uint2 tileCoord = (TILE_SIZE_FPTL * groupId) / GetTileSize();
uint2 pixelCoord = dispatchThreadId;
uint featureFlags = UINT_MAX;
uint featureFlags = UINT_MAX;
#endif

specularLightingUAV[pixelCoord] = float4(diffuseLighting + specularLighting, 1.0);
}
}

12
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/builddispatchindirect.compute


#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "../../Material/Material.hlsl" // This includes Material.hlsl
RWBuffer<uint> g_DispatchIndirectBuffer : register( u0 ); // Indirect arguments have to be in a _buffer_, not a structured buffer
RWBuffer<uint> g_DispatchIndirectBuffer : register( u0 ); // Indirect arguments have to be in a _buffer_, not a structured buffer
RWStructuredBuffer<uint> g_TileList;
StructuredBuffer<uint> g_TileFeatureFlags;

[numthreads(64, 1, 1)]
void BuildDispatchIndirect(uint dispatchThreadId : SV_DispatchThreadID)
{
if (dispatchThreadId >= g_NumTiles)
return;
if (dispatchThreadId >= g_NumTiles)
return;
uint featureFlags = g_TileFeatureFlags[dispatchThreadId];
uint featureFlags = g_TileFeatureFlags[dispatchThreadId];
uint tileY = (dispatchThreadId + 0.5f) / (float)g_NumTilesX; // Integer division is extremely expensive, so we better avoid it
uint tileX = dispatchThreadId - tileY * g_NumTilesX;
uint tileY = (dispatchThreadId + 0.5f) / (float)g_NumTilesX; // Integer division is extremely expensive, so we better avoid it
uint tileX = dispatchThreadId - tileY * g_NumTilesX;
// Check if there is no material (means it is a sky/background pixel).
// Note that we can have no lights, yet we still need to render geometry with precomputed illumination.

10
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/cleardispatchindirect.compute


#pragma kernel ClearDispatchIndirect
#pragma only_renderers d3d11 ps4 xboxone vulkan metal switch
RWBuffer<uint> g_DispatchIndirectBuffer : register( u0 ); // Indirect arguments have to be in a _buffer_, not a structured buffer
RWBuffer<uint> g_DispatchIndirectBuffer : register( u0 ); // Indirect arguments have to be in a _buffer_, not a structured buffer
g_DispatchIndirectBuffer[dispatchThreadId * 3 + 0] = 0; // ThreadGroupCountX
g_DispatchIndirectBuffer[dispatchThreadId * 3 + 1] = 1; // ThreadGroupCountY
g_DispatchIndirectBuffer[dispatchThreadId * 3 + 2] = 1; // ThreadGroupCountZ
}
g_DispatchIndirectBuffer[dispatchThreadId * 3 + 0] = 0; // ThreadGroupCountX
g_DispatchIndirectBuffer[dispatchThreadId * 3 + 1] = 1; // ThreadGroupCountY
g_DispatchIndirectBuffer[dispatchThreadId * 3 + 2] = 1; // ThreadGroupCountZ
}

4
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightCullUtils.hlsl


#ifndef __LIGHTCULLUTILS_H__
#define __LIGHTCULLUTILS_H__
// Used to index into our SFiniteLightBound (g_data) and
// Used to index into our SFiniteLightBound (g_data) and
// LightVolumeData (_LightVolumeData) buffers.
int GenerateLightCullDataIndex(int lightIndex, uint numVisibleLights, uint eyeIndex)
{

return indices;
}
#endif //__LIGHTCULLUTILS_H__
#endif //__LIGHTCULLUTILS_H__

12
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/ClusteredUtils.hlsl


float LogBase(float x, float b)
{
return log2(x) / log2(b);
return log2(x) / log2(b);
}
int SnapToClusterIdxFlex(float z_in, float suggestedBase, bool logBasePerTile)

//const float dist = max(0, z - g_fNearPlane);
//return (int)clamp(log2(dist * userscale * (suggestedBase - 1.0f) + 1) / log2(suggestedBase), 0.0, (float)((1 << g_iLog2NumClusters) - 1));
const int C = 1 << g_iLog2NumClusters;
const float rangeFittedDistance = max(0, z - g_fNearPlane) / (g_fFarPlane - g_fNearPlane);
const int C = 1 << g_iLog2NumClusters;
const float rangeFittedDistance = max(0, z - g_fNearPlane) / (g_fFarPlane - g_fNearPlane);
return (int)clamp( LogBase( lerp(1.0, PositivePow(suggestedBase, (float) C), rangeFittedDistance), suggestedBase), 0.0, (float)(C - 1));
}

//float dist = (PositivePow(suggestedBase, (float)k) - 1.0) / (userscale * (suggestedBase - 1.0f));
//res = dist + g_fNearPlane;
const float C = (float)(1 << g_iLog2NumClusters);
float rangeFittedDistance = (PositivePow(suggestedBase, (float)k) - 1.0) / (PositivePow(suggestedBase, C) - 1.0);
res = lerp(g_fNearPlane, g_fFarPlane, rangeFittedDistance);
const float C = (float)(1 << g_iLog2NumClusters);
float rangeFittedDistance = (PositivePow(suggestedBase, (float)k) - 1.0) / (PositivePow(suggestedBase, C) - 1.0);
res = lerp(g_fNearPlane, g_fFarPlane, rangeFittedDistance);
#if USE_LEFT_HAND_CAMERA_SPACE

70
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/Shadow.hlsl


// The enum value for the variant is in GPUShadowAlgorithm and is express like: PCF_tent_3x3 = ShadowAlgorithm.PCF << 3 | ShadowVariant.V2
//#define SHADOW_DISPATCH_USE_SEPARATE_CASCADE_ALGOS // enables separate cascade sampling variants for each cascade
//#define SHADOW_DISPATCH_USE_SEPARATE_PUNC_ALGOS // enables separate resources and algorithms for spot and point lights
//#define SHADOW_DISPATCH_USE_SEPARATE_PUNC_ALGOS // enables separate resources and algorithms for spot and point lights
// directional
#define SHADOW_DISPATCH_DIR_TEX 0

#ifdef SHADOW_DISPATCH_USE_CUSTOM_DIRECTIONAL
float GetDirectionalShadowAttenuation( ShadowContext shadowContext, float3 positionWS, float3 normalWS, int shadowDataIndex, float3 L )
{
Texture2DArray tex = shadowContext.tex2DArray[SHADOW_DISPATCH_DIR_TEX];
SamplerComparisonState compSamp = shadowContext.compSamplers[SHADOW_DISPATCH_DIR_SMP];
Texture2DArray tex = shadowContext.tex2DArray[SHADOW_DISPATCH_DIR_TEX];
SamplerComparisonState compSamp = shadowContext.compSamplers[SHADOW_DISPATCH_DIR_SMP];
uint algo[kMaxShadowCascades] = { SHADOW_DISPATCH_DIR_ALG_0, SHADOW_DISPATCH_DIR_ALG_1, SHADOW_DISPATCH_DIR_ALG_2, SHADOW_DISPATCH_DIR_ALG_3 };
uint algo[kMaxShadowCascades] = { SHADOW_DISPATCH_DIR_ALG_0, SHADOW_DISPATCH_DIR_ALG_1, SHADOW_DISPATCH_DIR_ALG_2, SHADOW_DISPATCH_DIR_ALG_3 };
uint algo = SHADOW_DISPATCH_DIR_ALG;
uint algo = SHADOW_DISPATCH_DIR_ALG;
return EvalShadow_CascadedDepth_Blend( shadowContext, algo, tex, compSamp, positionWS, normalWS, shadowDataIndex, L );
return EvalShadow_CascadedDepth_Blend( shadowContext, algo, tex, compSamp, positionWS, normalWS, shadowDataIndex, L );
return GetDirectionalShadowAttenuation( shadowContext, positionWS, normalWS, shadowDataIndex, L );
return GetDirectionalShadowAttenuation( shadowContext, positionWS, normalWS, shadowDataIndex, L );
return EvalShadow_GetClosestSample_Cascade( shadowContext, shadowContext.tex2DArray[SHADOW_DISPATCH_DIR_TEX], positionWS, normalWS, index, L );
return EvalShadow_GetClosestSample_Cascade( shadowContext, shadowContext.tex2DArray[SHADOW_DISPATCH_DIR_TEX], positionWS, normalWS, index, L );
}
#endif

float GetPunctualShadowAttenuation( ShadowContext shadowContext, float3 positionWS, float3 normalWS, int shadowDataIndex, float3 L, float L_dist )
{
#ifdef SHADOW_DISPATCH_USE_SEPARATE_PUNC_ALGOS
// example for choosing different algos for point and spot lights
ShadowData sd = shadowContext.shadowDatas[shadowDataIndex];
uint shadowType;
UnpackShadowType( sd.shadowType, shadowType );
// example for choosing different algos for point and spot lights
ShadowData sd = shadowContext.shadowDatas[shadowDataIndex];
uint shadowType;
UnpackShadowType( sd.shadowType, shadowType );
UNITY_BRANCH
if( shadowType == GPUSHADOWTYPE_POINT )
{
Texture2DArray tex = shadowContext.tex2DArray[SHADOW_DISPATCH_POINT_TEX];
SamplerComparisonState compSamp = shadowContext.compSamplers[SHADOW_DISPATCH_POINT_SMP];
uint algo = SHADOW_DISPATCH_POINT_ALG;
return EvalShadow_PointDepth( shadowContext, algo, tex, compSamp, positionWS, normalWS, shadowDataIndex, L, L_dist );
}
else
{
Texture2DArray tex = shadowContext.tex2DArray[SHADOW_DISPATCH_SPOT_TEX];
SamplerComparisonState compSamp = shadowContext.compSamplers[SHADOW_DISPATCH_SPOT_SMP];
uint algo = SHADOW_DISPATCH_SPOT_ALG;
return EvalShadow_SpotDepth( shadowContext, algo, tex, compSamp, positionWS, normalWS, shadowDataIndex, L, L_dist );
}
UNITY_BRANCH
if( shadowType == GPUSHADOWTYPE_POINT )
{
Texture2DArray tex = shadowContext.tex2DArray[SHADOW_DISPATCH_POINT_TEX];
SamplerComparisonState compSamp = shadowContext.compSamplers[SHADOW_DISPATCH_POINT_SMP];
uint algo = SHADOW_DISPATCH_POINT_ALG;
return EvalShadow_PointDepth( shadowContext, algo, tex, compSamp, positionWS, normalWS, shadowDataIndex, L, L_dist );
}
else
{
Texture2DArray tex = shadowContext.tex2DArray[SHADOW_DISPATCH_SPOT_TEX];
SamplerComparisonState compSamp = shadowContext.compSamplers[SHADOW_DISPATCH_SPOT_SMP];
uint algo = SHADOW_DISPATCH_SPOT_ALG;
return EvalShadow_SpotDepth( shadowContext, algo, tex, compSamp, positionWS, normalWS, shadowDataIndex, L, L_dist );
}
// example for choosing the same algo
Texture2DArray tex = shadowContext.tex2DArray[SHADOW_DISPATCH_PUNC_TEX];
SamplerComparisonState compSamp = shadowContext.compSamplers[SHADOW_DISPATCH_PUNC_SMP];
uint algo = SHADOW_DISPATCH_PUNC_ALG;
return EvalShadow_PunctualDepth( shadowContext, algo, tex, compSamp, positionWS, normalWS, shadowDataIndex, L, L_dist );
// example for choosing the same algo
Texture2DArray tex = shadowContext.tex2DArray[SHADOW_DISPATCH_PUNC_TEX];
SamplerComparisonState compSamp = shadowContext.compSamplers[SHADOW_DISPATCH_PUNC_SMP];
uint algo = SHADOW_DISPATCH_PUNC_ALG;
return EvalShadow_PunctualDepth( shadowContext, algo, tex, compSamp, positionWS, normalWS, shadowDataIndex, L, L_dist );
return GetPunctualShadowAttenuation( shadowContext, positionWS, normalWS, shadowDataIndex, L, L_dist );
return GetPunctualShadowAttenuation( shadowContext, positionWS, normalWS, shadowDataIndex, L, L_dist );
return EvalShadow_GetClosestSample_Punctual( shadowContext, shadowContext.tex2DArray[SHADOW_DISPATCH_PUNC_TEX], positionWS, index, L );
return EvalShadow_GetClosestSample_Punctual( shadowContext, shadowContext.tex2DArray[SHADOW_DISPATCH_PUNC_TEX], positionWS, index, L );
return EvalShadow_SampleClosestDistance_Punctual( shadowContext, shadowContext.tex2DArray[SHADOW_DISPATCH_PUNC_TEX], sampl, positionWS, index, L, lightPositionWS );
return EvalShadow_SampleClosestDistance_Punctual( shadowContext, shadowContext.tex2DArray[SHADOW_DISPATCH_PUNC_TEX], sampl, positionWS, index, L, lightPositionWS );
}
#endif

36
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/LightLoop.cs.hlsl


//
float3 GetBoxAxisX(SFiniteLightBound value)
{
return value.boxAxisX;
return value.boxAxisX;
return value.boxAxisY;
return value.boxAxisY;
return value.boxAxisZ;
return value.boxAxisZ;
return value.center;
return value.center;
return value.scaleXY;
return value.scaleXY;
return value.radius;
return value.radius;
}
//

{
return value.lightPos;
return value.lightPos;
return value.lightVolume;
return value.lightVolume;
return value.lightAxisX;
return value.lightAxisX;
return value.lightCategory;
return value.lightCategory;
return value.lightAxisY;
return value.lightAxisY;
return value.radiusSq;
return value.radiusSq;
return value.lightAxisZ;
return value.lightAxisZ;
return value.cotan;
return value.cotan;
return value.boxInnerDist;
return value.boxInnerDist;
return value.featureFlags;
return value.featureFlags;
return value.boxInvRange;
return value.boxInvRange;
return value.unused2;
return value.unused2;
}

250
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/lightlistbuild-bigtile.compute


#define EXACT_EDGE_TESTS
#define PERFORM_SPHERICAL_INTERSECTION_TESTS
#define MAX_NR_BIGTILE_LIGHTS (MAX_NR_BIG_TILE_LIGHTS_PLUS_ONE-1)
#define MAX_NR_BIGTILE_LIGHTS (MAX_NR_BIG_TILE_LIGHTS_PLUS_ONE-1)
uniform int g_iNrVisibLights;

StructuredBuffer<SFiniteLightBound> g_data : register( t3 );
#define NR_THREADS 64
#define NR_THREADS 64
RWStructuredBuffer<uint> g_vLightList : register( u0 ); // don't support RWBuffer yet in unity
RWStructuredBuffer<uint> g_vLightList : register( u0 ); // don't support RWBuffer yet in unity
// 2kB (room for roughly 30 wavefronts)

float4x4 g_mInvScrProjection = g_mInvScrProjectionArr[0];
// for perspective projection m22 is zero and m23 is +1/-1 (depends on left/right hand proj)
// however this function must also work for orthographic projection so we keep it like this.
// however this function must also work for orthographic projection so we keep it like this.
float m22 = g_mInvScrProjection[2].z, m23 = g_mInvScrProjection[2].w;
float m32 = g_mInvScrProjection[3].z, m33 = g_mInvScrProjection[3].w;

{
float4x4 g_mScrProjection = g_mScrProjectionArr[eyeIndex];
bool isOrthographic = g_isOrthographic!=0;
float fSx = g_mScrProjection[0].x;
float fSy = g_mScrProjection[1].y;
float fCx = isOrthographic ? g_mScrProjection[0].w : g_mScrProjection[0].z;
float fCy = isOrthographic ? g_mScrProjection[1].w : g_mScrProjection[1].z;
bool isOrthographic = g_isOrthographic!=0;
float fSx = g_mScrProjection[0].x;
float fSy = g_mScrProjection[1].y;
float fCx = isOrthographic ? g_mScrProjection[0].w : g_mScrProjection[0].z;
float fCy = isOrthographic ? g_mScrProjection[1].w : g_mScrProjection[1].z;
bool useLeftHandVersion = true;
bool useLeftHandVersion = true;
bool useLeftHandVersion = isOrthographic;
bool useLeftHandVersion = isOrthographic;
float s = useLeftHandVersion ? 1 : (-1);
float2 p = float2( (s*v2ScrPos.x-fCx)/fSx, (s*v2ScrPos.y-fCy)/fSy);
float s = useLeftHandVersion ? 1 : (-1);
float2 p = float2( (s*v2ScrPos.x-fCx)/fSx, (s*v2ScrPos.y-fCy)/fSy);
return float3(isOrthographic ? p.xy : (fLinDepth*p.xy), fLinDepth);
return float3(isOrthographic ? p.xy : (fLinDepth*p.xy), fLinDepth);
}
float GetOnePixDiagWorldDistAtDepthOne(uint eyeIndex)

float fSx = g_mScrProjection[0].x;
float fSy = g_mScrProjection[1].y;
float fSx = g_mScrProjection[0].x;
float fSy = g_mScrProjection[1].y;
return length( float2(1.0/fSx,1.0/fSy) );
return length( float2(1.0/fSx,1.0/fSy) );
}

{
uint eyeIndex = u3GroupID.z;
uint2 tileIDX = u3GroupID.xy;
uint t=threadID;
uint2 tileIDX = u3GroupID.xy;
uint t=threadID;
uint iWidth = g_viDimensions.x;
uint iHeight = g_viDimensions.y;
uint nrBigTilesX = (iWidth+63)/64;
uint nrBigTilesY = (iHeight+63)/64;
uint iWidth = g_viDimensions.x;
uint iHeight = g_viDimensions.y;
uint nrBigTilesX = (iWidth+63)/64;
uint nrBigTilesY = (iHeight+63)/64;
if(t==0) lightOffs = 0;
if(t==0) lightOffs = 0;
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
uint2 viTilLL = 64*tileIDX;
uint2 viTilUR = min( viTilLL+uint2(64,64), uint2(iWidth, iHeight) ); // not width and height minus 1 since viTilUR represents the end of the tile corner.
uint2 viTilLL = 64*tileIDX;
uint2 viTilUR = min( viTilLL+uint2(64,64), uint2(iWidth, iHeight) ); // not width and height minus 1 since viTilUR represents the end of the tile corner.
float2 vTileLL = float2(viTilLL.x/(float) iWidth, viTilLL.y/(float) iHeight);
float2 vTileUR = float2(viTilUR.x/(float) iWidth, viTilUR.y/(float) iHeight);
float2 vTileLL = float2(viTilLL.x/(float) iWidth, viTilLL.y/(float) iHeight);
float2 vTileUR = float2(viTilUR.x/(float) iWidth, viTilUR.y/(float) iHeight);
// build coarse list using AABB
for(int l=(int) t; l<(int) g_iNrVisibLights; l += NR_THREADS)
{
// build coarse list using AABB
for(int l=(int) t; l<(int) g_iNrVisibLights; l += NR_THREADS)
{
if( all(vMa>vTileLL) && all(vMi<vTileUR))
{
unsigned int uInc = 1;
unsigned int uIndex;
InterlockedAdd(lightOffs, uInc, uIndex);
if( all(vMa>vTileLL) && all(vMi<vTileUR))
{
unsigned int uInc = 1;
unsigned int uIndex;
InterlockedAdd(lightOffs, uInc, uIndex);
if(uIndex<MAX_NR_BIGTILE_LIGHTS) lightsListLDS[uIndex] = l; // add to light list
}
}
if(uIndex<MAX_NR_BIGTILE_LIGHTS) lightsListLDS[uIndex] = l; // add to light list
}
}
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
int iNrCoarseLights = min(lightOffs,MAX_NR_BIGTILE_LIGHTS);
int iNrCoarseLights = min(lightOffs,MAX_NR_BIGTILE_LIGHTS);
SphericalIntersectionTests( t, iNrCoarseLights, float2(min(viTilLL.xy+uint2(64/2,64/2), uint2(iWidth-1, iHeight-1))), eyeIndex );
SphericalIntersectionTests( t, iNrCoarseLights, float2(min(viTilLL.xy+uint2(64/2,64/2), uint2(iWidth-1, iHeight-1))), eyeIndex );
CullByExactEdgeTests(t, iNrCoarseLights, viTilLL.xy, viTilUR.xy, eyeIndex);
CullByExactEdgeTests(t, iNrCoarseLights, viTilLL.xy, viTilUR.xy, eyeIndex);
// sort lights
SORTLIST(lightsListLDS, iNrCoarseLights, MAX_NR_BIG_TILE_LIGHTS_PLUS_ONE, t, NR_THREADS);
// sort lights
SORTLIST(lightsListLDS, iNrCoarseLights, MAX_NR_BIG_TILE_LIGHTS_PLUS_ONE, t, NR_THREADS);
if(t==0) lightOffs = 0;
GroupMemoryBarrierWithGroupSync();
int i;
for(i=t; i<iNrCoarseLights; i+=NR_THREADS) if(lightsListLDS[i]<(uint)g_iNrVisibLights) InterlockedAdd(lightOffs, 1);
GroupMemoryBarrierWithGroupSync();
iNrCoarseLights = lightOffs;
if(t==0) lightOffs = 0;
GroupMemoryBarrierWithGroupSync();
int i;
for(i=t; i<iNrCoarseLights; i+=NR_THREADS) if(lightsListLDS[i]<(uint)g_iNrVisibLights) InterlockedAdd(lightOffs, 1);
GroupMemoryBarrierWithGroupSync();
iNrCoarseLights = lightOffs;
for(i=t; i<(iNrCoarseLights+1); i+=NR_THREADS)
g_vLightList[MAX_NR_BIG_TILE_LIGHTS_PLUS_ONE*offs + i] = i==0 ? iNrCoarseLights : lightsListLDS[max(i-1, 0)];
for(i=t; i<(iNrCoarseLights+1); i+=NR_THREADS)
g_vLightList[MAX_NR_BIG_TILE_LIGHTS_PLUS_ONE*offs + i] = i==0 ? iNrCoarseLights : lightsListLDS[max(i-1, 0)];
}

#if USE_LEFT_HAND_CAMERA_SPACE
float3 V = GetViewPosFromLinDepth( screenCoordinate, 1.0, eyeIndex);
float3 V = GetViewPosFromLinDepth( screenCoordinate, 1.0, eyeIndex);
float3 V = GetViewPosFromLinDepth( screenCoordinate, -1.0, eyeIndex);
float3 V = GetViewPosFromLinDepth( screenCoordinate, -1.0, eyeIndex);
float onePixDiagDist = GetOnePixDiagWorldDistAtDepthOne(eyeIndex);
float halfTileSizeAtZDistOne = 32*onePixDiagDist; // scale by half a tile
float onePixDiagDist = GetOnePixDiagWorldDistAtDepthOne(eyeIndex);
float halfTileSizeAtZDistOne = 32*onePixDiagDist; // scale by half a tile
for(int l=threadID; l<iNrCoarseLights; l+=NR_THREADS)
{
for(int l=threadID; l<iNrCoarseLights; l+=NR_THREADS)
{
if( !DoesSphereOverlapTile(V, halfTileSizeAtZDistOne, lgtDat.center.xyz, lgtDat.radius, g_isOrthographic!=0) )
lightsListLDS[l]=UINT_MAX;
}
if( !DoesSphereOverlapTile(V, halfTileSizeAtZDistOne, lgtDat.center.xyz, lgtDat.radius, g_isOrthographic!=0) )
lightsListLDS[l]=UINT_MAX;
}
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
#endif
}
#endif

#ifdef EXACT_EDGE_TESTS
float3 GetTileVertex(uint2 viTilLL, uint2 viTilUR, int i, float fTileFarPlane, uint eyeIndex)
{
float x = (i&1)==0 ? viTilLL.x : viTilUR.x;
float y = (i&2)==0 ? viTilLL.y : viTilUR.y;
float z = (i&4)==0 ? g_fNearPlane : fTileFarPlane;
float x = (i&1)==0 ? viTilLL.x : viTilUR.x;
float y = (i&2)==0 ? viTilLL.y : viTilUR.y;
float z = (i&4)==0 ? g_fNearPlane : fTileFarPlane;
z = -z;
z = -z;
return GetViewPosFromLinDepth( float2(x, y), z, eyeIndex);
return GetViewPosFromLinDepth( float2(x, y), z, eyeIndex);
int iSection = e0>>2; // section 0 is side edges, section 1 is near edges and section 2 is far edges
int iSwizzle = e0&0x3;
int iSection = e0>>2; // section 0 is side edges, section 1 is near edges and section 2 is far edges
int iSwizzle = e0&0x3;
int i=iSwizzle + (2*(iSection&0x2)); // offset by 4 at section 2
vP0 = GetTileVertex(uint2(viTilLL.x, viTilUR.y), uint2(viTilUR.x, viTilLL.y), i, fTileFarPlane, eyeIndex);
int i=iSwizzle + (2*(iSection&0x2)); // offset by 4 at section 2
vP0 = GetTileVertex(uint2(viTilLL.x, viTilUR.y), uint2(viTilUR.x, viTilLL.y), i, fTileFarPlane, eyeIndex);
float3 edgeSectionZero = g_isOrthographic==0 ? vP0 : float3(0.0,0.0,1.0);
float3 edgeSectionZero = g_isOrthographic==0 ? vP0 : float3(0.0,0.0,1.0);
float3 edgeSectionZero = g_isOrthographic==0 ? vP0 : float3(0.0,0.0,-1.0);
float3 edgeSectionZero = g_isOrthographic==0 ? vP0 : float3(0.0,0.0,-1.0);
vE0 = iSection == 0 ? edgeSectionZero : (((iSwizzle & 0x2) == 0 ? 1.0f : (-1.0f)) * ((int)(iSwizzle & 0x1) == (iSwizzle >> 1) ? float3(1, 0, 0) : float3(0, 1, 0)));
vE0 = iSection == 0 ? edgeSectionZero : (((iSwizzle & 0x2) == 0 ? 1.0f : (-1.0f)) * ((int)(iSwizzle & 0x1) == (iSwizzle >> 1) ? float3(1, 0, 0) : float3(0, 1, 0)));
const bool bOnlyNeedFrustumSideEdges = true;
const int nrFrustEdges = bOnlyNeedFrustumSideEdges ? 4 : 8; // max 8 since we never need to test 4 far edges of frustum since they are identical vectors to near edges and plane is placed at vP0 on light hull.
const bool bOnlyNeedFrustumSideEdges = true;
const int nrFrustEdges = bOnlyNeedFrustumSideEdges ? 4 : 8; // max 8 since we never need to test 4 far edges of frustum since they are identical vectors to near edges and plane is placed at vP0 on light hull.
const int totNrEdgePairs = 12*nrFrustEdges;
for(int l=0; l<iNrCoarseLights; l++)
{
const uint idxCoarse = lightsListLDS[l];
const int totNrEdgePairs = 12*nrFrustEdges;
for(int l=0; l<iNrCoarseLights; l++)
{
const uint idxCoarse = lightsListLDS[l];
bool canEnter = idxCoarse<(uint) g_iNrVisibLights;
bool canEnter = idxCoarse<(uint) g_iNrVisibLights;
if(canEnter) canEnter = _LightVolumeData[bufIdxCoarse].lightVolume != LIGHTVOLUMETYPE_SPHERE; // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
UNITY_BRANCH if(canEnter)
{
if(canEnter) canEnter = _LightVolumeData[bufIdxCoarse].lightVolume != LIGHTVOLUMETYPE_SPHERE; // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
UNITY_BRANCH if(canEnter)
{
const float3 boxX = lgtDat.boxAxisX.xyz;
const float3 boxY = lgtDat.boxAxisY.xyz;
const float3 boxZ = -lgtDat.boxAxisZ.xyz; // flip axis (so it points away from the light direction for a spot-light)
const float3 center = lgtDat.center.xyz;
const float2 scaleXY = lgtDat.scaleXY;
const float3 boxX = lgtDat.boxAxisX.xyz;
const float3 boxY = lgtDat.boxAxisY.xyz;
const float3 boxZ = -lgtDat.boxAxisZ.xyz; // flip axis (so it points away from the light direction for a spot-light)
const float3 center = lgtDat.center.xyz;
const float2 scaleXY = lgtDat.scaleXY;
for(int i=threadID; i<totNrEdgePairs; i+=NR_THREADS)
{
int e0 = (int) (((uint)i)/((uint) nrFrustEdges)); // should become a shift right
int e1 = i - e0*nrFrustEdges;
for(int i=threadID; i<totNrEdgePairs; i+=NR_THREADS)
{
int e0 = (int) (((uint)i)/((uint) nrFrustEdges)); // should become a shift right
int e1 = i - e0*nrFrustEdges;
int idx_cur=0, idx_twin=0;
float3 vP0, vE0;
GetHullEdge(idx_cur, idx_twin, vP0, vE0, e0, boxX, boxY, boxZ, center, scaleXY);
int idx_cur=0, idx_twin=0;
float3 vP0, vE0;
GetHullEdge(idx_cur, idx_twin, vP0, vE0, e0, boxX, boxY, boxZ, center, scaleXY);
float3 vP1, vE1;
GetFrustEdge(vP1, vE1, e1, viTilLL, viTilUR, g_fFarPlane, eyeIndex);
float3 vP1, vE1;
GetFrustEdge(vP1, vE1, e1, viTilLL, viTilUR, g_fFarPlane, eyeIndex);
// potential separation plane
float3 vN = cross(vE0, vE1);
// potential separation plane
float3 vN = cross(vE0, vE1);
int positive=0, negative=0;
for(int k=1; k<8; k++) // only need to test 7 verts (technically just 6).
{
int j = (idx_cur+k)&0x7;
float3 vPh = GetHullVertex(boxX, boxY, boxZ, center, scaleXY, j);
float fSignDist = idx_twin==j ? 0.0 : dot(vN, vPh-vP0);
if(fSignDist>0) ++positive; else if(fSignDist<0) ++negative;
}
int resh = (positive>0 && negative>0) ? 0 : (positive>0 ? 1 : (negative>0 ? (-1) : 0));
int positive=0, negative=0;
for(int k=1; k<8; k++) // only need to test 7 verts (technically just 6).
{
int j = (idx_cur+k)&0x7;
float3 vPh = GetHullVertex(boxX, boxY, boxZ, center, scaleXY, j);
float fSignDist = idx_twin==j ? 0.0 : dot(vN, vPh-vP0);
if(fSignDist>0) ++positive; else if(fSignDist<0) ++negative;
}
int resh = (positive>0 && negative>0) ? 0 : (positive>0 ? 1 : (negative>0 ? (-1) : 0));
positive=0; negative=0;
for(int j=0; j<8; j++)
{
float3 vPf = GetTileVertex(viTilLL, viTilUR, j, g_fFarPlane, eyeIndex);
float fSignDist = dot(vN, vPf-vP0);
if(fSignDist>0) ++positive; else if(fSignDist<0) ++negative;
}
int resf = (positive>0 && negative>0) ? 0 : (positive>0 ? 1 : (negative>0 ? (-1) : 0));
positive=0; negative=0;
for(int j=0; j<8; j++)
{
float3 vPf = GetTileVertex(viTilLL, viTilUR, j, g_fFarPlane, eyeIndex);
float fSignDist = dot(vN, vPf-vP0);
if(fSignDist>0) ++positive; else if(fSignDist<0) ++negative;
}
int resf = (positive>0 && negative>0) ? 0 : (positive>0 ? 1 : (negative>0 ? (-1) : 0));
bool bFoundSepPlane = (resh*resf)<0;
if(bFoundSepPlane) lightsListLDS[l]=UINT_MAX;
}
}
}
bool bFoundSepPlane = (resh*resf)<0;
if(bFoundSepPlane) lightsListLDS[l]=UINT_MAX;
}
}
}
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
#endif
}
#endif

530
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/lightlistbuild-clustered.compute


#pragma kernel TileLightListGen_NoDepthRT LIGHTLISTGEN=TileLightListGen_NoDepthRT
#pragma kernel TileLightListGen_DepthRT LIGHTLISTGEN=TileLightListGen_DepthRT ENABLE_DEPTH_TEXTURE_BACKPLANE
#pragma kernel TileLightListGen_DepthRT_MSAA LIGHTLISTGEN=TileLightListGen_DepthRT_MSAA ENABLE_DEPTH_TEXTURE_BACKPLANE MSAA_ENABLED
#pragma kernel TileLightListGen_NoDepthRT_SrcBigTile LIGHTLISTGEN=TileLightListGen_NoDepthRT_SrcBigTile USE_TWO_PASS_TILED_LIGHTING
#pragma kernel TileLightListGen_DepthRT_SrcBigTile LIGHTLISTGEN=TileLightListGen_DepthRT_SrcBigTile ENABLE_DEPTH_TEXTURE_BACKPLANE USE_TWO_PASS_TILED_LIGHTING
#pragma kernel TileLightListGen_DepthRT_MSAA_SrcBigTile LIGHTLISTGEN=TileLightListGen_DepthRT_MSAA_SrcBigTile ENABLE_DEPTH_TEXTURE_BACKPLANE MSAA_ENABLED USE_TWO_PASS_TILED_LIGHTING
#pragma kernel TileLightListGen_NoDepthRT LIGHTLISTGEN=TileLightListGen_NoDepthRT
#pragma kernel TileLightListGen_DepthRT LIGHTLISTGEN=TileLightListGen_DepthRT ENABLE_DEPTH_TEXTURE_BACKPLANE
#pragma kernel TileLightListGen_DepthRT_MSAA LIGHTLISTGEN=TileLightListGen_DepthRT_MSAA ENABLE_DEPTH_TEXTURE_BACKPLANE MSAA_ENABLED
#pragma kernel TileLightListGen_NoDepthRT_SrcBigTile LIGHTLISTGEN=TileLightListGen_NoDepthRT_SrcBigTile USE_TWO_PASS_TILED_LIGHTING
#pragma kernel TileLightListGen_DepthRT_SrcBigTile LIGHTLISTGEN=TileLightListGen_DepthRT_SrcBigTile ENABLE_DEPTH_TEXTURE_BACKPLANE USE_TWO_PASS_TILED_LIGHTING
#pragma kernel TileLightListGen_DepthRT_MSAA_SrcBigTile LIGHTLISTGEN=TileLightListGen_DepthRT_MSAA_SrcBigTile ENABLE_DEPTH_TEXTURE_BACKPLANE MSAA_ENABLED USE_TWO_PASS_TILED_LIGHTING
#pragma kernel ClearAtomic
#include "CoreRP/ShaderLibrary/Common.hlsl"

float g_fClustBase;
float g_fNearPlane;
float g_fFarPlane;
int g_iLog2NumClusters; // numClusters = (1<<g_iLog2NumClusters)
int g_iLog2NumClusters; // numClusters = (1<<g_iLog2NumClusters)
float4 g_screenSize;
int g_iNumSamplesMSAA;

StructuredBuffer<SFiniteLightBound> g_data : register( t3 );
#ifdef USE_TWO_PASS_TILED_LIGHTING
StructuredBuffer<uint> g_vBigTileLightList : register( t4 ); // don't support Buffer yet in unity
StructuredBuffer<uint> g_vBigTileLightList : register( t4 ); // don't support Buffer yet in unity
#define NR_THREADS 64
#define NR_THREADS 64
RWStructuredBuffer<uint> g_vLayeredLightList : register( u0 ); // don't support RWBuffer yet in unity
RWStructuredBuffer<uint> g_LayeredOffset : register( u1 ); // don't support RWBuffer yet in unity
RWStructuredBuffer<uint> g_LayeredSingleIdxBuffer : register( u2 ); // don't support RWBuffer yet in unity
RWStructuredBuffer<uint> g_vLayeredLightList : register( u0 ); // don't support RWBuffer yet in unity
RWStructuredBuffer<uint> g_LayeredOffset : register( u1 ); // don't support RWBuffer yet in unity
RWStructuredBuffer<uint> g_LayeredSingleIdxBuffer : register( u2 ); // don't support RWBuffer yet in unity
RWStructuredBuffer<float> g_logBaseBuffer : register( u3 ); // don't support RWBuffer yet in unity
RWStructuredBuffer<float> g_logBaseBuffer : register( u3 ); // don't support RWBuffer yet in unity
#define MAX_NR_COARSE_ENTRIES 128
#define MAX_NR_COARSE_ENTRIES 128
groupshared unsigned int coarseList[MAX_NR_COARSE_ENTRIES];
groupshared unsigned int clusterIdxs[MAX_NR_COARSE_ENTRIES/2];

float4x4 g_mInvScrProjection = g_mInvScrProjectionArr[eyeIndex];
// for perspective projection m22 is zero and m23 is +1/-1 (depends on left/right hand proj)
// however this function must also work for orthographic projection so we keep it like this.
// however this function must also work for orthographic projection so we keep it like this.
float m22 = g_mInvScrProjection[2].z, m23 = g_mInvScrProjection[2].w;
float m32 = g_mInvScrProjection[3].z, m33 = g_mInvScrProjection[3].w;

{
float4x4 g_mScrProjection = g_mScrProjectionArr[eyeIndex];
bool isOrthographic = g_isOrthographic!=0;
float fSx = g_mScrProjection[0].x;
float fSy = g_mScrProjection[1].y;
float fCx = isOrthographic ? g_mScrProjection[0].w : g_mScrProjection[0].z;
float fCy = isOrthographic ? g_mScrProjection[1].w : g_mScrProjection[1].z;
bool isOrthographic = g_isOrthographic!=0;
float fSx = g_mScrProjection[0].x;
float fSy = g_mScrProjection[1].y;
float fCx = isOrthographic ? g_mScrProjection[0].w : g_mScrProjection[0].z;
float fCy = isOrthographic ? g_mScrProjection[1].w : g_mScrProjection[1].z;
bool useLeftHandVersion = true;
bool useLeftHandVersion = true;
bool useLeftHandVersion = isOrthographic;
bool useLeftHandVersion = isOrthographic;
float s = useLeftHandVersion ? 1 : (-1);
float2 p = float2( (s*v2ScrPos.x-fCx)/fSx, (s*v2ScrPos.y-fCy)/fSy);
float s = useLeftHandVersion ? 1 : (-1);
float2 p = float2( (s*v2ScrPos.x-fCx)/fSx, (s*v2ScrPos.y-fCy)/fSy);
return float3(isOrthographic ? p.xy : (fLinDepth*p.xy), fLinDepth);
return float3(isOrthographic ? p.xy : (fLinDepth*p.xy), fLinDepth);
float fSx = g_mScrProjection[0].x;
float fSy = g_mScrProjection[1].y;
float fSx = g_mScrProjection[0].x;
float fSy = g_mScrProjection[1].y;
return length( float2(1.0/fSx,1.0/fSy) );
return length( float2(1.0/fSx,1.0/fSy) );
}
// SphericalIntersectionTests and CullByExactEdgeTests are close to the versions

{
// If this light's screen space depth bounds intersect this cluster...simple cluster test
// TODO: Unify this code with the code in CheckIntersectionBasic...
unsigned int val = (clusterIdxs[l>>1]>>(16*(l&1)))&0xffff;
bool bIsHit = ((val>>0)&0xff)<=((uint) k) && ((uint) k)<=((val>>8)&0xff);
if(bIsHit)
{
unsigned int val = (clusterIdxs[l>>1]>>(16*(l&1)))&0xffff;
bool bIsHit = ((val>>0)&0xff)<=((uint) k) && ((uint) k)<=((val>>8)&0xff);
if(bIsHit)
{
float depthAtNearZ = ClusterIdxToZ(k, suggestedBase);
float depthAtFarZ = ClusterIdxToZ(k+1, suggestedBase);
float depthAtNearZ = ClusterIdxToZ(k, suggestedBase);
float depthAtFarZ = ClusterIdxToZ(k+1, suggestedBase);
for(int p=0; p<6; p++)
{
float4 plane = lightPlanes[6*(l&3)+p];
for(int p=0; p<6; p++)
{
float4 plane = lightPlanes[6*(l&3)+p];
bool bAllInvisib = true;
bool bAllInvisib = true;
for(int i=0; i<8; i++)
{
float x = (i&1)==0 ? viTilLL.x : viTilUR.x;
float y = (i&2)==0 ? viTilLL.y : viTilUR.y;
float z = (i&4)==0 ? depthAtNearZ : depthAtFarZ;
for(int i=0; i<8; i++)
{
float x = (i&1)==0 ? viTilLL.x : viTilUR.x;
float y = (i&2)==0 ? viTilLL.y : viTilUR.y;
float z = (i&4)==0 ? depthAtNearZ : depthAtFarZ;
bAllInvisib = bAllInvisib && dot(plane, float4(vP,1.0))>0;
}
bAllInvisib = bAllInvisib && dot(plane, float4(vP,1.0))>0;
}
if(bAllInvisib) bIsHit = false;
}
if(bAllInvisib) bIsHit = false;
}
}
}
return bIsHit;
return bIsHit;
unsigned int val = (clusterIdxs[l>>1]>>(16*(l&1)))&0xffff;
return ((val>>0)&0xff)<=((uint) k) && ((uint) k)<=((val>>8)&0xff);
unsigned int val = (clusterIdxs[l>>1]>>(16*(l&1)))&0xffff;
return ((val>>0)&0xff)<=((uint) k) && ((uint) k)<=((val>>8)&0xff);
}

uint eyeIndex = u3GroupID.z;
uint2 tileIDX = u3GroupID.xy;
uint t=threadID;
uint2 tileIDX = u3GroupID.xy;
uint t=threadID;
const uint log2TileSize = firstbithigh(TILE_SIZE_CLUSTERED);
uint nrTilesX = ((uint)g_screenSize.x +(TILE_SIZE_CLUSTERED-1))>>log2TileSize;
uint nrTilesY = ((uint)g_screenSize.y +(TILE_SIZE_CLUSTERED-1))>>log2TileSize;
const uint log2TileSize = firstbithigh(TILE_SIZE_CLUSTERED);
uint nrTilesX = ((uint)g_screenSize.x +(TILE_SIZE_CLUSTERED-1))>>log2TileSize;
uint nrTilesY = ((uint)g_screenSize.y +(TILE_SIZE_CLUSTERED-1))>>log2TileSize;
uint2 viTilLL = TILE_SIZE_CLUSTERED*tileIDX;
uint2 viTilUR = min( viTilLL+uint2(TILE_SIZE_CLUSTERED,TILE_SIZE_CLUSTERED), uint2(g_screenSize.x, g_screenSize.y) ); // not width and height minus 1 since viTilUR represents the end of the tile corner.
uint2 viTilLL = TILE_SIZE_CLUSTERED*tileIDX;
uint2 viTilUR = min( viTilLL+uint2(TILE_SIZE_CLUSTERED,TILE_SIZE_CLUSTERED), uint2(g_screenSize.x, g_screenSize.y) ); // not width and height minus 1 since viTilUR represents the end of the tile corner.
if(t==0)
{
lightOffs = 0;
if(t==0)
{
lightOffs = 0;
ldsZMax = 0;
ldsZMax = 0;
}
}
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
float dpt_ma=1.0;
float dpt_ma=1.0;
// establish min and max depth first
dpt_ma=0.0;
// establish min and max depth first
dpt_ma=0.0;
for(int idx=t; idx<(TILE_SIZE_CLUSTERED*TILE_SIZE_CLUSTERED); idx+=NR_THREADS)
{
for(int idx=t; idx<(TILE_SIZE_CLUSTERED*TILE_SIZE_CLUSTERED); idx+=NR_THREADS)
{
uint2 uPixCrd = min( uint2(viTilLL.x+(idx&(TILE_SIZE_CLUSTERED-1)), viTilLL.y+(idx>>log2TileSize)), uint2(g_screenSize.x-1, g_screenSize.y-1) );
uint2 uPixCrd = min( uint2(viTilLL.x+(idx&(TILE_SIZE_CLUSTERED-1)), viTilLL.y+(idx>>log2TileSize)), uint2(g_screenSize.x-1, g_screenSize.y-1) );
// TODO: For stereo double-wide, I need a proper way to insert the second eye width offset. Right now, I can just
// use g_screenSize.x, but that's kinda cheating.

uPixCrd.x += stereoDWOffset;
#ifdef MSAA_ENABLED
for(int i=0; i<g_iNumSamplesMSAA; i++)
{
const float fDpth = FetchDepthMSAA(g_depth_tex, uPixCrd, i);
for(int i=0; i<g_iNumSamplesMSAA; i++)
{
const float fDpth = FetchDepthMSAA(g_depth_tex, uPixCrd, i);
const float fDpth = FetchDepth(g_depth_tex, uPixCrd);
const float fDpth = FetchDepth(g_depth_tex, uPixCrd);
if(fDpth<VIEWPORT_SCALE_Z) // if not skydome
{
dpt_ma = max(fDpth, dpt_ma);
}
if(fDpth<VIEWPORT_SCALE_Z) // if not skydome
{
dpt_ma = max(fDpth, dpt_ma);
}
}
}
}
}
InterlockedMax(ldsZMax, asuint(dpt_ma) );
InterlockedMax(ldsZMax, asuint(dpt_ma) );
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
dpt_ma = asfloat(ldsZMax);
if(dpt_ma<=0.0) dpt_ma = VIEWPORT_SCALE_Z; // assume sky pixel
dpt_ma = asfloat(ldsZMax);
if(dpt_ma<=0.0) dpt_ma = VIEWPORT_SCALE_Z; // assume sky pixel
float2 vTileLL = float2(viTilLL.x/g_screenSize.x, viTilLL.y/g_screenSize.y);
float2 vTileUR = float2(viTilUR.x/g_screenSize.x, viTilUR.y/g_screenSize.y);
float2 vTileLL = float2(viTilLL.x/g_screenSize.x, viTilLL.y/g_screenSize.y);
float2 vTileUR = float2(viTilUR.x/g_screenSize.x, viTilUR.y/g_screenSize.y);
// build coarse list using AABB
// build coarse list using AABB
const uint log2BigTileToClustTileRatio = firstbithigh(64) - log2TileSize;
const uint log2BigTileToClustTileRatio = firstbithigh(64) - log2TileSize;
const int bigTileIdx = bigTileBase + ((tileIDX.y>>log2BigTileToClustTileRatio)*NrBigTilesX) + (tileIDX.x>>log2BigTileToClustTileRatio); // map the idx to 64x64 tiles
const int bigTileIdx = bigTileBase + ((tileIDX.y>>log2BigTileToClustTileRatio)*NrBigTilesX) + (tileIDX.x>>log2BigTileToClustTileRatio); // map the idx to 64x64 tiles
for(int l0=(int) t; l0<(int) nrBigTileLights; l0 += NR_THREADS)
{
int l = g_vBigTileLightList[MAX_NR_BIG_TILE_LIGHTS_PLUS_ONE*bigTileIdx+l0+1];
for(int l0=(int) t; l0<(int) nrBigTileLights; l0 += NR_THREADS)
{
int l = g_vBigTileLightList[MAX_NR_BIG_TILE_LIGHTS_PLUS_ONE*bigTileIdx+l0+1];
for(int l=(int) t; l<(int) g_iNrVisibLights; l += NR_THREADS)
{
for(int l=(int) t; l<(int) g_iNrVisibLights; l += NR_THREADS)
{
#endif
// TODO: Seems kinda funny that we repeat this exact code here, bigtile, and FPTL...

if( all(vMa>vTileLL) && all(vMi<vTileUR))
{
unsigned int uInc = 1;
unsigned int uIndex;
InterlockedAdd(lightOffs, uInc, uIndex);
if(uIndex<MAX_NR_COARSE_ENTRIES) coarseList[uIndex] = l; // add to light list
}
}
if( all(vMa>vTileLL) && all(vMi<vTileUR))
{
unsigned int uInc = 1;
unsigned int uIndex;
InterlockedAdd(lightOffs, uInc, uIndex);
if(uIndex<MAX_NR_COARSE_ENTRIES) coarseList[uIndex] = l; // add to light list
}
}
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
int iNrCoarseLights = min(lightOffs,MAX_NR_COARSE_ENTRIES);
int iNrCoarseLights = min(lightOffs,MAX_NR_COARSE_ENTRIES);
iNrCoarseLights = SphericalIntersectionTests( t, iNrCoarseLights, float2(min(viTilLL.xy+uint2(TILE_SIZE_CLUSTERED/2,TILE_SIZE_CLUSTERED/2), uint2(g_screenSize.x-1, g_screenSize.y-1))), eyeIndex );
iNrCoarseLights = SphericalIntersectionTests( t, iNrCoarseLights, float2(min(viTilLL.xy+uint2(TILE_SIZE_CLUSTERED/2,TILE_SIZE_CLUSTERED/2), uint2(g_screenSize.x-1, g_screenSize.y-1))), eyeIndex );
#endif
#ifdef ENABLE_DEPTH_TEXTURE_BACKPLANE

#else // USE_LEFT_HAND_CAMERA_SPACE
float fTileFarPlane = -GetLinearDepth(dpt_ma, eyeIndex);
#endif
float suggestedBase = SuggestLogBase50(fTileFarPlane);
float suggestedBase = SuggestLogBase50(fTileFarPlane);
float fTileFarPlane = g_fFarPlane;
float suggestedBase = g_fClustBase;
float fTileFarPlane = g_fFarPlane;
float suggestedBase = g_fClustBase;
#endif

// sort lights (gives a more efficient execution in both deferred and tiled forward lighting).
// sort lights (gives a more efficient execution in both deferred and tiled forward lighting).
SORTLIST(coarseList, iNrCoarseLights, MAX_NR_COARSE_ENTRIES, t, NR_THREADS);
SORTLIST(coarseList, iNrCoarseLights, MAX_NR_COARSE_ENTRIES, t, NR_THREADS);
//////////// cell specific code
{
//////////// cell specific code
{
for(int l=(int) t; l<((iNrCoarseLights+1)>>1); l += NR_THREADS)
{
const int l0 = coarseList[2*l+0], l1 = coarseList[min(2*l+1,iNrCoarseLights-1)];
for(int l=(int) t; l<((iNrCoarseLights+1)>>1); l += NR_THREADS)
{
const int l0 = coarseList[2*l+0], l1 = coarseList[min(2*l+1,iNrCoarseLights-1)];
const ScreenSpaceBoundsIndices l0Bounds = GenerateScreenSpaceBoundsIndices(l0, g_iNrVisibLights, eyeIndex);
const ScreenSpaceBoundsIndices l1Bounds = GenerateScreenSpaceBoundsIndices(l1, g_iNrVisibLights, eyeIndex);

const unsigned int clustIdxMa1 = (const unsigned int)min(255, SnapToClusterIdx(GetLinearDepth(g_vBoundsBuffer[l1Bounds.max].z, eyeIndex), suggestedBase));
clusterIdxs[l] = (clustIdxMa1<<24) | (clustIdxMi1<<16) | (clustIdxMa0<<8) | (clustIdxMi0<<0);
}
}
clusterIdxs[l] = (clustIdxMa1<<24) | (clustIdxMi1<<16) | (clustIdxMa0<<8) | (clustIdxMi0<<0);
}
}
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
int nrClusters = (1<<g_iLog2NumClusters);
int nrClusters = (1<<g_iLog2NumClusters);
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
uint start = 0;
int i=(int) t;
int iSpaceAvail = 0;
int iSum = 0;
if(i<nrClusters)
{
uint start = 0;
int i=(int) t;
int iSpaceAvail = 0;
int iSum = 0;
if(i<nrClusters)
{
for(int l=0; l<iNrCoarseLights; l++)
{
iSum += (CheckIntersectionBasic(l, i) ? 1 : 0);
}
for(int l=0; l<iNrCoarseLights; l++)
{
iSum += (CheckIntersectionBasic(l, i) ? 1 : 0);
}
iSpaceAvail = min(iSum,MAX_NR_COARSE_ENTRIES); // combined storage for both direct lights and reflection
InterlockedAdd(g_LayeredSingleIdxBuffer[0], (uint) iSpaceAvail, start); // alloc list memory
}
iSpaceAvail = min(iSum,MAX_NR_COARSE_ENTRIES); // combined storage for both direct lights and reflection
InterlockedAdd(g_LayeredSingleIdxBuffer[0], (uint) iSpaceAvail, start); // alloc list memory
}
// All our cull data are in the same list, but at render time envLights are separated so we need to shift the index
// to make it work correctly
int shiftIndex[LIGHTCATEGORY_COUNT];
ZERO_INITIALIZE_ARRAY(int, shiftIndex, LIGHTCATEGORY_COUNT);
// All our cull data are in the same list, but at render time envLights are separated so we need to shift the index
// to make it work correctly
int shiftIndex[LIGHTCATEGORY_COUNT];
ZERO_INITIALIZE_ARRAY(int, shiftIndex, LIGHTCATEGORY_COUNT);
shiftIndex[LIGHTCATEGORY_COUNT - 3] = _EnvLightIndexShift;
shiftIndex[LIGHTCATEGORY_COUNT - 2] = _DecalIndexShift;
shiftIndex[LIGHTCATEGORY_COUNT - 1] = _DensityVolumeIndexShift;
shiftIndex[LIGHTCATEGORY_COUNT - 3] = _EnvLightIndexShift;
shiftIndex[LIGHTCATEGORY_COUNT - 2] = _DecalIndexShift;
shiftIndex[LIGHTCATEGORY_COUNT - 1] = _DensityVolumeIndexShift;
int categoryListCount[LIGHTCATEGORY_COUNT]; // number of direct lights, reflection probes, decals and density volumes
ZERO_INITIALIZE_ARRAY(int, categoryListCount, LIGHTCATEGORY_COUNT);
int categoryListCount[LIGHTCATEGORY_COUNT]; // number of direct lights, reflection probes, decals and density volumes
ZERO_INITIALIZE_ARRAY(int, categoryListCount, LIGHTCATEGORY_COUNT);
uint offs = start;
for(int ll=0; ll<iNrCoarseLights; ll+=4)
{
int p = i>>2;
int m = i&3;
if(i<24) lightPlanes[6*m+p] = FetchPlane(min(iNrCoarseLights-1,ll+m), p, eyeIndex);
uint offs = start;
for(int ll=0; ll<iNrCoarseLights; ll+=4)
{
int p = i>>2;
int m = i&3;
if(i<24) lightPlanes[6*m+p] = FetchPlane(min(iNrCoarseLights-1,ll+m), p, eyeIndex);
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
for(int l=ll; l<min(iNrCoarseLights,(ll+4)); l++)
{
if(offs<(start+iSpaceAvail) && i<nrClusters && CheckIntersection(l, i, viTilLL.xy, viTilUR.xy, suggestedBase, eyeIndex) )
{
for(int l=ll; l<min(iNrCoarseLights,(ll+4)); l++)
{
if(offs<(start+iSpaceAvail) && i<nrClusters && CheckIntersection(l, i, viTilLL.xy, viTilUR.xy, suggestedBase, eyeIndex) )
{
++categoryListCount[lightCategory];
g_vLayeredLightList[offs++] = coarseList[l] - shiftIndex[lightCategory];
}
}
++categoryListCount[lightCategory];
g_vLayeredLightList[offs++] = coarseList[l] - shiftIndex[lightCategory];
}
}
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
}
}
uint localOffs=0;
uint localOffs=0;
for(int category=0; category<LIGHTCATEGORY_COUNT; category++)
{
int numLights = min(categoryListCount[category],31); // only allow 5 bits
if(i<nrClusters)
{
g_LayeredOffset[offs] = (start+localOffs) | (((uint) numLights)<<27);
offs += (nrClusters*nrTilesX*nrTilesY);
localOffs += categoryListCount[category]; // use unclamped count for localOffs
}
}
for(int category=0; category<LIGHTCATEGORY_COUNT; category++)
{
int numLights = min(categoryListCount[category],31); // only allow 5 bits
if(i<nrClusters)
{
g_LayeredOffset[offs] = (start+localOffs) | (((uint) numLights)<<27);
offs += (nrClusters*nrTilesX*nrTilesY);
localOffs += categoryListCount[category]; // use unclamped count for localOffs
}
}
if(threadID==0) g_logBaseBuffer[logBaseIndex] = suggestedBase;
if(threadID==0) g_logBaseBuffer[logBaseIndex] = suggestedBase;
#endif
}

const int lightBoundIndex = GenerateLightCullDataIndex(coarseList[l], g_iNrVisibLights, eyeIndex);
SFiniteLightBound lgtDat = g_data[lightBoundIndex];
const float3 boxX = lgtDat.boxAxisX.xyz;
const float3 boxY = lgtDat.boxAxisY.xyz;
const float3 boxZ = -lgtDat.boxAxisZ.xyz; // flip axis (so it points away from the light direction for a spot-light)
const float3 center = lgtDat.center.xyz;
const float radius = lgtDat.radius;
const float2 scaleXY = lgtDat.scaleXY;
const float3 boxX = lgtDat.boxAxisX.xyz;
const float3 boxY = lgtDat.boxAxisY.xyz;
const float3 boxZ = -lgtDat.boxAxisZ.xyz; // flip axis (so it points away from the light direction for a spot-light)
const float3 center = lgtDat.center.xyz;
const float radius = lgtDat.radius;
const float2 scaleXY = lgtDat.scaleXY;
return GetHullPlaneEq(boxX, boxY, boxZ, center, scaleXY, p);
return GetHullPlaneEq(boxX, boxY, boxZ, center, scaleXY, p);
}

#if USE_LEFT_HAND_CAMERA_SPACE
float3 V = GetViewPosFromLinDepth( screenCoordinate, 1.0, eyeIndex);
#else
float3 V = GetViewPosFromLinDepth( screenCoordinate, -1.0, eyeIndex);
float3 V = GetViewPosFromLinDepth( screenCoordinate, -1.0, eyeIndex);
float halfTileSizeAtZDistOne = (TILE_SIZE_CLUSTERED/2)*onePixDiagDist; // scale by half a tile
float halfTileSizeAtZDistOne = (TILE_SIZE_CLUSTERED/2)*onePixDiagDist; // scale by half a tile
for(int l=threadID; l<iNrCoarseLights; l+=NR_THREADS)
{
for(int l=threadID; l<iNrCoarseLights; l+=NR_THREADS)
{
if( !DoesSphereOverlapTile(V, halfTileSizeAtZDistOne, lgtDat.center.xyz, lgtDat.radius, g_isOrthographic!=0) )
coarseList[l]=UINT_MAX;
}
if( !DoesSphereOverlapTile(V, halfTileSizeAtZDistOne, lgtDat.center.xyz, lgtDat.radius, g_isOrthographic!=0) )
coarseList[l]=UINT_MAX;
}
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
// to greedy to double buffer coarseList lds on this so serializing removal of gaps.
if(threadID==0)
{
int offs = 0;
for(int l=0; l<iNrCoarseLights; l++)
{
if(coarseList[l]!=UINT_MAX)
coarseList[offs++] = coarseList[l];
}
lightOffsSph = offs;
}
// to greedy to double buffer coarseList lds on this so serializing removal of gaps.
if(threadID==0)
{
int offs = 0;
for(int l=0; l<iNrCoarseLights; l++)
{
if(coarseList[l]!=UINT_MAX)
coarseList[offs++] = coarseList[l];
}
lightOffsSph = offs;
}
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
return lightOffsSph;
return lightOffsSph;
}
#endif

float3 GetTileVertex(uint2 viTilLL, uint2 viTilUR, int i, float fTileFarPlane, uint eyeIndex)
{
float x = (i&1)==0 ? viTilLL.x : viTilUR.x;
float y = (i&2)==0 ? viTilLL.y : viTilUR.y;
float z = (i&4)==0 ? g_fNearPlane : fTileFarPlane;
float x = (i&1)==0 ? viTilLL.x : viTilUR.x;
float y = (i&2)==0 ? viTilLL.y : viTilUR.y;
float z = (i&4)==0 ? g_fNearPlane : fTileFarPlane;
z = -z;
z = -z;
#endif
return GetViewPosFromLinDepth( float2(x, y), z, eyeIndex);
}

int iSection = e0>>2; // section 0 is side edges, section 1 is near edges and section 2 is far edges
int iSwizzle = e0&0x3;
int iSection = e0>>2; // section 0 is side edges, section 1 is near edges and section 2 is far edges
int iSwizzle = e0&0x3;
int i=iSwizzle + (2*(iSection&0x2)); // offset by 4 at section 2
int i=iSwizzle + (2*(iSection&0x2)); // offset by 4 at section 2
float3 edgeSectionZero = g_isOrthographic==0 ? vP0 : float3(0.0,0.0,1.0);
float3 edgeSectionZero = g_isOrthographic==0 ? vP0 : float3(0.0,0.0,1.0);
float3 edgeSectionZero = g_isOrthographic==0 ? vP0 : float3(0.0,0.0,-1.0);
float3 edgeSectionZero = g_isOrthographic==0 ? vP0 : float3(0.0,0.0,-1.0);
vE0 = iSection == 0 ? edgeSectionZero : (((iSwizzle & 0x2) == 0 ? 1.0f : (-1.0f)) * ((int)(iSwizzle & 0x1) == (iSwizzle >> 1) ? float3(1, 0, 0) : float3(0, 1, 0)));
vE0 = iSection == 0 ? edgeSectionZero : (((iSwizzle & 0x2) == 0 ? 1.0f : (-1.0f)) * ((int)(iSwizzle & 0x1) == (iSwizzle >> 1) ? float3(1, 0, 0) : float3(0, 1, 0)));
if(threadID==0) lightOffs2 = 0;
if(threadID==0) lightOffs2 = 0;
const bool bOnlyNeedFrustumSideEdges = true;
const int nrFrustEdges = bOnlyNeedFrustumSideEdges ? 4 : 8; // max 8 since we never need to test 4 far edges of frustum since they are identical vectors to near edges and plane is placed at vP0 on light hull.
const bool bOnlyNeedFrustumSideEdges = true;
const int nrFrustEdges = bOnlyNeedFrustumSideEdges ? 4 : 8; // max 8 since we never need to test 4 far edges of frustum since they are identical vectors to near edges and plane is placed at vP0 on light hull.
const int totNrEdgePairs = 12*nrFrustEdges;
for(int l=0; l<iNrCoarseLights; l++)
{
if(threadID==0) ldsIsLightInvisible=0;
const int totNrEdgePairs = 12*nrFrustEdges;
for(int l=0; l<iNrCoarseLights; l++)
{
if(threadID==0) ldsIsLightInvisible=0;
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
UNITY_BRANCH if (_LightVolumeData[lightCullIndex].lightVolume != LIGHTVOLUMETYPE_SPHERE) // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
{
UNITY_BRANCH if (_LightVolumeData[lightCullIndex].lightVolume != LIGHTVOLUMETYPE_SPHERE) // don't bother doing edge tests for sphere lights since these have camera aligned bboxes.
{
const float3 boxX = lgtDat.boxAxisX.xyz;
const float3 boxY = lgtDat.boxAxisY.xyz;
const float3 boxZ = -lgtDat.boxAxisZ.xyz; // flip axis (so it points away from the light direction for a spot-light)
const float3 center = lgtDat.center.xyz;
const float2 scaleXY = lgtDat.scaleXY;
const float3 boxX = lgtDat.boxAxisX.xyz;
const float3 boxY = lgtDat.boxAxisY.xyz;
const float3 boxZ = -lgtDat.boxAxisZ.xyz; // flip axis (so it points away from the light direction for a spot-light)
const float3 center = lgtDat.center.xyz;
const float2 scaleXY = lgtDat.scaleXY;
for(int i=threadID; i<totNrEdgePairs; i+=NR_THREADS)
{
int e0 = (int) (((uint)i)/((uint) nrFrustEdges)); // should become a shift right
int e1 = i - e0*nrFrustEdges;
for(int i=threadID; i<totNrEdgePairs; i+=NR_THREADS)
{
int e0 = (int) (((uint)i)/((uint) nrFrustEdges)); // should become a shift right
int e1 = i - e0*nrFrustEdges;
int idx_cur=0, idx_twin=0;
float3 vP0, vE0;
GetHullEdge(idx_cur, idx_twin, vP0, vE0, e0, boxX, boxY, boxZ, center, scaleXY);
int idx_cur=0, idx_twin=0;
float3 vP0, vE0;
GetHullEdge(idx_cur, idx_twin, vP0, vE0, e0, boxX, boxY, boxZ, center, scaleXY);
float3 vP1, vE1;
float3 vP1, vE1;
// potential separation plane
float3 vN = cross(vE0, vE1);
// potential separation plane
float3 vN = cross(vE0, vE1);
int positive=0, negative=0;
for(int k=1; k<8; k++) // only need to test 7 verts (technically just 6).
{
int j = (idx_cur+k)&0x7;
float3 vPh = GetHullVertex(boxX, boxY, boxZ, center, scaleXY, j);
float fSignDist = idx_twin==j ? 0.0 : dot(vN, vPh-vP0);
if(fSignDist>0) ++positive; else if(fSignDist<0) ++negative;
}
int resh = (positive>0 && negative>0) ? 0 : (positive>0 ? 1 : (negative>0 ? (-1) : 0));
int positive=0, negative=0;
for(int k=1; k<8; k++) // only need to test 7 verts (technically just 6).
{
int j = (idx_cur+k)&0x7;
float3 vPh = GetHullVertex(boxX, boxY, boxZ, center, scaleXY, j);
float fSignDist = idx_twin==j ? 0.0 : dot(vN, vPh-vP0);
if(fSignDist>0) ++positive; else if(fSignDist<0) ++negative;
}
int resh = (positive>0 && negative>0) ? 0 : (positive>0 ? 1 : (negative>0 ? (-1) : 0));
positive=0; negative=0;
for(int j=0; j<8; j++)
{
positive=0; negative=0;
for(int j=0; j<8; j++)
{
float fSignDist = dot(vN, vPf-vP0);
if(fSignDist>0) ++positive; else if(fSignDist<0) ++negative;
}
int resf = (positive>0 && negative>0) ? 0 : (positive>0 ? 1 : (negative>0 ? (-1) : 0));
float fSignDist = dot(vN, vPf-vP0);
if(fSignDist>0) ++positive; else if(fSignDist<0) ++negative;
}
int resf = (positive>0 && negative>0) ? 0 : (positive>0 ? 1 : (negative>0 ? (-1) : 0));
bool bFoundSepPlane = (resh*resf)<0;
bool bFoundSepPlane = (resh*resf)<0;
if(bFoundSepPlane) InterlockedOr(ldsIsLightInvisible, 1);
}
}
if(bFoundSepPlane) InterlockedOr(ldsIsLightInvisible, 1);
}
}
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
if(threadID==0 && ldsIsLightInvisible==0)
{
coarseList[lightOffs2++] = coarseList[l];
}
}
if(threadID==0 && ldsIsLightInvisible==0)
{
coarseList[lightOffs2++] = coarseList[l];
}
}
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
return lightOffs2;
return lightOffs2;
}
#endif

void ClearAtomic(uint threadID : SV_GroupIndex, uint3 u3GroupID : SV_GroupID)
{
g_LayeredSingleIdxBuffer[0]=0;
g_LayeredSingleIdxBuffer[0]=0;
}

524
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/lightlistbuild.compute


#pragma kernel TileLightListGen LIGHTLISTGEN=TileLightListGen
#pragma kernel TileLightListGen_SrcBigTile LIGHTLISTGEN=TileLightListGen_SrcBigTile USE_TWO_PASS_TILED_LIGHTING
#pragma kernel TileLightListGen_FeatureFlags LIGHTLISTGEN=TileLightListGen_FeatureFlags USE_FEATURE_FLAGS
#pragma kernel TileLightListGen_SrcBigTile_FeatureFlags LIGHTLISTGEN=TileLightListGen_SrcBigTile_FeatureFlags USE_TWO_PASS_TILED_LIGHTING USE_FEATURE_FLAGS
#pragma kernel TileLightListGen_SrcBigTile_FeatureFlags LIGHTLISTGEN=TileLightListGen_SrcBigTile_FeatureFlags USE_TWO_PASS_TILED_LIGHTING USE_FEATURE_FLAGS
//#pragma #pragma enable_d3d11_debug_symbols

StructuredBuffer<SFiniteLightBound> g_data : register( t3 );
#ifdef USE_TWO_PASS_TILED_LIGHTING
StructuredBuffer<uint> g_vBigTileLightList : register( t4 ); // don't support Buffer yet in unity
StructuredBuffer<uint> g_vBigTileLightList : register( t4 ); // don't support Buffer yet in unity
#define NR_THREADS 64
#define NR_THREADS 64
RWStructuredBuffer<uint> g_vLightList : register( u0 ); // don't support RWBuffer yet in unity
RWStructuredBuffer<uint> g_vLightList : register( u0 ); // don't support RWBuffer yet in unity
#define MAX_NR_COARSE_ENTRIES 64
#define MAX_NR_PRUNED_ENTRIES 24
#define MAX_NR_COARSE_ENTRIES 64
#define MAX_NR_PRUNED_ENTRIES 24
groupshared unsigned int prunedList[MAX_NR_COARSE_ENTRIES]; // temporarily support room for all 64 while in LDS
groupshared unsigned int prunedList[MAX_NR_COARSE_ENTRIES]; // temporarily support room for all 64 while in LDS
groupshared uint ldsZMin;
groupshared uint ldsZMax;

//float GetLinearDepth(float3 vP)
//{
// float4 v4Pres = mul(g_mInvScrProjection, float4(vP,1.0));
// return v4Pres.z / v4Pres.w;
// float4 v4Pres = mul(g_mInvScrProjection, float4(vP,1.0));
// return v4Pres.z / v4Pres.w;
// however this function must also work for orthographic projection so we keep it like this.
// however this function must also work for orthographic projection so we keep it like this.
float m22 = g_mInvScrProjection[2].z, m23 = g_mInvScrProjection[2].w;
float m32 = g_mInvScrProjection[3].z, m33 = g_mInvScrProjection[3].w;

float3 GetViewPosFromLinDepth(float2 v2ScrPos, float fLinDepth)
{
bool isOrthographic = g_isOrthographic!=0;
float fSx = g_mScrProjection[0].x;
float fSy = g_mScrProjection[1].y;
float fCx = isOrthographic ? g_mScrProjection[0].w : g_mScrProjection[0].z;
float fCy = isOrthographic ? g_mScrProjection[1].w : g_mScrProjection[1].z;
bool isOrthographic = g_isOrthographic!=0;
float fSx = g_mScrProjection[0].x;
float fSy = g_mScrProjection[1].y;
float fCx = isOrthographic ? g_mScrProjection[0].w : g_mScrProjection[0].z;
float fCy = isOrthographic ? g_mScrProjection[1].w : g_mScrProjection[1].z;
bool useLeftHandVersion = true;
bool useLeftHandVersion = true;
bool useLeftHandVersion = isOrthographic;
bool useLeftHandVersion = isOrthographic;
float s = useLeftHandVersion ? 1 : (-1);
float2 p = float2( (s*v2ScrPos.x-fCx)/fSx, (s*v2ScrPos.y-fCy)/fSy);
float s = useLeftHandVersion ? 1 : (-1);
float2 p = float2( (s*v2ScrPos.x-fCx)/fSx, (s*v2ScrPos.y-fCy)/fSy);
return float3(isOrthographic ? p.xy : (fLinDepth*p.xy), fLinDepth);
return float3(isOrthographic ? p.xy : (fLinDepth*p.xy), fLinDepth);
float fSx = g_mScrProjection[0].x;
float fSy = g_mScrProjection[1].y;
float fSx = g_mScrProjection[0].x;
float fSy = g_mScrProjection[1].y;
return length( float2(1.0/fSx,1.0/fSy) );
return length( float2(1.0/fSx,1.0/fSy) );
}
#ifdef PERFORM_SPHERICAL_INTERSECTION_TESTS

[numthreads(NR_THREADS, 1, 1)]
void LIGHTLISTGEN(uint threadID : SV_GroupIndex, uint3 u3GroupID : SV_GroupID)
{
uint2 tileIDX = u3GroupID.xy;
uint t=threadID;
uint2 tileIDX = u3GroupID.xy;
uint t=threadID;
if(t<MAX_NR_COARSE_ENTRIES)
prunedList[t]=0;
if(t<MAX_NR_COARSE_ENTRIES)
prunedList[t]=0;
uint iWidth = g_viDimensions.x;
uint iHeight = g_viDimensions.y;
uint nrTilesX = (iWidth+15)/16;
uint nrTilesY = (iHeight+15)/16;
uint nrTiles = nrTilesX * nrTilesY; // Precompute?
uint iWidth = g_viDimensions.x;
uint iHeight = g_viDimensions.y;
uint nrTilesX = (iWidth+15)/16;
uint nrTilesY = (iHeight+15)/16;
uint nrTiles = nrTilesX * nrTilesY; // Precompute?
// build tile scr boundary
const uint uFltMax = 0x7f7fffff; // FLT_MAX as a uint
if(t==0)
{
ldsZMin = uFltMax;
ldsZMax = 0;
lightOffs = 0;
}
// build tile scr boundary
const uint uFltMax = 0x7f7fffff; // FLT_MAX as a uint
if(t==0)
{
ldsZMin = uFltMax;
ldsZMax = 0;
lightOffs = 0;
}
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
uint2 viTilLL = 16*tileIDX;
uint2 viTilLL = 16*tileIDX;
// establish min and max depth first
float dpt_mi=asfloat(uFltMax), dpt_ma=0.0;
// establish min and max depth first
float dpt_mi=asfloat(uFltMax), dpt_ma=0.0;
float4 vLinDepths;
{
// Fetch depths and calculate min/max
UNITY_UNROLL
for(int i = 0; i < 4; i++)
{
int idx = i * NR_THREADS + t;
uint2 uCrd = min( uint2(viTilLL.x+(idx&0xf), viTilLL.y+(idx>>4)), uint2(iWidth-1, iHeight-1) );
const float fDepth = FetchDepth(g_depth_tex, uCrd);
vLinDepths[i] = GetLinearDepth(fDepth);
if(fDepth<VIEWPORT_SCALE_Z) // if not skydome
{
dpt_mi = min(fDepth, dpt_mi);
dpt_ma = max(fDepth, dpt_ma);
}
}
float4 vLinDepths;
{
// Fetch depths and calculate min/max
UNITY_UNROLL
for(int i = 0; i < 4; i++)
{
int idx = i * NR_THREADS + t;
uint2 uCrd = min( uint2(viTilLL.x+(idx&0xf), viTilLL.y+(idx>>4)), uint2(iWidth-1, iHeight-1) );
const float fDepth = FetchDepth(g_depth_tex, uCrd);
vLinDepths[i] = GetLinearDepth(fDepth);
if(fDepth<VIEWPORT_SCALE_Z) // if not skydome
{
dpt_mi = min(fDepth, dpt_mi);
dpt_ma = max(fDepth, dpt_ma);
}
}
InterlockedMax(ldsZMax, asuint(dpt_ma));
InterlockedMin(ldsZMin, asuint(dpt_mi));
InterlockedMax(ldsZMax, asuint(dpt_ma));
InterlockedMin(ldsZMin, asuint(dpt_mi));
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
}
}
float3 vTileLL = float3(viTilLL.x/(float) iWidth, viTilLL.y/(float) iHeight, asfloat(ldsZMin));
float3 vTileUR = float3((viTilLL.x+16)/(float) iWidth, (viTilLL.y+16)/(float) iHeight, asfloat(ldsZMax));
vTileUR.xy = min(vTileUR.xy,float2(1.0,1.0)).xy;
float3 vTileLL = float3(viTilLL.x/(float) iWidth, viTilLL.y/(float) iHeight, asfloat(ldsZMin));
float3 vTileUR = float3((viTilLL.x+16)/(float) iWidth, (viTilLL.y+16)/(float) iHeight, asfloat(ldsZMax));
vTileUR.xy = min(vTileUR.xy,float2(1.0,1.0)).xy;
// build coarse list using AABB
// build coarse list using AABB
const uint log2BigTileToTileRatio = firstbithigh(64) - firstbithigh(16);
const uint log2BigTileToTileRatio = firstbithigh(64) - firstbithigh(16);
int NrBigTilesX = (nrTilesX+((1<<log2BigTileToTileRatio)-1))>>log2BigTileToTileRatio;
const int bigTileIdx = (tileIDX.y>>log2BigTileToTileRatio)*NrBigTilesX + (tileIDX.x>>log2BigTileToTileRatio); // map the idx to 64x64 tiles
int nrBigTileLights = g_vBigTileLightList[MAX_NR_BIG_TILE_LIGHTS_PLUS_ONE*bigTileIdx+0];
for(int l0=(int) t; l0<(int) nrBigTileLights; l0 += NR_THREADS)
{
int l = g_vBigTileLightList[MAX_NR_BIG_TILE_LIGHTS_PLUS_ONE*bigTileIdx+l0+1];
int NrBigTilesX = (nrTilesX+((1<<log2BigTileToTileRatio)-1))>>log2BigTileToTileRatio;
const int bigTileIdx = (tileIDX.y>>log2BigTileToTileRatio)*NrBigTilesX + (tileIDX.x>>log2BigTileToTileRatio); // map the idx to 64x64 tiles
int nrBigTileLights = g_vBigTileLightList[MAX_NR_BIG_TILE_LIGHTS_PLUS_ONE*bigTileIdx+0];
for(int l0=(int) t; l0<(int) nrBigTileLights; l0 += NR_THREADS)
{
int l = g_vBigTileLightList[MAX_NR_BIG_TILE_LIGHTS_PLUS_ONE*bigTileIdx+l0+1];
for(int l=(int) t; l<(int) g_iNrVisibLights; l += NR_THREADS)
{
for(int l=(int) t; l<(int) g_iNrVisibLights; l += NR_THREADS)
{
// Skip density volumes (lights are sorted by category). TODO: improve data locality
if (_LightVolumeData[l].lightCategory == LIGHTCATEGORY_DENSITY_VOLUME) { break; }
// Skip density volumes (lights are sorted by category). TODO: improve data locality
if (_LightVolumeData[l].lightCategory == LIGHTCATEGORY_DENSITY_VOLUME) { break; }
const float3 vMi = g_vBoundsBuffer[l];
const float3 vMa = g_vBoundsBuffer[l+g_iNrVisibLights];
const float3 vMi = g_vBoundsBuffer[l];
const float3 vMa = g_vBoundsBuffer[l+g_iNrVisibLights];
if( all(vMa>vTileLL) && all(vMi<vTileUR))
{
unsigned int uInc = 1;
unsigned int uIndex;
InterlockedAdd(lightOffs, uInc, uIndex);
if(uIndex<MAX_NR_COARSE_ENTRIES) coarseList[uIndex] = l; // add to light list
}
}
if( all(vMa>vTileLL) && all(vMi<vTileUR))
{
unsigned int uInc = 1;
unsigned int uIndex;
InterlockedAdd(lightOffs, uInc, uIndex);
if(uIndex<MAX_NR_COARSE_ENTRIES) coarseList[uIndex] = l; // add to light list
}
}
if(t<2) ldsDoesLightIntersect[t] = 0;
if(t<2) ldsDoesLightIntersect[t] = 0;
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
int iNrCoarseLights = min(lightOffs,MAX_NR_COARSE_ENTRIES);
int iNrCoarseLights = min(lightOffs,MAX_NR_COARSE_ENTRIES);
iNrCoarseLights = SphericalIntersectionTests( t, iNrCoarseLights, float2(min(viTilLL.xy+uint2(16/2,16/2), uint2(iWidth-1, iHeight-1))) );
iNrCoarseLights = SphericalIntersectionTests( t, iNrCoarseLights, float2(min(viTilLL.xy+uint2(16/2,16/2), uint2(iWidth-1, iHeight-1))) );
{
if((int)t<iNrCoarseLights) prunedList[t] = coarseList[t];
if(t==0) ldsNrLightsFinal=iNrCoarseLights;
}
{
if((int)t<iNrCoarseLights) prunedList[t] = coarseList[t];
if(t==0) ldsNrLightsFinal=iNrCoarseLights;
}
{
// initializes ldsNrLightsFinal with the number of accepted lights.
// all accepted entries delivered in prunedList[].
FinePruneLights(t, iNrCoarseLights, viTilLL, vLinDepths);
}
{
// initializes ldsNrLightsFinal with the number of accepted lights.
// all accepted entries delivered in prunedList[].
FinePruneLights(t, iNrCoarseLights, viTilLL, vLinDepths);
}
if(t<CATEGORY_LIST_SIZE) ldsCategoryListCount[t]=0;
if(t<CATEGORY_LIST_SIZE) ldsCategoryListCount[t]=0;
if(t==0) ldsFeatureFlags=0;
if(t==0) ldsFeatureFlags=0;
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
int nrLightsCombinedList = min(ldsNrLightsFinal,MAX_NR_COARSE_ENTRIES);
for(int i=t; i<nrLightsCombinedList; i+=NR_THREADS)
{
InterlockedAdd(ldsCategoryListCount[_LightVolumeData[prunedList[i]].lightCategory], 1);
int nrLightsCombinedList = min(ldsNrLightsFinal,MAX_NR_COARSE_ENTRIES);
for(int i=t; i<nrLightsCombinedList; i+=NR_THREADS)
{
InterlockedAdd(ldsCategoryListCount[_LightVolumeData[prunedList[i]].lightCategory], 1);
InterlockedOr(ldsFeatureFlags, _LightVolumeData[prunedList[i]].featureFlags);
InterlockedOr(ldsFeatureFlags, _LightVolumeData[prunedList[i]].featureFlags);
}
}
// sort lights (gives a more efficient execution in both deferred and tiled forward lighting).
// sort lights (gives a more efficient execution in both deferred and tiled forward lighting).
SORTLIST(prunedList, nrLightsCombinedList, MAX_NR_COARSE_ENTRIES, t, NR_THREADS);
//MERGESORTLIST(prunedList, coarseList, nrLightsCombinedList, t, NR_THREADS);
SORTLIST(prunedList, nrLightsCombinedList, MAX_NR_COARSE_ENTRIES, t, NR_THREADS);
//MERGESORTLIST(prunedList, coarseList, nrLightsCombinedList, t, NR_THREADS);
if(t == 0)
{
uint featureFlags = ldsFeatureFlags | g_BaseFeatureFlags;
if(t == 0)
{
uint featureFlags = ldsFeatureFlags | g_BaseFeatureFlags;
if(ldsZMax < ldsZMin) // is background pixel
{
if(ldsZMax < ldsZMin) // is background pixel
{
featureFlags = 0;
}
featureFlags = 0;
}
g_TileFeatureFlags[tileIDX.y * nrTilesX + tileIDX.x] = featureFlags;
}
g_TileFeatureFlags[tileIDX.y * nrTilesX + tileIDX.x] = featureFlags;
}
// write lights to global buffers
int localOffs=0;
int offs = tileIDX.y*nrTilesX + tileIDX.x;
// write lights to global buffers
int localOffs=0;
int offs = tileIDX.y*nrTilesX + tileIDX.x;
// All our cull data are in the same list, but at render time envLights are separated so we need to shift the index
// to make it work correctly
int shiftIndex[CATEGORY_LIST_SIZE];
ZERO_INITIALIZE_ARRAY(int, shiftIndex, CATEGORY_LIST_SIZE);
shiftIndex[CATEGORY_LIST_SIZE - 2] = _EnvLightIndexShift;
shiftIndex[CATEGORY_LIST_SIZE - 1] = _DecalIndexShift;
// All our cull data are in the same list, but at render time envLights are separated so we need to shift the index
// to make it work correctly
int shiftIndex[CATEGORY_LIST_SIZE];
ZERO_INITIALIZE_ARRAY(int, shiftIndex, CATEGORY_LIST_SIZE);
shiftIndex[CATEGORY_LIST_SIZE - 2] = _EnvLightIndexShift;
shiftIndex[CATEGORY_LIST_SIZE - 1] = _DecalIndexShift;
for(int category=0; category<CATEGORY_LIST_SIZE; category++)
{
int nrLightsFinal = ldsCategoryListCount[category];
int nrLightsFinalClamped = nrLightsFinal<MAX_NR_PRUNED_ENTRIES ? nrLightsFinal : MAX_NR_PRUNED_ENTRIES;
for(int category=0; category<CATEGORY_LIST_SIZE; category++)
{
int nrLightsFinal = ldsCategoryListCount[category];
int nrLightsFinalClamped = nrLightsFinal<MAX_NR_PRUNED_ENTRIES ? nrLightsFinal : MAX_NR_PRUNED_ENTRIES;
const int nrDWords = ((nrLightsFinalClamped+1)+1)>>1;
for(int l=(int) t; l<(int) nrDWords; l += NR_THREADS)
{
// We remap the prunedList index to the original LightData / EnvLightData indices
uint uLow = l==0 ? nrLightsFinalClamped : prunedList[max(0,2 * l - 1 + localOffs)] - shiftIndex[category];
uint uHigh = prunedList[2 * l + 0 + localOffs] - shiftIndex[category];
const int nrDWords = ((nrLightsFinalClamped+1)+1)>>1;
for(int l=(int) t; l<(int) nrDWords; l += NR_THREADS)
{
// We remap the prunedList index to the original LightData / EnvLightData indices
uint uLow = l==0 ? nrLightsFinalClamped : prunedList[max(0,2 * l - 1 + localOffs)] - shiftIndex[category];
uint uHigh = prunedList[2 * l + 0 + localOffs] - shiftIndex[category];
g_vLightList[16*offs + l] = (uLow&0xffff) | (uHigh<<16);
}
g_vLightList[16*offs + l] = (uLow&0xffff) | (uHigh<<16);
}
localOffs += nrLightsFinal;
offs += (nrTilesX*nrTilesY);
}
localOffs += nrLightsFinal;
offs += (nrTilesX*nrTilesY);
}
}

{
if(threadID==0) lightOffsSph = 0;
if(threadID==0) lightOffsSph = 0;
// make a copy of coarseList in prunedList.
int l;
for(l=threadID; l<iNrCoarseLights; l+=NR_THREADS)
prunedList[l]=coarseList[l];
// make a copy of coarseList in prunedList.
int l;
for(l=threadID; l<iNrCoarseLights; l+=NR_THREADS)
prunedList[l]=coarseList[l];
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
float3 V = GetViewPosFromLinDepth( screenCoordinate, 1.0);
float3 V = GetViewPosFromLinDepth( screenCoordinate, 1.0);
float3 V = GetViewPosFromLinDepth( screenCoordinate, -1.0);
float3 V = GetViewPosFromLinDepth( screenCoordinate, -1.0);
float onePixDiagDist = GetOnePixDiagWorldDistAtDepthOne();
float halfTileSizeAtZDistOne = 8*onePixDiagDist; // scale by half a tile
float onePixDiagDist = GetOnePixDiagWorldDistAtDepthOne();
float halfTileSizeAtZDistOne = 8*onePixDiagDist; // scale by half a tile
for(l=threadID; l<iNrCoarseLights; l+=NR_THREADS)
{
SFiniteLightBound lightData = g_data[prunedList[l]];
for(l=threadID; l<iNrCoarseLights; l+=NR_THREADS)
{
SFiniteLightBound lightData = g_data[prunedList[l]];
if( DoesSphereOverlapTile(V, halfTileSizeAtZDistOne, lightData.center.xyz, lightData.radius, g_isOrthographic!=0) )
{
unsigned int uIndex;
InterlockedAdd(lightOffsSph, 1, uIndex);
coarseList[uIndex]=prunedList[l]; // read from the original copy of coarseList which is backed up in prunedList
}
}
if( DoesSphereOverlapTile(V, halfTileSizeAtZDistOne, lightData.center.xyz, lightData.radius, g_isOrthographic!=0) )
{
unsigned int uIndex;
InterlockedAdd(lightOffsSph, 1, uIndex);
coarseList[uIndex]=prunedList[l]; // read from the original copy of coarseList which is backed up in prunedList
}
}
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
return lightOffsSph;
return lightOffsSph;
}
#endif

// all accepted entries delivered in prunedList[].
void FinePruneLights(uint threadID, int iNrCoarseLights, uint2 viTilLL, float4 vLinDepths)
{
uint t = threadID;
uint iWidth = g_viDimensions.x;
uint iHeight = g_viDimensions.y;
uint t = threadID;
uint iWidth = g_viDimensions.x;
uint iHeight = g_viDimensions.y;
uint uLightsFlags[2] = {0,0};
int l=0;
// need this outer loop even on xb1 and ps4 since direct lights and
// reflection lights are kept in separate regions.
while(l<iNrCoarseLights)
{
// fetch light
int idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
uint uLightVolume = l<iNrCoarseLights ? _LightVolumeData[idxCoarse].lightVolume : 0;
uint uLightsFlags[2] = {0,0};
int l=0;
// need this outer loop even on xb1 and ps4 since direct lights and
// reflection lights are kept in separate regions.
while(l<iNrCoarseLights)
{
// fetch light
int idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
uint uLightVolume = l<iNrCoarseLights ? _LightVolumeData[idxCoarse].lightVolume : 0;
// spot
while(l<iNrCoarseLights && uLightVolume==LIGHTVOLUMETYPE_CONE)
{
LightVolumeData lightData = _LightVolumeData[idxCoarse];
// TODO: Change by SebL
const bool bIsSpotDisc = true; // (lightData.flags&IS_CIRCULAR_SPOT_SHAPE) != 0;
// spot
while(l<iNrCoarseLights && uLightVolume==LIGHTVOLUMETYPE_CONE)
{
LightVolumeData lightData = _LightVolumeData[idxCoarse];
// TODO: Change by SebL
const bool bIsSpotDisc = true; // (lightData.flags&IS_CIRCULAR_SPOT_SHAPE) != 0;
// serially check 4 pixels
uint uVal = 0;
for(int i=0; i<4; i++)
{
int idx = t + i*NR_THREADS;
// serially check 4 pixels
uint uVal = 0;
for(int i=0; i<4; i++)
{
int idx = t + i*NR_THREADS;
uint2 uPixLoc = min(uint2(viTilLL.x+(idx&0xf), viTilLL.y+(idx>>4)), uint2(iWidth-1, iHeight-1));
float3 vVPos = GetViewPosFromLinDepth(uPixLoc + float2(0.5,0.5), vLinDepths[i]);
uint2 uPixLoc = min(uint2(viTilLL.x+(idx&0xf), viTilLL.y+(idx>>4)), uint2(iWidth-1, iHeight-1));
float3 vVPos = GetViewPosFromLinDepth(uPixLoc + float2(0.5,0.5), vLinDepths[i]);
// check pixel
float3 fromLight = vVPos-lightData.lightPos.xyz;
float distSq = dot(fromLight,fromLight);
const float fSclProj = dot(fromLight, lightData.lightAxisZ.xyz); // spotDir = lightData.lightAxisZ.xyz
// check pixel
float3 fromLight = vVPos-lightData.lightPos.xyz;
float distSq = dot(fromLight,fromLight);
const float fSclProj = dot(fromLight, lightData.lightAxisZ.xyz); // spotDir = lightData.lightAxisZ.xyz
float2 V = abs( float2( dot(fromLight, lightData.lightAxisX.xyz), dot(fromLight, lightData.lightAxisY.xyz) ) );
float2 V = abs( float2( dot(fromLight, lightData.lightAxisX.xyz), dot(fromLight, lightData.lightAxisY.xyz) ) );
float fDist2D = bIsSpotDisc ? length(V) : max(V.x,V.y);
if( all( float2(lightData.radiusSq, fSclProj) > float2(distSq, fDist2D*lightData.cotan) ) ) uVal = 1;
}
float fDist2D = bIsSpotDisc ? length(V) : max(V.x,V.y);
if( all( float2(lightData.radiusSq, fSclProj) > float2(distSq, fDist2D*lightData.cotan) ) ) uVal = 1;
}
uLightsFlags[l<32 ? 0 : 1] |= (uVal<<(l&31));
++l; idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
uLightVolume = l<iNrCoarseLights ? _LightVolumeData[idxCoarse].lightVolume : 0;
}
uLightsFlags[l<32 ? 0 : 1] |= (uVal<<(l&31));
++l; idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
uLightVolume = l<iNrCoarseLights ? _LightVolumeData[idxCoarse].lightVolume : 0;
}
// sphere
while(l<iNrCoarseLights && uLightVolume==LIGHTVOLUMETYPE_SPHERE)
{
LightVolumeData lightData = _LightVolumeData[idxCoarse];
// sphere
while(l<iNrCoarseLights && uLightVolume==LIGHTVOLUMETYPE_SPHERE)
{
LightVolumeData lightData = _LightVolumeData[idxCoarse];
// serially check 4 pixels
uint uVal = 0;
for(int i=0; i<4; i++)
{
int idx = t + i*NR_THREADS;
// serially check 4 pixels
uint uVal = 0;
for(int i=0; i<4; i++)
{
int idx = t + i*NR_THREADS;
uint2 uPixLoc = min(uint2(viTilLL.x+(idx&0xf), viTilLL.y+(idx>>4)), uint2(iWidth-1, iHeight-1));
float3 vVPos = GetViewPosFromLinDepth(uPixLoc + float2(0.5,0.5), vLinDepths[i]);
uint2 uPixLoc = min(uint2(viTilLL.x+(idx&0xf), viTilLL.y+(idx>>4)), uint2(iWidth-1, iHeight-1));
float3 vVPos = GetViewPosFromLinDepth(uPixLoc + float2(0.5,0.5), vLinDepths[i]);
// check pixel
float3 vLp = lightData.lightPos.xyz;
float3 toLight = vLp - vVPos;
float distSq = dot(toLight,toLight);
// check pixel
float3 vLp = lightData.lightPos.xyz;
float3 toLight = vLp - vVPos;
float distSq = dot(toLight,toLight);
if(lightData.radiusSq>distSq) uVal = 1;
}
if(lightData.radiusSq>distSq) uVal = 1;
}
uLightsFlags[l<32 ? 0 : 1] |= (uVal<<(l&31));
++l; idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
uLightVolume = l<iNrCoarseLights ? _LightVolumeData[idxCoarse].lightVolume : 0;
}
uLightsFlags[l<32 ? 0 : 1] |= (uVal<<(l&31));
++l; idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
uLightVolume = l<iNrCoarseLights ? _LightVolumeData[idxCoarse].lightVolume : 0;
}
// Box
while(l<iNrCoarseLights && uLightVolume==LIGHTVOLUMETYPE_BOX)
{
LightVolumeData lightData = _LightVolumeData[idxCoarse];
// Box
while(l<iNrCoarseLights && uLightVolume==LIGHTVOLUMETYPE_BOX)
{
LightVolumeData lightData = _LightVolumeData[idxCoarse];
// serially check 4 pixels
uint uVal = 0;
for(int i=0; i<4; i++)
{
int idx = t + i*NR_THREADS;
// serially check 4 pixels
uint uVal = 0;
for(int i=0; i<4; i++)
{
int idx = t + i*NR_THREADS;
uint2 uPixLoc = min(uint2(viTilLL.x+(idx&0xf), viTilLL.y+(idx>>4)), uint2(iWidth-1, iHeight-1));
float3 vVPos = GetViewPosFromLinDepth(uPixLoc + float2(0.5,0.5), vLinDepths[i]);
uint2 uPixLoc = min(uint2(viTilLL.x+(idx&0xf), viTilLL.y+(idx>>4)), uint2(iWidth-1, iHeight-1));
float3 vVPos = GetViewPosFromLinDepth(uPixLoc + float2(0.5,0.5), vLinDepths[i]);
// check pixel
float3 toLight = lightData.lightPos.xyz - vVPos;
// check pixel
float3 toLight = lightData.lightPos.xyz - vVPos;
float3 dist = float3( dot(toLight, lightData.lightAxisX), dot(toLight, lightData.lightAxisY), dot(toLight, lightData.lightAxisZ) );
dist = (abs(dist) - lightData.boxInnerDist) * lightData.boxInvRange; // not as efficient as it could be
if( max(max(dist.x, dist.y), dist.z)<1 ) uVal = 1; // but allows us to not write out OuterDists
}
float3 dist = float3( dot(toLight, lightData.lightAxisX), dot(toLight, lightData.lightAxisY), dot(toLight, lightData.lightAxisZ) );
dist = (abs(dist) - lightData.boxInnerDist) * lightData.boxInvRange; // not as efficient as it could be
if( max(max(dist.x, dist.y), dist.z)<1 ) uVal = 1; // but allows us to not write out OuterDists
}
uLightsFlags[l<32 ? 0 : 1] |= (uVal<<(l&31));
++l; idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
uLightVolume = l<iNrCoarseLights ? _LightVolumeData[idxCoarse].lightVolume : 0;
}
uLightsFlags[l<32 ? 0 : 1] |= (uVal<<(l&31));
++l; idxCoarse = l<iNrCoarseLights ? coarseList[l] : 0;
uLightVolume = l<iNrCoarseLights ? _LightVolumeData[idxCoarse].lightVolume : 0;
}
// in case we have some corrupt data make sure we terminate
if(uLightVolume >=LIGHTVOLUMETYPE_COUNT) ++l;
}
// in case we have some corrupt data make sure we terminate
if(uLightVolume >=LIGHTVOLUMETYPE_COUNT) ++l;
}
InterlockedOr(ldsDoesLightIntersect[0], uLightsFlags[0]);
InterlockedOr(ldsDoesLightIntersect[1], uLightsFlags[1]);
if(t==0) ldsNrLightsFinal = 0;
InterlockedOr(ldsDoesLightIntersect[0], uLightsFlags[0]);
InterlockedOr(ldsDoesLightIntersect[1], uLightsFlags[1]);
if(t==0) ldsNrLightsFinal = 0;
GroupMemoryBarrierWithGroupSync();
GroupMemoryBarrierWithGroupSync();
if(t<(uint) iNrCoarseLights && (ldsDoesLightIntersect[t<32 ? 0 : 1]&(1<<(t&31)))!=0 )
{
unsigned int uInc = 1;
unsigned int uIndex;
InterlockedAdd(ldsNrLightsFinal, uInc, uIndex);
if(uIndex<MAX_NR_COARSE_ENTRIES) prunedList[uIndex] = coarseList[t]; // we allow up to 64 pruned lights while stored in LDS.
}
if(t<(uint) iNrCoarseLights && (ldsDoesLightIntersect[t<32 ? 0 : 1]&(1<<(t&31)))!=0 )
{
unsigned int uInc = 1;
unsigned int uIndex;
InterlockedAdd(ldsNrLightsFinal, uInc, uIndex);
if(uIndex<MAX_NR_COARSE_ENTRIES) prunedList[uIndex] = coarseList[t]; // we allow up to 64 pruned lights while stored in LDS.
}
}
#endif

60
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/materialflags.compute


#pragma kernel MaterialFlagsGen_Write MATERIALFLAGSGEN=MaterialFlagsGen_Write
#pragma kernel MaterialFlagsGen_Or MATERIALFLAGSGEN=MaterialFlagsGen_Or USE_OR
#pragma kernel MaterialFlagsGen_Write MATERIALFLAGSGEN=MaterialFlagsGen_Write
#pragma kernel MaterialFlagsGen_Or MATERIALFLAGSGEN=MaterialFlagsGen_Or USE_OR
// #pragma enable_d3d11_debug_symbols

#pragma only_renderers d3d11 ps4 xboxone vulkan metal switch
#define USE_MATERIAL_FEATURE_FLAGS
#define NR_THREADS 64
#define NR_THREADS 64
CBUFFER_START(UnityMaterialFlags)
uint2 g_viDimensions;

[numthreads(NR_THREADS, 1, 1)]
void MATERIALFLAGSGEN(uint threadID : SV_GroupIndex, uint3 u3GroupID : SV_GroupID)
{
uint2 tileIDX = u3GroupID.xy;
uint2 tileIDX = u3GroupID.xy;
uint iWidth = g_viDimensions.x;
uint iHeight = g_viDimensions.y;
uint iWidth = g_viDimensions.x;
uint iHeight = g_viDimensions.y;
float2 invScreenSize = float2(1.0f / iWidth, 1.0f / iHeight);
float2 invScreenSize = float2(1.0f / iWidth, 1.0f / iHeight);
if (threadID == 0)
{
ldsFeatureFlags = 0;
}
GroupMemoryBarrierWithGroupSync();
if (threadID == 0)
{
ldsFeatureFlags = 0;
}
GroupMemoryBarrierWithGroupSync();
uint materialFeatureFlags = g_BaseFeatureFlags; // Contain all lightFeatures or 0 (depends if we enable light classification or not)
UNITY_UNROLL
for(int i = 0; i < 4; i++)
{
int idx = i * NR_THREADS + threadID;
uint2 uCrd = min( uint2(viTilLL.x + (idx & 0xf), viTilLL.y + (idx >> 4)), uint2(iWidth - 1, iHeight - 1));
uint materialFeatureFlags = g_BaseFeatureFlags; // Contain all lightFeatures or 0 (depends if we enable light classification or not)
UNITY_UNROLL
for(int i = 0; i < 4; i++)
{
int idx = i * NR_THREADS + threadID;
uint2 uCrd = min( uint2(viTilLL.x + (idx & 0xf), viTilLL.y + (idx >> 4)), uint2(iWidth - 1, iHeight - 1));
if (LOAD_TEXTURE2D(_StencilTexture, uCrd).r == 1.0)
{
PositionInputs posInput = GetPositionInput(uCrd, invScreenSize);
if (LOAD_TEXTURE2D(_StencilTexture, uCrd).r == 1.0)
{
PositionInputs posInput = GetPositionInput(uCrd, invScreenSize);
}
}
}
}
InterlockedOr(ldsFeatureFlags, materialFeatureFlags); //TODO: driver might optimize this or we might have to do a manual reduction
GroupMemoryBarrierWithGroupSync();
InterlockedOr(ldsFeatureFlags, materialFeatureFlags); //TODO: driver might optimize this or we might have to do a manual reduction
GroupMemoryBarrierWithGroupSync();
if(threadID == 0)
{
if(threadID == 0)
{
g_TileFeatureFlags[tileIDX.y * nrTilesX + tileIDX.x] |= ldsFeatureFlags;
g_TileFeatureFlags[tileIDX.y * nrTilesX + tileIDX.x] |= ldsFeatureFlags;
g_TileFeatureFlags[tileIDX.y * nrTilesX + tileIDX.x] = ldsFeatureFlags;
g_TileFeatureFlags[tileIDX.y * nrTilesX + tileIDX.x] = ldsFeatureFlags;
}
}
}

638
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/scrbound.compute


StructuredBuffer<SFiniteLightBound> g_data : register( t0 );
#define NR_THREADS 64
#define NR_THREADS 64
#define MAX_PNTS 9 // strictly this should be 10=6+4 but we get more wavefronts and 10 seems to never hit (fingers crossed)
// However, worst case the plane that would be skipped if such an extreme case ever happened would be backplane
// clipping gets skipped which doesn't cause any errors.
#define MAX_PNTS 9 // strictly this should be 10=6+4 but we get more wavefronts and 10 seems to never hit (fingers crossed)
// However, worst case the plane that would be skipped if such an extreme case ever happened would be backplane
// clipping gets skipped which doesn't cause any errors.
// LDS (2496 bytes)

[numthreads(NR_THREADS, 1, 1)]
void ScreenBoundsAABB(uint threadID : SV_GroupIndex, uint3 u3GroupID : SV_GroupID)
{
uint groupID = u3GroupID.x;
uint groupID = u3GroupID.x;
uint eyeIndex = u3GroupID.y; // currently, can only be 0 or 1
// The g_ is preserved in order to make cross-pipeline (FPTL) updates easier

//uint vindex = groupID * NR_THREADS + threadID;
unsigned int g = groupID;
unsigned int t = threadID;
//uint vindex = groupID * NR_THREADS + threadID;
unsigned int g = groupID;
unsigned int t = threadID;
const int subLigt = (int) (t/8);
const int lgtIndex = subLigt+(int) g*8;
const int sideIndex = (int) (t%8);
const int subLigt = (int) (t/8);
const int lgtIndex = subLigt+(int) g*8;
const int sideIndex = (int) (t%8);
const float3 boxX = lgtDat.boxAxisX.xyz;
const float3 boxY = lgtDat.boxAxisY.xyz;
const float3 boxZ = -lgtDat.boxAxisZ.xyz; // flip axis (so it points away from the light direction for a spot-light)
const float3 center = lgtDat.center.xyz;
const float radius = lgtDat.radius;
const float2 scaleXY = lgtDat.scaleXY;
const float3 boxX = lgtDat.boxAxisX.xyz;
const float3 boxY = lgtDat.boxAxisY.xyz;
const float3 boxZ = -lgtDat.boxAxisZ.xyz; // flip axis (so it points away from the light direction for a spot-light)
const float3 center = lgtDat.center.xyz;
const float radius = lgtDat.radius;
const float2 scaleXY = lgtDat.scaleXY;
{
if(sideIndex<6 && lgtIndex<(int) g_iNrVisibLights) // mask 2 out of 8 threads
{
float3 q0, q1, q2, q3;
GetHullQuad(q0, q1, q2, q3, boxX, boxY, boxZ, center, scaleXY, sideIndex);
{
if(sideIndex<6 && lgtIndex<(int) g_iNrVisibLights) // mask 2 out of 8 threads
{
float3 q0, q1, q2, q3;
GetHullQuad(q0, q1, q2, q3, boxX, boxY, boxZ, center, scaleXY, sideIndex);
const float4 vP0 = mul(g_mProjection, float4(q0, 1));
const float4 vP1 = mul(g_mProjection, float4(q1, 1));
const float4 vP2 = mul(g_mProjection, float4(q2, 1));
const float4 vP3 = mul(g_mProjection, float4(q3, 1));
const float4 vP0 = mul(g_mProjection, float4(q0, 1));
const float4 vP1 = mul(g_mProjection, float4(q1, 1));
const float4 vP2 = mul(g_mProjection, float4(q2, 1));
const float4 vP3 = mul(g_mProjection, float4(q3, 1));
// test vertices of one quad (of the convex hull) for intersection
const unsigned int uFlag0 = GetClip(vP0);
const unsigned int uFlag1 = GetClip(vP1);
const unsigned int uFlag2 = GetClip(vP2);
const unsigned int uFlag3 = GetClip(vP3);
// test vertices of one quad (of the convex hull) for intersection
const unsigned int uFlag0 = GetClip(vP0);
const unsigned int uFlag1 = GetClip(vP1);
const unsigned int uFlag2 = GetClip(vP2);
const unsigned int uFlag3 = GetClip(vP3);
const float4 vPnts[] = {vP0, vP1, vP2, vP3};
const float4 vPnts[] = {vP0, vP1, vP2, vP3};
// screen-space AABB of one quad (assuming no intersection)
float3 vMin, vMax;
for(int k=0; k<4; k++)
{
float fW = vPnts[k].w;
float fS = fW<0 ? -1 : 1;
float fWabs = fW<0 ? (-fW) : fW;
fW = fS * (fWabs<FLT_EPS ? FLT_EPS : fWabs);
float3 vP = float3(vPnts[k].x/fW, vPnts[k].y/fW, vPnts[k].z/fW);
if(k==0) { vMin=vP; vMax=vP; }
// screen-space AABB of one quad (assuming no intersection)
float3 vMin, vMax;
for(int k=0; k<4; k++)
{
float fW = vPnts[k].w;
float fS = fW<0 ? -1 : 1;
float fWabs = fW<0 ? (-fW) : fW;
fW = fS * (fWabs<FLT_EPS ? FLT_EPS : fWabs);
float3 vP = float3(vPnts[k].x/fW, vPnts[k].y/fW, vPnts[k].z/fW);
if(k==0) { vMin=vP; vMax=vP; }
vMax = max(vMax, vP); vMin = min(vMin, vP);
}
vMax = max(vMax, vP); vMin = min(vMin, vP);
}
clipFlags[subLigt*6+sideIndex] = (uFlag0<<0) | (uFlag1<<6) | (uFlag2<<12) | (uFlag3<<18);
clipFlags[subLigt*6+sideIndex] = (uFlag0<<0) | (uFlag1<<6) | (uFlag2<<12) | (uFlag3<<18);
// store in clip buffer (only use these vMin and vMax if light is 100% visible in which case clipping isn't needed)
posX[subLigt*MAX_PNTS*2 + sideIndex] = vMin.x;
posY[subLigt*MAX_PNTS*2 + sideIndex] = vMin.y;
posZ[subLigt*MAX_PNTS*2 + sideIndex] = vMin.z;
// store in clip buffer (only use these vMin and vMax if light is 100% visible in which case clipping isn't needed)
posX[subLigt*MAX_PNTS*2 + sideIndex] = vMin.x;
posY[subLigt*MAX_PNTS*2 + sideIndex] = vMin.y;
posZ[subLigt*MAX_PNTS*2 + sideIndex] = vMin.z;
posX[subLigt*MAX_PNTS*2 + sideIndex + 6] = vMax.x;
posY[subLigt*MAX_PNTS*2 + sideIndex + 6] = vMax.y;
posZ[subLigt*MAX_PNTS*2 + sideIndex + 6] = vMax.z;
}
}
posX[subLigt*MAX_PNTS*2 + sideIndex + 6] = vMax.x;
posY[subLigt*MAX_PNTS*2 + sideIndex + 6] = vMax.y;
posZ[subLigt*MAX_PNTS*2 + sideIndex + 6] = vMax.z;
}
}
// if not XBONE and not PLAYSTATION4 we need a memorybarrier here
// since we can't rely on the gpu cores being 64 wide.
// We need a pound define around this.
GroupMemoryBarrierWithGroupSync();
// if not XBONE and not PLAYSTATION4 we need a memorybarrier here
// since we can't rely on the gpu cores being 64 wide.
// We need a pound define around this.
GroupMemoryBarrierWithGroupSync();
{
int f=0;
{
int f=0;
if(sideIndex==0 && lgtIndex<(int) g_iNrVisibLights)
{
// quick acceptance or rejection
unsigned int uCollectiveAnd = (unsigned int) -1;
unsigned int uCollectiveOr = 0;
for(f=0; f<6; f++)
{
unsigned int uFlagAnd = clipFlags[subLigt*6+f]&0x3f;
unsigned int uFlagOr = uFlagAnd;
for(int i=1; i<4; i++)
{
unsigned int uClipBits = (clipFlags[subLigt*6+f]>>(i*6))&0x3f;
uFlagAnd &= uClipBits;
uFlagOr |= uClipBits;
}
if(sideIndex==0 && lgtIndex<(int) g_iNrVisibLights)
{
// quick acceptance or rejection
unsigned int uCollectiveAnd = (unsigned int) -1;
unsigned int uCollectiveOr = 0;
for(f=0; f<6; f++)
{
unsigned int uFlagAnd = clipFlags[subLigt*6+f]&0x3f;
unsigned int uFlagOr = uFlagAnd;
for(int i=1; i<4; i++)
{
unsigned int uClipBits = (clipFlags[subLigt*6+f]>>(i*6))&0x3f;
uFlagAnd &= uClipBits;
uFlagOr |= uClipBits;
}
uCollectiveAnd &= uFlagAnd;
uCollectiveOr |= uFlagOr;
}
uCollectiveAnd &= uFlagAnd;
uCollectiveOr |= uFlagOr;
}
bool bSetBoundYet = false;
float3 vMin=0.0, vMax=0.0;
if(uCollectiveAnd!=0 || uCollectiveOr==0) // all invisible or all visible (early out)
{
if(uCollectiveOr==0) // all visible
{
for(f=0; f<6; f++)
{
const int sideIndex = f;
bool bSetBoundYet = false;
float3 vMin=0.0, vMax=0.0;
if(uCollectiveAnd!=0 || uCollectiveOr==0) // all invisible or all visible (early out)
{
if(uCollectiveOr==0) // all visible
{
for(f=0; f<6; f++)
{
const int sideIndex = f;
float3 vFaceMi = float3(posX[subLigt*MAX_PNTS*2 + sideIndex + 0], posY[subLigt*MAX_PNTS*2 + sideIndex + 0], posZ[subLigt*MAX_PNTS*2 + sideIndex + 0]);
float3 vFaceMa = float3(posX[subLigt*MAX_PNTS*2 + sideIndex + 6], posY[subLigt*MAX_PNTS*2 + sideIndex + 6], posZ[subLigt*MAX_PNTS*2 + sideIndex + 6]);
float3 vFaceMi = float3(posX[subLigt*MAX_PNTS*2 + sideIndex + 0], posY[subLigt*MAX_PNTS*2 + sideIndex + 0], posZ[subLigt*MAX_PNTS*2 + sideIndex + 0]);
float3 vFaceMa = float3(posX[subLigt*MAX_PNTS*2 + sideIndex + 6], posY[subLigt*MAX_PNTS*2 + sideIndex + 6], posZ[subLigt*MAX_PNTS*2 + sideIndex + 6]);
for(int k=0; k<2; k++)
{
float3 vP = k==0 ? vFaceMi : vFaceMa;
if(f==0 && k==0) { vMin=vP; vMax=vP; }
for(int k=0; k<2; k++)
{
float3 vP = k==0 ? vFaceMi : vFaceMa;
if(f==0 && k==0) { vMin=vP; vMax=vP; }
vMax = max(vMax, vP); vMin = min(vMin, vP);
}
}
bSetBoundYet=true;
}
}
else // :( need true clipping
{
vMax = max(vMax, vP); vMin = min(vMin, vP);
}
}
bSetBoundYet=true;
}
}
else // :( need true clipping
{
for(f=0; f<6; f++)
{
float3 q0, q1, q2, q3;
GetHullQuad(q0, q1, q2, q3, boxX, boxY, boxZ, center, scaleXY, f);
for(f=0; f<6; f++)
{
float3 q0, q1, q2, q3;
GetHullQuad(q0, q1, q2, q3, boxX, boxY, boxZ, center, scaleXY, f);
// 4 vertices to a quad of the convex hull in post projection space
const float4 vP0 = mul(g_mProjection, float4(q0, 1));
const float4 vP1 = mul(g_mProjection, float4(q1, 1));
const float4 vP2 = mul(g_mProjection, float4(q2, 1));
const float4 vP3 = mul(g_mProjection, float4(q3, 1));
// 4 vertices to a quad of the convex hull in post projection space
const float4 vP0 = mul(g_mProjection, float4(q0, 1));
const float4 vP1 = mul(g_mProjection, float4(q1, 1));
const float4 vP2 = mul(g_mProjection, float4(q2, 1));
const float4 vP3 = mul(g_mProjection, float4(q3, 1));
int iSrcIndex = 0;
int iSrcIndex = 0;
int offs = iSrcIndex*MAX_PNTS+subLigt*MAX_PNTS*2;
int offs = iSrcIndex*MAX_PNTS+subLigt*MAX_PNTS*2;
// fill up source clip buffer with the quad
posX[offs+0]=vP0.x; posX[offs+1]=vP1.x; posX[offs+2]=vP2.x; posX[offs+3]=vP3.x;
posY[offs+0]=vP0.y; posY[offs+1]=vP1.y; posY[offs+2]=vP2.y; posY[offs+3]=vP3.y;
posZ[offs+0]=vP0.z; posZ[offs+1]=vP1.z; posZ[offs+2]=vP2.z; posZ[offs+3]=vP3.z;
posW[offs+0]=vP0.w; posW[offs+1]=vP1.w; posW[offs+2]=vP2.w; posW[offs+3]=vP3.w;
// fill up source clip buffer with the quad
posX[offs+0]=vP0.x; posX[offs+1]=vP1.x; posX[offs+2]=vP2.x; posX[offs+3]=vP3.x;
posY[offs+0]=vP0.y; posY[offs+1]=vP1.y; posY[offs+2]=vP2.y; posY[offs+3]=vP3.y;
posZ[offs+0]=vP0.z; posZ[offs+1]=vP1.z; posZ[offs+2]=vP2.z; posZ[offs+3]=vP3.z;
posW[offs+0]=vP0.w; posW[offs+1]=vP1.w; posW[offs+2]=vP2.w; posW[offs+3]=vP3.w;
int iNrSrcVerts = 4;
int iNrSrcVerts = 4;
// do true clipping
for(int p=0; p<6; p++)
{
const int nrVertsDst = ClipAgainstPlane(iSrcIndex, iNrSrcVerts, subLigt, p);
// do true clipping
for(int p=0; p<6; p++)
{
const int nrVertsDst = ClipAgainstPlane(iSrcIndex, iNrSrcVerts, subLigt, p);
iSrcIndex = 1-iSrcIndex;
iNrSrcVerts = nrVertsDst;
iSrcIndex = 1-iSrcIndex;
iNrSrcVerts = nrVertsDst;
if(iNrSrcVerts<3 || iNrSrcVerts>=MAX_PNTS) break;
}
if(iNrSrcVerts<3 || iNrSrcVerts>=MAX_PNTS) break;
}
// final clipped convex primitive is in src buffer
if(iNrSrcVerts>2)
{
int offs_src = iSrcIndex*MAX_PNTS+subLigt*MAX_PNTS*2;
for(int k=0; k<iNrSrcVerts; k++)
{
float4 vCur = float4(posX[offs_src+k], posY[offs_src+k], posZ[offs_src+k], posW[offs_src+k]);
// final clipped convex primitive is in src buffer
if(iNrSrcVerts>2)
{
int offs_src = iSrcIndex*MAX_PNTS+subLigt*MAX_PNTS*2;
for(int k=0; k<iNrSrcVerts; k++)
{
float4 vCur = float4(posX[offs_src+k], posY[offs_src+k], posZ[offs_src+k], posW[offs_src+k]);
// project and apply toward AABB
float3 vP = float3(vCur.x/vCur.w, vCur.y/vCur.w, vCur.z/vCur.w);
if(!bSetBoundYet) { vMin=vP; vMax=vP; bSetBoundYet=true; }
// project and apply toward AABB
float3 vP = float3(vCur.x/vCur.w, vCur.y/vCur.w, vCur.z/vCur.w);
if(!bSetBoundYet) { vMin=vP; vMax=vP; bSetBoundYet=true; }
vMax = max(vMax, vP); vMin = min(vMin, vP);
}
}
vMax = max(vMax, vP); vMin = min(vMin, vP);
}
}
}
}
////////////////////// look for camera frustum verts that need to be included. That is frustum vertices inside the convex hull for the light
int i=0;
for(i=0; i<8; i++) // establish 8 camera frustum vertices
{
float3 vVertPSpace = float3((i&1)!=0 ? 1 : (-1), (i&2)!=0 ? 1 : (-1), (i&4)!=0 ? 1 : 0);
////////////////////// look for camera frustum verts that need to be included. That is frustum vertices inside the convex hull for the light
int i=0;
for(i=0; i<8; i++) // establish 8 camera frustum vertices
{
float3 vVertPSpace = float3((i&1)!=0 ? 1 : (-1), (i&2)!=0 ? 1 : (-1), (i&4)!=0 ? 1 : 0);
float4 v4ViewSpace = mul(g_mInvProjection, float4(vVertPSpace,1));
float3 vViewSpace = float3(v4ViewSpace.x/v4ViewSpace.w, v4ViewSpace.y/v4ViewSpace.w, v4ViewSpace.z/v4ViewSpace.w);
float4 v4ViewSpace = mul(g_mInvProjection, float4(vVertPSpace,1));
float3 vViewSpace = float3(v4ViewSpace.x/v4ViewSpace.w, v4ViewSpace.y/v4ViewSpace.w, v4ViewSpace.z/v4ViewSpace.w);
posX[subLigt*MAX_PNTS*2 + i] = vViewSpace.x;
posY[subLigt*MAX_PNTS*2 + i] = vViewSpace.y;
posZ[subLigt*MAX_PNTS*2 + i] = vViewSpace.z;
}
posX[subLigt*MAX_PNTS*2 + i] = vViewSpace.x;
posY[subLigt*MAX_PNTS*2 + i] = vViewSpace.y;
posZ[subLigt*MAX_PNTS*2 + i] = vViewSpace.z;
}
// determine which camera frustum vertices are inside the convex hull
uint uVisibFl = 0xff;
for(f=0; f<6; f++)
{
float3 vP0, vN;
GetHullPlane(vP0, vN, boxX, boxY, boxZ, center, scaleXY, f);
// determine which camera frustum vertices are inside the convex hull
uint uVisibFl = 0xff;
for(f=0; f<6; f++)
{
float3 vP0, vN;
GetHullPlane(vP0, vN, boxX, boxY, boxZ, center, scaleXY, f);
for(i=0; i<8; i++)
{
float3 vViewSpace = float3(posX[subLigt*MAX_PNTS*2 + i], posY[subLigt*MAX_PNTS*2 + i], posZ[subLigt*MAX_PNTS*2 + i]);
uVisibFl &= ( dot(vViewSpace-vP0, vN)<0 ? 0xff : (~(1<<i)) );
}
}
for(i=0; i<8; i++)
{
float3 vViewSpace = float3(posX[subLigt*MAX_PNTS*2 + i], posY[subLigt*MAX_PNTS*2 + i], posZ[subLigt*MAX_PNTS*2 + i]);
uVisibFl &= ( dot(vViewSpace-vP0, vN)<0 ? 0xff : (~(1<<i)) );
}
}
// apply camera frustum vertices inside the convex hull to the AABB
for(i=0; i<8; i++)
{
if((uVisibFl&(1<<i))!=0)
{
float3 vP = float3((i&1)!=0 ? 1 : (-1), (i&2)!=0 ? 1 : (-1), (i&4)!=0 ? 1 : 0);
// apply camera frustum vertices inside the convex hull to the AABB
for(i=0; i<8; i++)
{
if((uVisibFl&(1<<i))!=0)
{
float3 vP = float3((i&1)!=0 ? 1 : (-1), (i&2)!=0 ? 1 : (-1), (i&4)!=0 ? 1 : 0);
if(!bSetBoundYet) { vMin=vP; vMax=vP; bSetBoundYet=true; }
if(!bSetBoundYet) { vMin=vP; vMax=vP; bSetBoundYet=true; }
vMax = max(vMax, vP); vMin = min(vMin, vP);
}
}
}
vMax = max(vMax, vP); vMin = min(vMin, vP);
}
}
}
// determine AABB bound in [-1;1]x[-1;1] screen space using bounding sphere.
// Use the result to make our already established AABB from the convex hull
// potentially tighter.
if(!bSetBoundYet)
{
// set the AABB off-screen
vMin = float3(-3,-3,-3);
vMax = float3(-2,-2,-2);
}
else
{
//if((center.z+radius)<0.0)
if(g_isOrthographic==0 && length(center)>radius)
{
float2 vMi, vMa;
bool2 bMi, bMa;
CalcBound(bMi, bMa, vMi, vMa, g_mInvProjection, center, radius);
// determine AABB bound in [-1;1]x[-1;1] screen space using bounding sphere.
// Use the result to make our already established AABB from the convex hull
// potentially tighter.
if(!bSetBoundYet)
{
// set the AABB off-screen
vMin = float3(-3,-3,-3);
vMax = float3(-2,-2,-2);
}
else
{
//if((center.z+radius)<0.0)
if(g_isOrthographic==0 && length(center)>radius)
{
float2 vMi, vMa;
bool2 bMi, bMa;
CalcBound(bMi, bMa, vMi, vMa, g_mInvProjection, center, radius);
vMin.xy = bMi ? max(vMin.xy, vMi) : vMin.xy;
vMax.xy = bMa ? min(vMax.xy, vMa) : vMax.xy;
}
else if(g_isOrthographic!=0)
{
float2 vMi = mul(g_mProjection, float4(center.xyz-radius,1)).xy; // no division needed for ortho
float2 vMa = mul(g_mProjection, float4(center.xyz+radius,1)).xy; // no division needed for ortho
vMin.xy = max(vMin.xy, vMi);
vMax.xy = min(vMax.xy, vMa);
}
vMin.xy = bMi ? max(vMin.xy, vMi) : vMin.xy;
vMax.xy = bMa ? min(vMax.xy, vMa) : vMax.xy;
}
else if(g_isOrthographic!=0)
{
float2 vMi = mul(g_mProjection, float4(center.xyz-radius,1)).xy; // no division needed for ortho
float2 vMa = mul(g_mProjection, float4(center.xyz+radius,1)).xy; // no division needed for ortho
vMin.xy = max(vMin.xy, vMi);
vMax.xy = min(vMax.xy, vMa);
}
if((center.z-radius)>0.0)
{
float4 vPosF = mul(g_mProjection, float4(0,0,center.z-radius,1));
vMin.z = max(vMin.z, vPosF.z/vPosF.w);
}
if((center.z+radius)>0.0)
{
float4 vPosB = mul(g_mProjection, float4(0,0,center.z+radius,1));
vMax.z = min(vMax.z, vPosB.z/vPosB.w);
}
if((center.z-radius)>0.0)
{
float4 vPosF = mul(g_mProjection, float4(0,0,center.z-radius,1));
vMin.z = max(vMin.z, vPosF.z/vPosF.w);
}
if((center.z+radius)>0.0)
{
float4 vPosB = mul(g_mProjection, float4(0,0,center.z+radius,1));
vMax.z = min(vMax.z, vPosB.z/vPosB.w);
}
if((center.z+radius)<0.0)
{
float4 vPosF = mul(g_mProjection, float4(0,0,center.z+radius,1));
vMin.z = max(vMin.z, vPosF.z/vPosF.w);
}
if((center.z-radius)<0.0)
{
float4 vPosB = mul(g_mProjection, float4(0,0,center.z-radius,1));
vMax.z = min(vMax.z, vPosB.z/vPosB.w);
}
if((center.z+radius)<0.0)
{
float4 vPosF = mul(g_mProjection, float4(0,0,center.z+radius,1));
vMin.z = max(vMin.z, vPosF.z/vPosF.w);
}
if((center.z-radius)<0.0)
{
float4 vPosB = mul(g_mProjection, float4(0,0,center.z-radius,1));
vMax.z = min(vMax.z, vPosB.z/vPosB.w);
}
else
{
vMin = float3(-3,-3,-3);
vMax = float3(-2,-2,-2);
}
}
else
{
vMin = float3(-3,-3,-3);
vMax = float3(-2,-2,-2);
}
}
// we should consider doing a look-up here into a max depth mip chain
// to see if the light is occluded: vMin.z*VIEWPORT_SCALE_Z > MipTexelMaxDepth
//g_vBoundsBuffer[lgtIndex+0] = float3(0.5*vMin.x+0.5, -0.5*vMax.y+0.5, vMin.z*VIEWPORT_SCALE_Z);
//g_vBoundsBuffer[lgtIndex+g_iNrVisibLights] = float3(0.5*vMax.x+0.5, -0.5*vMin.y+0.5, vMax.z*VIEWPORT_SCALE_Z);
// we should consider doing a look-up here into a max depth mip chain
// to see if the light is occluded: vMin.z*VIEWPORT_SCALE_Z > MipTexelMaxDepth
//g_vBoundsBuffer[lgtIndex+0] = float3(0.5*vMin.x+0.5, -0.5*vMax.y+0.5, vMin.z*VIEWPORT_SCALE_Z);
//g_vBoundsBuffer[lgtIndex+g_iNrVisibLights] = float3(0.5*vMax.x+0.5, -0.5*vMin.y+0.5, vMax.z*VIEWPORT_SCALE_Z);
// changed for unity
// changed for unity
// Each light's AABB is represented by two float3s, the min and max of the box.
// And for stereo, we have two sets of lights. Therefore, each eye has a set of mins, followed by

g_vBoundsBuffer[boundsIndices.min] = float3(0.5*vMin.x + 0.5, 0.5*vMin.y + 0.5, vMin.z*VIEWPORT_SCALE_Z);
g_vBoundsBuffer[boundsIndices.max] = float3(0.5*vMax.x + 0.5, 0.5*vMax.y + 0.5, vMax.z*VIEWPORT_SCALE_Z);
}
}
}
}
}

{
int offs_src = iSrcIndex*MAX_PNTS+subLigt*MAX_PNTS*2;
int offs_dst = (1-iSrcIndex)*MAX_PNTS+subLigt*MAX_PNTS*2;
int offs_src = iSrcIndex*MAX_PNTS+subLigt*MAX_PNTS*2;
int offs_dst = (1-iSrcIndex)*MAX_PNTS+subLigt*MAX_PNTS*2;
float4 vPrev = float4(posX[offs_src+(iNrSrcVerts-1)], posY[offs_src+(iNrSrcVerts-1)], posZ[offs_src+(iNrSrcVerts-1)], posW[offs_src+(iNrSrcVerts-1)]);
float4 vPrev = float4(posX[offs_src+(iNrSrcVerts-1)], posY[offs_src+(iNrSrcVerts-1)], posZ[offs_src+(iNrSrcVerts-1)], posW[offs_src+(iNrSrcVerts-1)]);
int nrVertsDst = 0;
int nrVertsDst = 0;
unsigned int uMask = (1<<p);
bool bIsPrevVisib = (GetClip(vPrev)&uMask)==0;
for(int i=0; i<iNrSrcVerts; i++)
{
float4 vCur = float4(posX[offs_src+i], posY[offs_src+i], posZ[offs_src+i], posW[offs_src+i]);
bool bIsCurVisib = (GetClip(vCur)&uMask)==0;
if( (bIsCurVisib && !bIsPrevVisib) || (!bIsCurVisib && bIsPrevVisib) )
{
//assert(nrVertsDst<MAX_PNTS);
if(nrVertsDst<MAX_PNTS)
{
// generate new vertex
float4 vNew = GenNewVert(bIsCurVisib ? vCur : vPrev, bIsCurVisib ? vPrev : vCur, p);
posX[offs_dst+nrVertsDst]=vNew.x; posY[offs_dst+nrVertsDst]=vNew.y; posZ[offs_dst+nrVertsDst]=vNew.z; posW[offs_dst+nrVertsDst]=vNew.w;
++nrVertsDst;
}
}
unsigned int uMask = (1<<p);
bool bIsPrevVisib = (GetClip(vPrev)&uMask)==0;
for(int i=0; i<iNrSrcVerts; i++)
{
float4 vCur = float4(posX[offs_src+i], posY[offs_src+i], posZ[offs_src+i], posW[offs_src+i]);
bool bIsCurVisib = (GetClip(vCur)&uMask)==0;
if( (bIsCurVisib && !bIsPrevVisib) || (!bIsCurVisib && bIsPrevVisib) )
{
//assert(nrVertsDst<MAX_PNTS);
if(nrVertsDst<MAX_PNTS)
{
// generate new vertex
float4 vNew = GenNewVert(bIsCurVisib ? vCur : vPrev, bIsCurVisib ? vPrev : vCur, p);
posX[offs_dst+nrVertsDst]=vNew.x; posY[offs_dst+nrVertsDst]=vNew.y; posZ[offs_dst+nrVertsDst]=vNew.z; posW[offs_dst+nrVertsDst]=vNew.w;
++nrVertsDst;
}
}
if(bIsCurVisib)
{
//assert(nrVertsDst<MAX_PNTS);
if(nrVertsDst<MAX_PNTS)
{
posX[offs_dst+nrVertsDst]=vCur.x; posY[offs_dst+nrVertsDst]=vCur.y; posZ[offs_dst+nrVertsDst]=vCur.z; posW[offs_dst+nrVertsDst]=vCur.w;
++nrVertsDst;
}
}
if(bIsCurVisib)
{
//assert(nrVertsDst<MAX_PNTS);
if(nrVertsDst<MAX_PNTS)
{
posX[offs_dst+nrVertsDst]=vCur.x; posY[offs_dst+nrVertsDst]=vCur.y; posZ[offs_dst+nrVertsDst]=vCur.z; posW[offs_dst+nrVertsDst]=vCur.w;
++nrVertsDst;
}
}
vPrev = vCur;
bIsPrevVisib = bIsCurVisib;
}
vPrev = vCur;
bIsPrevVisib = bIsCurVisib;
}
return nrVertsDst;
return nrVertsDst;
}

//-P.w <= P.x <= P.w
return ((P.x<-P.w)?1:0) | ((P.x>P.w)?2:0) | ((P.y<-P.w)?4:0) | ((P.y>P.w)?8:0) | ((P.z<0)?16:0) | ((P.z>P.w)?32:0);
//-P.w <= P.x <= P.w
return ((P.x<-P.w)?1:0) | ((P.x>P.w)?2:0) | ((P.y<-P.w)?4:0) | ((P.y>P.w)?8:0) | ((P.z<0)?16:0) | ((P.z>P.w)?32:0);
const float fS = p==4 ? 0 : ((p&1)==0 ? -1 : 1);
const int index = ((uint) p)/2;
float x1 = index==0 ? vVisib.x : (index==1 ? vVisib.y : vVisib.z);
float x0 = index==0 ? vInvisib.x : (index==1 ? vInvisib.y : vInvisib.z);
const float fS = p==4 ? 0 : ((p&1)==0 ? -1 : 1);
const int index = ((uint) p)/2;
float x1 = index==0 ? vVisib.x : (index==1 ? vVisib.y : vVisib.z);
float x0 = index==0 ? vInvisib.x : (index==1 ? vInvisib.y : vInvisib.z);
//fS*((vVisib.w-vInvisib.w)*t + vInvisib.w) = (x1-x0)*t + x0;
//fS*((vVisib.w-vInvisib.w)*t + vInvisib.w) = (x1-x0)*t + x0;
const float fT = (fS*vInvisib.w-x0)/((x1-x0) - fS*(vVisib.w-vInvisib.w));
float4 vNew = vVisib*fT + vInvisib*(1-fT);
const float fT = (fS*vInvisib.w-x0)/((x1-x0) - fS*(vVisib.w-vInvisib.w));
float4 vNew = vVisib*fT + vInvisib*(1-fT);
// just to be really anal we make sure the clipped against coordinate is precise
if(index==0) vNew.x = fS*vNew.w;
else if(index==1) vNew.y = fS*vNew.w;
else vNew.z = fS*vNew.w;
// just to be really anal we make sure the clipped against coordinate is precise
if(index==0) vNew.x = fS*vNew.w;
else if(index==1) vNew.y = fS*vNew.w;
else vNew.z = fS*vNew.w;
return vNew;
return vNew;
return mul(plane, InvProjection);
return mul(plane, InvProjection);
// rotate by 90 degrees to avoid potential division by zero
bool bMustFlip = abs(posXY_in.y)<abs(posXY_in.x);
float2 posXY = bMustFlip ? float2(-posXY_in.y, posXY_in.x) : posXY_in;
// rotate by 90 degrees to avoid potential division by zero
bool bMustFlip = abs(posXY_in.y)<abs(posXY_in.x);
float2 posXY = bMustFlip ? float2(-posXY_in.y, posXY_in.x) : posXY_in;
float fLenSQ = dot(posXY, posXY);
float diffSq = fLenSQ - r*r;
float D = posXY.y * sqrt(max(0.0, diffSq));
float fLenSQ = dot(posXY, posXY);
float diffSq = fLenSQ - r*r;
float D = posXY.y * sqrt(max(0.0, diffSq));
float4 res;
res.x = (-r*posXY.x - D) / fLenSQ;
res.z = (-r*posXY.x + D) / fLenSQ;
res.y = (-r-res.x*posXY.x) / posXY.y;
res.w = (-r-res.z*posXY.x) / posXY.y;
float4 res;
res.x = (-r*posXY.x - D) / fLenSQ;
res.z = (-r*posXY.x + D) / fLenSQ;
res.y = (-r-res.x*posXY.x) / posXY.y;
res.w = (-r-res.z*posXY.x) / posXY.y;
// rotate back by 90 degrees
res = bMustFlip ? float4(res.y, -res.x, res.w, -res.z) : res;
// rotate back by 90 degrees
res = bMustFlip ? float4(res.y, -res.x, res.w, -res.z) : res;
validPlanes = diffSq>0.0;
validPlanes = diffSq>0.0;
return res;
return res;
bool validX, validY;
float4 planeX = EvalPlanePair(validX, float2(pos_view_space.x, pos_view_space.z), r);
float4 planeY = EvalPlanePair(validY, float2(pos_view_space.y, pos_view_space.z), r);
bool validX, validY;
float4 planeX = EvalPlanePair(validX, float2(pos_view_space.x, pos_view_space.z), r);
float4 planeY = EvalPlanePair(validY, float2(pos_view_space.y, pos_view_space.z), r);
planeX = planeX.zwxy; // need to swap left/right and top/bottom planes when using left hand system
planeY = planeY.zwxy;
planeX = planeX.zwxy; // need to swap left/right and top/bottom planes when using left hand system
planeY = planeY.zwxy;
bIsMinValid = bool2(planeX.z<0, planeY.z<0) && bool2(validX,validY);
bIsMaxValid = bool2((-planeX.x)<0, (-planeY.x)<0) && bool2(validX,validY);
bIsMinValid = bool2(planeX.z<0, planeY.z<0) && bool2(validX,validY);
bIsMaxValid = bool2((-planeX.x)<0, (-planeY.x)<0) && bool2(validX,validY);
// hopefully the compiler takes zeros into account
// should be the case since the transformation in TransformPlaneToPostSpace()
// is done using multiply-adds and not dot product instructions.
float4 planeX0 = TransformPlaneToPostSpace(InvProjection, float4(planeX.x, 0, planeX.y, 0));
float4 planeX1 = TransformPlaneToPostSpace(InvProjection, float4(planeX.z, 0, planeX.w, 0));
float4 planeY0 = TransformPlaneToPostSpace(InvProjection, float4(0, planeY.x, planeY.y, 0));
float4 planeY1 = TransformPlaneToPostSpace(InvProjection, float4(0, planeY.z, planeY.w, 0));
// hopefully the compiler takes zeros into account
// should be the case since the transformation in TransformPlaneToPostSpace()
// is done using multiply-adds and not dot product instructions.
float4 planeX0 = TransformPlaneToPostSpace(InvProjection, float4(planeX.x, 0, planeX.y, 0));
float4 planeX1 = TransformPlaneToPostSpace(InvProjection, float4(planeX.z, 0, planeX.w, 0));
float4 planeY0 = TransformPlaneToPostSpace(InvProjection, float4(0, planeY.x, planeY.y, 0));
float4 planeY1 = TransformPlaneToPostSpace(InvProjection, float4(0, planeY.z, planeY.w, 0));
// convert planes to the forms (1,0,0,D) and (0,1,0,D)
// 2D bound is given by -D components
float2 A = -float2(planeX0.w / planeX0.x, planeY0.w / planeY0.y);
float2 B = -float2(planeX1.w / planeX1.x, planeY1.w / planeY1.y);
// convert planes to the forms (1,0,0,D) and (0,1,0,D)
// 2D bound is given by -D components
float2 A = -float2(planeX0.w / planeX0.x, planeY0.w / planeY0.y);
float2 B = -float2(planeX1.w / planeX1.x, planeY1.w / planeY1.y);
// Bound is complete
vMin = B;
vMax = A;
// Bound is complete
vMin = B;
vMax = A;
}

3
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightLoop/GlobalLightLoopSettings.cs


public LayerMask skyLightingOverrideLayerMask = 0;
}
}

8
com.unity.render-pipelines.high-definition/HDRP/Lighting/Lighting.hlsl


// Volumetrics have their own light loop.
#ifndef UNITY_MATERIAL_VOLUMETRIC
// LightLoop use evaluation BSDF function for light type define in Material.hlsl
#if defined(LIGHTLOOP_SINGLE_PASS) || defined(LIGHTLOOP_TILE_PASS)
#include "../Lighting/LightLoop/LightLoop.hlsl"
#endif
// LightLoop use evaluation BSDF function for light type define in Material.hlsl
#if defined(LIGHTLOOP_SINGLE_PASS) || defined(LIGHTLOOP_TILE_PASS)
#include "../Lighting/LightLoop/LightLoop.hlsl"
#endif
#endif
#endif // UNITY_LIGHTING_INCLUDED

2
com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/Volumes/ShapeType.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public enum ShapeType
{

2
com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/Volumes/ReflectionProxyVolumeComponent.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class ReflectionProxyVolumeComponent : MonoBehaviour
{

部分文件因为文件数量过多而无法显示

正在加载...
取消
保存