浏览代码

Merge branch 'master' into metal

/main
Antti Tapaninen 8 年前
当前提交
c46cb0b5
共有 41 个文件被更改,包括 607 次插入179 次删除
  1. 14
      Assets/LowEndMobilePipeline/TestScenes/LDRenderPipelineBasicScene/LightingData.asset
  2. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/Resources/DebugViewMaterialGBuffer.shader
  3. 30
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
  4. 5
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  5. 5
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Resources/Deferred.shader
  6. 34
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/FeatureFlags.hlsl
  7. 39
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/Resources/lightlistbuild.compute
  8. 18
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/Resources/shadeopaque.compute
  9. 43
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  10. 16
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl
  11. 10
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePassLoop.hlsl
  12. 3
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePassProducer.asset
  13. 10
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs
  14. 9
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs.hlsl
  15. 153
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  16. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader
  17. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringProfile.cs
  18. 13
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Material.hlsl
  19. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl
  20. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassDistortion.hlsl
  21. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl
  22. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl
  23. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl
  24. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassVelocity.hlsl
  25. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Editor/HDRISkyEditor.cs
  26. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Resources/SkyProcedural.shader
  27. 84
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs
  28. 1
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs
  29. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Utilities.cs
  30. 3
      Assets/ScriptableRenderPipeline/RenderPasses/ShadowRenderPass.cs
  31. 21
      Assets/ScriptableRenderPipeline/ShaderLibrary/BSDF.hlsl
  32. 5
      Assets/ScriptableRenderPipeline/ShaderLibrary/Common.hlsl
  33. 110
      Assets/TestScenes/HDTest/GlobalIlluminationTest.unity
  34. 9
      Assets/ScriptableRenderPipeline/common/Resources.meta
  35. 20
      Assets/TestScenes/HDTest/GlobalIlluminationTest/CommonSettings_GlobalIllumination.asset
  36. 9
      Assets/TestScenes/HDTest/GlobalIlluminationTest/CommonSettings_GlobalIllumination.asset.meta
  37. 20
      Assets/TestScenes/HDTest/GlobalIlluminationTest/HDRISkySettings_GlobalIllumination.asset
  38. 9
      Assets/TestScenes/HDTest/GlobalIlluminationTest/HDRISkySettings_GlobalIllumination.asset.meta
  39. 9
      Assets/ScriptableRenderPipeline/common/Resources/BlitCubemap.shader.meta
  40. 56
      Assets/ScriptableRenderPipeline/common/Resources/BlitCubemap.shader

14
Assets/LowEndMobilePipeline/TestScenes/LDRenderPipelineBasicScene/LightingData.asset


