75 lines
3.5 KiB
C#

using UnityEngine;
using UnityEngine.Rendering;
// Include material common properties names
using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties;
namespace UnityEditor.Rendering.HighDefinition
{
/// <summary>
/// Common GUI for Lit ShaderGraphs.
/// </summary>
public class LightingShaderGraphGUI : HDShaderGUI
{
// For surface option shader graph we only want all unlit features but alpha clip and back then front rendering
const SurfaceOptionUIBlock.Features surfaceOptionFeatures = SurfaceOptionUIBlock.Features.Lit
| SurfaceOptionUIBlock.Features.ShowDepthOffsetOnly;
MaterialUIBlockList m_UIBlocks = new MaterialUIBlockList
{
new SurfaceOptionUIBlock(MaterialUIBlock.ExpandableBit.Base, features: surfaceOptionFeatures),
new ShaderGraphUIBlock(MaterialUIBlock.ExpandableBit.ShaderGraph),
new AdvancedOptionsUIBlock(MaterialUIBlock.ExpandableBit.Advance, ~AdvancedOptionsUIBlock.Features.SpecularOcclusion)
};
/// <summary>List of UI Blocks used to render the material inspector.</summary>
protected MaterialUIBlockList uiBlocks => m_UIBlocks;
/// <summary>
/// Implement your custom GUI in this function. To display a UI similar to HDRP shaders, use a MaterialUIBlockList.
/// </summary>
/// <param name="materialEditor">The current material editor.</param>
/// <param name="props">The list of properties the material has.</param>
protected override void OnMaterialGUI(MaterialEditor materialEditor, MaterialProperty[] props)
{
using (var changed = new EditorGUI.ChangeCheckScope())
{
m_UIBlocks.OnGUI(materialEditor, props);
ApplyKeywordsAndPassesIfNeeded(changed.changed, m_UIBlocks.materials);
}
}
/// <summary>
/// Sets up the keywords and passes for a Lit Shader Graph material.
/// </summary>
/// <param name="material">The target material.</param>
public static void SetupLightingKeywordsAndPass(Material material)
{
SynchronizeShaderGraphProperties(material);
BaseLitGUI.SetupBaseLitKeywords(material);
BaseLitGUI.SetupBaseLitMaterialPass(material);
bool receiveSSR = false;
if (material.GetSurfaceType() == SurfaceType.Transparent)
receiveSSR = material.HasProperty(kReceivesSSRTransparent) ? material.GetFloat(kReceivesSSRTransparent) != 0 : false;
else
receiveSSR = material.HasProperty(kReceivesSSR) ? material.GetFloat(kReceivesSSR) != 0 : false;
bool useSplitLighting = material.HasProperty(kUseSplitLighting) ? material.GetInt(kUseSplitLighting) != 0 : false;
BaseLitGUI.SetupStencil(material, receiveSSR, useSplitLighting);
if (material.HasProperty(kAddPrecomputedVelocity))
CoreUtils.SetKeyword(material, "_ADD_PRECOMPUTED_VELOCITY", material.GetInt(kAddPrecomputedVelocity) != 0);
if (HDSpeedTree8MaterialUpgrader.IsHDSpeedTree8Material(material))
HDSpeedTree8MaterialUpgrader.RestoreHDSpeedTree8Keywords(material);
}
/// <summary>
/// Sets up the keywords and passes for the current selected material.
/// </summary>
/// <param name="material">The selected material.</param>
protected override void SetupMaterialKeywordsAndPass(Material material) => SetupLightingKeywordsAndPass(material);
}
}