sebastienlagarde
7 年前
当前提交
5a6d78c4
共有 179 个文件被更改,包括 4670 次插入 和 2193 次删除
-
4ScriptableRenderPipeline/Core/Debugging/DebugActionManager.cs
-
3ScriptableRenderPipeline/Core/Debugging/DebugItemHandler.cs
-
9ScriptableRenderPipeline/Core/Debugging/DebugPanel.cs
-
7ScriptableRenderPipeline/Core/Debugging/DebugPanelUI.cs
-
9ScriptableRenderPipeline/Core/ShaderLibrary/Shadow/Shadow.hlsl
-
310ScriptableRenderPipeline/Core/ShaderLibrary/Shadow/ShadowAlgorithms.hlsl
-
46ScriptableRenderPipeline/Core/ShaderLibrary/Shadow/ShadowSampling.hlsl
-
32ScriptableRenderPipeline/Core/ShaderLibrary/Wind.hlsl
-
3ScriptableRenderPipeline/Core/Shadow/AdditionalShadowData.cs
-
11ScriptableRenderPipeline/Core/Shadow/Shadow.cs
-
9ScriptableRenderPipeline/Core/TextureCache.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/AdditionalData/HDAdditionalCameraData.cs
-
109ScriptableRenderPipeline/HDRenderPipeline/AdditionalData/HDAdditionalLightData.cs
-
4ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs
-
18ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs.hlsl
-
8ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.hlsl
-
5ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugFullScreen.shader
-
38ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
-
63ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
-
505ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
-
927ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.asset
-
6ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.cs
-
14ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs
-
6ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl
-
10ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/Deferred.compute
-
20ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/LightingConvexHullUtils.hlsl
-
3ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/ShadowContext.hlsl
-
25ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/ShadowDispatch.hlsl
-
188ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
-
4ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl
-
2ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.hlsl
-
5ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/builddispatchindirect.compute
-
2ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/lightlistbuild-clustered.compute
-
6ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/scrbound.compute
-
2ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/VolumetricLighting.cs
-
72ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs
-
63ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
-
88ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
-
123ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs
-
14ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs
-
15ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs.hlsl
-
196ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
-
65ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
-
54ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
-
15ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
-
26ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitReference.hlsl
-
120ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.hlsl
-
78ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader
-
1ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SSSProfile.meta
-
15ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/ShaderPass/LitDepthPass.hlsl
-
6ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/ShaderPass/LitDistortionPass.hlsl
-
11ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/ShaderPass/LitMetaPass.hlsl
-
20ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/ShaderPass/LitVelocityPass.hlsl
-
28ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringProfile.cs
-
16ScriptableRenderPipeline/HDRenderPipeline/Material/Material.hlsl
-
10ScriptableRenderPipeline/HDRenderPipeline/Material/MaterialUtilities.hlsl
-
56ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Editor/BaseUnlitUI.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Unlit.shader
-
3ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/DefaultAmbientOcclusionSettings.asset
-
10ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/DefaultHDMaterial.mat
-
2ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset
-
2ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset.meta
-
60ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineResources.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/ShaderConfig.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/ShaderConfig.cs.hlsl
-
17ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassForward.hlsl
-
13ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/TessellationShare.hlsl
-
10ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/VaryingMesh.hlsl
-
49ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/VertMesh.hlsl
-
2ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs
-
20ScriptableRenderPipeline/HDRenderPipeline/Utilities.cs
-
25ScriptableRenderPipeline/Core/ShadowIncludes.inl
-
8ScriptableRenderPipeline/Core/ShadowIncludes.inl.meta
-
63ScriptableRenderPipeline/HDRenderPipeline/Editor/SceneSettingsManagementWindow.cs
-
12ScriptableRenderPipeline/HDRenderPipeline/Editor/SceneSettingsManagementWindow.cs.meta
-
185ScriptableRenderPipeline/HDRenderPipeline/HDShaderIDs.cs
-
13ScriptableRenderPipeline/HDRenderPipeline/HDShaderIDs.cs.meta
-
10ScriptableRenderPipeline/HDRenderPipeline/Material/Eye.meta
-
10ScriptableRenderPipeline/HDRenderPipeline/Material/Fabric.meta
-
10ScriptableRenderPipeline/HDRenderPipeline/Material/Hair.meta
-
265ScriptableRenderPipeline/HDRenderPipeline/Material/LightEvaluationShare1.hlsl
-
10ScriptableRenderPipeline/HDRenderPipeline/Material/LightEvaluationShare1.hlsl.meta
-
601ScriptableRenderPipeline/HDRenderPipeline/Material/LightEvaluationShare2.hlsl
-
10ScriptableRenderPipeline/HDRenderPipeline/Material/LightEvaluationShare2.hlsl.meta
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Eye/Editor.meta
-
353ScriptableRenderPipeline/HDRenderPipeline/Material/Eye/Editor/BaseEyeUI.cs
-
12ScriptableRenderPipeline/HDRenderPipeline/Material/Eye/Editor/BaseEyeUI.cs.meta
-
469ScriptableRenderPipeline/HDRenderPipeline/Material/Eye/Editor/EyeUI.cs
-
12ScriptableRenderPipeline/HDRenderPipeline/Material/Eye/Editor/EyeUI.cs.meta
-
284ScriptableRenderPipeline/HDRenderPipeline/Material/Eye/Eye.cs
-
236ScriptableRenderPipeline/HDRenderPipeline/Material/Eye/Eye.cs.hlsl
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Eye/Eye.cs.hlsl.meta
-
12ScriptableRenderPipeline/HDRenderPipeline/Material/Eye/Eye.cs.meta
-
174ScriptableRenderPipeline/HDRenderPipeline/Material/Eye/Eye.hlsl
-
9ScriptableRenderPipeline/HDRenderPipeline/Material/Eye/Eye.hlsl.meta
-
361ScriptableRenderPipeline/HDRenderPipeline/Material/Eye/Eye.shader
|
|||
// This file is inlined by ShaderLibrary/Shadow/Shadow.hlsl twice. |
|||
// Each time either SHADOW_CONTEXT_INCLUDE or SHADOW_DISPATCH_INCLUDE is defined. |
|||
// In the case of SHADOW_CONTEXT_INCLUDE a valid path must be given to a file that contains |
|||
// the code to initialize a shadow context. |
|||
// SHADOW_DISPATCH_INCLUDE is optional. |
|||
|
|||
#ifdef SHADOW_CONTEXT_INCLUDE |
|||
# ifdef SHADOW_TILEPASS |
|||
# include "../HDRenderPipeline/Lighting/TilePass/ShadowContext.hlsl" |
|||
# elif defined( SHADOW_FPTL ) |
|||
# include "../../TestbedPipelines/fptl/ShadowContext.hlsl" |
|||
# else |
|||
# error "No valid path to the shadow context has been given." |
|||
# endif |
|||
#endif |
|||
|
|||
#ifdef SHADOW_DISPATCH_INCLUDE |
|||
# ifdef SHADOW_TILEPASS |
|||
# include "../HDRenderPipeline/Lighting/TilePass/ShadowDispatch.hlsl" |
|||
# elif defined( SHADOW_FPTL ) |
|||
# include "../../TestbedPipelines/fptl/ShadowDispatch.hlsl" |
|||
# else |
|||
// It's ok not to have a dispatcher include as it only acts as an override |
|||
# endif |
|||
#endif |
|
|||
fileFormatVersion: 2 |
|||
guid: cbc2765f95de56a47a8f39f5f1badd58 |
|||
timeCreated: 1491314187 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class SceneSettingsManagementWindow : EditorWindow |
|||
{ |
|||
[MenuItem("HDRenderPipeline/Scene Settings Management")] |
|||
static void SceneSettingsManagement() |
|||
{ |
|||
GetWindow<SceneSettingsManagementWindow>().Show(); |
|||
} |
|||
|
|||
static private string m_LastCreationPath = "Assets"; |
|||
|
|||
void CreateAsset<AssetType>(string assetName) where AssetType : ScriptableObject |
|||
{ |
|||
string assetPath = EditorUtility.SaveFilePanel("Create new Asset", m_LastCreationPath, assetName, "asset"); |
|||
if (!string.IsNullOrEmpty(assetPath)) |
|||
{ |
|||
assetPath = assetPath.Substring(assetPath.LastIndexOf("Assets")); |
|||
m_LastCreationPath = System.IO.Path.GetDirectoryName(assetPath); |
|||
var instance = CreateInstance<AssetType>(); |
|||
AssetDatabase.CreateAsset(instance, assetPath); |
|||
} |
|||
} |
|||
|
|||
void OnGUI() |
|||
{ |
|||
// Keep it there temporarily until it's back to an "engine" setting in the HDRenderPipeline asset.
|
|||
EditorGUILayout.Space(); |
|||
|
|||
if (GUILayout.Button("Create new Common Settings")) |
|||
{ |
|||
CreateAsset<CommonSettings>("NewCommonSettings"); |
|||
} |
|||
|
|||
if (GUILayout.Button("Create new HDRI Sky Settings")) |
|||
{ |
|||
CreateAsset<HDRISkySettings>("NewHDRISkySettings"); |
|||
} |
|||
|
|||
if (GUILayout.Button("Create new Procedural Sky Settings")) |
|||
{ |
|||
CreateAsset<ProceduralSkySettings>("NewProceduralSkySettings"); |
|||
} |
|||
|
|||
if (GUILayout.Button("Create new Ambient Occlusion Settings")) |
|||
{ |
|||
CreateAsset<ScreenSpaceAmbientOcclusionSettings>("NewAmbientOcclusionSettings"); |
|||
} |
|||
|
|||
EditorGUILayout.Space(); |
|||
|
|||
if (GUILayout.Button("Create Scene Settings")) |
|||
{ |
|||
var manager = new GameObject(); |
|||
manager.name = "Scene Settings"; |
|||
manager.AddComponent<SceneSettings>(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a6a2e8d7ee3eb2c46962c9b49ff6c8ef |
|||
timeCreated: 1485262288 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
// Pre-hashed shader ids - naming conventions are a bit off in this file as we use the same
|
|||
// fields names as in the shaders for ease of use... Would be nice to clean this up at some
|
|||
// point.
|
|||
static class HDShaderIDs |
|||
{ |
|||
internal static readonly int _ShadowDatasExp = Shader.PropertyToID("_ShadowDatasExp"); |
|||
internal static readonly int _ShadowPayloads = Shader.PropertyToID("_ShadowPayloads"); |
|||
internal static readonly int _ShadowmapExp_VSM_0 = Shader.PropertyToID("_ShadowmapExp_VSM_0"); |
|||
internal static readonly int _ShadowmapExp_VSM_1 = Shader.PropertyToID("_ShadowmapExp_VSM_1"); |
|||
internal static readonly int _ShadowmapExp_VSM_2 = Shader.PropertyToID("_ShadowmapExp_VSM_2"); |
|||
internal static readonly int _ShadowmapExp_PCF = Shader.PropertyToID("_ShadowmapExp_PCF"); |
|||
|
|||
internal static readonly int g_LayeredSingleIdxBuffer = Shader.PropertyToID("g_LayeredSingleIdxBuffer"); |
|||
internal static readonly int _EnvLightIndexShift = Shader.PropertyToID("_EnvLightIndexShift"); |
|||
internal static readonly int g_isOrthographic = Shader.PropertyToID("g_isOrthographic"); |
|||
internal static readonly int g_iNrVisibLights = Shader.PropertyToID("g_iNrVisibLights"); |
|||
internal static readonly int g_mScrProjection = Shader.PropertyToID("g_mScrProjection"); |
|||
internal static readonly int g_mInvScrProjection = Shader.PropertyToID("g_mInvScrProjection"); |
|||
internal static readonly int g_iLog2NumClusters = Shader.PropertyToID("g_iLog2NumClusters"); |
|||
internal static readonly int g_fNearPlane = Shader.PropertyToID("g_fNearPlane"); |
|||
internal static readonly int g_fFarPlane = Shader.PropertyToID("g_fFarPlane"); |
|||
internal static readonly int g_fClustScale = Shader.PropertyToID("g_fClustScale"); |
|||
internal static readonly int g_fClustBase = Shader.PropertyToID("g_fClustBase"); |
|||
internal static readonly int g_depth_tex = Shader.PropertyToID("g_depth_tex"); |
|||
internal static readonly int g_vLayeredLightList = Shader.PropertyToID("g_vLayeredLightList"); |
|||
internal static readonly int g_LayeredOffset = Shader.PropertyToID("g_LayeredOffset"); |
|||
internal static readonly int g_vBigTileLightList = Shader.PropertyToID("g_vBigTileLightList"); |
|||
internal static readonly int g_logBaseBuffer = Shader.PropertyToID("g_logBaseBuffer"); |
|||
internal static readonly int g_vBoundsBuffer = Shader.PropertyToID("g_vBoundsBuffer"); |
|||
internal static readonly int _LightVolumeData = Shader.PropertyToID("_LightVolumeData"); |
|||
internal static readonly int g_data = Shader.PropertyToID("g_data"); |
|||
internal static readonly int g_mProjection = Shader.PropertyToID("g_mProjection"); |
|||
internal static readonly int g_mInvProjection = Shader.PropertyToID("g_mInvProjection"); |
|||
internal static readonly int g_viDimensions = Shader.PropertyToID("g_viDimensions"); |
|||
internal static readonly int g_vLightList = Shader.PropertyToID("g_vLightList"); |
|||
|
|||
internal static readonly int g_BaseFeatureFlags = Shader.PropertyToID("g_BaseFeatureFlags"); |
|||
internal static readonly int g_TileFeatureFlags = Shader.PropertyToID("g_TileFeatureFlags"); |
|||
|
|||
internal static readonly int _GBufferTexture0 = Shader.PropertyToID("_GBufferTexture0"); |
|||
internal static readonly int _GBufferTexture1 = Shader.PropertyToID("_GBufferTexture1"); |
|||
internal static readonly int _GBufferTexture2 = Shader.PropertyToID("_GBufferTexture2"); |
|||
internal static readonly int _GBufferTexture3 = Shader.PropertyToID("_GBufferTexture3"); |
|||
|
|||
internal static readonly int g_DispatchIndirectBuffer = Shader.PropertyToID("g_DispatchIndirectBuffer"); |
|||
internal static readonly int g_TileList = Shader.PropertyToID("g_TileList"); |
|||
internal static readonly int g_NumTiles = Shader.PropertyToID("g_NumTiles"); |
|||
internal static readonly int g_NumTilesX = Shader.PropertyToID("g_NumTilesX"); |
|||
|
|||
internal static readonly int _NumTiles = Shader.PropertyToID("_NumTiles"); |
|||
|
|||
internal static readonly int _CookieTextures = Shader.PropertyToID("_CookieTextures"); |
|||
internal static readonly int _CookieCubeTextures = Shader.PropertyToID("_CookieCubeTextures"); |
|||
internal static readonly int _EnvTextures = Shader.PropertyToID("_EnvTextures"); |
|||
internal static readonly int _DirectionalLightDatas = Shader.PropertyToID("_DirectionalLightDatas"); |
|||
internal static readonly int _DirectionalLightCount = Shader.PropertyToID("_DirectionalLightCount"); |
|||
internal static readonly int _LightDatas = Shader.PropertyToID("_LightDatas"); |
|||
internal static readonly int _PunctualLightCount = Shader.PropertyToID("_PunctualLightCount"); |
|||
internal static readonly int _AreaLightCount = Shader.PropertyToID("_AreaLightCount"); |
|||
internal static readonly int g_vLightListGlobal = Shader.PropertyToID("g_vLightListGlobal"); |
|||
internal static readonly int _EnvLightDatas = Shader.PropertyToID("_EnvLightDatas"); |
|||
internal static readonly int _EnvLightCount = Shader.PropertyToID("_EnvLightCount"); |
|||
internal static readonly int _ShadowDatas = Shader.PropertyToID("_ShadowDatas"); |
|||
internal static readonly int _DirShadowSplitSpheres = Shader.PropertyToID("_DirShadowSplitSpheres"); |
|||
internal static readonly int _NumTileFtplX = Shader.PropertyToID("_NumTileFtplX"); |
|||
internal static readonly int _NumTileFtplY = Shader.PropertyToID("_NumTileFtplY"); |
|||
internal static readonly int _NumTileClusteredX = Shader.PropertyToID("_NumTileClusteredX"); |
|||
internal static readonly int _NumTileClusteredY = Shader.PropertyToID("_NumTileClusteredY"); |
|||
|
|||
internal static readonly int g_isLogBaseBufferEnabled = Shader.PropertyToID("g_isLogBaseBufferEnabled"); |
|||
internal static readonly int g_vLayeredOffsetsBuffer = Shader.PropertyToID("g_vLayeredOffsetsBuffer"); |
|||
|
|||
internal static readonly int _ViewTilesFlags = Shader.PropertyToID("_ViewTilesFlags"); |
|||
internal static readonly int _MousePixelCoord = Shader.PropertyToID("_MousePixelCoord"); |
|||
|
|||
internal static readonly int _DebugViewMaterial = Shader.PropertyToID("_DebugViewMaterial"); |
|||
internal static readonly int _DebugLightingMode = Shader.PropertyToID("_DebugLightingMode"); |
|||
internal static readonly int _DebugLightingAlbedo = Shader.PropertyToID("_DebugLightingAlbedo"); |
|||
internal static readonly int _DebugLightingSmoothness = Shader.PropertyToID("_DebugLightingSmoothness"); |
|||
internal static readonly int _AmbientOcclusionTexture = Shader.PropertyToID("_AmbientOcclusionTexture"); |
|||
|
|||
internal static readonly int _UseTileLightList = Shader.PropertyToID("_UseTileLightList"); |
|||
internal static readonly int _Time = Shader.PropertyToID("_Time"); |
|||
internal static readonly int _SinTime = Shader.PropertyToID("_SinTime"); |
|||
internal static readonly int _CosTime = Shader.PropertyToID("_CosTime"); |
|||
internal static readonly int unity_DeltaTime = Shader.PropertyToID("unity_DeltaTime"); |
|||
internal static readonly int _EnvLightSkyEnabled = Shader.PropertyToID("_EnvLightSkyEnabled"); |
|||
internal static readonly int _AmbientOcclusionDirectLightStrenght = Shader.PropertyToID("_AmbientOcclusionDirectLightStrenght"); |
|||
internal static readonly int _SkyTexture = Shader.PropertyToID("_SkyTexture"); |
|||
|
|||
internal static readonly int _UseDisneySSS = Shader.PropertyToID("_UseDisneySSS"); |
|||
internal static readonly int _EnableSSSAndTransmission = Shader.PropertyToID("_EnableSSSAndTransmission"); |
|||
internal static readonly int _TexturingModeFlags = Shader.PropertyToID("_TexturingModeFlags"); |
|||
internal static readonly int _TransmissionFlags = Shader.PropertyToID("_TransmissionFlags"); |
|||
internal static readonly int _ThicknessRemaps = Shader.PropertyToID("_ThicknessRemaps"); |
|||
internal static readonly int _ShapeParams = Shader.PropertyToID("_ShapeParams"); |
|||
internal static readonly int _HalfRcpVariancesAndWeights = Shader.PropertyToID("_HalfRcpVariancesAndWeights"); |
|||
internal static readonly int _TransmissionTints = Shader.PropertyToID("_TransmissionTints"); |
|||
internal static readonly int specularLightingUAV = Shader.PropertyToID("specularLightingUAV"); |
|||
internal static readonly int diffuseLightingUAV = Shader.PropertyToID("diffuseLightingUAV"); |
|||
|
|||
internal static readonly int g_TileListOffset = Shader.PropertyToID("g_TileListOffset"); |
|||
|
|||
internal static readonly int _LtcData = Shader.PropertyToID("_LtcData"); |
|||
internal static readonly int _PreIntegratedFGD = Shader.PropertyToID("_PreIntegratedFGD"); |
|||
internal static readonly int _LtcGGXMatrix = Shader.PropertyToID("_LtcGGXMatrix"); |
|||
internal static readonly int _LtcDisneyDiffuseMatrix = Shader.PropertyToID("_LtcDisneyDiffuseMatrix"); |
|||
internal static readonly int _LtcMultiGGXFresnelDisneyDiffuse = Shader.PropertyToID("_LtcMultiGGXFresnelDisneyDiffuse"); |
|||
|
|||
internal static readonly int _MainDepthTexture = Shader.PropertyToID("_MainDepthTexture"); |
|||
|
|||
internal static readonly int unity_OrthoParams = Shader.PropertyToID("unity_OrthoParams"); |
|||
internal static readonly int _ZBufferParams = Shader.PropertyToID("_ZBufferParams"); |
|||
internal static readonly int _ScreenParams = Shader.PropertyToID("_ScreenParams"); |
|||
internal static readonly int _ProjectionParams = Shader.PropertyToID("_ProjectionParams"); |
|||
internal static readonly int _WorldSpaceCameraPos = Shader.PropertyToID("_WorldSpaceCameraPos"); |
|||
|
|||
|
|||
internal static readonly int _StencilRef = Shader.PropertyToID("_StencilRef"); |
|||
internal static readonly int _StencilCmp = Shader.PropertyToID("_StencilCmp"); |
|||
|
|||
internal static readonly int _SrcBlend = Shader.PropertyToID("_SrcBlend"); |
|||
internal static readonly int _DstBlend = Shader.PropertyToID("_DstBlend"); |
|||
|
|||
internal static readonly int _HTile = Shader.PropertyToID("_HTile"); |
|||
internal static readonly int _StencilTexture = Shader.PropertyToID("_StencilTexture"); |
|||
|
|||
internal static readonly int _ViewMatrix = Shader.PropertyToID("_ViewMatrix"); |
|||
internal static readonly int _InvViewMatrix = Shader.PropertyToID("_InvViewMatrix"); |
|||
internal static readonly int _ProjMatrix = Shader.PropertyToID("_ProjMatrix"); |
|||
internal static readonly int _InvProjMatrix = Shader.PropertyToID("_InvProjMatrix"); |
|||
internal static readonly int _NonJitteredViewProjMatrix = Shader.PropertyToID("_NonJitteredViewProjMatrix"); |
|||
internal static readonly int _ViewProjMatrix = Shader.PropertyToID("_ViewProjMatrix"); |
|||
internal static readonly int _InvViewProjMatrix = Shader.PropertyToID("_InvViewProjMatrix"); |
|||
internal static readonly int _InvProjParam = Shader.PropertyToID("_InvProjParam"); |
|||
internal static readonly int _ScreenSize = Shader.PropertyToID("_ScreenSize"); |
|||
internal static readonly int _PrevViewProjMatrix = Shader.PropertyToID("_PrevViewProjMatrix"); |
|||
internal static readonly int _FrustumPlanes = Shader.PropertyToID("_FrustumPlanes"); |
|||
|
|||
internal static readonly int _DepthTexture = Shader.PropertyToID("_DepthTexture"); |
|||
internal static readonly int _CameraColorTexture = Shader.PropertyToID("_CameraColorTexture"); |
|||
internal static readonly int _CameraSssDiffuseLightingBuffer = Shader.PropertyToID("_CameraSssDiffuseLightingTexture"); |
|||
internal static readonly int _CameraFilteringBuffer = Shader.PropertyToID("_CameraFilteringTexture"); |
|||
internal static readonly int _IrradianceSource = Shader.PropertyToID("_IrradianceSource"); |
|||
|
|||
internal static readonly int _VelocityTexture = Shader.PropertyToID("_VelocityTexture"); |
|||
internal static readonly int _DistortionTexture = Shader.PropertyToID("_DistortionTexture"); |
|||
internal static readonly int _DebugFullScreenTexture = Shader.PropertyToID("_DebugFullScreenTexture"); |
|||
|
|||
internal static readonly int _WorldScales = Shader.PropertyToID("_WorldScales"); |
|||
internal static readonly int _FilterKernels = Shader.PropertyToID("_FilterKernels"); |
|||
internal static readonly int _FilterKernelsBasic = Shader.PropertyToID("_FilterKernelsBasic"); |
|||
internal static readonly int _HalfRcpWeightedVariances = Shader.PropertyToID("_HalfRcpWeightedVariances"); |
|||
|
|||
internal static readonly int _CameraPosDiff = Shader.PropertyToID("_CameraPosDiff"); |
|||
|
|||
internal static readonly int _CameraDepthTexture = Shader.PropertyToID("_CameraDepthTexture"); |
|||
internal static readonly int _CameraMotionVectorsTexture = Shader.PropertyToID("_CameraMotionVectorsTexture"); |
|||
internal static readonly int _FullScreenDebugMode = Shader.PropertyToID("_FullScreenDebugMode"); |
|||
|
|||
internal static readonly int _InputCubemap = Shader.PropertyToID("_InputCubemap"); |
|||
internal static readonly int _Mipmap = Shader.PropertyToID("_Mipmap"); |
|||
|
|||
|
|||
internal static readonly int _MaxRadius = Shader.PropertyToID("_MaxRadius"); |
|||
internal static readonly int _ShapeParam = Shader.PropertyToID("_ShapeParam"); |
|||
internal static readonly int _StdDev1 = Shader.PropertyToID("_StdDev1"); |
|||
internal static readonly int _StdDev2 = Shader.PropertyToID("_StdDev2"); |
|||
internal static readonly int _LerpWeight = Shader.PropertyToID("_LerpWeight"); |
|||
internal static readonly int _HalfRcpVarianceAndWeight1 = Shader.PropertyToID("_HalfRcpVarianceAndWeight1"); |
|||
internal static readonly int _HalfRcpVarianceAndWeight2 = Shader.PropertyToID("_HalfRcpVarianceAndWeight2"); |
|||
internal static readonly int _TransmissionTint = Shader.PropertyToID("_TransmissionTint"); |
|||
internal static readonly int _ThicknessRemap = Shader.PropertyToID("_ThicknessRemap"); |
|||
|
|||
internal static readonly int _Cubemap = Shader.PropertyToID("_Cubemap"); |
|||
internal static readonly int _SkyParam = Shader.PropertyToID("_SkyParam"); |
|||
internal static readonly int _PixelCoordToViewDirWS = Shader.PropertyToID("_PixelCoordToViewDirWS"); |
|||
|
|||
internal static readonly int _GlobalFog_Extinction = Shader.PropertyToID("_GlobalFog_Extinction"); |
|||
internal static readonly int _GlobalFog_Asymmetry = Shader.PropertyToID("_GlobalFog_Asymmetry"); |
|||
internal static readonly int _GlobalFog_Scattering = Shader.PropertyToID("_GlobalFog_Scattering"); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a586982c0c38ee64095f06495d043462 |
|||
timeCreated: 1501072635 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 99b28ae1899c34841bb5edf61823d22d |
|||
folderAsset: yes |
|||
timeCreated: 1504677840 |
|||
licenseType: Free |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 6bee56a72daba3d479259196d046864c |
|||
folderAsset: yes |
|||
timeCreated: 1504677840 |
|||
licenseType: Free |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: dfab746be3b7dc34ebec9f9c63bc9a74 |
|||
folderAsset: yes |
|||
timeCreated: 1504677840 |
|||
licenseType: Free |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
|
|||
// Area light textures specific constant |
|||
SamplerState ltc_linear_clamp_sampler; |
|||
// TODO: This one should be set into a constant Buffer at pass frequency (with _Screensize) |
|||
TEXTURE2D(_PreIntegratedFGD); |
|||
TEXTURE2D_ARRAY(_LtcData); // We pack the 3 Ltc data inside a texture array |
|||
#define LTC_GGX_MATRIX_INDEX 0 // RGBA |
|||
#define LTC_DISNEY_DIFFUSE_MATRIX_INDEX 1 // RGBA |
|||
#define LTC_MULTI_GGX_FRESNEL_DISNEY_DIFFUSE_INDEX 2 // RGB, A unused |
|||
#define LTC_LUT_SIZE 64 |
|||
#define LTC_LUT_SCALE ((LTC_LUT_SIZE - 1) * rcp(LTC_LUT_SIZE)) |
|||
#define LTC_LUT_OFFSET (0.5 * rcp(LTC_LUT_SIZE)) |
|||
|
|||
#define MIN_N_DOT_V 0.0001 // The minimum value of 'NdotV' |
|||
|
|||
#ifdef WANT_SSS_CODE |
|||
// Subsurface scattering specific constant |
|||
#define SSS_WRAP_ANGLE (PI/12) // Used for wrap lighting |
|||
#define SSS_WRAP_LIGHT cos(PI/2 - SSS_WRAP_ANGLE) |
|||
|
|||
CBUFFER_START(UnitySSSParameters) |
|||
uint _EnableSSSAndTransmission; // Globally toggles subsurface and transmission scattering on/off |
|||
uint _TexturingModeFlags; // 1 bit/profile; 0 = PreAndPostScatter, 1 = PostScatter |
|||
uint _TransmissionFlags; // 2 bit/profile; 0 = inf. thick, 1 = thin, 2 = regular |
|||
// Old SSS Model >>> |
|||
uint _UseDisneySSS; |
|||
float4 _HalfRcpVariancesAndWeights[SSS_N_PROFILES][2]; // 2x Gaussians in RGB, A is interpolation weights |
|||
// <<< Old SSS Model |
|||
// Use float4 to avoid any packing issue between compute and pixel shaders |
|||
float4 _ThicknessRemaps[SSS_N_PROFILES]; // R: start, G = end - start, BA unused |
|||
float4 _ShapeParams[SSS_N_PROFILES]; // RGB = S = 1 / D, A = filter radius |
|||
float4 _TransmissionTints[SSS_N_PROFILES]; // RGB = 1/4 * color, A = unused |
|||
CBUFFER_END |
|||
#endif |
|||
|
|||
void ApplyDebugToSurfaceData(inout SurfaceData surfaceData) |
|||
{ |
|||
#ifdef DEBUG_DISPLAY |
|||
if (_DebugLightingMode == DEBUGLIGHTINGMODE_SPECULAR_LIGHTING) |
|||
{ |
|||
bool overrideSmoothness = _DebugLightingSmoothness.x != 0.0; |
|||
float overrideSmoothnessValue = _DebugLightingSmoothness.y; |
|||
|
|||
if (overrideSmoothness) |
|||
{ |
|||
surfaceData.perceptualSmoothness = overrideSmoothnessValue; |
|||
} |
|||
} |
|||
|
|||
if (_DebugLightingMode == DEBUGLIGHTINGMODE_DIFFUSE_LIGHTING) |
|||
{ |
|||
surfaceData.baseColor = _DebugLightingAlbedo.xyz; |
|||
} |
|||
#endif |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// Debug method (use to display values) |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
void GetSurfaceDataDebug(uint paramId, SurfaceData surfaceData, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
GetGeneratedSurfaceDataDebug(paramId, surfaceData, result, needLinearToSRGB); |
|||
} |
|||
|
|||
void GetBSDFDataDebug(uint paramId, BSDFData bsdfData, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
GetGeneratedBSDFDataDebug(paramId, bsdfData, result, needLinearToSRGB); |
|||
} |
|||
|
|||
#ifdef WANT_SSS_CODE |
|||
void FillMaterialIdSSSData(float3 baseColor, int subsurfaceProfile, float subsurfaceRadius, float thickness, inout BSDFData bsdfData) |
|||
{ |
|||
bsdfData.diffuseColor = baseColor; |
|||
|
|||
bsdfData.fresnel0 = 0.028; // TODO take from subsurfaceProfile instead |
|||
bsdfData.subsurfaceProfile = subsurfaceProfile; |
|||
bsdfData.subsurfaceRadius = subsurfaceRadius; |
|||
bsdfData.thickness = _ThicknessRemaps[subsurfaceProfile].x + _ThicknessRemaps[subsurfaceProfile].y * thickness; |
|||
|
|||
uint transmissionMode = BitFieldExtract(_TransmissionFlags, 2u, 2u * subsurfaceProfile); |
|||
|
|||
bsdfData.enableTransmission = transmissionMode != SSS_TRSM_MODE_NONE && (_EnableSSSAndTransmission > 0); |
|||
bsdfData.useThinObjectMode = transmissionMode == SSS_TRSM_MODE_THIN; |
|||
|
|||
bool performPostScatterTexturing = IsBitSet(_TexturingModeFlags, subsurfaceProfile); |
|||
|
|||
#if defined(SHADERPASS) && (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) // In case of GI pass don't modify the diffuseColor |
|||
bool enableSssAndTransmission = false; |
|||
#elif defined(SHADERPASS) && (SHADERPASS == SHADERPASS_SUBSURFACE_SCATTERING) |
|||
bool enableSssAndTransmission = true; |
|||
#else |
|||
bool enableSssAndTransmission = _EnableSSSAndTransmission != 0; |
|||
#endif |
|||
|
|||
if (enableSssAndTransmission) // If we globally disable SSS effect, don't modify diffuseColor |
|||
{ |
|||
// We modify the albedo here as this code is used by all lighting (including light maps and GI). |
|||
if (performPostScatterTexturing) |
|||
{ |
|||
#if !defined(SHADERPASS) || (SHADERPASS != SHADERPASS_SUBSURFACE_SCATTERING) |
|||
bsdfData.diffuseColor = float3(1.0, 1.0, 1.0); |
|||
#endif |
|||
} |
|||
else |
|||
{ |
|||
bsdfData.diffuseColor = sqrt(bsdfData.diffuseColor); |
|||
} |
|||
} |
|||
|
|||
if (bsdfData.enableTransmission) |
|||
{ |
|||
if (_UseDisneySSS) |
|||
{ |
|||
bsdfData.transmittance = ComputeTransmittance(_ShapeParams[subsurfaceProfile].rgb, |
|||
_TransmissionTints[subsurfaceProfile].rgb, |
|||
bsdfData.thickness, bsdfData.subsurfaceRadius); |
|||
} |
|||
else |
|||
{ |
|||
bsdfData.transmittance = ComputeTransmittanceJimenez(_HalfRcpVariancesAndWeights[subsurfaceProfile][0].rgb, |
|||
_HalfRcpVariancesAndWeights[subsurfaceProfile][0].a, |
|||
_HalfRcpVariancesAndWeights[subsurfaceProfile][1].rgb, |
|||
_HalfRcpVariancesAndWeights[subsurfaceProfile][1].a, |
|||
_TransmissionTints[subsurfaceProfile].rgb, |
|||
bsdfData.thickness, bsdfData.subsurfaceRadius); |
|||
} |
|||
|
|||
bsdfData.transmittance *= bsdfData.diffuseColor; // Premultiply |
|||
} |
|||
} |
|||
#endif |
|||
|
|||
// For image based lighting, a part of the BSDF is pre-integrated. |
|||
// This is done both for specular and diffuse (in case of DisneyDiffuse) |
|||
void GetPreIntegratedFGD(float NdotV, float perceptualRoughness, float3 fresnel0, out float3 specularFGD, out float diffuseFGD) |
|||
{ |
|||
// Pre-integrate GGX FGD |
|||
// _PreIntegratedFGD.x = Gv * (1 - Fc) with Fc = (1 - H.L)^5 |
|||
// _PreIntegratedFGD.y = Gv * Fc |
|||
// Pre integrate DisneyDiffuse FGD: |
|||
// _PreIntegratedFGD.z = DisneyDiffuse |
|||
float3 preFGD = SAMPLE_TEXTURE2D_LOD(_PreIntegratedFGD, ltc_linear_clamp_sampler, float2(NdotV, perceptualRoughness), 0).xyz; |
|||
|
|||
// f0 * Gv * (1 - Fc) + Gv * Fc |
|||
specularFGD = fresnel0 * preFGD.x + preFGD.y; |
|||
|
|||
#ifdef LIT_DIFFUSE_LAMBERT_BRDF |
|||
diffuseFGD = 1.0; |
|||
#else |
|||
diffuseFGD = preFGD.z; |
|||
#endif |
|||
} |
|||
|
|||
// Precomputed lighting data to send to the various lighting functions |
|||
struct PreLightData |
|||
{ |
|||
// General |
|||
float NdotV; // Geometric version (could be negative) |
|||
|
|||
// GGX iso |
|||
float ggxLambdaV; |
|||
|
|||
// GGX Aniso |
|||
float TdotV; |
|||
float BdotV; |
|||
float anisoGGXLambdaV; |
|||
|
|||
// IBL |
|||
float3 iblDirWS; // Dominant specular direction, used for IBL in EvaluateBSDF_Env() |
|||
float iblMipLevel; |
|||
|
|||
float3 specularFGD; // Store preconvoled BRDF for both specular and diffuse |
|||
float diffuseFGD; |
|||
|
|||
// Area lights (17 VGPRs) |
|||
float3x3 orthoBasisViewNormal; // Right-handed view-dependent orthogonal basis around the normal (6x VGPRs) |
|||
float3x3 ltcTransformDiffuse; // Inverse transformation for Lambertian or Disney Diffuse (4x VGPRs) |
|||
float3x3 ltcTransformSpecular; // Inverse transformation for GGX (4x VGPRs) |
|||
float ltcMagnitudeDiffuse; |
|||
float3 ltcMagnitudeFresnel; |
|||
}; |
|||
|
|||
PreLightData GetPreLightData(float3 V, PositionInputs posInput, BSDFData bsdfData) |
|||
{ |
|||
PreLightData preLightData; |
|||
|
|||
preLightData.NdotV = dot(bsdfData.normalWS, V); // Store the unaltered (geometric) version |
|||
float NdotV = preLightData.NdotV; |
|||
|
|||
// In the case of IBL we want shift a bit the normal that are not toward the viewver to reduce artifact |
|||
float3 iblNormalWS = GetViewShiftedNormal(bsdfData.normalWS, V, NdotV, MIN_N_DOT_V); // Use non clamped NdotV |
|||
float3 iblR = reflect(-V, iblNormalWS); |
|||
|
|||
NdotV = max(NdotV, MIN_N_DOT_V); // Use the modified (clamped) version |
|||
|
|||
// GGX iso |
|||
preLightData.ggxLambdaV = GetSmithJointGGXLambdaV(NdotV, bsdfData.roughness); |
|||
|
|||
// GGX aniso |
|||
preLightData.TdotV = 0.0; |
|||
preLightData.BdotV = 0.0; |
|||
if (bsdfData.materialId == MATERIALID_LIT_ANISO) |
|||
{ |
|||
preLightData.TdotV = dot(bsdfData.tangentWS, V); |
|||
preLightData.BdotV = dot(bsdfData.bitangentWS, V); |
|||
preLightData.anisoGGXLambdaV = GetSmithJointGGXAnisoLambdaV(preLightData.TdotV, preLightData.BdotV, NdotV, bsdfData.roughnessT, bsdfData.roughnessB); |
|||
// Tangent = highlight stretch (anisotropy) direction. Bitangent = grain (brush) direction. |
|||
float3 anisoIblNormalWS = GetAnisotropicModifiedNormal(bsdfData.bitangentWS, iblNormalWS, V, bsdfData.anisotropy); |
|||
|
|||
// NOTE: If we follow the theory we should use the modified normal for the different calculation implying a normal (like NdotV) and use iblNormalWS |
|||
// into function like GetSpecularDominantDir(). However modified normal is just a hack. The goal is just to stretch a cubemap, no accuracy here. |
|||
// With this in mind and for performance reasons we chose to only use modified normal to calculate R. |
|||
iblR = reflect(-V, anisoIblNormalWS); |
|||
} |
|||
|
|||
// IBL |
|||
GetPreIntegratedFGD(NdotV, bsdfData.perceptualRoughness, bsdfData.fresnel0, preLightData.specularFGD, preLightData.diffuseFGD); |
|||
|
|||
preLightData.iblDirWS = GetSpecularDominantDir(iblNormalWS, iblR, bsdfData.roughness, NdotV); |
|||
preLightData.iblMipLevel = PerceptualRoughnessToMipmapLevel(bsdfData.perceptualRoughness); |
|||
|
|||
// Area light |
|||
// UVs for sampling the LUTs |
|||
float theta = FastACos(NdotV); // For Area light - UVs for sampling the LUTs |
|||
float2 uv = LTC_LUT_OFFSET + LTC_LUT_SCALE * float2(bsdfData.perceptualRoughness, theta * INV_HALF_PI); |
|||
|
|||
// Note we load the matrix transpose (avoid to have to transpose it in shader) |
|||
#ifdef LIT_DIFFUSE_LAMBERT_BRDF |
|||
preLightData.ltcTransformDiffuse = k_identity3x3; |
|||
#else |
|||
// Get the inverse LTC matrix for Disney Diffuse |
|||
preLightData.ltcTransformDiffuse = 0.0; |
|||
preLightData.ltcTransformDiffuse._m22 = 1.0; |
|||
preLightData.ltcTransformDiffuse._m00_m02_m11_m20 = SAMPLE_TEXTURE2D_ARRAY_LOD(_LtcData, ltc_linear_clamp_sampler, uv, LTC_DISNEY_DIFFUSE_MATRIX_INDEX, 0); |
|||
#endif |
|||
|
|||
// Get the inverse LTC matrix for GGX |
|||
// Note we load the matrix transpose (avoid to have to transpose it in shader) |
|||
preLightData.ltcTransformSpecular = 0.0; |
|||
preLightData.ltcTransformSpecular._m22 = 1.0; |
|||
preLightData.ltcTransformSpecular._m00_m02_m11_m20 = SAMPLE_TEXTURE2D_ARRAY_LOD(_LtcData, ltc_linear_clamp_sampler, uv, LTC_GGX_MATRIX_INDEX, 0); |
|||
|
|||
// Construct a right-handed view-dependent orthogonal basis around the normal |
|||
preLightData.orthoBasisViewNormal[0] = normalize(V - bsdfData.normalWS * preLightData.NdotV); |
|||
preLightData.orthoBasisViewNormal[2] = bsdfData.normalWS; |
|||
preLightData.orthoBasisViewNormal[1] = normalize(cross(preLightData.orthoBasisViewNormal[2], preLightData.orthoBasisViewNormal[0])); |
|||
|
|||
float3 ltcMagnitude = SAMPLE_TEXTURE2D_ARRAY_LOD(_LtcData, ltc_linear_clamp_sampler, uv, LTC_MULTI_GGX_FRESNEL_DISNEY_DIFFUSE_INDEX, 0).rgb; |
|||
float ltcGGXFresnelMagnitudeDiff = ltcMagnitude.r; // The difference of magnitudes of GGX and Fresnel |
|||
float ltcGGXFresnelMagnitude = ltcMagnitude.g; |
|||
float ltcDisneyDiffuseMagnitude = ltcMagnitude.b; |
|||
|
|||
#ifdef LIT_DIFFUSE_LAMBERT_BRDF |
|||
preLightData.ltcMagnitudeDiffuse = 1; |
|||
#else |
|||
preLightData.ltcMagnitudeDiffuse = ltcDisneyDiffuseMagnitude; |
|||
#endif |
|||
|
|||
// TODO: the fit seems rather poor. The scaling factor of 0.5 allows us |
|||
// to match the reference for rough metals, but further darkens dielectrics. |
|||
preLightData.ltcMagnitudeFresnel = bsdfData.fresnel0 * ltcGGXFresnelMagnitudeDiff + (float3)ltcGGXFresnelMagnitude; |
|||
|
|||
return preLightData; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0f24f4070ad17d14196c6ed72276a144 |
|||
timeCreated: 1504900828 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifdef HAS_LIGHTLOOP |
|||
|
|||
|
|||
#ifdef WANT_SSS_CODE |
|||
// Currently, we only model diffuse transmission. Specular transmission is not yet supported. |
|||
// We assume that the back side of the object is a uniformly illuminated infinite plane |
|||
// with the reversed normal (and the view vector) of the current sample. |
|||
float3 EvaluateTransmission(BSDFData bsdfData, float intensity, float shadow) |
|||
{ |
|||
// For low thickness, we can reuse the shadowing status for the back of the object. |
|||
shadow = bsdfData.useThinObjectMode ? shadow : 1; |
|||
|
|||
float backLight = intensity * shadow; |
|||
|
|||
return backLight * bsdfData.transmittance; // Premultiplied with the diffuse color |
|||
} |
|||
#endif |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Directional (supports directional and box projector lights) |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
float4 EvaluateCookie_Directional(LightLoopContext lightLoopContext, DirectionalLightData lightData, |
|||
float3 lighToSample) |
|||
{ |
|||
// Compute the NDC position (in [-1, 1]^2) by projecting 'positionWS' onto the near plane. |
|||
// 'lightData.right' and 'lightData.up' are pre-scaled on CPU. |
|||
float3x3 lightToWorld = float3x3(lightData.right, lightData.up, lightData.forward); |
|||
float3 positionLS = mul(lighToSample, transpose(lightToWorld)); |
|||
float2 positionNDC = positionLS.xy; |
|||
|
|||
bool isInBounds; |
|||
|
|||
// Remap the texture coordinates from [-1, 1]^2 to [0, 1]^2. |
|||
float2 coord = positionNDC * 0.5 + 0.5; |
|||
|
|||
if (lightData.tileCookie) |
|||
{ |
|||
// Tile the texture if the 'repeat' wrap mode is enabled. |
|||
coord = frac(coord); |
|||
isInBounds = true; |
|||
} |
|||
else |
|||
{ |
|||
isInBounds = Max3(abs(positionNDC.x), abs(positionNDC.y), 1 - positionLS.z) <= 1; |
|||
} |
|||
|
|||
// We let the sampler handle tiling or clamping to border. |
|||
// Note: tiling (the repeat mode) is not currently supported. |
|||
float4 cookie = SampleCookie2D(lightLoopContext, coord, lightData.cookieIndex); |
|||
|
|||
cookie.a = isInBounds ? cookie.a : 0; |
|||
|
|||
return cookie; |
|||
} |
|||
|
|||
void EvaluateBSDF_Directional(LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, PreLightData preLightData, |
|||
DirectionalLightData lightData, BSDFData bsdfData, |
|||
out float3 diffuseLighting, |
|||
out float3 specularLighting) |
|||
{ |
|||
float3 positionWS = posInput.positionWS; |
|||
|
|||
float3 L = -lightData.forward; // Lights are pointing backward in Unity |
|||
float NdotL = dot(bsdfData.normalWS, L); |
|||
float illuminance = saturate(NdotL); |
|||
|
|||
diffuseLighting = float3(0, 0, 0); // TODO: check whether using 'out' instead of 'inout' increases the VGPR pressure |
|||
specularLighting = float3(0, 0, 0); // TODO: check whether using 'out' instead of 'inout' increases the VGPR pressure |
|||
float shadow = 1; |
|||
|
|||
[branch] if (lightData.shadowIndex >= 0) |
|||
{ |
|||
shadow = GetDirectionalShadowAttenuation(lightLoopContext.shadowContext, positionWS, bsdfData.normalWS, lightData.shadowIndex, L, posInput.unPositionSS); |
|||
illuminance *= shadow; |
|||
} |
|||
|
|||
[branch] if (lightData.cookieIndex >= 0) |
|||
{ |
|||
float3 lightToSurface = positionWS - lightData.positionWS; |
|||
float4 cookie = EvaluateCookie_Directional(lightLoopContext, lightData, lightToSurface); |
|||
|
|||
// Premultiply. |
|||
lightData.color *= cookie.rgb; |
|||
lightData.diffuseScale *= cookie.a; |
|||
lightData.specularScale *= cookie.a; |
|||
} |
|||
|
|||
[branch] if (illuminance > 0.0) |
|||
{ |
|||
BSDF(V, L, positionWS, preLightData, bsdfData, diffuseLighting, specularLighting); |
|||
|
|||
diffuseLighting *= illuminance * lightData.diffuseScale; |
|||
specularLighting *= illuminance * lightData.specularScale; |
|||
} |
|||
|
|||
#ifdef WANT_SSS_CODE |
|||
[branch] if (bsdfData.enableTransmission) |
|||
{ |
|||
// We apply wrapped lighting instead of the regular Lambertian diffuse |
|||
// to compensate for approximations within EvaluateTransmission(). |
|||
float illuminance = Lambert() * ComputeWrappedDiffuseLighting(-NdotL, SSS_WRAP_LIGHT); |
|||
|
|||
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass. |
|||
diffuseLighting += EvaluateTransmission(bsdfData, illuminance * lightData.diffuseScale, shadow); |
|||
} |
|||
#endif |
|||
|
|||
// Save ALU by applying 'lightData.color' only once. |
|||
diffuseLighting *= lightData.color; |
|||
specularLighting *= lightData.color; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Punctual (supports spot, point and projector lights) |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
float4 EvaluateCookie_Punctual(LightLoopContext lightLoopContext, LightData lightData, |
|||
float3 lighToSample) |
|||
{ |
|||
int lightType = lightData.lightType; |
|||
|
|||
// Translate and rotate 'positionWS' into the light space. |
|||
// 'lightData.right' and 'lightData.up' are pre-scaled on CPU. |
|||
float3x3 lightToWorld = float3x3(lightData.right, lightData.up, lightData.forward); |
|||
float3 positionLS = mul(lighToSample, transpose(lightToWorld)); |
|||
|
|||
float4 cookie; |
|||
|
|||
[branch] if (lightType == GPULIGHTTYPE_POINT) |
|||
{ |
|||
cookie = SampleCookieCube(lightLoopContext, positionLS, lightData.cookieIndex); |
|||
} |
|||
else |
|||
{ |
|||
// Compute the NDC position (in [-1, 1]^2) by projecting 'positionWS' onto the plane at 1m distance. |
|||
// Box projector lights require no perspective division. |
|||
float perspectiveZ = (lightType != GPULIGHTTYPE_PROJECTOR_BOX) ? positionLS.z : 1; |
|||
float2 positionNDC = positionLS.xy / perspectiveZ; |
|||
bool isInBounds = Max3(abs(positionNDC.x), abs(positionNDC.y), 1 - positionLS.z) <= 1; |
|||
|
|||
// Remap the texture coordinates from [-1, 1]^2 to [0, 1]^2. |
|||
float2 coord = positionNDC * 0.5 + 0.5; |
|||
|
|||
// We let the sampler handle clamping to border. |
|||
cookie = SampleCookie2D(lightLoopContext, coord, lightData.cookieIndex); |
|||
cookie.a = isInBounds ? cookie.a : 0; |
|||
} |
|||
|
|||
return cookie; |
|||
} |
|||
|
|||
float GetPunctualShapeAttenuation(LightData lightData, float3 L, float distSq) |
|||
{ |
|||
// Note: lightData.invSqrAttenuationRadius is 0 when applyRangeAttenuation is false |
|||
float attenuation = GetDistanceAttenuation(distSq, lightData.invSqrAttenuationRadius); |
|||
// Reminder: lights are oriented backward (-Z) |
|||
return attenuation * GetAngleAttenuation(L, -lightData.forward, lightData.angleScale, lightData.angleOffset); |
|||
} |
|||
|
|||
void EvaluateBSDF_Punctual( LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, PreLightData preLightData, LightData lightData, BSDFData bsdfData, |
|||
out float3 diffuseLighting, |
|||
out float3 specularLighting) |
|||
{ |
|||
float3 positionWS = posInput.positionWS; |
|||
int lightType = lightData.lightType; |
|||
|
|||
// All punctual light type in the same formula, attenuation is neutral depends on light type. |
|||
// light.positionWS is the normalize light direction in case of directional light and invSqrAttenuationRadius is 0 |
|||
// mean dot(unL, unL) = 1 and mean GetDistanceAttenuation() will return 1 |
|||
// For point light and directional GetAngleAttenuation() return 1 |
|||
|
|||
float3 lightToSurface = positionWS - lightData.positionWS; |
|||
float3 unL = -lightToSurface; |
|||
float distSq = dot(unL, unL); |
|||
float dist = sqrt(distSq); |
|||
float3 L = (lightType != GPULIGHTTYPE_PROJECTOR_BOX) ? unL * rsqrt(distSq) : -lightData.forward; |
|||
float NdotL = dot(bsdfData.normalWS, L); |
|||
float illuminance = saturate(NdotL); |
|||
|
|||
float attenuation = GetPunctualShapeAttenuation(lightData, L, distSq); |
|||
|
|||
// Premultiply. |
|||
lightData.diffuseScale *= attenuation; |
|||
lightData.specularScale *= attenuation; |
|||
|
|||
diffuseLighting = float3(0, 0, 0); // TODO: check whether using 'out' instead of 'inout' increases the VGPR pressure |
|||
specularLighting = float3(0, 0, 0); // TODO: check whether using 'out' instead of 'inout' increases the VGPR pressure |
|||
float shadow = 1; |
|||
|
|||
[branch] if (lightData.shadowIndex >= 0) |
|||
{ |
|||
// TODO: make projector lights cast shadows. |
|||
float3 offset = float3(0.0, 0.0, 0.0); // GetShadowPosOffset(nDotL, normal); |
|||
float4 L_dist = { L, dist }; |
|||
shadow = GetPunctualShadowAttenuation(lightLoopContext.shadowContext, positionWS + offset, bsdfData.normalWS, lightData.shadowIndex, L_dist, posInput.unPositionSS); |
|||
shadow = lerp(1.0, shadow, lightData.shadowDimmer); |
|||
illuminance *= shadow; |
|||
} |
|||
|
|||
// Projector lights always have a cookies, so we can perform clipping inside the if(). |
|||
[branch] if (lightData.cookieIndex >= 0) |
|||
{ |
|||
float4 cookie = EvaluateCookie_Punctual(lightLoopContext, lightData, lightToSurface); |
|||
|
|||
// Premultiply. |
|||
lightData.color *= cookie.rgb; |
|||
lightData.diffuseScale *= cookie.a; |
|||
lightData.specularScale *= cookie.a; |
|||
} |
|||
|
|||
[branch] if (illuminance > 0.0) |
|||
{ |
|||
bsdfData.roughness = max(bsdfData.roughness, lightData.minRoughness); // Simulate that a punctual ligth have a radius with this hack |
|||
BSDF(V, L, positionWS, preLightData, bsdfData, diffuseLighting, specularLighting); |
|||
|
|||
diffuseLighting *= illuminance * lightData.diffuseScale; |
|||
specularLighting *= illuminance * lightData.specularScale; |
|||
} |
|||
|
|||
#ifdef WANT_SSS_CODE |
|||
[branch] if (bsdfData.enableTransmission) |
|||
{ |
|||
// We apply wrapped lighting instead of the regular Lambertian diffuse |
|||
// to compensate for approximations within EvaluateTransmission(). |
|||
float illuminance = Lambert() * ComputeWrappedDiffuseLighting(-NdotL, SSS_WRAP_LIGHT); |
|||
|
|||
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass. |
|||
diffuseLighting += EvaluateTransmission(bsdfData, illuminance * lightData.diffuseScale, shadow); |
|||
} |
|||
#endif |
|||
|
|||
// Save ALU by applying 'lightData.color' only once. |
|||
diffuseLighting *= lightData.color; |
|||
specularLighting *= lightData.color; |
|||
} |
|||
|
|||
#include "Lit/LitReference.hlsl" |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Line - Approximation with Linearly Transformed Cosines |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
void EvaluateBSDF_Line(LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, LightData lightData, BSDFData bsdfData, |
|||
out float3 diffuseLighting, out float3 specularLighting) |
|||
{ |
|||
float3 positionWS = posInput.positionWS; |
|||
|
|||
#ifdef LIT_DISPLAY_REFERENCE_AREA |
|||
IntegrateBSDF_LineRef(V, positionWS, preLightData, lightData, bsdfData, |
|||
diffuseLighting, specularLighting); |
|||
#else |
|||
diffuseLighting = float3(0.0, 0.0, 0.0); |
|||
specularLighting = float3(0.0, 0.0, 0.0); |
|||
|
|||
float len = lightData.size.x; |
|||
float3 T = lightData.right; |
|||
|
|||
float3 unL = lightData.positionWS - positionWS; |
|||
|
|||
// Pick the major axis of the ellipsoid. |
|||
float3 axis = lightData.right; |
|||
|
|||
// We define the ellipsoid s.t. r1 = (r + len / 2), r2 = r3 = r. |
|||
// TODO: This could be precomputed. |
|||
float radius = rsqrt(lightData.invSqrAttenuationRadius); |
|||
float invAspectRatio = radius / (radius + (0.5 * len)); |
|||
|
|||
// Compute the light attenuation. |
|||
float intensity = GetEllipsoidalDistanceAttenuation(unL, lightData.invSqrAttenuationRadius, |
|||
axis, invAspectRatio); |
|||
|
|||
// Terminate if the shaded point is too far away. |
|||
if (intensity == 0.0) return; |
|||
|
|||
lightData.diffuseScale *= intensity; |
|||
lightData.specularScale *= intensity; |
|||
|
|||
// Translate the light s.t. the shaded point is at the origin of the coordinate system. |
|||
lightData.positionWS -= positionWS; |
|||
|
|||
// TODO: some of this could be precomputed. |
|||
float3 P1 = lightData.positionWS - T * (0.5 * len); |
|||
float3 P2 = lightData.positionWS + T * (0.5 * len); |
|||
|
|||
// Rotate the endpoints into the local coordinate system. |
|||
P1 = mul(P1, transpose(preLightData.orthoBasisViewNormal)); |
|||
P2 = mul(P2, transpose(preLightData.orthoBasisViewNormal)); |
|||
|
|||
// Compute the binormal in the local coordinate system. |
|||
float3 B = normalize(cross(P1, P2)); |
|||
|
|||
float ltcValue; |
|||
|
|||
// Evaluate the diffuse part |
|||
{ |
|||
ltcValue = LTCEvaluate(P1, P2, B, preLightData.ltcTransformDiffuse); |
|||
ltcValue *= lightData.diffuseScale; |
|||
diffuseLighting = bsdfData.diffuseColor * (preLightData.ltcMagnitudeDiffuse * ltcValue); |
|||
} |
|||
|
|||
#ifdef WANT_SSS_CODE |
|||
[branch] if (bsdfData.enableTransmission) |
|||
{ |
|||
// Flip the view vector and the normal. The bitangent stays the same. |
|||
float3x3 flipMatrix = float3x3(-1, 0, 0, |
|||
0, 1, 0, |
|||
0, 0, -1); |
|||
|
|||
// Use the Lambertian approximation for performance reasons. |
|||
// The matrix multiplication should not generate any extra ALU on GCN. |
|||
ltcValue = LTCEvaluate(P1, P2, B, mul(flipMatrix, k_identity3x3)); |
|||
ltcValue *= lightData.diffuseScale; |
|||
|
|||
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass. |
|||
diffuseLighting += EvaluateTransmission(bsdfData, ltcValue, 1); |
|||
} |
|||
#endif |
|||
|
|||
// Evaluate the specular part |
|||
{ |
|||
ltcValue = LTCEvaluate(P1, P2, B, preLightData.ltcTransformSpecular); |
|||
ltcValue *= lightData.specularScale; |
|||
specularLighting += preLightData.ltcMagnitudeFresnel * ltcValue; |
|||
} |
|||
|
|||
// Save ALU by applying 'lightData.color' only once. |
|||
diffuseLighting *= lightData.color; |
|||
specularLighting *= lightData.color; |
|||
#endif // LIT_DISPLAY_REFERENCE_AREA |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Area - Approximation with Linearly Transformed Cosines |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// #define ELLIPSOIDAL_ATTENUATION |
|||
|
|||
void EvaluateBSDF_Rect( LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, LightData lightData, BSDFData bsdfData, |
|||
out float3 diffuseLighting, out float3 specularLighting) |
|||
{ |
|||
float3 positionWS = posInput.positionWS; |
|||
|
|||
#ifdef LIT_DISPLAY_REFERENCE_AREA |
|||
IntegrateBSDF_AreaRef(V, positionWS, preLightData, lightData, bsdfData, |
|||
diffuseLighting, specularLighting); |
|||
#else |
|||
diffuseLighting = float3(0.0, 0.0, 0.0); |
|||
specularLighting = float3(0.0, 0.0, 0.0); |
|||
|
|||
float3 unL = lightData.positionWS - positionWS; |
|||
|
|||
[branch] |
|||
if (dot(lightData.forward, unL) >= 0.0001) |
|||
{ |
|||
// The light is back-facing. |
|||
return; |
|||
} |
|||
|
|||
// Rotate the light direction into the light space. |
|||
float3x3 lightToWorld = float3x3(lightData.right, lightData.up, -lightData.forward); |
|||
unL = mul(unL, transpose(lightToWorld)); |
|||
|
|||
// TODO: This could be precomputed. |
|||
float halfWidth = lightData.size.x * 0.5; |
|||
float halfHeight = lightData.size.y * 0.5; |
|||
|
|||
// Define the dimensions of the attenuation volume. |
|||
// TODO: This could be precomputed. |
|||
float radius = rsqrt(lightData.invSqrAttenuationRadius); |
|||
float3 invHalfDim = rcp(float3(radius + halfWidth, |
|||
radius + halfHeight, |
|||
radius)); |
|||
|
|||
// Compute the light attenuation. |
|||
#ifdef ELLIPSOIDAL_ATTENUATION |
|||
// The attenuation volume is an axis-aligned ellipsoid s.t. |
|||
// r1 = (r + w / 2), r2 = (r + h / 2), r3 = r. |
|||
float intensity = GetEllipsoidalDistanceAttenuation(unL, invHalfDim); |
|||
#else |
|||
// The attenuation volume is an axis-aligned box s.t. |
|||
// hX = (r + w / 2), hY = (r + h / 2), hZ = r. |
|||
float intensity = GetBoxDistanceAttenuation(unL, invHalfDim); |
|||
#endif |
|||
|
|||
// Terminate if the shaded point is too far away. |
|||
if (intensity == 0.0) return; |
|||
|
|||
lightData.diffuseScale *= intensity; |
|||
lightData.specularScale *= intensity; |
|||
|
|||
// Translate the light s.t. the shaded point is at the origin of the coordinate system. |
|||
lightData.positionWS -= positionWS; |
|||
|
|||
float4x3 lightVerts; |
|||
|
|||
// TODO: some of this could be precomputed. |
|||
lightVerts[0] = lightData.positionWS + lightData.right * halfWidth + lightData.up * halfHeight; |
|||
lightVerts[1] = lightData.positionWS + lightData.right * halfWidth + lightData.up * -halfHeight; |
|||
lightVerts[2] = lightData.positionWS + lightData.right * -halfWidth + lightData.up * -halfHeight; |
|||
lightVerts[3] = lightData.positionWS + lightData.right * -halfWidth + lightData.up * halfHeight; |
|||
|
|||
// Rotate the endpoints into the local coordinate system. |
|||
lightVerts = mul(lightVerts, transpose(preLightData.orthoBasisViewNormal)); |
|||
|
|||
float ltcValue; |
|||
|
|||
// Evaluate the diffuse part |
|||
{ |
|||
// Polygon irradiance in the transformed configuration. |
|||
ltcValue = PolygonIrradiance(mul(lightVerts, preLightData.ltcTransformDiffuse)); |
|||
ltcValue *= lightData.diffuseScale; |
|||
diffuseLighting = bsdfData.diffuseColor * (preLightData.ltcMagnitudeDiffuse * ltcValue); |
|||
} |
|||
|
|||
#ifdef WANT_SSS_CODE |
|||
[branch] if (bsdfData.enableTransmission) |
|||
{ |
|||
// Flip the view vector and the normal. The bitangent stays the same. |
|||
float3x3 flipMatrix = float3x3(-1, 0, 0, |
|||
0, 1, 0, |
|||
0, 0, -1); |
|||
|
|||
// Use the Lambertian approximation for performance reasons. |
|||
// The matrix multiplication should not generate any extra ALU on GCN. |
|||
float3x3 ltcTransform = mul(flipMatrix, k_identity3x3); |
|||
|
|||
// Polygon irradiance in the transformed configuration. |
|||
ltcValue = PolygonIrradiance(mul(lightVerts, ltcTransform)); |
|||
ltcValue *= lightData.diffuseScale; |
|||
|
|||
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass. |
|||
diffuseLighting += EvaluateTransmission(bsdfData, ltcValue, 1); |
|||
} |
|||
#endif |
|||
|
|||
// Evaluate the specular part |
|||
{ |
|||
// Polygon irradiance in the transformed configuration. |
|||
ltcValue = PolygonIrradiance(mul(lightVerts, preLightData.ltcTransformSpecular)); |
|||
ltcValue *= lightData.specularScale; |
|||
specularLighting += preLightData.ltcMagnitudeFresnel * ltcValue; |
|||
} |
|||
|
|||
// Save ALU by applying 'lightData.color' only once. |
|||
diffuseLighting *= lightData.color; |
|||
specularLighting *= lightData.color; |
|||
#endif // LIT_DISPLAY_REFERENCE_AREA |
|||
} |
|||
|
|||
void EvaluateBSDF_Area(LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, LightData lightData, BSDFData bsdfData, int GPULightType, |
|||
out float3 diffuseLighting, out float3 specularLighting) |
|||
{ |
|||
if (GPULightType == GPULIGHTTYPE_LINE) |
|||
{ |
|||
EvaluateBSDF_Line(lightLoopContext, V, posInput, preLightData, lightData, bsdfData, diffuseLighting, specularLighting); |
|||
} |
|||
else |
|||
{ |
|||
EvaluateBSDF_Rect(lightLoopContext, V, posInput, preLightData, lightData, bsdfData, diffuseLighting, specularLighting); |
|||
} |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Env |
|||
// ---------------------------------------------------------------------------- |
|||
|
|||
// _preIntegratedFGD and _CubemapLD are unique for each BRDF |
|||
void EvaluateBSDF_Env( LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, PreLightData preLightData, EnvLightData lightData, BSDFData bsdfData, |
|||
out float3 diffuseLighting, out float3 specularLighting, out float2 weight) |
|||
{ |
|||
float3 positionWS = posInput.positionWS; |
|||
|
|||
#ifdef LIT_DISPLAY_REFERENCE_IBL |
|||
|
|||
specularLighting = IntegrateSpecularGGXIBLRef(lightLoopContext, V, preLightData, lightData, bsdfData); |
|||
|
|||
/* |
|||
#ifdef LIT_DIFFUSE_LAMBERT_BRDF |
|||
diffuseLighting = IntegrateLambertIBLRef(lightData, V, bsdfData); |
|||
#else |
|||
diffuseLighting = IntegrateDisneyDiffuseIBLRef(lightLoopContext, V, preLightData, lightData, bsdfData); |
|||
#endif |
|||
*/ |
|||
diffuseLighting = float3(0.0, 0.0, 0.0); |
|||
|
|||
weight = float2(0.0, 1.0); |
|||
|
|||
#else |
|||
// TODO: factor this code in common, so other material authoring don't require to rewrite everything, |
|||
// also think about how such a loop can handle 2 cubemap at the same time as old unity. Macro can allow to do that |
|||
// but we need to have UNITY_SAMPLE_ENV_LOD replace by a true function instead that is define by the lighting arcitecture. |
|||
// Also not sure how to deal with 2 intersection.... |
|||
// Box and sphere are related to light property (but we have also distance based roughness etc...) |
|||
|
|||
// TODO: test the strech from Tomasz |
|||
// float shrinkedRoughness = AnisotropicStrechAtGrazingAngle(bsdfData.roughness, bsdfData.perceptualRoughness, NdotV); |
|||
|
|||
// In this code we redefine a bit the behavior of the reflcetion proble. We separate the projection volume (the proxy of the scene) form the influence volume (what pixel on the screen is affected) |
|||
|
|||
// 1. First determine the projection volume |
|||
|
|||
// In Unity the cubemaps are capture with the localToWorld transform of the component. |
|||
// This mean that location and oritention matter. So after intersection of proxy volume we need to convert back to world. |
|||
|
|||
// CAUTION: localToWorld is the transform use to convert the cubemap capture point to world space (mean it include the offset) |
|||
// the center of the bounding box is thus in locals space: positionLS - offsetLS |
|||
// We use this formulation as it is the one of legacy unity that was using only AABB box. |
|||
|
|||
float3 R = preLightData.iblDirWS; |
|||
|
|||
float3x3 worldToLocal = transpose(float3x3(lightData.right, lightData.up, lightData.forward)); // worldToLocal assume no scaling |
|||
float3 positionLS = positionWS - lightData.positionWS; |
|||
positionLS = mul(positionLS, worldToLocal).xyz - lightData.offsetLS; // We want to calculate the intersection from the center of the bounding box. |
|||
|
|||
if (lightData.envShapeType == ENVSHAPETYPE_SPHERE) |
|||
{ |
|||
float3 dirLS = mul(R, worldToLocal); |
|||
float sphereOuterDistance = lightData.innerDistance.x + lightData.blendDistance; |
|||
float dist = SphereRayIntersectSimple(positionLS, dirLS, sphereOuterDistance); |
|||
|
|||
R = (positionWS + dist * R) - lightData.positionWS; |
|||
} |
|||
else if (lightData.envShapeType == ENVSHAPETYPE_BOX) |
|||
{ |
|||
float3 dirLS = mul(R, worldToLocal); |
|||
float3 boxOuterDistance = lightData.innerDistance + float3(lightData.blendDistance, lightData.blendDistance, lightData.blendDistance); |
|||
float dist = BoxRayIntersectSimple(positionLS, dirLS, -boxOuterDistance, boxOuterDistance); |
|||
|
|||
// No need to normalize for fetching cubemap |
|||
// We can reuse dist calculate in LS directly in WS as there is no scaling. Also the offset is already include in lightData.positionWS |
|||
R = (positionWS + dist * R) - lightData.positionWS; |
|||
|
|||
// TODO: add distance based roughness |
|||
} |
|||
|
|||
// 2. Apply the influence volume (Box volume is used for culling whatever the influence shape) |
|||
// TODO: In the future we could have an influence volume inside the projection volume (so with a different transform, in this case we will need another transform) |
|||
weight.y = 1.0; |
|||
|
|||
if (lightData.envShapeType == ENVSHAPETYPE_SPHERE) |
|||
{ |
|||
float distFade = max(length(positionLS) - lightData.innerDistance.x, 0.0); |
|||
weight.y = saturate(1.0 - distFade / max(lightData.blendDistance, 0.0001)); // avoid divide by zero |
|||
} |
|||
else if (lightData.envShapeType == ENVSHAPETYPE_BOX || |
|||
lightData.envShapeType == ENVSHAPETYPE_NONE) |
|||
{ |
|||
// Calculate falloff value, so reflections on the edges of the volume would gradually blend to previous reflection. |
|||
float distFade = DistancePointBox(positionLS, -lightData.innerDistance, lightData.innerDistance); |
|||
weight.y = saturate(1.0 - distFade / max(lightData.blendDistance, 0.0001)); // avoid divide by zero |
|||
} |
|||
|
|||
// Smooth weighting |
|||
weight.x = 0.0; |
|||
weight.y = Smoothstep01(weight.y); |
|||
|
|||
float3 F = 1.0; |
|||
specularLighting = float3(0.0, 0.0, 0.0); |
|||
|
|||
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, R, preLightData.iblMipLevel); |
|||
specularLighting += F * preLD.rgb * preLightData.specularFGD; |
|||
|
|||
diffuseLighting = float3(0.0, 0.0, 0.0); |
|||
|
|||
#endif |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// PostEvaluateBSDF |
|||
// ---------------------------------------------------------------------------- |
|||
|
|||
void PostEvaluateBSDF( LightLoopContext lightLoopContext, PreLightData preLightData, BSDFData bsdfData, LightLoopAccumulatedLighting accLighting, float3 bakeDiffuseLighting, |
|||
out float3 diffuseLighting, out float3 specularLighting) |
|||
{ |
|||
// Add indirect diffuse + emissive (if any) - Ambient occlusion is multiply by emissive which is wrong but not a big deal |
|||
bakeDiffuseLighting *= GTAOMultiBounce(lightLoopContext.indirectAmbientOcclusion, bsdfData.diffuseColor); |
|||
|
|||
float specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(preLightData.NdotV, lightLoopContext.indirectAmbientOcclusion, bsdfData.roughness); |
|||
// Try to mimic multibounce with specular color. Not the point of the original formula but ok result. |
|||
// Take the min of screenspace specular occlusion and visibility cone specular occlusion |
|||
accLighting.envSpecularLighting *= GTAOMultiBounce(min(bsdfData.specularOcclusion, specularOcclusion), bsdfData.fresnel0); |
|||
|
|||
// TODO: we could call a function like PostBSDF that will apply albedo and divide by PI once for the loop |
|||
|
|||
// envDiffuseLighting is not used in our case |
|||
diffuseLighting = (accLighting.dirDiffuseLighting + accLighting.punctualDiffuseLighting + accLighting.areaDiffuseLighting) * GTAOMultiBounce(lightLoopContext.directAmbientOcclusion, bsdfData.diffuseColor) + bakeDiffuseLighting; |
|||
specularLighting = accLighting.dirSpecularLighting + accLighting.punctualSpecularLighting + accLighting.areaSpecularLighting + accLighting.envSpecularLighting; |
|||
} |
|||
|
|||
|
|||
#endif // #ifdef HAS_LIGHTLOOP |
|
|||
fileFormatVersion: 2 |
|||
guid: a5ae278c101d602428cf78a26d2444e9 |
|||
timeCreated: 1504900828 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 5cacfca84329cc344aab142e0642329b |
|||
folderAsset: yes |
|||
timeCreated: 1497326931 |
|||
licenseType: Free |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
// A Material can be authored from the shader graph or by hand. When written by hand we need to provide an inspector.
|
|||
// Such a Material will share some properties between it various variant (shader graph variant or hand authored variant).
|
|||
// This is the purpose of BaseLitGUI. It contain all properties that are common to all Material based on Lit template.
|
|||
// For the default hand written Lit material see LitUI.cs that contain specific properties for our default implementation.
|
|||
public abstract class BaseEyeGUI : BaseUnlitGUI |
|||
{ |
|||
protected static class StylesBaseLit |
|||
{ |
|||
public static GUIContent doubleSidedNormalModeText = new GUIContent("Normal mode", "This will modify the normal base on the selected mode. None: untouch, Mirror: Mirror the normal with vertex normal plane, Flip: Flip the normal"); |
|||
public static GUIContent depthOffsetEnableText = new GUIContent("Enable Depth Offset", "EnableDepthOffset on this shader (Use with heightmap)"); |
|||
|
|||
// Per pixel displacement
|
|||
public static GUIContent enablePerPixelDisplacementText = new GUIContent("Enable Per Pixel Displacement", ""); |
|||
public static GUIContent ppdMinSamplesText = new GUIContent("Minimum samples", "Minimum samples to use with per pixel displacement mapping"); |
|||
public static GUIContent ppdMaxSamplesText = new GUIContent("Maximum samples", "Maximum samples to use with per pixel displacement mapping"); |
|||
public static GUIContent ppdLodThresholdText = new GUIContent("Fading LOD start", "Starting Lod where the parallax occlusion mapping effect start to disappear"); |
|||
|
|||
// Tessellation
|
|||
public static string tessellationModeText = "Tessellation Mode"; |
|||
public static readonly string[] tessellationModeNames = Enum.GetNames(typeof(TessellationMode)); |
|||
|
|||
public static GUIContent tessellationText = new GUIContent("Tessellation options", "Tessellation options"); |
|||
public static GUIContent tessellationFactorText = new GUIContent("Tessellation factor", "This value is the tessellation factor use for tessellation, higher mean more tessellated"); |
|||
public static GUIContent tessellationFactorMinDistanceText = new GUIContent("Start fade distance", "Distance (in unity unit) at which the tessellation start to fade out. Must be inferior at Max distance"); |
|||
public static GUIContent tessellationFactorMaxDistanceText = new GUIContent("End fade distance", "Maximum distance (in unity unit) to the camera where triangle are tessellated"); |
|||
public static GUIContent tessellationFactorTriangleSizeText = new GUIContent("Triangle size", "Desired screen space sized of triangle (in pixel). Smaller value mean smaller triangle."); |
|||
public static GUIContent tessellationShapeFactorText = new GUIContent("Shape factor", "Strength of Phong tessellation shape (lerp factor)"); |
|||
public static GUIContent tessellationBackFaceCullEpsilonText = new GUIContent("Triangle culling Epsilon", "If -1.0 back face culling is enabled for tessellation, higher number mean more aggressive culling and better performance"); |
|||
public static GUIContent tessellationObjectScaleText = new GUIContent("Enable object scale", "Tessellation displacement will take into account the object scale - Only work with uniform positive scale"); |
|||
public static GUIContent tessellationTilingScaleText = new GUIContent("Enable tiling scale", "Tessellation displacement will take into account the tiling scale - Only work with uniform positive scale"); |
|||
|
|||
// Wind
|
|||
public static GUIContent windText = new GUIContent("Enable Wind"); |
|||
public static GUIContent windInitialBendText = new GUIContent("Initial Bend"); |
|||
public static GUIContent windStiffnessText = new GUIContent("Stiffness"); |
|||
public static GUIContent windDragText = new GUIContent("Drag"); |
|||
public static GUIContent windShiverDragText = new GUIContent("Shiver Drag"); |
|||
public static GUIContent windShiverDirectionalityText = new GUIContent("Shiver Directionality"); |
|||
|
|||
public static string vertexAnimation = "Vertex Animation"; |
|||
} |
|||
|
|||
public enum DoubleSidedNormalMode |
|||
{ |
|||
None, |
|||
Mirror, |
|||
Flip |
|||
} |
|||
|
|||
public enum TessellationMode |
|||
{ |
|||
Phong, |
|||
Displacement, |
|||
DisplacementPhong, |
|||
} |
|||
|
|||
protected MaterialProperty doubleSidedNormalMode = null; |
|||
protected const string kDoubleSidedNormalMode = "_DoubleSidedNormalMode"; |
|||
protected MaterialProperty depthOffsetEnable = null; |
|||
protected const string kDepthOffsetEnable = "_DepthOffsetEnable"; |
|||
|
|||
// Properties
|
|||
// Material ID
|
|||
protected MaterialProperty materialID = null; |
|||
protected const string kMaterialID = "_MaterialID"; |
|||
|
|||
protected const string kStencilRef = "_StencilRef"; |
|||
|
|||
// Wind
|
|||
protected MaterialProperty windEnable = null; |
|||
protected const string kWindEnabled = "_EnableWind"; |
|||
protected MaterialProperty windInitialBend = null; |
|||
protected const string kWindInitialBend = "_InitialBend"; |
|||
protected MaterialProperty windStiffness = null; |
|||
protected const string kWindStiffness = "_Stiffness"; |
|||
protected MaterialProperty windDrag = null; |
|||
protected const string kWindDrag = "_Drag"; |
|||
protected MaterialProperty windShiverDrag = null; |
|||
protected const string kWindShiverDrag = "_ShiverDrag"; |
|||
protected MaterialProperty windShiverDirectionality = null; |
|||
protected const string kWindShiverDirectionality = "_ShiverDirectionality"; |
|||
|
|||
// Per pixel displacement params
|
|||
protected MaterialProperty enablePerPixelDisplacement = null; |
|||
protected const string kEnablePerPixelDisplacement = "_EnablePerPixelDisplacement"; |
|||
protected MaterialProperty ppdMinSamples = null; |
|||
protected const string kPpdMinSamples = "_PPDMinSamples"; |
|||
protected MaterialProperty ppdMaxSamples = null; |
|||
protected const string kPpdMaxSamples = "_PPDMaxSamples"; |
|||
protected MaterialProperty ppdLodThreshold = null; |
|||
protected const string kPpdLodThreshold = "_PPDLodThreshold"; |
|||
|
|||
// tessellation params
|
|||
protected MaterialProperty tessellationMode = null; |
|||
protected const string kTessellationMode = "_TessellationMode"; |
|||
protected MaterialProperty tessellationFactor = null; |
|||
protected const string kTessellationFactor = "_TessellationFactor"; |
|||
protected MaterialProperty tessellationFactorMinDistance = null; |
|||
protected const string kTessellationFactorMinDistance = "_TessellationFactorMinDistance"; |
|||
protected MaterialProperty tessellationFactorMaxDistance = null; |
|||
protected const string kTessellationFactorMaxDistance = "_TessellationFactorMaxDistance"; |
|||
protected MaterialProperty tessellationFactorTriangleSize = null; |
|||
protected const string kTessellationFactorTriangleSize = "_TessellationFactorTriangleSize"; |
|||
protected MaterialProperty tessellationShapeFactor = null; |
|||
protected const string kTessellationShapeFactor = "_TessellationShapeFactor"; |
|||
protected MaterialProperty tessellationBackFaceCullEpsilon = null; |
|||
protected const string kTessellationBackFaceCullEpsilon = "_TessellationBackFaceCullEpsilon"; |
|||
protected MaterialProperty tessellationObjectScale = null; |
|||
protected const string kTessellationObjectScale = "_TessellationObjectScale"; |
|||
protected MaterialProperty tessellationTilingScale = null; |
|||
protected const string kTessellationTilingScale = "_TessellationTilingScale"; |
|||
|
|||
protected override void FindBaseMaterialProperties(MaterialProperty[] props) |
|||
{ |
|||
base.FindBaseMaterialProperties(props); |
|||
|
|||
doubleSidedNormalMode = FindProperty(kDoubleSidedNormalMode, props); |
|||
depthOffsetEnable = FindProperty(kDepthOffsetEnable, props); |
|||
|
|||
// MaterialID
|
|||
materialID = FindProperty(kMaterialID, props, false); // LayeredLit is force to be standard for now, so materialID could not exist
|
|||
|
|||
// Per pixel displacement
|
|||
enablePerPixelDisplacement = FindProperty(kEnablePerPixelDisplacement, props); |
|||
ppdMinSamples = FindProperty(kPpdMinSamples, props); |
|||
ppdMaxSamples = FindProperty(kPpdMaxSamples, props); |
|||
ppdLodThreshold = FindProperty(kPpdLodThreshold, props); |
|||
|
|||
// tessellation specific, silent if not found
|
|||
tessellationMode = FindProperty(kTessellationMode, props, false); |
|||
tessellationFactor = FindProperty(kTessellationFactor, props, false); |
|||
tessellationFactorMinDistance = FindProperty(kTessellationFactorMinDistance, props, false); |
|||
tessellationFactorMaxDistance = FindProperty(kTessellationFactorMaxDistance, props, false); |
|||
tessellationFactorTriangleSize = FindProperty(kTessellationFactorTriangleSize, props, false); |
|||
tessellationShapeFactor = FindProperty(kTessellationShapeFactor, props, false); |
|||
tessellationBackFaceCullEpsilon = FindProperty(kTessellationBackFaceCullEpsilon, props, false); |
|||
tessellationObjectScale = FindProperty(kTessellationObjectScale, props, false); |
|||
tessellationTilingScale = FindProperty(kTessellationTilingScale, props, false); |
|||
|
|||
// Wind
|
|||
windEnable = FindProperty(kWindEnabled, props); |
|||
windInitialBend = FindProperty(kWindInitialBend, props); |
|||
windStiffness = FindProperty(kWindStiffness, props); |
|||
windDrag = FindProperty(kWindDrag, props); |
|||
windShiverDrag = FindProperty(kWindShiverDrag, props); |
|||
windShiverDirectionality = FindProperty(kWindShiverDirectionality, props); |
|||
} |
|||
|
|||
void TessellationModePopup() |
|||
{ |
|||
EditorGUI.showMixedValue = tessellationMode.hasMixedValue; |
|||
var mode = (TessellationMode)tessellationMode.floatValue; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
mode = (TessellationMode)EditorGUILayout.Popup(StylesBaseLit.tessellationModeText, (int)mode, StylesBaseLit.tessellationModeNames); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MaterialEditor.RegisterPropertyChangeUndo("Tessellation Mode"); |
|||
tessellationMode.floatValue = (float)mode; |
|||
} |
|||
|
|||
EditorGUI.showMixedValue = false; |
|||
} |
|||
|
|||
protected override void BaseMaterialPropertiesGUI() |
|||
{ |
|||
base.BaseMaterialPropertiesGUI(); |
|||
|
|||
// This follow double sided option
|
|||
if (doubleSidedEnable.floatValue > 0.0f) |
|||
{ |
|||
EditorGUI.indentLevel++; |
|||
m_MaterialEditor.ShaderProperty(doubleSidedNormalMode, StylesBaseLit.doubleSidedNormalModeText); |
|||
EditorGUI.indentLevel--; |
|||
} |
|||
|
|||
|
|||
m_MaterialEditor.ShaderProperty(enablePerPixelDisplacement, StylesBaseLit.enablePerPixelDisplacementText); |
|||
if (enablePerPixelDisplacement.floatValue > 0.0f) |
|||
{ |
|||
EditorGUI.indentLevel++; |
|||
m_MaterialEditor.ShaderProperty(ppdMinSamples, StylesBaseLit.ppdMinSamplesText); |
|||
m_MaterialEditor.ShaderProperty(ppdMaxSamples, StylesBaseLit.ppdMaxSamplesText); |
|||
ppdMinSamples.floatValue = Mathf.Min(ppdMinSamples.floatValue, ppdMaxSamples.floatValue); |
|||
m_MaterialEditor.ShaderProperty(ppdLodThreshold, StylesBaseLit.ppdLodThresholdText); |
|||
m_MaterialEditor.ShaderProperty(depthOffsetEnable, StylesBaseLit.depthOffsetEnableText); |
|||
EditorGUI.indentLevel--; |
|||
} |
|||
|
|||
EditorGUI.indentLevel--; |
|||
|
|||
// Display tessellation option if it exist
|
|||
if (tessellationMode != null) |
|||
{ |
|||
GUILayout.Label(StylesBaseLit.tessellationText, EditorStyles.boldLabel); |
|||
EditorGUI.indentLevel++; |
|||
TessellationModePopup(); |
|||
m_MaterialEditor.ShaderProperty(tessellationFactor, StylesBaseLit.tessellationFactorText); |
|||
m_MaterialEditor.ShaderProperty(tessellationFactorMinDistance, StylesBaseLit.tessellationFactorMinDistanceText); |
|||
m_MaterialEditor.ShaderProperty(tessellationFactorMaxDistance, StylesBaseLit.tessellationFactorMaxDistanceText); |
|||
// clamp min distance to be below max distance
|
|||
tessellationFactorMinDistance.floatValue = Math.Min(tessellationFactorMaxDistance.floatValue, tessellationFactorMinDistance.floatValue); |
|||
m_MaterialEditor.ShaderProperty(tessellationFactorTriangleSize, StylesBaseLit.tessellationFactorTriangleSizeText); |
|||
if ((TessellationMode)tessellationMode.floatValue == TessellationMode.Phong || |
|||
(TessellationMode)tessellationMode.floatValue == TessellationMode.DisplacementPhong) |
|||
{ |
|||
m_MaterialEditor.ShaderProperty(tessellationShapeFactor, StylesBaseLit.tessellationShapeFactorText); |
|||
} |
|||
if (doubleSidedEnable.floatValue == 0.0) |
|||
{ |
|||
m_MaterialEditor.ShaderProperty(tessellationBackFaceCullEpsilon, StylesBaseLit.tessellationBackFaceCullEpsilonText); |
|||
} |
|||
m_MaterialEditor.ShaderProperty(tessellationObjectScale, StylesBaseLit.tessellationObjectScaleText); |
|||
m_MaterialEditor.ShaderProperty(tessellationTilingScale, StylesBaseLit.tessellationTilingScaleText); |
|||
EditorGUI.indentLevel--; |
|||
} |
|||
} |
|||
|
|||
protected override void VertexAnimationPropertiesGUI() |
|||
{ |
|||
GUILayout.Label(StylesBaseLit.vertexAnimation, EditorStyles.boldLabel); |
|||
|
|||
EditorGUI.indentLevel++; |
|||
|
|||
m_MaterialEditor.ShaderProperty(windEnable, StylesBaseLit.windText); |
|||
if (!windEnable.hasMixedValue && windEnable.floatValue > 0.0f) |
|||
{ |
|||
EditorGUI.indentLevel++; |
|||
m_MaterialEditor.ShaderProperty(windInitialBend, StylesBaseLit.windInitialBendText); |
|||
m_MaterialEditor.ShaderProperty(windStiffness, StylesBaseLit.windStiffnessText); |
|||
m_MaterialEditor.ShaderProperty(windDrag, StylesBaseLit.windDragText); |
|||
m_MaterialEditor.ShaderProperty(windShiverDrag, StylesBaseLit.windShiverDragText); |
|||
m_MaterialEditor.ShaderProperty(windShiverDirectionality, StylesBaseLit.windShiverDirectionalityText); |
|||
EditorGUI.indentLevel--; |
|||
} |
|||
|
|||
EditorGUI.indentLevel--; |
|||
} |
|||
|
|||
// 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 SetupBaseLitKeywords(Material material) |
|||
{ |
|||
SetupBaseUnlitKeywords(material); |
|||
|
|||
bool doubleSidedEnable = material.GetFloat(kDoubleSidedEnable) > 0.0f; |
|||
|
|||
if (doubleSidedEnable) |
|||
{ |
|||
DoubleSidedNormalMode doubleSidedNormalMode = (DoubleSidedNormalMode)material.GetFloat(kDoubleSidedNormalMode); |
|||
switch (doubleSidedNormalMode) |
|||
{ |
|||
case DoubleSidedNormalMode.None: |
|||
material.SetVector("_DoubleSidedConstants", new Vector4(1.0f, 1.0f, 1.0f, 0.0f)); |
|||
break; |
|||
|
|||
case DoubleSidedNormalMode.Mirror: // Mirror mode (in tangent space)
|
|||
material.SetVector("_DoubleSidedConstants", new Vector4(1.0f, 1.0f, -1.0f, 0.0f)); |
|||
break; |
|||
|
|||
case DoubleSidedNormalMode.Flip: // Flip mode (in tangent space)
|
|||
material.SetVector("_DoubleSidedConstants", new Vector4(-1.0f, -1.0f, -1.0f, 0.0f)); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
// Depth offset is only enabled if per pixel displacement is
|
|||
bool depthOffsetEnable = (material.GetFloat(kDepthOffsetEnable) > 0.0f) && (material.GetFloat(kEnablePerPixelDisplacement) > 0.0f); |
|||
SetKeyword(material, "_DEPTHOFFSET_ON", depthOffsetEnable); |
|||
|
|||
// Set the reference value for the stencil test.
|
|||
int stencilRef = (int)StencilLightingUsage.RegularLighting; |
|||
if (material.HasProperty(kMaterialID)) |
|||
{ |
|||
if ((int)material.GetFloat(kMaterialID) == (int)UnityEngine.Experimental.Rendering.HDPipeline.Lit.MaterialId.LitSSS) |
|||
{ |
|||
stencilRef = (int)StencilLightingUsage.SplitLighting; |
|||
} |
|||
} |
|||
material.SetInt(kStencilRef, stencilRef); |
|||
|
|||
bool enablePerPixelDisplacement = material.GetFloat(kEnablePerPixelDisplacement) > 0.0f; |
|||
SetKeyword(material, "_PER_PIXEL_DISPLACEMENT", enablePerPixelDisplacement); |
|||
|
|||
if (material.HasProperty(kTessellationMode)) |
|||
{ |
|||
TessellationMode tessMode = (TessellationMode)material.GetFloat(kTessellationMode); |
|||
|
|||
if (tessMode == TessellationMode.Phong) |
|||
{ |
|||
material.DisableKeyword("_TESSELLATION_DISPLACEMENT"); |
|||
material.DisableKeyword("_TESSELLATION_DISPLACEMENT_PHONG"); |
|||
} |
|||
else if (tessMode == TessellationMode.Displacement) |
|||
{ |
|||
material.EnableKeyword("_TESSELLATION_DISPLACEMENT"); |
|||
material.DisableKeyword("_TESSELLATION_DISPLACEMENT_PHONG"); |
|||
} |
|||
else |
|||
{ |
|||
material.DisableKeyword("_TESSELLATION_DISPLACEMENT"); |
|||
material.EnableKeyword("_TESSELLATION_DISPLACEMENT_PHONG"); |
|||
} |
|||
|
|||
bool tessellationObjectScaleEnable = material.GetFloat(kTessellationObjectScale) > 0.0; |
|||
SetKeyword(material, "_TESSELLATION_OBJECT_SCALE", tessellationObjectScaleEnable); |
|||
|
|||
bool tessellationTilingScaleEnable = material.GetFloat(kTessellationTilingScale) > 0.0; |
|||
SetKeyword(material, "_TESSELLATION_TILING_SCALE", tessellationTilingScaleEnable); |
|||
} |
|||
|
|||
bool windEnabled = material.GetFloat(kWindEnabled) > 0.0f; |
|||
SetKeyword(material, "_VERTEX_WIND", windEnabled); |
|||
} |
|||
|
|||
static public void SetupBaseLitMaterialPass(Material material) |
|||
{ |
|||
bool distortionEnable = material.GetFloat(kDistortionEnable) > 0.0f; |
|||
bool distortionOnly = material.GetFloat(kDistortionOnly) > 0.0f; |
|||
|
|||
if (distortionEnable && distortionOnly) |
|||
{ |
|||
// Disable all passes except distortion (setup in BaseUnlitUI.cs) and debug passes (to visualize distortion)
|
|||
material.SetShaderPassEnabled("GBuffer", false); |
|||
material.SetShaderPassEnabled("GBufferDisplayDebug", true); |
|||
material.SetShaderPassEnabled("Meta", false); |
|||
material.SetShaderPassEnabled("ShadowCaster", false); |
|||
material.SetShaderPassEnabled("DepthOnly", false); |
|||
material.SetShaderPassEnabled("MotionVectors", false); |
|||
material.SetShaderPassEnabled("Forward", false); |
|||
material.SetShaderPassEnabled("ForwardDisplayDebug", true); |
|||
} |
|||
else |
|||
{ |
|||
// Enable all passes except distortion (setup in BaseUnlitUI.cs)
|
|||
material.SetShaderPassEnabled("GBuffer", true); |
|||
material.SetShaderPassEnabled("GBufferDisplayDebug", true); |
|||
material.SetShaderPassEnabled("Meta", true); |
|||
material.SetShaderPassEnabled("ShadowCaster", true); |
|||
material.SetShaderPassEnabled("DepthOnly", true); |
|||
material.SetShaderPassEnabled("MotionVectors", true); |
|||
material.SetShaderPassEnabled("Forward", true); |
|||
material.SetShaderPassEnabled("ForwardDisplayDebug", true); |
|||
} |
|||
} |
|||
} |
|||
} // namespace UnityEditor
|
|
|||
fileFormatVersion: 2 |
|||
guid: df9022cd736930941a20c626564bef21 |
|||
timeCreated: 1497326875 |
|||
licenseType: Free |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
class EyeGUI : BaseEyeGUI |
|||
{ |
|||
protected static class Styles |
|||
{ |
|||
public static string InputsText = "Inputs"; |
|||
|
|||
public static GUIContent baseColorText = new GUIContent("Base Color + Opacity", "Albedo (RGB) and Opacity (A)"); |
|||
public static GUIContent baseColorSmoothnessText = new GUIContent("Base Color + Smoothness", "Albedo (RGB) and Smoothness (A)"); |
|||
|
|||
public static GUIContent smoothnessMapChannelText = new GUIContent("Smoothness Source", "Smoothness texture and channel"); |
|||
public static GUIContent smoothnessText = new GUIContent("Smoothness", "Smoothness scale factor"); |
|||
public static GUIContent maskMapESText = new GUIContent("Iris Mask", "Mask map"); |
|||
public static GUIContent maskMapSText = new GUIContent("Iris Mask", "Mask map"); |
|||
|
|||
public static GUIContent irisDepthText = new GUIContent("IrisDepth", "Iris Depth factor"); |
|||
public static GUIContent irisRadiusText = new GUIContent("IrisRadius", "Iris Radius factor"); |
|||
public static GUIContent iorText = new GUIContent("IOR", "IOR factor"); |
|||
|
|||
public static GUIContent normalMapSpaceText = new GUIContent("Normal/Tangent Map space", ""); |
|||
public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map (BC7/BC5/DXT5(nm))"); |
|||
public static GUIContent normalMapOSText = new GUIContent("Normal Map OS", "Normal Map (BC7/DXT1/RGB)"); |
|||
public static GUIContent specularOcclusionMapText = new GUIContent("Specular Occlusion Map (RGBA)", "Specular Occlusion Map"); |
|||
|
|||
public static GUIContent heightMapText = new GUIContent("Height Map (R)", "Height Map"); |
|||
public static GUIContent heightMapAmplitudeText = new GUIContent("Height Map Amplitude", "Height Map amplitude in world units."); |
|||
public static GUIContent heightMapCenterText = new GUIContent("Height Map Center", "Center of the heightmap in the texture (between 0 and 1)"); |
|||
|
|||
public static GUIContent tangentMapText = new GUIContent("Tangent Map", "Tangent Map (BC7/BC5/DXT5(nm))"); |
|||
public static GUIContent tangentMapOSText = new GUIContent("Tangent Map OS", "Tangent Map (BC7/DXT1/RGB)"); |
|||
public static GUIContent anisotropyText = new GUIContent("Anisotropy", "Anisotropy scale factor"); |
|||
public static GUIContent anisotropyMapText = new GUIContent("Anisotropy Map (B)", "Anisotropy"); |
|||
|
|||
public static string textureControlText = "Input textures control"; |
|||
public static GUIContent UVBaseMappingText = new GUIContent("Base UV mapping", ""); |
|||
public static GUIContent UVHeightMappingText = new GUIContent("Height UV mapping", ""); |
|||
public static GUIContent texWorldScaleText = new GUIContent("World scale", "Tiling factor applied to Planar/Trilinear mapping"); |
|||
|
|||
// Subsurface
|
|||
public static GUIContent subsurfaceProfileText = new GUIContent("Subsurface profile", "A profile determines the shape of the blur filter."); |
|||
public static GUIContent subsurfaceRadiusText = new GUIContent("Subsurface radius", "Determines the range of the blur."); |
|||
public static GUIContent subsurfaceRadiusMapText = new GUIContent("Subsurface radius map (R)", "Determines the range of the blur."); |
|||
public static GUIContent thicknessText = new GUIContent("Thickness", "If subsurface scattering is enabled, low values allow some light to be transmitted through the object."); |
|||
public static GUIContent thicknessMapText = new GUIContent("Thickness map (R)", "If subsurface scattering is enabled, low values allow some light to be transmitted through the object."); |
|||
|
|||
// Specular color
|
|||
public static GUIContent specularColorText = new GUIContent("Specular Color", "Specular color (RGB)"); |
|||
|
|||
// Emissive
|
|||
public static string lightingText = "Inputs Lighting"; |
|||
public static GUIContent emissiveText = new GUIContent("Emissive Color", "Emissive"); |
|||
public static GUIContent emissiveIntensityText = new GUIContent("Emissive Intensity", "Emissive"); |
|||
public static GUIContent emissiveColorModeText = new GUIContent("Emissive Color Usage", "Use emissive color or emissive mask"); |
|||
|
|||
public static GUIContent normalMapSpaceWarning = new GUIContent("Object space normal can't be use with triplanar mapping."); |
|||
} |
|||
|
|||
public enum UVBaseMapping |
|||
{ |
|||
UV0, |
|||
Planar, |
|||
Triplanar |
|||
} |
|||
|
|||
public enum UVHeightMapping |
|||
{ |
|||
UV0, |
|||
Planar, |
|||
Triplanar |
|||
} |
|||
|
|||
public enum NormalMapSpace |
|||
{ |
|||
TangentSpace, |
|||
ObjectSpace, |
|||
} |
|||
|
|||
public enum HeightmapMode |
|||
{ |
|||
Parallax, |
|||
Displacement, |
|||
} |
|||
|
|||
public enum UVDetailMapping |
|||
{ |
|||
UV0, |
|||
UV1, |
|||
UV2, |
|||
UV3 |
|||
} |
|||
|
|||
public enum EmissiveColorMode |
|||
{ |
|||
UseEmissiveColor, |
|||
UseEmissiveMask, |
|||
} |
|||
|
|||
protected MaterialProperty UVBase = null; |
|||
protected const string kUVBase = "_UVBase"; |
|||
protected MaterialProperty TexWorldScale = null; |
|||
protected const string kTexWorldScale = "_TexWorldScale"; |
|||
protected MaterialProperty UVMappingMask = null; |
|||
protected const string kUVMappingMask = "_UVMappingMask"; |
|||
|
|||
protected MaterialProperty baseColor = null; |
|||
protected const string kBaseColor = "_BaseColor"; |
|||
protected MaterialProperty baseColorMap = null; |
|||
protected const string kBaseColorMap = "_BaseColorMap"; |
|||
protected MaterialProperty smoothness = null; |
|||
protected const string kSmoothness = "_Smoothness"; |
|||
protected MaterialProperty maskMap = null; |
|||
protected const string kMaskMap = "_MaskMap"; |
|||
protected MaterialProperty specularOcclusionMap = null; |
|||
protected const string kSpecularOcclusionMap = "_SpecularOcclusionMap"; |
|||
protected MaterialProperty normalMap = null; |
|||
protected const string kNormalMap = "_NormalMap"; |
|||
protected MaterialProperty normalMapOS = null; |
|||
protected const string kNormalMapOS = "_NormalMapOS"; |
|||
protected MaterialProperty normalScale = null; |
|||
protected const string kNormalScale = "_NormalScale"; |
|||
protected MaterialProperty normalMapSpace = null; |
|||
protected const string kNormalMapSpace = "_NormalMapSpace"; |
|||
protected MaterialProperty heightMap = null; |
|||
protected const string kHeightMap = "_HeightMap"; |
|||
protected MaterialProperty heightAmplitude = null; |
|||
protected const string kHeightAmplitude = "_HeightAmplitude"; |
|||
protected MaterialProperty heightCenter = null; |
|||
protected const string kHeightCenter = "_HeightCenter"; |
|||
protected MaterialProperty tangentMap = null; |
|||
protected const string kTangentMap = "_TangentMap"; |
|||
protected MaterialProperty tangentMapOS = null; |
|||
protected const string kTangentMapOS = "_TangentMapOS"; |
|||
protected MaterialProperty specularColor = null; |
|||
protected const string kSpecularColor = "_SpecularColor"; |
|||
protected MaterialProperty specularColorMap = null; |
|||
protected const string kSpecularColorMap = "_SpecularColorMap"; |
|||
|
|||
protected MaterialProperty irisDepth = null; |
|||
protected const string kIrisDepth = "_IrisDepth"; |
|||
protected MaterialProperty irisRadius = null; |
|||
protected const string kIrisRadius = "_IrisRadius"; |
|||
protected MaterialProperty ior = null; |
|||
protected const string kIor = "_Ior"; |
|||
|
|||
protected MaterialProperty UVDetail = null; |
|||
protected const string kUVDetail = "_UVDetail"; |
|||
protected MaterialProperty UVDetailsMappingMask = null; |
|||
protected const string kUVDetailsMappingMask = "_UVDetailsMappingMask"; |
|||
protected MaterialProperty detailMap = null; |
|||
protected const string kDetailMap = "_DetailMap"; |
|||
protected MaterialProperty detailMask = null; |
|||
protected const string kDetailMask = "_DetailMask"; |
|||
protected MaterialProperty detailFuzz1 = null; |
|||
protected const string kDetailFuzz1 = "_DetailFuzz1"; |
|||
protected MaterialProperty detailAlbedoScale = null; |
|||
protected const string kDetailAlbedoScale = "_DetailAlbedoScale"; |
|||
protected MaterialProperty detailNormalScale = null; |
|||
protected const string kDetailNormalScale = "_DetailNormalScale"; |
|||
protected MaterialProperty detailSmoothnessScale = null; |
|||
protected const string kDetailSmoothnessScale = "_DetailSmoothnessScale"; |
|||
|
|||
protected SubsurfaceScatteringProfile subsurfaceProfile = null; |
|||
protected MaterialProperty subsurfaceProfileID = null; |
|||
protected const string kSubsurfaceProfileID = "_SubsurfaceProfile"; |
|||
protected MaterialProperty subsurfaceRadius = null; |
|||
protected const string kSubsurfaceRadius = "_SubsurfaceRadius"; |
|||
protected MaterialProperty subsurfaceRadiusMap = null; |
|||
protected const string kSubsurfaceRadiusMap = "_SubsurfaceRadiusMap"; |
|||
protected MaterialProperty thickness = null; |
|||
protected const string kThickness = "_Thickness"; |
|||
protected MaterialProperty thicknessMap = null; |
|||
protected const string kThicknessMap = "_ThicknessMap"; |
|||
|
|||
protected MaterialProperty emissiveColorMode = null; |
|||
protected const string kEmissiveColorMode = "_EmissiveColorMode"; |
|||
protected MaterialProperty emissiveColor = null; |
|||
protected const string kEmissiveColor = "_EmissiveColor"; |
|||
protected MaterialProperty emissiveColorMap = null; |
|||
protected const string kEmissiveColorMap = "_EmissiveColorMap"; |
|||
protected MaterialProperty emissiveIntensity = null; |
|||
protected const string kEmissiveIntensity = "_EmissiveIntensity"; |
|||
|
|||
protected override void FindMaterialProperties(MaterialProperty[] props) |
|||
{ |
|||
UVBase = FindProperty(kUVBase, props); |
|||
TexWorldScale = FindProperty(kTexWorldScale, props); |
|||
UVMappingMask = FindProperty(kUVMappingMask, props); |
|||
|
|||
baseColor = FindProperty(kBaseColor, props); |
|||
baseColorMap = FindProperty(kBaseColorMap, props); |
|||
smoothness = FindProperty(kSmoothness, props); |
|||
maskMap = FindProperty(kMaskMap, props); |
|||
specularOcclusionMap = FindProperty(kSpecularOcclusionMap, props); |
|||
normalMap = FindProperty(kNormalMap, props); |
|||
normalMapOS = FindProperty(kNormalMapOS, props); |
|||
normalScale = FindProperty(kNormalScale, props); |
|||
normalMapSpace = FindProperty(kNormalMapSpace, props); |
|||
heightMap = FindProperty(kHeightMap, props); |
|||
heightAmplitude = FindProperty(kHeightAmplitude, props); |
|||
heightCenter = FindProperty(kHeightCenter, props); |
|||
tangentMap = FindProperty(kTangentMap, props); |
|||
tangentMapOS = FindProperty(kTangentMapOS, props); |
|||
specularColor = FindProperty(kSpecularColor, props); |
|||
specularColorMap = FindProperty(kSpecularColorMap, props); |
|||
|
|||
//eye
|
|||
irisDepth = FindProperty(kIrisDepth, props); |
|||
irisRadius = FindProperty(kIrisRadius, props); |
|||
ior = FindProperty(kIor, props); |
|||
|
|||
// Sub surface
|
|||
subsurfaceProfileID = FindProperty(kSubsurfaceProfileID, props); |
|||
subsurfaceRadius = FindProperty(kSubsurfaceRadius, props); |
|||
subsurfaceRadiusMap = FindProperty(kSubsurfaceRadiusMap, props); |
|||
thickness = FindProperty(kThickness, props); |
|||
thicknessMap = FindProperty(kThicknessMap, props); |
|||
|
|||
// Emissive
|
|||
emissiveColorMode = FindProperty(kEmissiveColorMode, props); |
|||
emissiveColor = FindProperty(kEmissiveColor, props); |
|||
emissiveColorMap = FindProperty(kEmissiveColorMap, props); |
|||
emissiveIntensity = FindProperty(kEmissiveIntensity, props); |
|||
} |
|||
|
|||
protected void ShaderSSSInputGUI(Material material) |
|||
{ |
|||
HDRenderPipeline hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline; |
|||
|
|||
if (subsurfaceProfile == null) |
|||
{ |
|||
// Attempt to load the profile from the SSS Settings.
|
|||
int profileID = (int)subsurfaceProfileID.floatValue; |
|||
|
|||
if (0 <= profileID && profileID < hdPipeline.sssSettings.profiles.Length && |
|||
hdPipeline.sssSettings.profiles[profileID] != null) |
|||
{ |
|||
// This is a valid profile ID.
|
|||
subsurfaceProfile = hdPipeline.sssSettings.profiles[profileID]; |
|||
|
|||
// Refresh the ID of the profile.
|
|||
hdPipeline.sssSettings.OnValidate(); |
|||
} |
|||
} |
|||
|
|||
subsurfaceProfile = EditorGUILayout.ObjectField(Styles.subsurfaceProfileText, subsurfaceProfile, typeof(SubsurfaceScatteringProfile), false) as SubsurfaceScatteringProfile; |
|||
|
|||
bool validProfile = false; |
|||
|
|||
// Set the profile ID.
|
|||
if (subsurfaceProfile != null) |
|||
{ |
|||
// Load the profile from the GUI field.
|
|||
int profileID = subsurfaceProfile.settingsIndex; |
|||
|
|||
if (0 <= profileID && profileID < hdPipeline.sssSettings.profiles.Length && |
|||
hdPipeline.sssSettings.profiles[profileID] != null && |
|||
hdPipeline.sssSettings.profiles[profileID] == subsurfaceProfile) |
|||
{ |
|||
validProfile = true; |
|||
material.SetInt("_SubsurfaceProfile", profileID); |
|||
} |
|||
else |
|||
{ |
|||
subsurfaceProfile = null; |
|||
Debug.LogError("The SSS Profile assigned to the material has an invalid index. First, add the Profile to the SSS Settings, and then reassign it to the material."); |
|||
} |
|||
} |
|||
|
|||
if (!validProfile) |
|||
{ |
|||
// Disable SSS for this object.
|
|||
material.SetInt("_SubsurfaceProfile", SssConstants.SSS_NEUTRAL_PROFILE_ID); |
|||
} |
|||
|
|||
m_MaterialEditor.ShaderProperty(subsurfaceRadius, Styles.subsurfaceRadiusText); |
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.subsurfaceRadiusMapText, subsurfaceRadiusMap); |
|||
} |
|||
|
|||
protected void ShaderStandardInputGUI() |
|||
{ |
|||
if ((NormalMapSpace)normalMapSpace.floatValue == NormalMapSpace.TangentSpace) |
|||
{ |
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.tangentMapText, tangentMap); |
|||
} |
|||
else |
|||
{ |
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.tangentMapOSText, tangentMapOS); |
|||
} |
|||
|
|||
} |
|||
|
|||
protected override void MaterialPropertiesGUI(Material material) |
|||
{ |
|||
GUILayout.Label("Eye Options", EditorStyles.boldLabel); |
|||
EditorGUI.indentLevel++; |
|||
EditorGUI.indentLevel--; |
|||
|
|||
bool useEmissiveMask = (EmissiveColorMode)emissiveColorMode.floatValue == EmissiveColorMode.UseEmissiveMask; |
|||
|
|||
GUILayout.Label(Styles.InputsText, EditorStyles.boldLabel); |
|||
|
|||
EditorGUI.indentLevel++; |
|||
|
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap, baseColor); |
|||
|
|||
m_MaterialEditor.ShaderProperty(smoothness, Styles.smoothnessText); |
|||
|
|||
m_MaterialEditor.ShaderProperty(irisDepth, Styles.irisDepthText); |
|||
m_MaterialEditor.ShaderProperty(irisRadius, Styles.irisRadiusText); |
|||
m_MaterialEditor.ShaderProperty(ior, Styles.iorText); |
|||
|
|||
if (useEmissiveMask) |
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapESText, maskMap); |
|||
else |
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapSText, maskMap); |
|||
|
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.specularOcclusionMapText, specularOcclusionMap); |
|||
|
|||
m_MaterialEditor.ShaderProperty(normalMapSpace, Styles.normalMapSpaceText); |
|||
|
|||
// Triplanar only work with tangent space normal
|
|||
if ((NormalMapSpace)normalMapSpace.floatValue == NormalMapSpace.ObjectSpace && ((UVBaseMapping)UVBase.floatValue == UVBaseMapping.Triplanar)) |
|||
{ |
|||
EditorGUILayout.HelpBox(Styles.normalMapSpaceWarning.text, MessageType.Error); |
|||
} |
|||
|
|||
// We have two different property for object space and tangent space normal map to allow
|
|||
// 1. to go back and forth
|
|||
// 2. to avoid the warning that ask to fix the object normal map texture (normalOS are just linear RGB texture
|
|||
if ((NormalMapSpace)normalMapSpace.floatValue == NormalMapSpace.TangentSpace) |
|||
{ |
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap, normalScale); |
|||
} |
|||
else |
|||
{ |
|||
// No scaling in object space
|
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapOSText, normalMapOS); |
|||
} |
|||
|
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.heightMapText, heightMap); |
|||
if (!heightMap.hasMixedValue && heightMap.textureValue != null) |
|||
{ |
|||
EditorGUI.indentLevel++; |
|||
m_MaterialEditor.ShaderProperty(heightAmplitude, Styles.heightMapAmplitudeText); |
|||
heightAmplitude.floatValue = Math.Max(0.0f, heightAmplitude.floatValue); // Must be positive
|
|||
m_MaterialEditor.ShaderProperty(heightCenter, Styles.heightMapCenterText); |
|||
EditorGUI.showMixedValue = false; |
|||
EditorGUI.indentLevel--; |
|||
} |
|||
|
|||
ShaderSSSInputGUI(material); /* |
|||
switch ((Lit.MaterialId)materialID.floatValue) |
|||
{ |
|||
case Lit.MaterialId.LitSSS: |
|||
ShaderSSSInputGUI(material); |
|||
break; |
|||
case Lit.MaterialId.LitStandard: |
|||
ShaderStandardInputGUI(); |
|||
break; |
|||
case Lit.MaterialId.LitSpecular: |
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.specularColorText, specularColorMap, specularColor); |
|||
break; |
|||
default: |
|||
Debug.Assert(false, "Encountered an unsupported MaterialID."); |
|||
break; |
|||
}*/ |
|||
|
|||
EditorGUILayout.Space(); |
|||
GUILayout.Label(" " + Styles.textureControlText, EditorStyles.label); |
|||
m_MaterialEditor.ShaderProperty(UVBase, Styles.UVBaseMappingText); |
|||
// UVSet0 is always set, planar and triplanar will override it.
|
|||
UVMappingMask.colorValue = new Color(1.0f, 0.0f, 0.0f, 0.0f); // This is override in the shader anyway but just in case.
|
|||
if (((UVBaseMapping)UVBase.floatValue == UVBaseMapping.Planar) || ((UVBaseMapping)UVBase.floatValue == UVBaseMapping.Triplanar)) |
|||
{ |
|||
m_MaterialEditor.ShaderProperty(TexWorldScale, Styles.texWorldScaleText); |
|||
} |
|||
m_MaterialEditor.TextureScaleOffsetProperty(baseColorMap); |
|||
|
|||
// Setup the UVSet for detail, if planar/triplanar is use for base, it will override the mapping of detail (See shader code)
|
|||
EditorGUI.indentLevel--; |
|||
|
|||
EditorGUILayout.Space(); |
|||
GUILayout.Label(Styles.lightingText, EditorStyles.boldLabel); |
|||
m_MaterialEditor.ShaderProperty(emissiveColorMode, Styles.emissiveColorModeText); |
|||
|
|||
if (!useEmissiveMask) |
|||
{ |
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.emissiveText, emissiveColorMap, emissiveColor); |
|||
} |
|||
|
|||
m_MaterialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText); |
|||
|
|||
// The parent Base.ShaderPropertiesGUI will call DoEmissionArea
|
|||
} |
|||
|
|||
protected override bool ShouldEmissionBeEnabled(Material mat) |
|||
{ |
|||
return mat.GetFloat(kEmissiveIntensity) > 0.0f; |
|||
} |
|||
|
|||
protected override void SetupMaterialKeywordsAndPassInternal(Material material) |
|||
{ |
|||
SetupMaterialKeywordsAndPass(material); |
|||
} |
|||
|
|||
// 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) |
|||
{ |
|||
SetupBaseLitKeywords(material); |
|||
SetupBaseLitMaterialPass(material); |
|||
|
|||
NormalMapSpace normalMapSpace = (NormalMapSpace)material.GetFloat(kNormalMapSpace); |
|||
|
|||
// Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation
|
|||
// (MaterialProperty value might come from renderer material property block)
|
|||
SetKeyword(material, "_MAPPING_PLANAR", ((UVBaseMapping)material.GetFloat(kUVBase)) == UVBaseMapping.Planar); |
|||
SetKeyword(material, "_MAPPING_TRIPLANAR", ((UVBaseMapping)material.GetFloat(kUVBase)) == UVBaseMapping.Triplanar); |
|||
SetKeyword(material, "_NORMALMAP_TANGENT_SPACE", (normalMapSpace == NormalMapSpace.TangentSpace)); |
|||
SetKeyword(material, "_EMISSIVE_COLOR", ((EmissiveColorMode)material.GetFloat(kEmissiveColorMode)) == EmissiveColorMode.UseEmissiveColor); |
|||
|
|||
if (normalMapSpace == NormalMapSpace.TangentSpace) |
|||
{ |
|||
// With details map, we always use a normal map and Unity provide a default (0, 0, 1) normal map for it
|
|||
SetKeyword(material, "_NORMALMAP", material.GetTexture(kNormalMap) || material.GetTexture(kDetailMap)); |
|||
SetKeyword(material, "_TANGENTMAP", material.GetTexture(kTangentMap)); |
|||
} |
|||
else // Object space
|
|||
{ |
|||
// With details map, we always use a normal map but in case of objects space there is no good default, so the result will be weird until users fix it
|
|||
SetKeyword(material, "_NORMALMAP", material.GetTexture(kNormalMapOS) || material.GetTexture(kDetailMap)); |
|||
SetKeyword(material, "_TANGENTMAP", material.GetTexture(kTangentMapOS)); |
|||
} |
|||
SetKeyword(material, "_MASKMAP", material.GetTexture(kMaskMap)); |
|||
SetKeyword(material, "_SPECULAROCCLUSIONMAP", material.GetTexture(kSpecularOcclusionMap)); |
|||
SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap)); |
|||
SetKeyword(material, "_HEIGHTMAP", material.GetTexture(kHeightMap)); |
|||
SetKeyword(material, "_DETAIL_MAP", material.GetTexture(kDetailMap)); |
|||
SetKeyword(material, "_SUBSURFACE_RADIUS_MAP", material.GetTexture(kSubsurfaceRadiusMap)); |
|||
SetKeyword(material, "_THICKNESSMAP", material.GetTexture(kThicknessMap)); |
|||
SetKeyword(material, "_SPECULARCOLORMAP", material.GetTexture(kSpecularColorMap)); |
|||
|
|||
bool needUV2 = (UVBaseMapping)material.GetFloat(kUVBase) == UVBaseMapping.UV0; |
|||
bool needUV3 = (UVBaseMapping)material.GetFloat(kUVBase) == UVBaseMapping.UV0; |
|||
|
|||
if (needUV3) |
|||
{ |
|||
material.DisableKeyword("_REQUIRE_UV2"); |
|||
material.EnableKeyword("_REQUIRE_UV3"); |
|||
} |
|||
else if (needUV2) |
|||
{ |
|||
material.EnableKeyword("_REQUIRE_UV2"); |
|||
material.DisableKeyword("_REQUIRE_UV3"); |
|||
} |
|||
else |
|||
{ |
|||
material.DisableKeyword("_REQUIRE_UV2"); |
|||
material.DisableKeyword("_REQUIRE_UV3"); |
|||
} |
|||
} |
|||
} |
|||
} // namespace UnityEditor
|
|
|||
fileFormatVersion: 2 |
|||
guid: 41d12be52f312cb47a51902cccbcf67e |
|||
timeCreated: 1497327220 |
|||
licenseType: Free |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public partial class Eye : RenderPipelineMaterial |
|||
{ |
|||
[GenerateHLSL(PackingRules.Exact)] |
|||
public enum MaterialId |
|||
{ |
|||
LitSSS = 0, |
|||
LitStandard = 1, |
|||
LitUnused0 = 2, |
|||
LitUnused1 = 3, |
|||
LitAniso = 4, // Should be the last as it is not setup by the users but generated based on anisotropy property
|
|||
LitSpecular = 5, // Should be the last as it is not setup by the users but generated based on anisotropy property and specular
|
|||
}; |
|||
|
|||
[GenerateHLSL] |
|||
public enum MaterialFeatureFlags |
|||
{ |
|||
LitSSS = 1 << 12, |
|||
LitStandard = 1 << 13, |
|||
LitAniso = 1 << 14, |
|||
LitSpecular = 1 << 15 |
|||
} |
|||
|
|||
//-----------------------------------------------------------------------------
|
|||
// SurfaceData
|
|||
//-----------------------------------------------------------------------------
|
|||
|
|||
// Main structure that store the user data (i.e user input of master node in material graph)
|
|||
[GenerateHLSL(PackingRules.Exact, false, true, 1000)] |
|||
public struct SurfaceData |
|||
{ |
|||
[SurfaceDataAttributes("Base Color", false, true)] |
|||
public Vector3 baseColor; |
|||
[SurfaceDataAttributes("Specular Occlusion")] |
|||
public float specularOcclusion; |
|||
|
|||
[SurfaceDataAttributes("Normal", true)] |
|||
public Vector3 normalWS; |
|||
[SurfaceDataAttributes("Smoothness")] |
|||
public float perceptualSmoothness; |
|||
[SurfaceDataAttributes("Material ID")] |
|||
public int materialId; |
|||
|
|||
[SurfaceDataAttributes("Ambient Occlusion")] |
|||
public float ambientOcclusion; |
|||
|
|||
// standard
|
|||
[SurfaceDataAttributes("Tangent", true)] |
|||
public Vector3 tangentWS; |
|||
[SurfaceDataAttributes("Anisotropy")] |
|||
public float anisotropy; // anisotropic ratio(0->no isotropic; 1->full anisotropy in tangent direction)
|
|||
[SurfaceDataAttributes("Specular")] |
|||
public float specular; // 0.02, 0.04, 0.16, 0.2
|
|||
|
|||
// SSS
|
|||
[SurfaceDataAttributes("Subsurface Radius")] |
|||
public float subsurfaceRadius; |
|||
[SurfaceDataAttributes("Thickness")] |
|||
public float thickness; |
|||
[SurfaceDataAttributes("Subsurface Profile")] |
|||
public int subsurfaceProfile; |
|||
|
|||
// SpecColor
|
|||
[SurfaceDataAttributes("Specular Color", false, true)] |
|||
public Vector3 specularColor; |
|||
}; |
|||
|
|||
//-----------------------------------------------------------------------------
|
|||
// BSDFData
|
|||
//-----------------------------------------------------------------------------
|
|||
|
|||
[GenerateHLSL(PackingRules.Exact)] |
|||
public enum TransmissionType |
|||
{ |
|||
None = 0, |
|||
Regular = 1, |
|||
ThinObject = 2, |
|||
}; |
|||
|
|||
[GenerateHLSL(PackingRules.Exact, false, true, 1030)] |
|||
public struct BSDFData |
|||
{ |
|||
[SurfaceDataAttributes("", false, true)] |
|||
public Vector3 diffuseColor; |
|||
|
|||
public Vector3 fresnel0; |
|||
|
|||
public float specularOcclusion; |
|||
|
|||
[SurfaceDataAttributes("", true)] |
|||
public Vector3 normalWS; |
|||
public float perceptualRoughness; |
|||
public float roughness; |
|||
public int materialId; |
|||
|
|||
// standard
|
|||
[SurfaceDataAttributes("", true)] |
|||
public Vector3 tangentWS; |
|||
[SurfaceDataAttributes("", true)] |
|||
public Vector3 bitangentWS; |
|||
public float roughnessT; |
|||
public float roughnessB; |
|||
public float anisotropy; |
|||
|
|||
// fold into fresnel0
|
|||
|
|||
// SSS
|
|||
public float subsurfaceRadius; |
|||
public float thickness; |
|||
public int subsurfaceProfile; |
|||
public bool enableTransmission; // Read from the SSS profile
|
|||
public bool useThinObjectMode; // Read from the SSS profile
|
|||
public Vector3 transmittance; |
|||
|
|||
// SpecColor
|
|||
// fold into fresnel0
|
|||
}; |
|||
|
|||
//-----------------------------------------------------------------------------
|
|||
// RenderLoop management
|
|||
//-----------------------------------------------------------------------------
|
|||
|
|||
[GenerateHLSL(PackingRules.Exact)] |
|||
public enum GBufferMaterial |
|||
{ |
|||
// Note: This count doesn't include the velocity buffer. On shader and csharp side the velocity buffer will be added by the framework
|
|||
Count = (ShaderConfig.k_PackgbufferInU16 == 1) ? 2 : 4 |
|||
}; |
|||
|
|||
//-----------------------------------------------------------------------------
|
|||
// GBuffer management
|
|||
//-----------------------------------------------------------------------------
|
|||
|
|||
public override int GetMaterialGBufferCount() { return (int)GBufferMaterial.Count; } |
|||
|
|||
public override void GetMaterialGBufferDescription(out RenderTextureFormat[] RTFormat, out RenderTextureReadWrite[] RTReadWrite) |
|||
{ |
|||
RTFormat = new RenderTextureFormat[(int)GBufferMaterial.Count]; |
|||
RTReadWrite = new RenderTextureReadWrite[(int)GBufferMaterial.Count]; |
|||
|
|||
if (ShaderConfig.s_PackgbufferInU16 == 1) |
|||
{ |
|||
// TODO: Just discovered that Unity doesn't support unsigned 16 RT format.
|
|||
RTFormat[0] = RenderTextureFormat.ARGBInt; RTReadWrite[0] = RenderTextureReadWrite.Linear; |
|||
RTFormat[1] = RenderTextureFormat.ARGBInt; RTReadWrite[1] = RenderTextureReadWrite.Linear; |
|||
} |
|||
else |
|||
{ |
|||
RTFormat[0] = RenderTextureFormat.ARGB32; RTReadWrite[0] = RenderTextureReadWrite.sRGB; |
|||
RTFormat[1] = RenderTextureFormat.ARGB2101010; RTReadWrite[1] = RenderTextureReadWrite.Linear; |
|||
RTFormat[2] = RenderTextureFormat.ARGB32; RTReadWrite[2] = RenderTextureReadWrite.Linear; |
|||
RTFormat[3] = RenderTextureFormat.RGB111110Float; RTReadWrite[3] = RenderTextureReadWrite.Linear; |
|||
} |
|||
} |
|||
|
|||
//-----------------------------------------------------------------------------
|
|||
// Init precomputed texture
|
|||
//-----------------------------------------------------------------------------
|
|||
|
|||
bool m_isInit; |
|||
|
|||
// For image based lighting
|
|||
Material m_InitPreFGD; |
|||
RenderTexture m_PreIntegratedFGD; |
|||
|
|||
// For area lighting - We pack all texture inside a texture array to reduce the number of resource required
|
|||
Texture2DArray m_LtcData; // 0: m_LtcGGXMatrix - RGBA, 2: m_LtcDisneyDiffuseMatrix - RGBA, 3: m_LtcMultiGGXFresnelDisneyDiffuse - RGB, A unused
|
|||
|
|||
const int k_LtcLUTMatrixDim = 3; // size of the matrix (3x3)
|
|||
const int k_LtcLUTResolution = 64; |
|||
|
|||
|
|||
// Load LUT with one scalar in alpha of a tex2D
|
|||
void LoadLUT(Texture2DArray tex, int arrayElement, TextureFormat format, float[] LUTScalar) |
|||
{ |
|||
const int count = k_LtcLUTResolution * k_LtcLUTResolution; |
|||
Color[] pixels = new Color[count]; |
|||
|
|||
for (int i = 0; i < count; i++) |
|||
{ |
|||
pixels[i] = new Color(0, 0, 0, LUTScalar[i]); |
|||
} |
|||
|
|||
tex.SetPixels(pixels, arrayElement); |
|||
} |
|||
|
|||
// Load LUT with 3x3 matrix in RGBA of a tex2D (some part are zero)
|
|||
void LoadLUT(Texture2DArray tex, int arrayElement, TextureFormat format, double[,] LUTTransformInv) |
|||
{ |
|||
const int count = k_LtcLUTResolution * k_LtcLUTResolution; |
|||
Color[] pixels = new Color[count]; |
|||
|
|||
for (int i = 0; i < count; i++) |
|||
{ |
|||
// Both GGX and Disney Diffuse BRDFs have zero values in columns 1, 3, 5, 7.
|
|||
// Column 8 contains only ones.
|
|||
pixels[i] = new Color((float)LUTTransformInv[i, 0], |
|||
(float)LUTTransformInv[i, 2], |
|||
(float)LUTTransformInv[i, 4], |
|||
(float)LUTTransformInv[i, 6]); |
|||
} |
|||
|
|||
tex.SetPixels(pixels, arrayElement); |
|||
} |
|||
|
|||
// Special-case function for 'm_LtcMultiGGXFresnelDisneyDiffuse'.
|
|||
void LoadLUT(Texture2DArray tex, int arrayElement, TextureFormat format, float[] LtcGGXMagnitudeData, |
|||
float[] LtcGGXFresnelData, |
|||
float[] LtcDisneyDiffuseMagnitudeData) |
|||
{ |
|||
const int count = k_LtcLUTResolution * k_LtcLUTResolution; |
|||
Color[] pixels = new Color[count]; |
|||
|
|||
for (int i = 0; i < count; i++) |
|||
{ |
|||
// We store the result of the subtraction as a run-time optimization.
|
|||
// See the footnote 2 of "LTC Fresnel Approximation" by Stephen Hill.
|
|||
pixels[i] = new Color(LtcGGXMagnitudeData[i] - LtcGGXFresnelData[i], |
|||
LtcGGXFresnelData[i], LtcDisneyDiffuseMagnitudeData[i], 1); |
|||
} |
|||
|
|||
tex.SetPixels(pixels, arrayElement); |
|||
} |
|||
|
|||
public Eye() { } |
|||
|
|||
public override void Build(RenderPipelineResources renderPipelineResources) |
|||
{ |
|||
m_InitPreFGD = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/PreIntegratedFGD"); |
|||
|
|||
// For DisneyDiffuse integration values goes from (0.5 to 1.53125). GGX need 0 to 1. Use float format.
|
|||
m_PreIntegratedFGD = new RenderTexture(128, 128, 0, RenderTextureFormat.RGB111110Float, RenderTextureReadWrite.Linear); |
|||
m_PreIntegratedFGD.filterMode = FilterMode.Bilinear; |
|||
m_PreIntegratedFGD.wrapMode = TextureWrapMode.Clamp; |
|||
m_PreIntegratedFGD.hideFlags = HideFlags.DontSave; |
|||
m_PreIntegratedFGD.Create(); |
|||
|
|||
m_LtcData = new Texture2DArray(k_LtcLUTResolution, k_LtcLUTResolution, 3, TextureFormat.RGBAHalf, false /*mipmap*/, true /* linear */) |
|||
{ |
|||
hideFlags = HideFlags.HideAndDontSave, |
|||
wrapMode = TextureWrapMode.Clamp, |
|||
filterMode = FilterMode.Bilinear |
|||
}; |
|||
|
|||
LoadLUT(m_LtcData, 0, TextureFormat.RGBAHalf, Lit.s_LtcGGXMatrixData); |
|||
LoadLUT(m_LtcData, 1, TextureFormat.RGBAHalf, Lit.s_LtcDisneyDiffuseMatrixData); |
|||
// TODO: switch to RGBA64 when it becomes available.
|
|||
LoadLUT(m_LtcData, 2, TextureFormat.RGBAHalf, Lit.s_LtcGGXMagnitudeData, Lit.s_LtcGGXFresnelData, Lit.s_LtcDisneyDiffuseMagnitudeData); |
|||
|
|||
m_LtcData.Apply(); |
|||
|
|||
m_isInit = false; |
|||
} |
|||
|
|||
public override void Cleanup() |
|||
{ |
|||
Utilities.Destroy(m_InitPreFGD); |
|||
|
|||
// TODO: how to delete RenderTexture ? or do we need to do it ?
|
|||
m_isInit = false; |
|||
} |
|||
|
|||
public override void RenderInit(CommandBuffer cmd) |
|||
{ |
|||
if (m_isInit) |
|||
return; |
|||
|
|||
using (new Utilities.ProfilingSample("Init PreFGD", cmd)) |
|||
{ |
|||
Utilities.DrawFullScreen(cmd, m_InitPreFGD, new RenderTargetIdentifier(m_PreIntegratedFGD)); |
|||
} |
|||
m_isInit = true; |
|||
} |
|||
|
|||
public override void Bind() |
|||
{ |
|||
Shader.SetGlobalTexture("_PreIntegratedFGD", m_PreIntegratedFGD); |
|||
Shader.SetGlobalTexture("_LtcData", m_LtcData); |
|||
} |
|||
} |
|||
} |
|
|||
// |
|||
// This file was automatically generated from Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Eye/Eye.cs. Please don't edit by hand. |
|||
// |
|||
|
|||
#ifndef EYE_CS_HLSL |
|||
#define EYE_CS_HLSL |
|||
// |
|||
// UnityEngine.Experimental.Rendering.HDPipeline.Eye+MaterialId: static fields |
|||
// |
|||
#define MATERIALID_LIT_SSS (0) |
|||
#define MATERIALID_LIT_STANDARD (1) |
|||
#define MATERIALID_LIT_UNUSED0 (2) |
|||
#define MATERIALID_LIT_UNUSED1 (3) |
|||
#define MATERIALID_LIT_ANISO (4) |
|||
#define MATERIALID_LIT_SPECULAR (5) |
|||
|
|||
// |
|||
// UnityEngine.Experimental.Rendering.HDPipeline.Eye+MaterialFeatureFlags: static fields |
|||
// |
|||
#define MATERIALFEATUREFLAGS_LIT_SSS (4096) |
|||
#define MATERIALFEATUREFLAGS_LIT_STANDARD (8192) |
|||
#define MATERIALFEATUREFLAGS_LIT_ANISO (16384) |
|||
#define MATERIALFEATUREFLAGS_LIT_SPECULAR (32768) |
|||
|
|||
// |
|||
// UnityEngine.Experimental.Rendering.HDPipeline.Eye+SurfaceData: static fields |
|||
// |
|||
#define DEBUGVIEW_EYE_SURFACEDATA_BASE_COLOR (1000) |
|||
#define DEBUGVIEW_EYE_SURFACEDATA_SPECULAR_OCCLUSION (1001) |
|||
#define DEBUGVIEW_EYE_SURFACEDATA_NORMAL_WS (1002) |
|||
#define DEBUGVIEW_EYE_SURFACEDATA_PERCEPTUAL_SMOOTHNESS (1003) |
|||
#define DEBUGVIEW_EYE_SURFACEDATA_MATERIAL_ID (1004) |
|||
#define DEBUGVIEW_EYE_SURFACEDATA_AMBIENT_OCCLUSION (1005) |
|||
#define DEBUGVIEW_EYE_SURFACEDATA_TANGENT_WS (1006) |
|||
#define DEBUGVIEW_EYE_SURFACEDATA_ANISOTROPY (1007) |
|||
#define DEBUGVIEW_EYE_SURFACEDATA_SPECULAR (1008) |
|||
#define DEBUGVIEW_EYE_SURFACEDATA_SUBSURFACE_RADIUS (1009) |
|||
#define DEBUGVIEW_EYE_SURFACEDATA_THICKNESS (1010) |
|||
#define DEBUGVIEW_EYE_SURFACEDATA_SUBSURFACE_PROFILE (1011) |
|||
#define DEBUGVIEW_EYE_SURFACEDATA_SPECULAR_COLOR (1012) |
|||
|
|||
// |
|||
// UnityEngine.Experimental.Rendering.HDPipeline.Eye+TransmissionType: static fields |
|||
// |
|||
#define TRANSMISSIONTYPE_NONE (0) |
|||
#define TRANSMISSIONTYPE_REGULAR (1) |
|||
#define TRANSMISSIONTYPE_THIN_OBJECT (2) |
|||
|
|||
// |
|||
// UnityEngine.Experimental.Rendering.HDPipeline.Eye+BSDFData: static fields |
|||
// |
|||
#define DEBUGVIEW_EYE_BSDFDATA_DIFFUSE_COLOR (1030) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_FRESNEL0 (1031) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_SPECULAR_OCCLUSION (1032) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_NORMAL_WS (1033) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_PERCEPTUAL_ROUGHNESS (1034) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_ROUGHNESS (1035) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_MATERIAL_ID (1036) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_TANGENT_WS (1037) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_BITANGENT_WS (1038) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_ROUGHNESS_T (1039) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_ROUGHNESS_B (1040) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_ANISOTROPY (1041) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_SUBSURFACE_RADIUS (1042) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_THICKNESS (1043) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_SUBSURFACE_PROFILE (1044) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_ENABLE_TRANSMISSION (1045) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_USE_THIN_OBJECT_MODE (1046) |
|||
#define DEBUGVIEW_EYE_BSDFDATA_TRANSMITTANCE (1047) |
|||
|
|||
// |
|||
// UnityEngine.Experimental.Rendering.HDPipeline.Eye+GBufferMaterial: static fields |
|||
// |
|||
#define GBUFFERMATERIAL_COUNT (4) |
|||
|
|||
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Eye+SurfaceData |
|||
// PackingRules = Exact |
|||
struct SurfaceData |
|||
{ |
|||
float3 baseColor; |
|||
float specularOcclusion; |
|||
float3 normalWS; |
|||
float perceptualSmoothness; |
|||
int materialId; |
|||
float ambientOcclusion; |
|||
float3 tangentWS; |
|||
float anisotropy; |
|||
float specular; |
|||
float subsurfaceRadius; |
|||
float thickness; |
|||
int subsurfaceProfile; |
|||
float3 specularColor; |
|||
}; |
|||
|
|||
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Eye+BSDFData |
|||
// PackingRules = Exact |
|||
struct BSDFData |
|||
{ |
|||
float3 diffuseColor; |
|||
float3 fresnel0; |
|||
float specularOcclusion; |
|||
float3 normalWS; |
|||
float perceptualRoughness; |
|||
float roughness; |
|||
int materialId; |
|||
float3 tangentWS; |
|||
float3 bitangentWS; |
|||
float roughnessT; |
|||
float roughnessB; |
|||
float anisotropy; |
|||
float subsurfaceRadius; |
|||
float thickness; |
|||
int subsurfaceProfile; |
|||
bool enableTransmission; |
|||
bool useThinObjectMode; |
|||
float3 transmittance; |
|||
}; |
|||
|
|||
// |
|||
// Debug functions |
|||
// |
|||
void GetGeneratedSurfaceDataDebug(uint paramId, SurfaceData surfacedata, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
switch (paramId) |
|||
{ |
|||
case DEBUGVIEW_EYE_SURFACEDATA_BASE_COLOR: |
|||
result = surfacedata.baseColor; |
|||
needLinearToSRGB = true; |
|||
break; |
|||
case DEBUGVIEW_EYE_SURFACEDATA_SPECULAR_OCCLUSION: |
|||
result = surfacedata.specularOcclusion.xxx; |
|||
break; |
|||
case DEBUGVIEW_EYE_SURFACEDATA_NORMAL_WS: |
|||
result = surfacedata.normalWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_EYE_SURFACEDATA_PERCEPTUAL_SMOOTHNESS: |
|||
result = surfacedata.perceptualSmoothness.xxx; |
|||
break; |
|||
case DEBUGVIEW_EYE_SURFACEDATA_MATERIAL_ID: |
|||
result = GetIndexColor(surfacedata.materialId); |
|||
break; |
|||
case DEBUGVIEW_EYE_SURFACEDATA_AMBIENT_OCCLUSION: |
|||
result = surfacedata.ambientOcclusion.xxx; |
|||
break; |
|||
case DEBUGVIEW_EYE_SURFACEDATA_TANGENT_WS: |
|||
result = surfacedata.tangentWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_EYE_SURFACEDATA_ANISOTROPY: |
|||
result = surfacedata.anisotropy.xxx; |
|||
break; |
|||
case DEBUGVIEW_EYE_SURFACEDATA_SPECULAR: |
|||
result = surfacedata.specular.xxx; |
|||
break; |
|||
case DEBUGVIEW_EYE_SURFACEDATA_SUBSURFACE_RADIUS: |
|||
result = surfacedata.subsurfaceRadius.xxx; |
|||
break; |
|||
case DEBUGVIEW_EYE_SURFACEDATA_THICKNESS: |
|||
result = surfacedata.thickness.xxx; |
|||
break; |
|||
case DEBUGVIEW_EYE_SURFACEDATA_SUBSURFACE_PROFILE: |
|||
result = GetIndexColor(surfacedata.subsurfaceProfile); |
|||
break; |
|||
case DEBUGVIEW_EYE_SURFACEDATA_SPECULAR_COLOR: |
|||
result = surfacedata.specularColor; |
|||
needLinearToSRGB = true; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
// |
|||
// Debug functions |
|||
// |
|||
void GetGeneratedBSDFDataDebug(uint paramId, BSDFData bsdfdata, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
switch (paramId) |
|||
{ |
|||
case DEBUGVIEW_EYE_BSDFDATA_DIFFUSE_COLOR: |
|||
result = bsdfdata.diffuseColor; |
|||
needLinearToSRGB = true; |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_FRESNEL0: |
|||
result = bsdfdata.fresnel0; |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_SPECULAR_OCCLUSION: |
|||
result = bsdfdata.specularOcclusion.xxx; |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_NORMAL_WS: |
|||
result = bsdfdata.normalWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_PERCEPTUAL_ROUGHNESS: |
|||
result = bsdfdata.perceptualRoughness.xxx; |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_ROUGHNESS: |
|||
result = bsdfdata.roughness.xxx; |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_MATERIAL_ID: |
|||
result = GetIndexColor(bsdfdata.materialId); |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_TANGENT_WS: |
|||
result = bsdfdata.tangentWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_BITANGENT_WS: |
|||
result = bsdfdata.bitangentWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_ROUGHNESS_T: |
|||
result = bsdfdata.roughnessT.xxx; |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_ROUGHNESS_B: |
|||
result = bsdfdata.roughnessB.xxx; |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_ANISOTROPY: |
|||
result = bsdfdata.anisotropy.xxx; |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_SUBSURFACE_RADIUS: |
|||
result = bsdfdata.subsurfaceRadius.xxx; |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_THICKNESS: |
|||
result = bsdfdata.thickness.xxx; |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_SUBSURFACE_PROFILE: |
|||
result = GetIndexColor(bsdfdata.subsurfaceProfile); |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_ENABLE_TRANSMISSION: |
|||
result = (bsdfdata.enableTransmission) ? float3(1.0, 1.0, 1.0) : float3(0.0, 0.0, 0.0); |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_USE_THIN_OBJECT_MODE: |
|||
result = (bsdfdata.useThinObjectMode) ? float3(1.0, 1.0, 1.0) : float3(0.0, 0.0, 0.0); |
|||
break; |
|||
case DEBUGVIEW_EYE_BSDFDATA_TRANSMITTANCE: |
|||
result = bsdfdata.transmittance; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
|
|||
#endif |
|
|||
fileFormatVersion: 2 |
|||
guid: 3ea703cf2ae98674b85f343ad45a0eca |
|||
timeCreated: 1497329223 |
|||
licenseType: Free |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: d1de5b761a16187448117d2400903cb2 |
|||
timeCreated: 1497326983 |
|||
licenseType: Free |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
//----------------------------------------------------------------------------- |
|||
// SurfaceData and BSDFData |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// SurfaceData is define in Eye.cs which generate Eye.cs.hlsl |
|||
#include "Eye.cs.hlsl" |
|||
#include "../Lit/SubsurfaceScatteringProfile.cs.hlsl" |
|||
|
|||
#define WANT_SSS_CODE |
|||
#include "../LightEvaluationShare1.hlsl" |
|||
|
|||
void FillMaterialIdStandardData(float3 baseColor, float specular, float metallic, float roughness, float3 normalWS, float3 tangentWS, float anisotropy, inout BSDFData bsdfData) |
|||
{ |
|||
bsdfData.diffuseColor = baseColor*0.5; |
|||
bsdfData.fresnel0 =1; |
|||
|
|||
// TODO: encode specular |
|||
|
|||
bsdfData.tangentWS = tangentWS; |
|||
bsdfData.bitangentWS = cross(normalWS, tangentWS); |
|||
ConvertAnisotropyToRoughness(roughness, anisotropy, bsdfData.roughnessT, bsdfData.roughnessB); |
|||
bsdfData.anisotropy = 0; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// conversion function for forward |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
BSDFData ConvertSurfaceDataToBSDFData(SurfaceData surfaceData) |
|||
{ |
|||
ApplyDebugToSurfaceData(surfaceData); |
|||
|
|||
BSDFData bsdfData; |
|||
ZERO_INITIALIZE(BSDFData, bsdfData); |
|||
|
|||
bsdfData.specularOcclusion = surfaceData.specularOcclusion; |
|||
bsdfData.normalWS = surfaceData.normalWS; |
|||
bsdfData.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness); |
|||
bsdfData.roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness); |
|||
bsdfData.materialId = surfaceData.materialId; |
|||
|
|||
FillMaterialIdStandardData(surfaceData.baseColor, surfaceData.specular, 0, bsdfData.roughness, surfaceData.normalWS, surfaceData.tangentWS, surfaceData.anisotropy, bsdfData); |
|||
bsdfData.materialId = surfaceData.anisotropy > 0.0 ? MATERIALID_LIT_ANISO : bsdfData.materialId; |
|||
|
|||
FillMaterialIdSSSData(surfaceData.baseColor, surfaceData.subsurfaceProfile, surfaceData.subsurfaceRadius, surfaceData.thickness, bsdfData); |
|||
|
|||
return bsdfData; |
|||
} |
|||
|
|||
float4 EncodeSplitLightingGBuffer0(SurfaceData surfaceData) |
|||
{ |
|||
return float4(surfaceData.baseColor, 1.0); |
|||
} |
|||
|
|||
float4 EncodeSplitLightingGBuffer1(SurfaceData surfaceData) |
|||
{ |
|||
return float4(surfaceData.subsurfaceRadius, 1.0, 0.0, PackByte(surfaceData.subsurfaceProfile)); //TODO: Eye UI |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// bake lighting function |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// GetBakedDiffuseLigthing function compute the bake lighting + emissive color to be store in emissive buffer (Deferred case) |
|||
// In forward it must be add to the final contribution. |
|||
// This function require the 3 structure surfaceData, builtinData, bsdfData because it may require both the engine side data, and data that will not be store inside the gbuffer. |
|||
float3 GetBakedDiffuseLigthing(SurfaceData surfaceData, BuiltinData builtinData, BSDFData bsdfData, PreLightData preLightData) |
|||
{ |
|||
// Premultiply bake diffuse lighting information with DisneyDiffuse pre-integration |
|||
return builtinData.bakeDiffuseLighting * preLightData.diffuseFGD * surfaceData.ambientOcclusion * bsdfData.diffuseColor + builtinData.emissiveColor; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// light transport functions |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
LightTransportData GetLightTransportData(SurfaceData surfaceData, BuiltinData builtinData, BSDFData bsdfData) |
|||
{ |
|||
LightTransportData lightTransportData; |
|||
|
|||
// diffuseColor for lightmapping should basically be diffuse color. |
|||
// But rough metals (black diffuse) still scatter quite a lot of light around, so |
|||
// we want to take some of that into account too. |
|||
|
|||
lightTransportData.diffuseColor = bsdfData.diffuseColor; |
|||
lightTransportData.emissiveColor = builtinData.emissiveColor; |
|||
|
|||
return lightTransportData; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// LightLoop related function (Only include if required) |
|||
// HAS_LIGHTLOOP is define in Lighting.hlsl |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
#ifdef HAS_LIGHTLOOP |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// BSDF share between directional light, punctual light and area light (reference) |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
#define BSDF BSDF_EYE |
|||
|
|||
|
|||
void BSDF_EYE(float3 V, float3 L, float3 positionWS, PreLightData preLightData, BSDFData bsdfData, |
|||
out float3 diffuseLighting, |
|||
out float3 specularLighting) |
|||
{ |
|||
// Optimized math. Ref: PBR Diffuse Lighting for GGX + Smith Microsurfaces (slide 114). |
|||
float NdotL = saturate(dot(bsdfData.normalWS, L)); // Must have the same value without the clamp |
|||
float NdotV = preLightData.NdotV; // Get the unaltered (geometric) version |
|||
float LdotV = dot(L, V); |
|||
float invLenLV = rsqrt(abs(2 * LdotV + 2)); // invLenLV = rcp(length(L + V)) |
|||
float NdotH = saturate((NdotL + NdotV) * invLenLV); |
|||
float LdotH = saturate(invLenLV * LdotV + invLenLV); |
|||
|
|||
NdotV = max(NdotV, MIN_N_DOT_V); // Use the modified (clamped) version |
|||
|
|||
float3 F = F_Schlick(bsdfData.fresnel0, LdotH); |
|||
|
|||
float Vis; |
|||
float D; |
|||
// TODO: this way of handling aniso may not be efficient, or maybe with material classification, need to check perf here |
|||
// Maybe always using aniso maybe a win ? |
|||
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); |
|||
float BdotH = dot(bsdfData.bitangentWS, H); |
|||
float BdotL = dot(bsdfData.bitangentWS, L); |
|||
|
|||
bsdfData.roughnessT = ClampRoughnessForAnalyticalLights(bsdfData.roughnessT); |
|||
bsdfData.roughnessB = ClampRoughnessForAnalyticalLights(bsdfData.roughnessB); |
|||
|
|||
#ifdef LIT_USE_BSDF_PRE_LAMBDAV |
|||
Vis = V_SmithJointGGXAnisoLambdaV(preLightData.TdotV, preLightData.BdotV, NdotV, TdotL, BdotL, NdotL, |
|||
bsdfData.roughnessT, bsdfData.roughnessB, preLightData.anisoGGXLambdaV); |
|||
#else |
|||
// TODO: Do comparison between this correct version and the one from isotropic and see if there is any visual difference |
|||
Vis = V_SmithJointGGXAniso(preLightData.TdotV, preLightData.BdotV, NdotV, TdotL, BdotL, NdotL, |
|||
bsdfData.roughnessT, bsdfData.roughnessB); |
|||
#endif |
|||
|
|||
D = D_GGXAniso(TdotH, BdotH, NdotH, bsdfData.roughnessT, bsdfData.roughnessB); |
|||
} |
|||
else |
|||
{ |
|||
bsdfData.roughness = ClampRoughnessForAnalyticalLights(bsdfData.roughness); |
|||
|
|||
#ifdef LIT_USE_BSDF_PRE_LAMBDAV |
|||
Vis = V_SmithJointGGX(NdotL, NdotV, bsdfData.roughness, preLightData.ggxLambdaV); |
|||
#else |
|||
Vis = V_SmithJointGGX(NdotL, NdotV, bsdfData.roughness); |
|||
#endif |
|||
D = D_GGX(NdotH, bsdfData.roughness); |
|||
} |
|||
specularLighting = 10*F * (Vis * D); |
|||
|
|||
#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; |
|||
} |
|||
|
|||
#endif // #ifdef HAS_LIGHTLOOP |
|||
|
|||
#include "../LightEvaluationShare2.hlsl" |
|
|||
fileFormatVersion: 2 |
|||
guid: 04104d8f9ef87224fa781b53467029a1 |
|||
timeCreated: 1497327754 |
|||
licenseType: Free |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "HDRenderPipeline/ExperimentalEye" |
|||
{ |
|||
Properties |
|||
{ |
|||
// Following set of parameters represent the parameters node inside the MaterialGraph. |
|||
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist. |
|||
|
|||
// Reminder. Color here are in linear but the UI (color picker) do the conversion sRGB to linear |
|||
_BaseColor("BaseColor", Color) = (1,1,1,1) |
|||
_BaseColorMap("BaseColorMap", 2D) = "white" {} |
|||
|
|||
_Smoothness("Smoothness", Range(0.0, 1.0)) = 1.0 |
|||
|
|||
_MaskMap("MaskMap", 2D) = "white" {} |
|||
|
|||
_IrisDepth("Iris Depth", Range(0.0, 1.0)) = 0.5 |
|||
_IrisRadius("Iris Radius", Range(0.0, 1.0)) = 0.5 |
|||
_Ior("IOR", Range(0.0, 1.0)) = 0.5 |
|||
_frontNormalWS("Eye Front Normal",Vector) = (0,0,-1) |
|||
_SpecularOcclusionMap("SpecularOcclusion", 2D) = "white" {} |
|||
|
|||
_NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map |
|||
_NormalMapOS("NormalMapOS", 2D) = "white" {} // Object space normal map - no good default value |
|||
_NormalScale("NormalScale", Range(0.0, 2.0)) = 1 |
|||
|
|||
_HeightMap("HeightMap", 2D) = "black" {} |
|||
_HeightAmplitude("Height Amplitude", Float) = 0.01 // In world units |
|||
_HeightCenter("Height Center", Float) = 0.5 // In texture space |
|||
|
|||
_DetailMap("DetailMap", 2D) = "black" {} |
|||
_DetailMask("DetailMask", 2D) = "white" {} |
|||
_DetailFuzz1("DetailFuzz1", Range(0.0, 1.0)) = 1 |
|||
_DetailAlbedoScale("DetailAlbedoScale", Range(0.0, 1.0)) = 1 |
|||
_DetailNormalScale("DetailNormalScale", Range(0.0, 2.0)) = 1 |
|||
_DetailSmoothnessScale("DetailSmoothnessScale", Range(-2.0, 2.0)) = 1 |
|||
|
|||
_TangentMap("TangentMap", 2D) = "bump" {} |
|||
_TangentMapOS("TangentMapOS", 2D) = "white" {} |
|||
|
|||
_SubsurfaceProfile("Subsurface Profile", Int) = 0 |
|||
_SubsurfaceRadius("Subsurface Radius", Range(0.0, 1.0)) = 1.0 |
|||
_SubsurfaceRadiusMap("Subsurface Radius Map", 2D) = "white" {} |
|||
_Thickness("Thickness", Range(0.0, 1.0)) = 1.0 |
|||
_ThicknessMap("Thickness Map", 2D) = "white" {} |
|||
|
|||
_SpecularColor("SpecularColor", Color) = (1, 1, 1, 1) |
|||
_SpecularColorMap("SpecularColorMap", 2D) = "white" {} |
|||
|
|||
// Wind |
|||
[ToggleOff] _EnableWind("Enable Wind", Float) = 0.0 |
|||
_InitialBend("Initial Bend", float) = 1.0 |
|||
_Stiffness("Stiffness", float) = 1.0 |
|||
_Drag("Drag", float) = 1.0 |
|||
_ShiverDrag("Shiver Drag", float) = 0.2 |
|||
_ShiverDirectionality("Shiver Directionality", Range(0.0, 1.0)) = 0.5 |
|||
|
|||
_DistortionVectorMap("DistortionVectorMap", 2D) = "black" {} |
|||
|
|||
// Following options are for the GUI inspector and different from the input parameters above |
|||
// These option below will cause different compilation flag. |
|||
|
|||
_EmissiveColor("EmissiveColor", Color) = (0, 0, 0) |
|||
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {} |
|||
_EmissiveIntensity("EmissiveIntensity", Float) = 0 |
|||
|
|||
[ToggleOff] _DistortionEnable("Enable Distortion", Float) = 0.0 |
|||
[ToggleOff] _DistortionOnly("Distortion Only", Float) = 0.0 |
|||
[ToggleOff] _DistortionDepthTest("Distortion Depth Test Enable", Float) = 0.0 |
|||
[ToggleOff] _DepthOffsetEnable("Depth Offset View space", Float) = 0.0 |
|||
|
|||
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
_TransparentDepthWritePrepassEnable("Alpha Cutoff Enable", Float) = 1.0 |
|||
_AlphaCutoffPrepass("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
_AlphaCutoffOpacityThreshold("Alpha Cutoff", Range(0.0, 1.0)) = 0.99 |
|||
|
|||
// Stencil state |
|||
[HideInInspector] _StencilRef("_StencilRef", Int) = 2 // StencilLightingUsage.RegularLighting (fixed at compile time) |
|||
|
|||
// Blending state |
|||
[HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0 |
|||
[HideInInspector] _BlendMode("__blendmode", Float) = 0.0 |
|||
[HideInInspector] _SrcBlend("__src", Float) = 1.0 |
|||
[HideInInspector] _DstBlend("__dst", Float) = 0.0 |
|||
[HideInInspector] _ZWrite("__zw", Float) = 1.0 |
|||
[HideInInspector] _CullMode("__cullmode", Float) = 2.0 |
|||
[HideInInspector] _ZTestMode("_ZTestMode", Int) = 8 |
|||
|
|||
[ToggleOff] _DoubleSidedEnable("Double sided enable", Float) = 0.0 |
|||
[Enum(None, 0, Mirror, 1, Flip, 2)] _DoubleSidedNormalMode("Double sided normal mode", Float) = 1 |
|||
[HideInInspector] _DoubleSidedConstants("_DoubleSidedConstants", Vector) = (1, 1, -1, 0) |
|||
|
|||
[Enum(UV0, 0, Planar, 1, TriPlanar, 2)] _UVBase("UV Set for base", Float) = 0 |
|||
_TexWorldScale("Scale to apply on world coordinate", Float) = 1.0 |
|||
[HideInInspector] _UVMappingMask("_UVMappingMask", Color) = (1, 0, 0, 0) |
|||
[Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace("NormalMap space", Float) = 0 |
|||
[HideInInspector]_MaterialID("MaterialId", Int) = 0 // MaterialId.Subsurface |
|||
|
|||
|
|||
[ToggleOff] _EnablePerPixelDisplacement("Enable per pixel displacement", Float) = 0.0 |
|||
_PPDMinSamples("Min sample for POM", Range(1.0, 64.0)) = 5 |
|||
_PPDMaxSamples("Max sample for POM", Range(1.0, 64.0)) = 15 |
|||
_PPDLodThreshold("Start lod to fade out the POM effect", Range(0.0, 16.0)) = 5 |
|||
[Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1 |
|||
|
|||
// Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor" |
|||
// value that exist to identify if the GI emission need to be enabled. |
|||
// In our case we don't use such a mechanism but need to keep the code quiet. We declare the value and always enable it. |
|||
// TODO: Fix the code in legacy unity so we can customize the beahvior for GI |
|||
_EmissionColor("Color", Color) = (1, 1, 1) |
|||
} |
|||
|
|||
HLSLINCLUDE |
|||
|
|||
#pragma target 4.5 |
|||
#pragma only_renderers d3d11 ps4 metal // TEMP: until we go futher in dev |
|||
// #pragma enable_d3d11_debug_symbols |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Variant |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#pragma shader_feature _ALPHATEST_ON |
|||
#pragma shader_feature _DISTORTION_ON |
|||
#pragma shader_feature _DEPTHOFFSET_ON |
|||
#pragma shader_feature _DOUBLESIDED_ON |
|||
#pragma shader_feature _PER_PIXEL_DISPLACEMENT |
|||
|
|||
#pragma shader_feature _ _MAPPING_PLANAR _MAPPING_TRIPLANAR |
|||
#pragma shader_feature _NORMALMAP_TANGENT_SPACE |
|||
#pragma shader_feature _ _REQUIRE_UV2 _REQUIRE_UV3 |
|||
#pragma shader_feature _EMISSIVE_COLOR |
|||
|
|||
#pragma shader_feature _NORMALMAP |
|||
#pragma shader_feature _MASKMAP |
|||
#pragma shader_feature _SPECULAROCCLUSIONMAP |
|||
#pragma shader_feature _EMISSIVE_COLOR_MAP |
|||
#pragma shader_feature _HEIGHTMAP |
|||
#pragma shader_feature _TANGENTMAP |
|||
#pragma shader_feature _DETAIL_MAP |
|||
#pragma shader_feature _SUBSURFACE_RADIUS_MAP |
|||
#pragma shader_feature _THICKNESSMAP |
|||
#pragma shader_feature _SPECULARCOLORMAP |
|||
#pragma shader_feature _VERTEX_WIND |
|||
|
|||
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON |
|||
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED |
|||
#pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON |
|||
// enable dithering LOD crossfade |
|||
#pragma multi_compile _ LOD_FADE_CROSSFADE |
|||
// TODO: We should have this keyword only if VelocityInGBuffer is enable, how to do that ? |
|||
//#pragma multi_compile VELOCITYOUTPUT_OFF VELOCITYOUTPUT_ON |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Define |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#define UNITY_MATERIAL_EYE // Need to be define before including Material.hlsl |
|||
// Use surface gradient normal mapping as it handle correctly triplanar normal mapping and multiple UVSet |
|||
#define SURFACE_GRADIENT |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Include |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#include "../../../Core/ShaderLibrary/Common.hlsl" |
|||
#include "../../../Core/ShaderLibrary/Wind.hlsl" |
|||
#include "../../ShaderPass/FragInputs.hlsl" |
|||
#include "../../ShaderPass/ShaderPass.cs.hlsl" |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// variable declaration |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#include "../../Material/Eye/EyeProperties.hlsl" |
|||
|
|||
// All our shaders use same name for entry point |
|||
#pragma vertex Vert |
|||
#pragma fragment Frag |
|||
|
|||
ENDHLSL |
|||
|
|||
SubShader |
|||
{ |
|||
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" } |
|||
LOD 300 |
|||
|
|||
Pass |
|||
{ |
|||
Name "ForwardOnlyOpaqueSplitLighting" |
|||
Tags { "LightMode"="ForwardOnlyOpaqueSplitLighting" } |
|||
|
|||
Blend One Zero |
|||
ZWrite [_ZWrite] |
|||
Cull [_CullMode] |
|||
|
|||
Stencil |
|||
{ |
|||
Ref 1 |
|||
Comp Always |
|||
Pass Replace |
|||
} |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#define FORWARD_SPLIT_LIGHTING |
|||
|
|||
#define SHADERPASS SHADERPASS_FORWARD |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "../../Lighting/Forward.hlsl" |
|||
#pragma multi_compile LIGHTLOOP_SINGLE_PASS LIGHTLOOP_TILE_PASS |
|||
|
|||
#include "../../Lighting/Lighting.hlsl" |
|||
#include "ShaderPass/EyeSharePass.hlsl" |
|||
#include "EyeData.hlsl" |
|||
#include "../../ShaderPass/ShaderPassForward.hlsl" |
|||
|
|||
ENDHLSL |
|||
|
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Name "ForwardOnlyOpaqueDepthOnly" |
|||
Tags{ "LightMode" = "ForwardOnlyOpaqueDepthOnly" } |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
ZWrite On |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#define SHADERPASS SHADERPASS_DEPTH_ONLY |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "../../Material/Material.hlsl" |
|||
#include "ShaderPass/EyeDepthPass.hlsl" |
|||
#include "EyeData.hlsl" |
|||
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// Extracts information for lightmapping, GI (emission, albedo, ...) |
|||
// This pass it not used during regular rendering. |
|||
Pass |
|||
{ |
|||
Name "META" |
|||
Tags{ "LightMode" = "Meta" } |
|||
|
|||
Cull Off |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
// Lightmap memo |
|||
// DYNAMICLIGHTMAP_ON is used when we have an "enlighten lightmap" ie a lightmap updated at runtime by enlighten.This lightmap contain indirect lighting from realtime lights and realtime emissive material.Offline baked lighting(from baked material / light, |
|||
// both direct and indirect lighting) will hand up in the "regular" lightmap->LIGHTMAP_ON. |
|||
|
|||
#define SHADERPASS SHADERPASS_LIGHT_TRANSPORT |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "../../Material/Material.hlsl" |
|||
#include "ShaderPass/EyeMetaPass.hlsl" |
|||
#include "EyeData.hlsl" |
|||
#include "../../ShaderPass/ShaderPassLightTransport.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Name "ShadowCaster" |
|||
Tags{ "LightMode" = "ShadowCaster" } |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
ZClip Off |
|||
ZWrite On |
|||
ZTest LEqual |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#define SHADERPASS SHADERPASS_SHADOWS |
|||
#define USE_LEGACY_UNITY_MATRIX_VARIABLES |
|||
|
|||
#include "../../ShaderVariables.hlsl" |
|||
|
|||
#include "../../Material/Material.hlsl" |
|||
#include "ShaderPass/EyeDepthPass.hlsl" |
|||
#include "EyeData.hlsl" |
|||
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Name "DepthOnly" |
|||
Tags{ "LightMode" = "DepthOnly" } |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
ZWrite On |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#define SHADERPASS SHADERPASS_DEPTH_ONLY |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "../../Material/Material.hlsl" |
|||
#include "ShaderPass/EyeDepthPass.hlsl" |
|||
#include "EyeData.hlsl" |
|||
#include "../../ShaderPass/ShaderPassDepthOnly.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Name "Motion Vectors" |
|||
Tags{ "LightMode" = "MotionVectors" } // Caution, this need to be call like this to setup the correct parameters by C++ (legacy Unity) |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
ZWrite Off // TODO: Test Z equal here. |
|||
|
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#define SHADERPASS SHADERPASS_VELOCITY |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "../../Material/Material.hlsl" |
|||
#include "ShaderPass/EyeVelocityPass.hlsl" |
|||
#include "EyeData.hlsl" |
|||
#include "../../ShaderPass/ShaderPassVelocity.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Name "Distortion" // Name is not used |
|||
Tags { "LightMode" = "DistortionVectors" } // This will be only for transparent object based on the RenderQueue index |
|||
|
|||
Blend One One |
|||
ZTest [_ZTestMode] |
|||
ZWrite off |
|||
Cull [_CullMode] |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#define SHADERPASS SHADERPASS_DISTORTION |
|||
#include "../../ShaderVariables.hlsl" |
|||
#include "../../Material/Material.hlsl" |
|||
#include "ShaderPass/EyeDistortionPass.hlsl" |
|||
#include "EyeData.hlsl" |
|||
#include "../../ShaderPass/ShaderPassDistortion.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
} |
|||
|
|||
CustomEditor "Experimental.Rendering.HDPipeline.EyeGUI" |
|||
} |
部分文件因为文件数量过多而无法显示
撰写
预览
正在加载...
取消
保存
Reference in new issue