1;�1 2017.1.0a3������:'���BIr���:�b���7���������� �� ��".�+���� ��".�+H��������1�1����� @���
Q�j� 4C���� Je���� ��z����1�1���������j�P��������������������������0���� �� ������ ��!��!"��%#��)$��-%��1&��5����'1�1�����(���)��j� * ��@+ ��B, ��D- ��F����.1�1�����/���0Rj�1`h2��o3��x4���5���6���7���8���9���:���;���<���=���>���?���@���A���B��C��D������E1�1�����F���G��j� H ��@I ��BJ ��DK ��!����L1�1�����M���N�j�O`��P��oQ��xR���S���T���U���V���W���X���Y���Z���[���\���]���^���_���`��
�a��F����b1�1�����c���dZj�le��of��vg��}h���i���j���k���l���m���n���o���p���q���r���s���t���u���v���w���x���y���z��{�� |��}��~����%���,�����1�1����������Bj������;�V�����1�1������������j��;�q�����1�1������������j��;�}�����1�1����������5�j��LightProbesPPtr<EditorExtension>m_FileIDm_PathIDLightProbeDatam_DataProbeSetTetrahedralizationm_Tetrahedralizationm_TetrahedraTetrahedronindices[0]indices[1]indices[2]indices[3]neighbors[0]neighbors[1]neighbors[2]neighbors[3]Matrix3x4fmatrixe00e01e02e03e10e11e12e13e20e21e22e23m_HullRaysxyzm_ProbeSetsProbeSetIndexHash128m_Hashbytes[0]bytes[1]bytes[2]bytes[3]bytes[4]bytes[5]bytes[6]bytes[7]bytes[8]bytes[9]bytes[10]bytes[11]bytes[12]bytes[13]bytes[14]bytes[15]m_Offsetm_Sizem_Positionsm_NonTetrahedralizedProbeSetIndexMapm_BakedCoefficientsSphericalHarmonicsL2sh[ 0]sh[ 1]sh[ 2]sh[ 3]sh[ 4]sh[ 5]sh[ 6]sh[ 7]sh[ 8]sh[ 9]sh[10]sh[11]sh[12]sh[13]sh[14]sh[15]sh[16]sh[17]sh[18]sh[19]sh[20]sh[21]sh[22]sh[23]sh[24]sh[25]sh[26]m_BakedLightOcclusionLightProbeOcclusionm_ProbeOcclusionLightIndexm_Occlusionm_OcclusionMaskChannel`���-�G�2��(����1� �7������������ ��(.�1���� ��(.�1H��������1�1����� @���
Q�j� ��:���� 1�1����� ���Fj�$��S ��(.�1��^ ��(.�1��l ��(.�1y� ��(.�1�����l��������� ���!���"���#��$�� %��&��'�� (��')��.*��5+��<,��C-��J.��Q/��X0��_1��f2��m3��t4��{5���6���7���8�������91�1�����:���;�j�P<�� =��(>.�1?���@ ���A ���B ���C ���D ���E ���F ���G ���H ���I ��J��K��&L ���M ���N ���O ���P ��1Q ���R ���S ���T ���U ��C����V1�1�����W���X`j�Y.�vZ.��[������\�������]1�1�����^���_�j�@`y�� a��(b.�1c���d ���e ���f ���g ���h ��
ij��(k��1l��:m��Cn��Lo��Up��^q��gr��ps��yt���u���v���w���x���y���z�{���(|���1}���:~���C���L����U����^����g����p����y����������������������������������������1�1�����������j�4����������� ������#�0���(���1���:���C���L���U���^���g���p���y�������������������������@���(���1���:���C���L���U���^���g���p���y���������������������������T�����1�1����������j����(���1���:���C���L���U���^���g���p���y���������������������������`�����1�1����������pj����������(���1���:���C���L���U���^���g���p���y�������������������������������������1�1�����������j� ���������������������1�1����������`j��.�v�.�����!�����1�1����������`j��.�v�.�����*�����1�1����������?j� ���Q���j������������1�1������������j� ���(.�1�������1�1��������`j�.�v.����������1�1����� @���
��j� ��� LightingDataAssetPPtr<EditorExtension>m_FileIDm_PathIDm_LightmapsLightmapDatam_Lightmapm_DirLightmapm_ShadowMaskPPtr<LightProbes>m_LightProbesm_LightmapsModeSphericalHarmonicsL2m_BakedAmbientProbeInLinearsh[ 0]sh[ 1]sh[ 2]sh[ 3]sh[ 4]sh[ 5]sh[ 6]sh[ 7]sh[ 8]sh[ 9]sh[10]sh[11]sh[12]sh[13]sh[14]sh[15]sh[16]sh[17]sh[18]sh[19]sh[20]sh[21]sh[22]sh[23]sh[24]sh[25]sh[26]m_LightmappedRendererDataRendererDataPPtr<Mesh>uvMeshterrainDynamicUVSTxyzwterrainChunkDynamicUVSTlightmapIndexlightmapIndexDynamiclightmapSTlightmapSTDynamicm_LightmappedRendererDataIDsSceneObjectIdentifiertargetObjecttargetPrefabEnlightenSceneMappingm_EnlightenSceneMappingm_RenderersEnlightenRendererInformationrendererdynamicLightmapSTInSystemsystemIdHash128instanceHashbytes[0]bytes[1]bytes[2]bytes[3]bytes[4]bytes[5]bytes[6]bytes[7]bytes[8]bytes[9]bytes[10]bytes[11]bytes[12]bytes[13]bytes[14]bytes[15]geometryHashm_SystemsEnlightenSystemInformationrendererIndexrendererSizeatlasIndexatlasOffsetXatlasOffsetYinputSystemHashradiositySystemHashm_Probesetsm_SystemAtlasesEnlightenSystemAtlasInformationatlasSizeatlasHashfirstSystemIdm_TerrainChunksEnlightenTerrainChunksInformationnumChunksInXnumChunksInYm_EnlightenSceneMappingRendererIDsm_Lightsm_LightBakingOutputsLightBakingOutputprobeOcclusionLightIndexocclusionMaskChannellightmappingMaskm_BakedReflectionProbeCubemapsm_BakedReflectionProbesm_EnlightenDatam_EnlightenDataVersion@��H��H@
<'��S��I�3�UO�-1�ʭ�G��A��R�@ LightingDataLightingDataAsset��*@��v�;>l����<���d���R�;NAV<$��q��<�Fh>$�*=��i<��5P��K�1<�L�<�����%=�ߖ>�/�=��<d��� 9L��x�<��<�B5�tC=�?�?�?�?��G>G>J>�?�?�?�?�?�?����+=��+=@I?�?�?�?�?�?�?��H>H>�?�?�?�?�?�?��G>G>I>J?�?�?�?�?�?�?��G>G>��>�?�?�?�?�?�?����+=��+=>@I?�?�?�?�?�?�?��H>H>I>�?�?�?�?�?�?�?���O>�O>!�?�(I>�?�?�?�?�?�?����+=��+=�=@I?�?�?�?�?�?�?��[+`=[+`=h=nlk?�?�?�?�?�?�?��G>G>��>J>�?�?�?�?�?�?����+=��+=4=@I?�?�?�?�?�?�?��H>H>I>J>�?�?�?�?�?�?��H>H>�>�?�?�?�?�?�?��H>H>J>�?�?�?�?�?�?��H>H>I>�>�?�?�?�?�?�?��G>G>?�?�?�?�?�?�?��H>H>�?�?�?�?�?�?�?��G>G>J?�?�?�?�?�?�?��[+`=[+`=�=nlk?�?�?�?�?�?�?��D1!>D1!>�\'���P?�?�?�?�?�?�?��[+`=[+`=nlk?�?�?O��C��RdG�z���d��5=\(_F�.dEKP�wCh�44fR �e�ZY OL�v�*��� �����)� a)F{~mp�J5�V�V�X��J�BnQ\�eV?$�b���q�S�x�������������������������͇;UnityFS5.x.x2017.1.0a3;
1;�1 2017.1.0b1�������Ƣ��^Ee��c���_��7���������� �� ��".�+���� ��".�+H��������1�1����� @���
Q�j� 4C���� �Je���� ���z�����1�1�����@����j�P��������������������������0���� �� ������ ��!��!"��%#��)$��-%��1&��5����'�1�1�����(@���)��j� * ��@+ ��B, ��D- ��F����.�1�1�����/@���0Rj�1`h2��o3��x4���5���6���7���8���9���:���;���<���=���>���?���@���A���B��C��D������E�1�1�����F@���G��j� H ��@I ��BJ ��DK ��!����L1�1�����M���N�j�O`��P��oQ��xR���S���T���U���V���W���X���Y���Z���[���\���]���^���_���`��
�a��F����b�1�1�����c@���dZj�le��of��vg��}h���i���j���k���l���m���n���o���p���q���r���s���t���u���v���w���x���y���z��{�� |��}��~����%���,������1�1������@����Bj������;�V�����1�1������������j��;�q�����1�1������������j��;�}�����1�1����������5�j��LightProbesPPtr<EditorExtension>m_FileIDm_PathIDLightProbeDatam_DataProbeSetTetrahedralizationm_Tetrahedralizationm_TetrahedraTetrahedronindices[0]indices[1]indices[2]indices[3]neighbors[0]neighbors[1]neighbors[2]neighbors[3]Matrix3x4fmatrixe00e01e02e03e10e11e12e13e20e21e22e23m_HullRaysxyzm_ProbeSetsProbeSetIndexHash128m_Hashbytes[0]bytes[1]bytes[2]bytes[3]bytes[4]bytes[5]bytes[6]bytes[7]bytes[8]bytes[9]bytes[10]bytes[11]bytes[12]bytes[13]bytes[14]bytes[15]m_Offsetm_Sizem_Positionsm_NonTetrahedralizedProbeSetIndexMapm_BakedCoefficientsSphericalHarmonicsL2sh[ 0]sh[ 1]sh[ 2]sh[ 3]sh[ 4]sh[ 5]sh[ 6]sh[ 7]sh[ 8]sh[ 9]sh[10]sh[11]sh[12]sh[13]sh[14]sh[15]sh[16]sh[17]sh[18]sh[19]sh[20]sh[21]sh[22]sh[23]sh[24]sh[25]sh[26]m_BakedLightOcclusionLightProbeOcclusionm_ProbeOcclusionLightIndexm_Occlusionm_OcclusionMaskChannel`�����/�:�AI�I F� �7������������ ��(.�1���� ��(.�1H��������1�1����� @���
Q�j� ��:���� �1�1����� @���Fj�$��S ��(.�1��^ ��(.�1��l ��(.�1y� ��(.�1�����l��������� ���!���"���#��$�� %��&��'�� (��')��.*��5+��<,��C-��J.��Q/��X0��_1��f2��m3��t4��{5���6���7���8�������9�1�1�����:@���;�j�P<�� =��(>.�1?���@ ���A ���B ���C ���D ���E ���F ���G ���H ���I ��J��K��&L ���M ���N ���O ���P ��1Q ���R ���S ���T ���U ��C����V�1�1�����W@���X`j�Y.�vZ.��[������\��������]�1�1�����^@���_�j�@`y�� a��(b.�1c���d ���e ���f ���g ���h ��
ij��(k��1l��:m��Cn��Lo��Up��^q��gr��ps��yt���u���v���w���x���y���z�{���(|���1}���:~���C���L����U����^����g����p����y�����������������������������������������1�1������@�����j�4����������� ������#�0���(���1���:���C���L���U���^���g���p���y�������������������������@���(���1���:���C���L���U���^���g���p���y���������������������������T������1�1������@����j����(���1���:���C���L���U���^���g���p���y���������������������������`������1�1������@����pj����������(���1���:���C���L���U���^���g���p���y��������������������������������������1�1������@�����j� ����������������������1�1������@����`j��.�v�.�����!������1�1������@����`j��.�v�.�����*������1�1������@����?j� ���Q���j�������������1�1������@������j� ���(.�1��������1�1�����@���`j�.�v.����������1�1����� @���
��j� ��� LightingDataAssetPPtr<EditorExtension>m_FileIDm_PathIDm_LightmapsLightmapDatam_Lightmapm_DirLightmapm_ShadowMaskPPtr<LightProbes>m_LightProbesm_LightmapsModeSphericalHarmonicsL2m_BakedAmbientProbeInLinearsh[ 0]sh[ 1]sh[ 2]sh[ 3]sh[ 4]sh[ 5]sh[ 6]sh[ 7]sh[ 8]sh[ 9]sh[10]sh[11]sh[12]sh[13]sh[14]sh[15]sh[16]sh[17]sh[18]sh[19]sh[20]sh[21]sh[22]sh[23]sh[24]sh[25]sh[26]m_LightmappedRendererDataRendererDataPPtr<Mesh>uvMeshterrainDynamicUVSTxyzwterrainChunkDynamicUVSTlightmapIndexlightmapIndexDynamiclightmapSTlightmapSTDynamicm_LightmappedRendererDataIDsSceneObjectIdentifiertargetObjecttargetPrefabEnlightenSceneMappingm_EnlightenSceneMappingm_RenderersEnlightenRendererInformationrendererdynamicLightmapSTInSystemsystemIdHash128instanceHashbytes[0]bytes[1]bytes[2]bytes[3]bytes[4]bytes[5]bytes[6]bytes[7]bytes[8]bytes[9]bytes[10]bytes[11]bytes[12]bytes[13]bytes[14]bytes[15]geometryHashm_SystemsEnlightenSystemInformationrendererIndexrendererSizeatlasIndexatlasOffsetXatlasOffsetYinputSystemHashradiositySystemHashm_Probesetsm_SystemAtlasesEnlightenSystemAtlasInformationatlasSizeatlasHashfirstSystemIdm_TerrainChunksEnlightenTerrainChunksInformationnumChunksInXnumChunksInYm_EnlightenSceneMappingRendererIDsm_Lightsm_LightBakingOutputsLightBakingOutputprobeOcclusionLightIndexocclusionMaskChannellightmappingMaskm_BakedReflectionProbeCubemapsm_BakedReflectionProbesm_EnlightenDatam_EnlightenDataVersion@��H��H8
<'��S��I�3�UO�-1�ʭ�G��A��R�@ LightingData LightingData��*@��v�;>l����<���d���R�;NAV<$��q��<�Fh>$�*=��i<��5P��K�1<�L�<�����%=�ߖ>�/�=��<d��� 9L��x�<��<�B5�tC=�?�?�?�?��G>G>J>�?�?�?�?�?�?����+=��+=@I?�?�?�?�?�?�?��H>H>�?�?�?�?�?�?��G>G>I>J?�?�?�?�?�?�?��G>G>��>�?�?�?�?�?�?����+=��+=>@I?�?�?�?�?�?�?��H>H>I>�?�?�?�?�?�?�?���O>�O>!�?�(I>�?�?�?�?�?�?����+=��+=�=@I?�?�?�?�?�?�?��[+`=[+`=h=nlk?�?�?�?�?�?�?��G>G>��>J>�?�?�?�?�?�?����+=��+=4=@I?�?�?�?�?�?�?��H>H>I>J>�?�?�?�?�?�?��H>H>�>�?�?�?�?�?�?��H>H>J>�?�?�?�?�?�?��H>H>I>�>�?�?�?�?�?�?��G>G>?�?�?�?�?�?�?��H>H>�?�?�?�?�?�?�?��G>G>J?�?�?�?�?�?�?��[+`=[+`=�=nlk?�?�?�?�?�?�?��D1!>D1!>�\'���P?�?�?�?�?�?�?��[+`=[+`=nlk?�?�?O��C��RdG�z���d��5=\(_F�.dEKP�wCh�44fR �e�ZY OL�v�*��� �����)� a)F{~mp�J5�V�V�X��J�BnQ\�eV?$�b���q�S�x�������������������������͇;UnityFS5.x.x2017.1.0a3;
�Pk

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/Resources/DebugViewMaterialGBuffer.shader


float4 Frag(Varyings input) : SV_Target
{
// input.positionCS is SV_Position
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw, uint2(0, 0));
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw);
float depth = LOAD_TEXTURE2D(_MainDepthTexture, posInput.unPositionSS).x;
UpdatePositionInput(depth, _InvViewProjMatrix, _ViewProjMatrix, posInput);

DECODE_FROM_GBUFFER(gbuffer, bsdfData, bakeDiffuseLighting);
DECODE_FROM_GBUFFER(gbuffer, 0xFFFFFFFF, bsdfData, bakeDiffuseLighting);
// Init to not expected value
float3 result = float3(-666.0, 0.0, 0.0);

30
Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs


using UnityEditor;
using UnityEngine.SceneManagement;
using UnityEngine.Experimental.Rendering.HDPipeline;
using System.IO;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{

LayeredLitGUI.SetupMaterialKeywordsAndPass(mat);
EditorUtility.SetDirty(mat);
}
}
}
[MenuItem("HDRenderPipeline/Export Sky to Image")]
static void ExportSkyToImage()
{
HDRenderPipelineInstance renderpipelineInstance = UnityEngine.Experimental.Rendering.RenderPipelineManager.currentPipeline as HDRenderPipelineInstance;
if(renderpipelineInstance == null)
{
Debug.LogError("HDRenderPipeline is not instantiated.");
return;
}
Texture2D result = renderpipelineInstance.ExportSkyToTexture();
if(result == null)
{
return;
}
// Encode texture into PNG
byte[] bytes = null;
bytes = result.EncodeToEXR(Texture2D.EXRFlags.CompressZIP);
Object.DestroyImmediate(result);
string assetPath = EditorUtility.SaveFilePanel("Export Sky", "Assets", "SkyExport", "exr");
if (!string.IsNullOrEmpty(assetPath))
{
File.WriteAllBytes(assetPath, bytes);
AssetDatabase.Refresh();
}
}
}

5
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


m_SkyManager.RenderSky(hdCamera, m_LightLoop == null ? null : m_LightLoop.GetCurrentSunLight(), m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, renderContext);
}
public Texture2D ExportSkyToTexture()
{
return m_SkyManager.ExportSkyToTexture();
}
void RenderForward(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext, bool renderOpaque)
{
// TODO: Currently we can't render opaque object forward when deferred is enabled

5
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Resources/Deferred.shader


UpdatePositionInput(depth, _InvViewProjMatrix, _ViewProjMatrix, posInput);
float3 V = GetWorldSpaceNormalizeViewDir(posInput.positionWS);
uint featureFlags = 0xFFFFFFFF;
DECODE_FROM_GBUFFER(gbuffer, bsdfData, bakeDiffuseLighting);
DECODE_FROM_GBUFFER(gbuffer, featureFlags, bsdfData, bakeDiffuseLighting);
uint featureFlags = 0xFFFFFFFF;
float3 diffuseLighting;
float3 specularLighting;
LightLoop(V, posInput, preLightData, bsdfData, bakeDiffuseLighting, featureFlags, diffuseLighting, specularLighting);

34
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/FeatureFlags.hlsl


#ifndef __FEATURE_FLAGS_H__
#define __FEATURE_FLAGS_H__
#include "TilePass.cs.hlsl"
static const uint FEATURE_FLAG_ALL_MATERIALS = FEATURE_FLAG_MATERIAL_LIT_STANDARD | FEATURE_FLAG_MATERIAL_LIT_SSS | FEATURE_FLAG_MATERIAL_LIT_CLEAR_COAT | FEATURE_FLAG_MATERIAL_LIT_SPECULAR | FEATURE_FLAG_MATERIAL_LIT_ANISO;
/* 0 */ 0,
/* 1 */ FEATURE_FLAG_SKY_LIGHT | FEATURE_FLAG_DIRECTIONAL_LIGHT,
/* 2 */ FEATURE_FLAG_SKY_LIGHT | FEATURE_FLAG_DIRECTIONAL_LIGHT | FEATURE_FLAG_ENV_LIGHT,
/* 3 */ FEATURE_FLAG_SKY_LIGHT | FEATURE_FLAG_DIRECTIONAL_LIGHT | FEATURE_FLAG_PUNCTUAL_LIGHT,
/* 3 */ FEATURE_FLAG_SKY_LIGHT | FEATURE_FLAG_DIRECTIONAL_LIGHT | FEATURE_FLAG_PUNCTUAL_LIGHT | FEATURE_FLAG_ENV_LIGHT,
/* 5 */ FEATURE_FLAG_SKY_LIGHT | FEATURE_FLAG_DIRECTIONAL_LIGHT | FEATURE_FLAG_AREA_LIGHT,
/* 6 */ FEATURE_FLAG_SKY_LIGHT | FEATURE_FLAG_DIRECTIONAL_LIGHT | FEATURE_FLAG_AREA_LIGHT | FEATURE_FLAG_PUNCTUAL_LIGHT | FEATURE_FLAG_ENV_LIGHT,
/* 7 */ 0xFFFFFFFF,
/* 0 */ 0 | FEATURE_FLAG_ALL_MATERIALS,
/* 1 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 2 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 3 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 3 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 5 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_AREA | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 6 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_AREA | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_MATERIAL_LIT_STANDARD,
/* 7 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_ALL_MATERIALS,
/* 8 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_ALL_MATERIALS,
/* 9 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_ALL_MATERIALS,
/*10 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_ALL_MATERIALS,
/*11 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_AREA | FEATURE_FLAG_ALL_MATERIALS,
/*12 */ FEATURE_FLAG_LIGHT_SKY | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_AREA | FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_LIGHT_ENV | FEATURE_FLAG_ALL_MATERIALS,
/*13 */ 0xFFFFFFFF,
/*14 */ 0xFFFFFFFF,
/*15 */ 0xFFFFFFFF,
/*
public static uint FEATURE_FLAG_PUNCTUAL_LIGHT = 1<<0;
public static uint FEATURE_FLAG_AREA_LIGHT = 1<<1;
public static uint FEATURE_FLAG_DIRECTIONAL_LIGHT = 1<<2;
public static uint FEATURE_FLAG_ENV_LIGHT = 1<<3;
public static uint FEATURE_FLAG_SKY_LIGHT = 1<<4;
*/
uint FeatureFlagsToTileVariant(uint featureFlags)
{

39
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/Resources/lightlistbuild.compute


#include "../ShaderBase.hlsl"
#include "../TilePass.cs.hlsl"
#include "../LightingConvexHullUtils.hlsl"
#include "../FeatureFlags.hlsl"
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "../../../Material/Material.hlsl" // This include Material.hlsl
#include "../FeatureFlags.hlsl"
#define USE_MATERIAL_FEATURE_FLAGS
uniform int g_iNrVisibLights;
uniform uint2 g_viDimensions;

groupshared uint ldsFeatureFlags;
RWBuffer<uint> g_DispatchIndirectBuffer;
RWStructuredBuffer<uint> g_TileList;
#ifdef USE_MATERIAL_FEATURE_FLAGS
DECLARE_GBUFFER_TEXTURE(_GBufferTexture);
#endif
#endif

#ifdef FINE_PRUNING_ENABLED
void FinePruneLights(uint threadID, int iNrCoarseLights, uint2 viTilLL, float4 vLinDepths);
#endif
[numthreads(NR_THREADS, 1, 1)]
void LIGHTLISTGEN(uint threadID : SV_GroupIndex, uint3 u3GroupID : SV_GroupID)

iNrCoarseLights = SphericalIntersectionTests( t, iNrCoarseLights, float2(min(viTilLL.xy+uint2(16/2,16/2), uint2(iWidth-1, iHeight-1))) );
#endif
#ifndef FINE_PRUNING_ENABLED
#ifndef FINE_PRUNING_ENABLED
{
if((int)t<iNrCoarseLights) prunedList[t] = coarseList[t];
if(t==0) ldsNrLightsFinal=iNrCoarseLights;

#endif
#ifdef USE_FEATURE_FLAGS
#ifdef USE_MATERIAL_FEATURE_FLAGS
float2 invScreenSize = float2(1.0f / iWidth, 1.0f / iHeight);
uint materialFeatureFlags = 0;
{
[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));
if(FetchDepth(g_depth_tex, uCrd) < VIEWPORT_SCALE_Z) // if not skydome. //TODO: reuse depths from before
{
PositionInputs posInput = GetPositionInput(uCrd, invScreenSize);
FETCH_GBUFFER(gbuffer, _GBufferTexture, posInput.unPositionSS);
materialFeatureFlags |= MATERIAL_FEATURE_FLAGS_FROM_GBUFFER(gbuffer);
}
}
}
InterlockedOr(ldsFeatureFlags, materialFeatureFlags); //TODO: driver might optimize this or we might have to do a manual reduction
GroupMemoryBarrierWithGroupSync();
#else
uint materialFeatureFlags = 0xFFFFF000;
#endif
featureFlags &= ~(FEATURE_FLAG_PUNCTUAL_LIGHT | FEATURE_FLAG_AREA_LIGHT | FEATURE_FLAG_DIRECTIONAL_LIGHT | FEATURE_FLAG_ENV_LIGHT); // list of features that are not enabled on background
featureFlags &= ~(FEATURE_FLAG_LIGHT_PUNCTUAL | FEATURE_FLAG_LIGHT_AREA | FEATURE_FLAG_LIGHT_DIRECTIONAL | FEATURE_FLAG_LIGHT_ENV | 0xFFFFF); // list of features that are not enabled on background
}
uint variant = FeatureFlagsToTileVariant(featureFlags);

18
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/Resources/shadeopaque.compute


#pragma kernel ShadeOpaque_Indirect_Fptl_Variant5 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Fptl_Variant5 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=5
#pragma kernel ShadeOpaque_Indirect_Fptl_Variant6 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Fptl_Variant6 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=6
#pragma kernel ShadeOpaque_Indirect_Fptl_Variant7 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Fptl_Variant7 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=7
#pragma kernel ShadeOpaque_Indirect_Fptl_Variant8 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Fptl_Variant8 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=8
#pragma kernel ShadeOpaque_Indirect_Fptl_Variant9 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Fptl_Variant9 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=9
#pragma kernel ShadeOpaque_Indirect_Fptl_Variant10 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Fptl_Variant10 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=10
#pragma kernel ShadeOpaque_Indirect_Fptl_Variant11 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Fptl_Variant11 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=11
#pragma kernel ShadeOpaque_Indirect_Fptl_Variant12 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Fptl_Variant12 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=12
#pragma kernel ShadeOpaque_Indirect_Fptl_Variant13 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Fptl_Variant13 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=13
#pragma kernel ShadeOpaque_Indirect_Fptl_Variant14 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Fptl_Variant14 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=14
#pragma kernel ShadeOpaque_Indirect_Fptl_Variant15 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Fptl_Variant15 USE_FPTL_LIGHTLIST USE_INDIRECT VARIANT=15
#pragma kernel ShadeOpaque_Indirect_Clustered_Variant0 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Clustered_Variant0 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=0
#pragma kernel ShadeOpaque_Indirect_Clustered_Variant1 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Clustered_Variant1 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=1

#pragma kernel ShadeOpaque_Indirect_Clustered_Variant5 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Clustered_Variant5 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=5
#pragma kernel ShadeOpaque_Indirect_Clustered_Variant6 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Clustered_Variant6 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=6
#pragma kernel ShadeOpaque_Indirect_Clustered_Variant7 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Clustered_Variant7 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=7
#pragma kernel ShadeOpaque_Indirect_Clustered_Variant8 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Clustered_Variant8 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=8
#pragma kernel ShadeOpaque_Indirect_Clustered_Variant9 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Clustered_Variant9 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=9
#pragma kernel ShadeOpaque_Indirect_Clustered_Variant10 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Clustered_Variant10 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=10
#pragma kernel ShadeOpaque_Indirect_Clustered_Variant11 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Clustered_Variant11 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=11
#pragma kernel ShadeOpaque_Indirect_Clustered_Variant12 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Clustered_Variant12 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=12
#pragma kernel ShadeOpaque_Indirect_Clustered_Variant13 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Clustered_Variant13 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=13
#pragma kernel ShadeOpaque_Indirect_Clustered_Variant14 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Clustered_Variant14 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=14
#pragma kernel ShadeOpaque_Indirect_Clustered_Variant15 SHADE_OPAQUE_ENTRY=ShadeOpaque_Indirect_Clustered_Variant15 USE_CLUSTERED_LIGHTLIST USE_INDIRECT VARIANT=15
#pragma #pragma enable_d3d11_debug_symbols

FETCH_GBUFFER(gbuffer, _GBufferTexture, posInput.unPositionSS);
BSDFData bsdfData;
float3 bakeDiffuseLighting;
DECODE_FROM_GBUFFER(gbuffer, bsdfData, bakeDiffuseLighting);
DECODE_FROM_GBUFFER(gbuffer, featureFlags, bsdfData, bakeDiffuseLighting);
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);

43
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


}
[GenerateHLSL]
public class LightFeatureFlags
{
public static uint FEATURE_FLAG_LIGHT_PUNCTUAL = 1 << 0;
public static uint FEATURE_FLAG_LIGHT_AREA = 1 << 1;
public static uint FEATURE_FLAG_LIGHT_DIRECTIONAL = 1 << 2;
public static uint FEATURE_FLAG_LIGHT_ENV = 1 << 3;
public static uint FEATURE_FLAG_LIGHT_SKY = 1 << 4;
}
[GenerateHLSL]
public class LightDefinitions
{
public static int MAX_NR_LIGHTS_PER_CAMERA = 1024;

public static int IS_BOX_PROJECTED = 4;
public static int HAS_SHADOW = 8;
// feature flags
public static uint FEATURE_FLAG_PUNCTUAL_LIGHT = 1 << 0;
public static uint FEATURE_FLAG_AREA_LIGHT = 1 << 1;
public static uint FEATURE_FLAG_DIRECTIONAL_LIGHT = 1 << 2;
public static uint FEATURE_FLAG_ENV_LIGHT = 1 << 3;
public static uint FEATURE_FLAG_SKY_LIGHT = 1 << 4;
public static int NUM_FEATURE_VARIANTS = 8;
public static int NUM_FEATURE_VARIANTS = 16;
}
[GenerateHLSL]

bool GetFeatureVariantsEnabled()
{
return m_PassSettings.enableComputeLightEvaluation && m_PassSettings.enableComputeFeatureVariants;
return m_PassSettings.enableComputeLightEvaluation && m_PassSettings.enableComputeFeatureVariants && !(m_PassSettings.enableClustered && !m_PassSettings.enableFptlForOpaqueWhenClustered);
}
TileLightLoopProducer.TileSettings m_PassSettings;

lightVolumeData.lightPos = worldToView.MultiplyPoint(lightPos);
lightVolumeData.radiusSq = range * range;
lightVolumeData.cotan = cota;
lightVolumeData.featureFlags = LightDefinitions.FEATURE_FLAG_PUNCTUAL_LIGHT;
lightVolumeData.featureFlags = LightFeatureFlags.FEATURE_FLAG_LIGHT_PUNCTUAL;
}
else if (gpuLightType == GPULightType.Point)
{

lightVolumeData.lightAxisZ = vz;
lightVolumeData.lightPos = bound.center;
lightVolumeData.radiusSq = range * range;
lightVolumeData.featureFlags = LightDefinitions.FEATURE_FLAG_PUNCTUAL_LIGHT;
lightVolumeData.featureFlags = LightFeatureFlags.FEATURE_FLAG_LIGHT_PUNCTUAL;
}
else if (gpuLightType == GPULightType.Rectangle)
{

lightVolumeData.lightAxisZ = zAxisVS;
lightVolumeData.boxInnerDist = dimensions;
lightVolumeData.boxInvRange.Set(1e5f, 1e5f, 1e5f);
lightVolumeData.featureFlags = LightDefinitions.FEATURE_FLAG_AREA_LIGHT;
lightVolumeData.featureFlags = LightFeatureFlags.FEATURE_FLAG_LIGHT_AREA;
}
else if (gpuLightType == GPULightType.Line)
{

lightVolumeData.lightAxisZ = zAxisVS;
lightVolumeData.boxInnerDist = new Vector3(lightData.size.x * 0.5f, 0.01f, 0.01f);
lightVolumeData.boxInvRange.Set(1.0f / radius, 1.0f / radius, 1.0f / radius);
lightVolumeData.featureFlags = LightDefinitions.FEATURE_FLAG_AREA_LIGHT;
lightVolumeData.featureFlags = LightFeatureFlags.FEATURE_FLAG_LIGHT_AREA;
}
else
{

lightVolumeData.lightCategory = (uint)LightCategory.Env;
lightVolumeData.lightVolume = (uint)lightVolumeType;
lightVolumeData.featureFlags = LightDefinitions.FEATURE_FLAG_ENV_LIGHT;
lightVolumeData.featureFlags = LightFeatureFlags.FEATURE_FLAG_LIGHT_ENV;
lightVolumeData.lightPos = Cw;
lightVolumeData.lightAxisX = vx;

var invProjscr = projscr.inverse;
var cmd = new CommandBuffer() { name = "" };
cmd.SetRenderTarget(new RenderTargetIdentifier((Texture)null));
// generate screen-space AABBs (used for both fptl and clustered).
if (m_lightCount != 0)

if (m_PassSettings.enableBigTilePrepass)
cmd.SetComputeBufferParam(buildPerTileLightListShader, s_GenListPerTileKernel, "g_vBigTileLightList", s_BigTileLightList);
cmd.SetComputeTextureParam(buildPerTileLightListShader, s_GenListPerTileKernel, "_GBufferTexture0", Shader.PropertyToID("_GBufferTexture0"));
cmd.SetComputeTextureParam(buildPerTileLightListShader, s_GenListPerTileKernel, "_GBufferTexture1", Shader.PropertyToID("_GBufferTexture1"));
cmd.SetComputeTextureParam(buildPerTileLightListShader, s_GenListPerTileKernel, "_GBufferTexture2", Shader.PropertyToID("_GBufferTexture2"));
cmd.SetComputeTextureParam(buildPerTileLightListShader, s_GenListPerTileKernel, "_GBufferTexture3", Shader.PropertyToID("_GBufferTexture3"));
baseFeatureFlags |= LightDefinitions.FEATURE_FLAG_DIRECTIONAL_LIGHT;
baseFeatureFlags |= LightFeatureFlags.FEATURE_FLAG_LIGHT_DIRECTIONAL;
baseFeatureFlags |= LightDefinitions.FEATURE_FLAG_SKY_LIGHT;
baseFeatureFlags |= LightFeatureFlags.FEATURE_FLAG_LIGHT_SKY;
}
cmd.SetComputeBufferParam(buildPerTileLightListShader, s_GenListPerTileKernel, "g_DispatchIndirectBuffer", s_DispatchIndirectBuffer);
cmd.SetComputeBufferParam(buildPerTileLightListShader, s_GenListPerTileKernel, "g_TileList", s_TileList);

cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "_GBufferTexture1", Shader.PropertyToID("_GBufferTexture1"));
cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "_GBufferTexture2", Shader.PropertyToID("_GBufferTexture2"));
cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "_GBufferTexture3", Shader.PropertyToID("_GBufferTexture3"));
//cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "_GBufferTexture4", Shader.PropertyToID("_GBufferTexture4"));
cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "g_tShadowBuffer", Shader.PropertyToID("g_tShadowBuffer"));
cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "_LtcData", Shader.GetGlobalTexture(Shader.PropertyToID("_LtcData")));

16
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl


#define LIGHTCATEGORY_COUNT (3)
//
// UnityEngine.Experimental.Rendering.HDPipeline.TilePass.LightFeatureFlags: static fields
//
#define FEATURE_FLAG_LIGHT_PUNCTUAL (1)
#define FEATURE_FLAG_LIGHT_AREA (2)
#define FEATURE_FLAG_LIGHT_DIRECTIONAL (4)
#define FEATURE_FLAG_LIGHT_ENV (8)
#define FEATURE_FLAG_LIGHT_SKY (16)
//
// UnityEngine.Experimental.Rendering.HDPipeline.TilePass.LightDefinitions: static fields
//
#define MAX_NR_LIGHTS_PER_CAMERA (1024)

#define HAS_COOKIE_TEXTURE (2)
#define IS_BOX_PROJECTED (4)
#define HAS_SHADOW (8)
#define FEATURE_FLAG_PUNCTUAL_LIGHT (1)
#define FEATURE_FLAG_AREA_LIGHT (2)
#define FEATURE_FLAG_DIRECTIONAL_LIGHT (4)
#define FEATURE_FLAG_ENV_LIGHT (8)
#define FEATURE_FLAG_SKY_LIGHT (16)
#define NUM_FEATURE_VARIANTS (8)
#define NUM_FEATURE_VARIANTS (16)
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.TilePass.SFiniteLightBound
// PackingRules = Exact

10
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePassLoop.hlsl


uint i = 0; // Declare once to avoid the D3D11 compiler warning.
#ifdef PROCESS_DIRECTIONAL_LIGHT
if(featureFlags & FEATURE_FLAG_DIRECTIONAL_LIGHT)
if(featureFlags & FEATURE_FLAG_LIGHT_DIRECTIONAL)
{
for(i = 0; i < _DirectionalLightCount; ++i)
{

#endif
#ifdef PROCESS_PUNCTUAL_LIGHT
if(featureFlags & FEATURE_FLAG_PUNCTUAL_LIGHT)
if(featureFlags & FEATURE_FLAG_LIGHT_PUNCTUAL)
{
// TODO: Convert the for loop below to a while on each type as we know we are sorted!
uint punctualLightStart;

#endif
#ifdef PROCESS_AREA_LIGHT
if(featureFlags & FEATURE_FLAG_AREA_LIGHT)
if(featureFlags & FEATURE_FLAG_LIGHT_AREA)
{
// TODO: Convert the for loop below to a while on each type as we know we are sorted!
uint areaLightStart;

float3 iblSpecularLighting = float3(0.0, 0.0, 0.0);
// Only apply sky IBL if the sky texture is available.
if(featureFlags & FEATURE_FLAG_SKY_LIGHT)
if(featureFlags & FEATURE_FLAG_LIGHT_SKY)
{
if(_EnvLightSkyEnabled)
{

}
if(featureFlags & FEATURE_FLAG_ENV_LIGHT)
if(featureFlags & FEATURE_FLAG_LIGHT_ENV)
{
uint envLightStart;
uint envLightCount;

3
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePassProducer.asset


enableTileAndCluster: 1
enableSplitLightEvaluation: 1
enableComputeLightEvaluation: 0
debugViewTilesFlags: 0
enableComputeFeatureVariants: 1
tileDebugByCategory: 0
m_PassResources: {fileID: 11400000, guid: 7f2998544b2ac3848822b80ec3e6c446, type: 2}

10
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs


LitAniso = 4 // Should be the last as it is not setup by the users but generated based on anisotropy property
};
[GenerateHLSL]
public class MaterialFeatureFlags
{
public static uint FEATURE_FLAG_MATERIAL_LIT_STANDARD = 1 << 12;
public static uint FEATURE_FLAG_MATERIAL_LIT_SSS = 1 << 13;
public static uint FEATURE_FLAG_MATERIAL_LIT_CLEAR_COAT = 1 << 14;
public static uint FEATURE_FLAG_MATERIAL_LIT_SPECULAR = 1 << 15;
public static uint FEATURE_FLAG_MATERIAL_LIT_ANISO = 1 << 16;
}
//-----------------------------------------------------------------------------
// SurfaceData
//-----------------------------------------------------------------------------

9
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs.hlsl


#define MATERIALID_LIT_ANISO (4)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Lit.MaterialFeatureFlags: static fields
//
#define FEATURE_FLAG_MATERIAL_LIT_STANDARD (4096)
#define FEATURE_FLAG_MATERIAL_LIT_SSS (8192)
#define FEATURE_FLAG_MATERIAL_LIT_CLEAR_COAT (16384)
#define FEATURE_FLAG_MATERIAL_LIT_SPECULAR (32768)
#define FEATURE_FLAG_MATERIAL_LIT_ANISO (65536)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Lit.SurfaceData: static fields
//
#define DEBUGVIEW_LIT_SURFACEDATA_BASE_COLOR (1000)

153
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


else if (bsdfData.materialId == MATERIALID_LIT_SSS)
{
bsdfData.diffuseColor = surfaceData.baseColor;
bsdfData.fresnel0 = 0.028; // TODO take from subsurfaceProfile
// TODO take from subsurfaceProfile
bsdfData.fresnel0 = 0.04; /* 0.028 ? */
bsdfData.subsurfaceProfile = surfaceData.subsurfaceProfile;
// Make the Std. Dev. of 1 correspond to the effective radius of 1 cm (three-sigma rule).
bsdfData.subsurfaceRadius = SSS_UNIT_CONVERSION * surfaceData.subsurfaceRadius;

}
void DecodeFromGBuffer(
#if SHADEROPTIONS_PACK_GBUFFER_IN_U16
GBufferType0 inGBufferU0,
GBufferType1 inGBufferU1,
#else
GBufferType0 inGBuffer0,
GBufferType1 inGBuffer1,
GBufferType2 inGBuffer2,
GBufferType3 inGBuffer3,
#endif
out BSDFData bsdfData,
out float3 bakeDiffuseLighting)
#if SHADEROPTIONS_PACK_GBUFFER_IN_U16
GBufferType0 inGBufferU0,
GBufferType1 inGBufferU1,
#else
GBufferType0 inGBuffer0,
GBufferType1 inGBuffer1,
GBufferType2 inGBuffer2,
GBufferType3 inGBuffer3,
#endif
uint featureFlags,
out BSDFData bsdfData,
out float3 bakeDiffuseLighting)
#if SHADEROPTIONS_PACK_GBUFFER_IN_U16
#if SHADEROPTIONS_PACK_GBUFFER_IN_U16
float4 inGBuffer0, inGBuffer1, inGBuffer2, inGBuffer3;
inGBuffer0 = DecodeGBuffer0(inGBufferU0);

uint packedGBuffer3 = inGBufferU1.z | inGBufferU1.w << 16;
inGBuffer3.xyz = UnpackR11G11B10f(packedGBuffer1);
inGBuffer3.w = 0.0;
#endif
#endif
float3 baseColor = inGBuffer0.rgb;
bsdfData.specularOcclusion = inGBuffer0.a;

bsdfData.roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness);
bsdfData.materialId = UnpackMaterialId(inGBuffer1.a);
if (bsdfData.materialId == MATERIALID_LIT_STANDARD)
int supportsStandard = (featureFlags & (FEATURE_FLAG_MATERIAL_LIT_STANDARD | FEATURE_FLAG_MATERIAL_LIT_ANISO)) != 0;
int supportsSSS = (featureFlags & (FEATURE_FLAG_MATERIAL_LIT_SSS)) != 0;
int supportsClearCoat = (featureFlags & (MATERIALID_LIT_CLEAR_COAT)) != 0;
int supportsSpecular = (featureFlags & (FEATURE_FLAG_MATERIAL_LIT_SPECULAR)) != 0;
if(supportsStandard + supportsSSS + supportsClearCoat + supportsSpecular > 1)
{
bsdfData.materialId = UnpackMaterialId(inGBuffer1.a); // only fetch materialid if it is not statically known from feature flags
}
else
{
// materialid is statically known. this allows the compiler to eliminate a lot of code.
if(supportsStandard) bsdfData.materialId = MATERIALID_LIT_STANDARD;
else if(supportsSSS) bsdfData.materialId = MATERIALID_LIT_SSS;
else if(supportsClearCoat) bsdfData.materialId = MATERIALID_LIT_CLEAR_COAT;
else bsdfData.materialId = MATERIALID_LIT_SPECULAR;
}
if (supportsStandard && bsdfData.materialId == MATERIALID_LIT_STANDARD)
{
float metallic = inGBuffer2.a;
// TODO extract spec

ConvertAnisotropyToRoughness(bsdfData.roughness, anisotropy, bsdfData.roughnessT, bsdfData.roughnessB);
bsdfData.anisotropy = anisotropy;
bsdfData.materialId = anisotropy > 0 ? MATERIALID_LIT_ANISO : bsdfData.materialId;
if ((featureFlags & FEATURE_FLAG_MATERIAL_LIT_ANISO) && (featureFlags & FEATURE_FLAG_MATERIAL_LIT_STANDARD) == 0 || anisotropy > 0)
{
bsdfData.materialId = MATERIALID_LIT_ANISO;
}
else if (bsdfData.materialId == MATERIALID_LIT_SSS)
else if (supportsSSS && bsdfData.materialId == MATERIALID_LIT_SSS)
bsdfData.fresnel0 = 0.028; // TODO take from subsurfaceProfile
// TODO take from subsurfaceProfile
bsdfData.fresnel0 = 0.04; /* 0.028 ? */
bsdfData.subsurfaceProfile = (SSS_N_PROFILES - 1) * inGBuffer2.a;
// Make the Std. Dev. of 1 correspond to the effective radius of 1 cm (three-sigma rule).
bsdfData.subsurfaceRadius = SSS_UNIT_CONVERSION * inGBuffer2.r;

bsdfData.thickness, bsdfData.subsurfaceRadius);
}
}
else if (bsdfData.materialId == MATERIALID_LIT_CLEAR_COAT)
else if (supportsClearCoat && bsdfData.materialId == MATERIALID_LIT_CLEAR_COAT)
{
float metallic = inGBuffer2.a;
// TODO extract spec

bsdfData.coatNormalWS = UnpackNormalOctEncode(float2(inGBuffer2.rg * 2.0 - 1.0));
bsdfData.coatRoughness = inGBuffer2.b;
}
else if (bsdfData.materialId == MATERIALID_LIT_SPECULAR)
else if (supportsSpecular && bsdfData.materialId == MATERIALID_LIT_SPECULAR)
{
bsdfData.diffuseColor = baseColor;
bsdfData.fresnel0 = inGBuffer2.rgb;

ApplyDebugToBSDFData(bsdfData);
}
uint MaterialFeatureFlagsFromGBuffer(
#if SHADEROPTIONS_PACK_GBUFFER_IN_U16
GBufferType0 inGBufferU0,
GBufferType1 inGBufferU1
#else
GBufferType0 inGBuffer0,
GBufferType1 inGBuffer1,
GBufferType2 inGBuffer2,
GBufferType3 inGBuffer3
#endif
)
{
#if SHADEROPTIONS_PACK_GBUFFER_IN_U16
float4 inGBuffer0, inGBuffer1, inGBuffer2, inGBuffer3;
inGBuffer0 = DecodeGBuffer0(inGBufferU0);
uint packedGBuffer1 = inGBufferU0.z | inGBufferU0.w << 16;
inGBuffer1 = UnpackR10G10B10A2(packedGBuffer1);
inGBuffer2.x = UnpackUIntToFloat(inGBufferU1.x, 8, 0);
inGBuffer2.y = UnpackUIntToFloat(inGBufferU1.x, 8, 8);
inGBuffer2.z = UnpackUIntToFloat(inGBufferU1.y, 8, 0);
inGBuffer2.w = UnpackUIntToFloat(inGBufferU1.y, 8, 8);
uint packedGBuffer3 = inGBufferU1.z | inGBufferU1.w << 16;
inGBuffer3.xyz = UnpackR11G11B10f(packedGBuffer1);
inGBuffer3.w = 0.0;
#endif
int materialId = UnpackMaterialId(inGBuffer1.a);
float anisotropy = inGBuffer2.b;
uint featureFlags = 0;
if (materialId == MATERIALID_LIT_STANDARD)
{
featureFlags |= (anisotropy > 0) ? FEATURE_FLAG_MATERIAL_LIT_ANISO : FEATURE_FLAG_MATERIAL_LIT_STANDARD;
}
else if (materialId == MATERIALID_LIT_SSS)
{
featureFlags |= FEATURE_FLAG_MATERIAL_LIT_SSS;
}
else if (materialId == MATERIALID_LIT_CLEAR_COAT)
{
featureFlags |= FEATURE_FLAG_MATERIAL_LIT_CLEAR_COAT;
}
else if (materialId == MATERIALID_LIT_SPECULAR)
{
featureFlags |= FEATURE_FLAG_MATERIAL_LIT_SPECULAR;
}
return featureFlags;
}
//-----------------------------------------------------------------------------
// Debug method (use to display values)
//-----------------------------------------------------------------------------

out float3 diffuseLighting,
out float3 specularLighting)
{
float3 H = normalize(V + L);
float LdotH = saturate(dot(L, H));
float NdotH = saturate(dot(bsdfData.normalWS, H));
float NdotL = saturate(dot(bsdfData.normalWS, L));
float NdotL = saturate(dot(bsdfData.normalWS, L));
float NdotV = preLightData.NdotV;
float LdotV = dot(L, V);
float invLenLV = rsqrt(abs(2 + 2 * LdotV)); // invLenLV = rcp(length(L + V))
float NdotH = saturate((NdotL + NdotV) * invLenLV);
float LdotH = saturate(invLenLV + invLenLV * LdotV);
float3 F = F_Schlick(bsdfData.fresnel0, LdotH);
float Vis;

if (bsdfData.materialId == MATERIALID_LIT_ANISO)
{
float3 H = (L + V) * invLenLV;
// For anisotropy we must not saturate these values
float TdotH = dot(bsdfData.tangentWS, H);
float TdotL = dot(bsdfData.tangentWS, L);

bsdfData.roughnessB = ClampRoughnessForAnalyticalLights(bsdfData.roughnessB);
#ifdef LIT_USE_BSDF_PRE_LAMBDAV
Vis = V_SmithJointGGXAnisoLambdaV( preLightData.TdotV, preLightData.BdotV, preLightData.NdotV, TdotL, BdotL, NdotL,
Vis = V_SmithJointGGXAnisoLambdaV( preLightData.TdotV, preLightData.BdotV, NdotV, TdotL, BdotL, NdotL,
Vis = V_SmithJointGGXAniso( preLightData.TdotV, preLightData.BdotV, preLightData.NdotV, TdotL, BdotL, NdotL,
Vis = V_SmithJointGGXAniso( preLightData.TdotV, preLightData.BdotV, NdotV, TdotL, BdotL, NdotL,
bsdfData.roughnessT, bsdfData.roughnessB);
#endif

bsdfData.roughness = ClampRoughnessForAnalyticalLights(bsdfData.roughness);
#ifdef LIT_USE_BSDF_PRE_LAMBDAV
Vis = V_SmithJointGGX(NdotL, preLightData.NdotV, bsdfData.roughness, preLightData.ggxLambdaV);
Vis = V_SmithJointGGX(NdotL, NdotV, bsdfData.roughness, preLightData.ggxLambdaV);
Vis = V_SmithJointGGX(NdotL, preLightData.NdotV, bsdfData.roughness);
Vis = V_SmithJointGGX(NdotL, NdotV, bsdfData.roughness);
#ifdef LIT_DIFFUSE_LAMBERT_BRDF
float diffuseTerm = Lambert();
#else
float diffuseTerm = DisneyDiffuse(preLightData.NdotV, NdotL, LdotH, bsdfData.perceptualRoughness);
#endif
#ifdef LIT_DIFFUSE_LAMBERT_BRDF
float diffuseTerm = Lambert();
#elif LIT_DIFFUSE_GGX_BRDF
float3 diffuseTerm = DiffuseGGX(bsdfData.diffuseColor, NdotV, NdotL, NdotH, LdotV, bsdfData.perceptualRoughness);
#else
float diffuseTerm = DisneyDiffuse(NdotV, NdotL, LdotH, bsdfData.perceptualRoughness);
#endif
diffuseLighting = bsdfData.diffuseColor * diffuseTerm;
}

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader


BSDFData bsdfData;
FETCH_GBUFFER(gbuffer, _GBufferTexture, posInput.unPositionSS);
DECODE_FROM_GBUFFER(gbuffer, bsdfData, unused);
DECODE_FROM_GBUFFER(gbuffer, 0xFFFFFFFF, bsdfData, unused);
int profileID = bsdfData.subsurfaceProfile;
float distScale = bsdfData.subsurfaceRadius;

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringProfile.cs


halfRcpVariancesAndLerpWeights = null;
halfRcpWeightedVariances = null;
filterKernels = null;
OnValidate(); // Perform initialization
}
public void OnValidate()

13
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Material.hlsl


GBufferType1 MERGE_NAME(NAME, 1) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 1), unCoord2);
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, NAME) EncodeIntoGBuffer(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1))
#define DECODE_FROM_GBUFFER(NAME, BSDF_DATA, BAKE_DIFFUSE_LIGHTING) DecodeFromGBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), BSDF_DATA, BAKE_DIFFUSE_LIGHTING)
#define DECODE_FROM_GBUFFER(NAME, FEATURE_FLAGS, BSDF_DATA, BAKE_DIFFUSE_LIGHTING) DecodeFromGBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), FEATURE_FLAGS, BSDF_DATA, BAKE_DIFFUSE_LIGHTING)
#define MATERIAL_FEATURE_FLAGS_FROM_GBUFFER(NAME) MaterialFeatureFlagsFromGBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1))
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target2

GBufferType2 MERGE_NAME(NAME, 2) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 2), unCoord2);
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, NAME) EncodeIntoGBuffer(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2))
#define DECODE_FROM_GBUFFER(NAME, BSDF_DATA, BAKE_DIFFUSE_LIGHTING) DecodeFromGBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2), BSDF_DATA, BAKE_DIFFUSE_LIGHTING)
#define DECODE_FROM_GBUFFER(NAME, FEATURE_FLAGS, BSDF_DATA, BAKE_DIFFUSE_LIGHTING) DecodeFromGBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2), FEATURE_FLAGS, BSDF_DATA, BAKE_DIFFUSE_LIGHTING)
#define MATERIAL_FEATURE_FLAGS_FROM_GBUFFER(NAME) MaterialFeatureFlagsFromGBuffer(MERGE_NAME(NAME,0), MERGE_NAME(NAME,1), MERGE_NAME(NAME,2))
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target3

GBufferType3 MERGE_NAME(NAME, 3) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 3), unCoord2);
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, NAME) EncodeIntoGBuffer(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3))
#define DECODE_FROM_GBUFFER(NAME, BSDF_DATA, BAKE_DIFFUSE_LIGHTING) DecodeFromGBuffer(MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), BSDF_DATA, BAKE_DIFFUSE_LIGHTING)
#define DECODE_FROM_GBUFFER(NAME, FEATURE_FLAGS, BSDF_DATA, BAKE_DIFFUSE_LIGHTING) DecodeFromGBuffer(MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), FEATURE_FLAGS, BSDF_DATA, BAKE_DIFFUSE_LIGHTING)
#define MATERIAL_FEATURE_FLAGS_FROM_GBUFFER(NAME) MaterialFeatureFlagsFromGBuffer(MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3))
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target4

GBufferType4 MERGE_NAME(NAME, 4) = LOAD_TEXTURE2D(MERGE_NAME(TEX, 4), unCoord2);
#define ENCODE_INTO_GBUFFER(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, NAME) EncodeIntoGBuffer(SURFACE_DATA, BAKE_DIFFUSE_LIGHTING, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), MERGE_NAME(NAME, 4))
#define DECODE_FROM_GBUFFER(NAME, BSDF_DATA, BAKE_DIFFUSE_LIGHTING) DecodeFromGBuffer(MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), MERGE_NAME(NAME, 4), BSDF_DATA, BAKE_DIFFUSE_LIGHTING)
#define DECODE_FROM_GBUFFER(NAME, FEATURE_FLAGS, BSDF_DATA, BAKE_DIFFUSE_LIGHTING) DecodeFromGBuffer(MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), MERGE_NAME(NAME, 4), FEATURE_FLAGS, BSDF_DATA, BAKE_DIFFUSE_LIGHTING)
#define MATERIAL_FEATURE_FLAGS_FROM_GBUFFER(NAME) MaterialFeatureFlagsFromGBuffer(MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1), MERGE_NAME(NAME, 2), MERGE_NAME(NAME, 3), MERGE_NAME(NAME, 4))
#if SHADEROPTIONS_VELOCITY_IN_GBUFFER
#define OUTPUT_GBUFFER_VELOCITY(NAME) ,out float4 NAME : SV_Target5

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl


FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw, uint2(0, 0));
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);
UpdatePositionInput(input.unPositionSS.z, input.unPositionSS.w, input.positionWS, posInput);
float3 V = GetWorldSpaceNormalizeViewDir(input.positionWS);

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassDistortion.hlsl


FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw, uint2(0, 0));
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);
UpdatePositionInput(input.unPositionSS.z, input.unPositionSS.w, input.positionWS, posInput);
float3 V = GetWorldSpaceNormalizeViewDir(input.positionWS);

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl


FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw, uint2(0, 0));
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);
UpdatePositionInput(input.unPositionSS.z, input.unPositionSS.w, input.positionWS, posInput);
float3 V = GetWorldSpaceNormalizeViewDir(input.positionWS);

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl


FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw, uint2(0, 0));
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);
UpdatePositionInput(input.unPositionSS.z, input.unPositionSS.w, input.positionWS, posInput);
float3 V = GetWorldSpaceNormalizeViewDir(input.positionWS);

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl


FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw, uint2(0, 0));
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);
// No position and depth in case of light transport
float3 V = float3(0, 0, 1); // No vector view in case of light transport

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassVelocity.hlsl


FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
// input.unPositionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw, uint2(0, 0));
PositionInputs posInput = GetPositionInput(input.unPositionSS.xy, _ScreenSize.zw);
UpdatePositionInput(input.unPositionSS.z, input.unPositionSS.w, input.positionWS, posInput);
float3 V = GetWorldSpaceNormalizeViewDir(input.positionWS);

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Editor/HDRISkyEditor.cs


public readonly GUIContent skyMultiplier = new GUIContent("Multiplier", "Intensity multiplier for the sky.");
public readonly GUIContent environmentUpdateMode = new GUIContent("Environment Update Mode", "Specify how the environment lighting should be updated.");
public readonly GUIContent environmentUpdatePeriod = new GUIContent("Environment Update Period", "If environment update is set to realtime, period in seconds at which it is updated (0.0 means every frame).");
public readonly GUIContent lightingOverride = new GUIContent("Lighting Override", "If a lighting override cubemap is provided, this cubemap will be used to compute lighting instead of the result from the visible sky.");
}
private static Styles s_Styles = null;

private SerializedProperty m_SkyRotation;
private SerializedProperty m_EnvUpdateMode;
private SerializedProperty m_EnvUpdatePeriod;
private SerializedProperty m_LightingOverride;
void OnEnable()
{

m_SkyRotation = serializedObject.FindProperty("rotation");
m_EnvUpdateMode = serializedObject.FindProperty("updateMode");
m_EnvUpdatePeriod = serializedObject.FindProperty("updatePeriod");
m_LightingOverride = serializedObject.FindProperty("lightingOverride");
}
public override void OnInspectorGUI()

{
EditorGUILayout.PropertyField(m_EnvUpdatePeriod, styles.environmentUpdatePeriod);
}
EditorGUILayout.PropertyField(m_LightingOverride, styles.lightingOverride);
serializedObject.ApplyModifiedProperties();
}

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Resources/SkyProcedural.shader


float3 rotatedDir = float3(dot(rotDirX, dir), dir.y, dot(rotDirY, dir));
// input.positionCS is SV_Position
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw, uint2(0,0));
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw);
// An arbitrary value attempting to match the size of the sky mesh from the Blacksmith demo.
const float skyDepth = 0.00025;

84
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs


RenderTexture m_SkyboxConditionalCdfRT = null;
Material m_StandardSkyboxMaterial = null; // This is the Unity standard skybox material. Used to pass the correct cubemap to Enlighten.
Material m_BlitCubemapMaterial = null;
IBLFilterGGX m_iblFilterGgx = null;

m_iblFilterGgx = new IBLFilterGGX();
// TODO: We need to have an API to send our sky information to Enlighten. For now use a workaround through skybox/cubemap material...
m_StandardSkyboxMaterial = Utilities.CreateEngineMaterial("Skybox/Cubemap");
m_StandardSkyboxMaterial = Utilities.CreateEngineMaterial("Skybox/Cubemap");
m_BlitCubemapMaterial = Utilities.CreateEngineMaterial("Hidden/BlitCubemap");
m_CurrentUpdateTime = 0.0f;
}

}
}
private void BlitCubemap(ScriptableRenderContext renderContext, Cubemap source, RenderTexture dest)
{
MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
for (int i = 0; i < 6; ++i)
{
Utilities.SetRenderTarget(renderContext, dest, ClearFlag.ClearNone, 0, (CubemapFace)i);
var cmd = new CommandBuffer { name = "" };
propertyBlock.SetTexture("_MainTex", source);
propertyBlock.SetFloat("_faceIndex", (float)i);
cmd.DrawProcedural(Matrix4x4.identity, m_BlitCubemapMaterial, 0, MeshTopology.Triangles, 3, 1, propertyBlock);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}
private void RenderCubemapGGXConvolution(ScriptableRenderContext renderContext, BuiltinSkyParameters builtinParams, SkySettings skyParams, Texture input, RenderTexture target)
{
using (new Utilities.ProfilingSample("Sky Pass: GGX Convolution", renderContext))

)
{
// Render sky into a cubemap - doesn't happen every frame, can be controlled
RenderSkyToCubemap(m_BuiltinParameters, skySettings, m_SkyboxCubemapRT);
if(m_SkySettings.lightingOverride == null)
RenderSkyToCubemap(m_BuiltinParameters, skySettings, m_SkyboxCubemapRT);
// In case the user overrides the lighting, we already have a cubemap ready but we need to blit it anyway for potential resize and so that we can generate proper mipmaps for enlighten.
else
BlitCubemap(renderContext, m_SkySettings.lightingOverride, m_SkyboxCubemapRT);
// Convolve downsampled cubemap
RenderCubemapGGXConvolution(renderContext, m_BuiltinParameters, skySettings, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT);

m_Renderer.RenderSky(m_BuiltinParameters, skySettings, false);
}
}
}
public Texture2D ExportSkyToTexture()
{
if(m_Renderer == null)
{
Debug.LogError("Cannot export sky to a texture, no SkyRenderer is setup.");
return null;
}
if(m_SkySettings == null)
{
Debug.LogError("Cannot export sky to a texture, no Sky settings are setup.");
return null;
}
int resolution = (int)m_SkySettings.resolution;
RenderTexture tempRT = new RenderTexture(resolution * 6, resolution, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
tempRT.dimension = TextureDimension.Tex2D;
tempRT.useMipMap = false;
tempRT.autoGenerateMips = false;
tempRT.filterMode = FilterMode.Trilinear;
tempRT.Create();
Texture2D temp = new Texture2D(resolution * 6, resolution, TextureFormat.RGBAFloat, false);
Texture2D result = new Texture2D(resolution * 6, resolution, TextureFormat.RGBAFloat, false);
// Note: We need to invert in Y the cubemap faces because the current sky cubemap is inverted (because it's a RT)
// So to invert it again so that it's a proper cubemap image we need to do it in several steps because ReadPixels does not have scale parameters:
// - Convert the cubemap into a 2D texture
// - Blit and invert it to a temporary target.
// - Read this target again into the result texture.
int offset = 0;
for (int i = 0; i < 6; ++i)
{
Graphics.SetRenderTarget(m_SkyboxCubemapRT, 0, (CubemapFace)i);
temp.ReadPixels(new Rect(0, 0, resolution, resolution), offset, 0);
temp.Apply();
offset += resolution;
}
// Flip texture.
// Temporarily disabled until proper API reaches trunk
//Graphics.Blit(temp, tempRT, new Vector2(1.0f, -1.0f), new Vector2(0.0f, 0.0f));
Graphics.Blit(temp, tempRT);
result.ReadPixels(new Rect(0, 0, resolution * 6, resolution), 0, 0);
result.Apply();
Graphics.SetRenderTarget(null);
Object.DestroyImmediate(temp);
Object.DestroyImmediate(tempRT);
return result;
}
}
}

1
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs


public SkyResolution resolution = SkyResolution.SkyResolution256;
public EnvironementUpdateMode updateMode = EnvironementUpdateMode.OnChanged;
public float updatePeriod = 0.0f;
public Cubemap lightingOverride = null;
private FieldInfo[] m_Properties;

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Utilities.cs


HDRenderPipeline renderContext = GraphicsSettings.renderPipelineAsset as HDRenderPipeline;
if (renderContext == null)
{
Debug.LogWarning("SkyParameters component can only be used with HDRenderPipeline custom RenderPipeline.");
Debug.LogWarning("HDRenderPipeline is not instantiated.");
return null;
}

3
Assets/ScriptableRenderPipeline/RenderPasses/ShadowRenderPass.cs


var settings = new DrawShadowsSettings(cullResults, lightIndex);
bool needRendering = cullResults.ComputePointShadowMatricesAndCullingPrimitives(lightIndex, (CubemapFace)s, 2.0f, out view, out proj, out settings.splitData);
// The view matrix for point lights flips primitives. We fix it here (by making it left-handed).
view.SetRow(1, -view.GetRow(1));
SetupShadowSplitMatrices(ref shadowSlices[shadowSliceIndex], proj, view);
if (needRendering)
RenderShadowSplit(ref shadowSlices[shadowSliceIndex], lightDirection, proj, view, ref loop, settings);

21
Assets/ScriptableRenderPipeline/ShaderLibrary/BSDF.hlsl


return INV_PI * DisneyDiffuseNoPI(NdotV, NdotL, LdotH, perceptualRoughness);
}
// Ref: Diffuse Lighting for GGX + Smith Microsurfaces, p. 113.
float3 DiffuseGGXNoPI(float3 albedo, float NdotV, float NdotL, float NdotH, float LdotV, float perceptualRoughness)
{
float facing = 0.5 + 0.5 * LdotV;
float rough = facing * (0.9 - 0.4 * facing) * ((0.5 + NdotH) / NdotH);
float transmitL = 1 - F_Schlick(0, 1, NdotL);
float transmitV = 1 - F_Schlick(0, 1, NdotV);
float smooth = transmitL * transmitV * 1.05; // Normalize F_t over the hemisphere
float single = lerp(smooth, rough, perceptualRoughness); // Rescaled by PI
// This constant is picked s.t. setting perceptualRoughness, albedo and all angles to 1
// allows us to match the Lambertian and the Disney Diffuse models. Original value: 0.1159.
float multiple = perceptualRoughness * (0.079577 * PI); // Rescaled by PI
return single + albedo * multiple;
}
float3 DiffuseGGX(float3 albedo, float NdotV, float NdotL, float NdotH, float LdotV, float perceptualRoughness)
{
// Note that we could save 2 cycles by inlining the multiplication by INV_PI.
return INV_PI * DiffuseGGXNoPI(albedo, NdotV, NdotL, NdotH, LdotV, perceptualRoughness);
}
#endif // UNITY_BSDF_INCLUDED

5
Assets/ScriptableRenderPipeline/ShaderLibrary/Common.hlsl


return posInput;
}
PositionInputs GetPositionInput(float2 unPositionSS, float2 invScreenSize)
{
return GetPositionInput(unPositionSS, invScreenSize, uint2(0, 0));
}
// From forward
// depthRaw and depthVS come directly form .zw of SV_Position
void UpdatePositionInput(float depthRaw, float depthVS, float3 positionWS, inout PositionInputs posInput)

110
Assets/TestScenes/HDTest/GlobalIlluminationTest.unity


m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_IndirectSpecularColor: {r: 0.3199536, g: 0.2875398, b: 0.2644253, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 20738779}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &29795110
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 29795112}
- component: {fileID: 29795111}
m_Layer: 0
m_Name: Scene Settings
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &29795111
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 29795110}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0e34c98127e05d340ba44a1d4a734454, type: 3}
m_Name:
m_EditorClassIdentifier:
m_CommonSettings: {fileID: 11400000, guid: 99a5b1b4f3634864da02f42919203da9, type: 2}
m_SkySettings: {fileID: 11400000, guid: 6708eedd5f11b464aa0e50eb2f100ae4, type: 2}
--- !u!4 &29795112
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 29795110}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &32562342
GameObject:
m_ObjectHideFlags: 0

- {x: -1, y: 1, z: -1}
- {x: -1, y: -1, z: 1}
- {x: -1, y: -1, z: -1}
--- !u!1 &1944423445
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1944423448}
- component: {fileID: 1944423447}
- component: {fileID: 1944423446}
m_Layer: 0
m_Name: SceneSettings
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1944423446
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1944423445}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 59b6606ef2548734bb6d11b9d160bc7e, type: 3}
m_Name:
m_EditorClassIdentifier:
rotation: 0
exposure: 0
multiplier: 1
resolution: 256
updateMode: 0
updatePeriod: 0
skyHDRI: {fileID: 8900000, guid: de78f930088fc194290da7400c89bfb5, type: 3}
--- !u!114 &1944423447
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1944423445}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bc357c46587fc9d4cb8f311794d7d2f3, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Settings:
m_ShadowMaxDistance: 1000
m_ShadowCascadeCount: 4
m_ShadowCascadeSplit0: 0.05
m_ShadowCascadeSplit1: 0.2
m_ShadowCascadeSplit2: 0.3
m_ShadowNearPlaneOffset: 5
--- !u!4 &1944423448
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1944423445}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

9
Assets/ScriptableRenderPipeline/common/Resources.meta


fileFormatVersion: 2
guid: 1e02c245110074e4aa88a9b408060d4f
folderAsset: yes
timeCreated: 1491318329
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

20
Assets/TestScenes/HDTest/GlobalIlluminationTest/CommonSettings_GlobalIllumination.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bc357c46587fc9d4cb8f311794d7d2f3, type: 3}
m_Name: CommonSettings_GlobalIllumination
m_EditorClassIdentifier:
m_Settings:
m_ShadowMaxDistance: 400
m_ShadowCascadeCount: 4
m_ShadowCascadeSplit0: 0.05
m_ShadowCascadeSplit1: 0.2
m_ShadowCascadeSplit2: 0.3
m_ShadowNearPlaneOffset: 5

9
Assets/TestScenes/HDTest/GlobalIlluminationTest/CommonSettings_GlobalIllumination.asset.meta


fileFormatVersion: 2
guid: 99a5b1b4f3634864da02f42919203da9
timeCreated: 1491228144
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

20
Assets/TestScenes/HDTest/GlobalIlluminationTest/HDRISkySettings_GlobalIllumination.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 59b6606ef2548734bb6d11b9d160bc7e, type: 3}
m_Name: HDRISkySettings_GlobalIllumination
m_EditorClassIdentifier:
rotation: 0
exposure: 0
multiplier: 1
resolution: 256
updateMode: 0
updatePeriod: 0
skyHDRI: {fileID: 8900000, guid: de78f930088fc194290da7400c89bfb5, type: 3}

9
Assets/TestScenes/HDTest/GlobalIlluminationTest/HDRISkySettings_GlobalIllumination.asset.meta


fileFormatVersion: 2
guid: 6708eedd5f11b464aa0e50eb2f100ae4
timeCreated: 1488464830
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderPipeline/common/Resources/BlitCubemap.shader.meta


fileFormatVersion: 2
guid: d05913e251bed7a4992c921c62e1b647
timeCreated: 1491318357
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

56
Assets/ScriptableRenderPipeline/common/Resources/BlitCubemap.shader


// Note: This shader is supposed to be removed at some point when Graphics.ConvertTexture can take a RenderTexture as a destination (it's only used by sky manager for now).
Shader "Hidden/BlitCubemap" {
SubShader {
// Cubemap blit. Takes a face index.
Pass {
ZTest Always Cull Off ZWrite Off
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 4.5
#include "../../ShaderLibrary/Common.hlsl"
TEXTURECUBE(_MainTex);
SAMPLERCUBE(sampler_MainTex);
float _faceIndex;
struct appdata_t {
uint vertexID : SV_VertexID;
};
struct v2f {
float4 vertex : SV_POSITION;
float3 texcoord : TEXCOORD0;
};
static const float3 faceU[6] = { float3(0, 0, -1), float3(0, 0, 1), float3(1, 0, 0), float3(1, 0, 0), float3(1, 0, 0), float3(-1, 0, 0) };
static const float3 faceV[6] = { float3(0, -1, 0), float3(0, -1, 0), float3(0, 0, 1), float3(0, 0, -1), float3(0, -1, 0), float3(0, -1, 0) };
v2f vert (appdata_t v)
{
v2f o;
o.vertex = GetFullScreenTriangleVertexPosition(v.vertexID);
float2 uv = GetFullScreenTriangleTexcoord(v.vertexID) * 2.0 - 1.0;
int idx = (int)_faceIndex;
float3 transformU = faceU[idx];
float3 transformV = faceV[idx];
float3 n = cross(transformV, transformU);
o.texcoord = n + uv.x * transformU + uv.y * transformV;
return o;
}
float4 frag (v2f i) : SV_Target
{
return SAMPLE_TEXTURECUBE(_MainTex, sampler_MainTex, i.texcoord);
}
ENDHLSL
}
}
Fallback Off
}
正在加载...
取消
保存