Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEditor.ShaderGraph;
using UnityEngine.UIElements;
using UnityEditor.UIElements;
using UnityEngine;

// We share the name of the properties in the UI to avoid duplication
using static UnityEditor.Rendering.HighDefinition.DecalSurfaceInputsUIBlock.Styles;
using static UnityEditor.Rendering.HighDefinition.SurfaceOptionUIBlock.Styles;

namespace UnityEditor.Rendering.HighDefinition.ShaderGraph
{
class DecalPropertyBlock : SubTargetPropertyBlock
{
class Styles
{
public static GUIContent normalModeText = new GUIContent("Affect Normal", "TODO");
public static GUIContent affectEmissionText = new GUIContent("Affect Emission", "TODO");
}

DecalData decalData;

protected override string title => "Surface Settings";
protected override int foldoutIndex => 4;

public DecalPropertyBlock(DecalData decalData) => this.decalData = decalData;

protected override void CreatePropertyGUI()
{
AddProperty(albedoModeText, () => decalData.affectsAlbedo, (newValue) => decalData.affectsAlbedo = newValue);
AddProperty(Styles.normalModeText, () => decalData.affectsNormal, (newValue) => decalData.affectsNormal = newValue);
AddProperty(affectMetalText, () => decalData.affectsMetal, (newValue) => decalData.affectsMetal = newValue);
AddProperty(affectAmbientOcclusionText, () => decalData.affectsAO, (newValue) => decalData.affectsAO = newValue);
AddProperty(affectSmoothnessText, () => decalData.affectsSmoothness, (newValue) => decalData.affectsSmoothness = newValue);
AddProperty(Styles.affectEmissionText, () => decalData.affectsEmission, (newValue) => decalData.affectsEmission = newValue);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Internal;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Legacy;
using UnityEditor.Rendering.HighDefinition.ShaderGraph.Legacy;
using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties;
using static UnityEditor.Rendering.HighDefinition.HDShaderUtils;

namespace UnityEditor.Rendering.HighDefinition.ShaderGraph
{
sealed partial class DecalSubTarget : HDSubTarget, ILegacyTarget, IRequiresData<DecalData>
{
public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<BlockFieldDescriptor, int> blockMap)
{
blockMap = null;
if(!(masterNode is DecalMasterNode1 decalMasterNode))
return false;

// Set data
systemData.surfaceType = (SurfaceType)decalMasterNode.m_SurfaceType;
systemData.dotsInstancing = decalMasterNode.m_DOTSInstancing;
decalData.affectsMetal = decalMasterNode.m_AffectsMetal;
decalData.affectsAO = decalMasterNode.m_AffectsAO;
decalData.affectsSmoothness = decalMasterNode.m_AffectsSmoothness;
decalData.affectsAlbedo = decalMasterNode.m_AffectsAlbedo;
decalData.affectsNormal = decalMasterNode.m_AffectsNormal;
decalData.affectsEmission = decalMasterNode.m_AffectsEmission;
decalData.drawOrder = decalMasterNode.m_DrawOrder;
target.customEditorGUI = decalMasterNode.m_OverrideEnabled ? decalMasterNode.m_ShaderGUIOverride : "";

// Convert SlotMask to BlockMap entries
var blockMapLookup = new Dictionary<DecalMasterNode1.SlotMask, BlockFieldDescriptor>()
{
{ DecalMasterNode1.SlotMask.Position, BlockFields.VertexDescription.Position },
{ DecalMasterNode1.SlotMask.VertexNormal, BlockFields.VertexDescription.Normal },
{ DecalMasterNode1.SlotMask.VertexTangent, BlockFields.VertexDescription.Tangent },
{ DecalMasterNode1.SlotMask.Albedo, BlockFields.SurfaceDescription.BaseColor },
{ DecalMasterNode1.SlotMask.AlphaAlbedo, BlockFields.SurfaceDescription.Alpha },
{ DecalMasterNode1.SlotMask.Normal, BlockFields.SurfaceDescription.NormalTS },
{ DecalMasterNode1.SlotMask.AlphaNormal, HDBlockFields.SurfaceDescription.NormalAlpha },
{ DecalMasterNode1.SlotMask.Metallic, BlockFields.SurfaceDescription.Metallic },
{ DecalMasterNode1.SlotMask.Occlusion, BlockFields.SurfaceDescription.Occlusion },
{ DecalMasterNode1.SlotMask.Smoothness, BlockFields.SurfaceDescription.Smoothness },
{ DecalMasterNode1.SlotMask.AlphaMAOS, HDBlockFields.SurfaceDescription.MAOSAlpha },
{ DecalMasterNode1.SlotMask.Emission, BlockFields.SurfaceDescription.Emission },
};

// Set blockmap
blockMap = new Dictionary<BlockFieldDescriptor, int>();
foreach(DecalMasterNode1.SlotMask slotMask in Enum.GetValues(typeof(DecalMasterNode1.SlotMask)))
{
if(decalMasterNode.MaterialTypeUsesSlotMask(slotMask))
{
if(!blockMapLookup.TryGetValue(slotMask, out var blockFieldDescriptor))
continue;

var slotId = Mathf.Log((int)slotMask, 2);
blockMap.Add(blockFieldDescriptor, (int)slotId);
}
}

return true;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace UnityEditor.Rendering.HighDefinition.ShaderGraph
{
sealed class DecalSubTarget : HDSubTarget, ILegacyTarget, IRequiresData<DecalData>
sealed partial class DecalSubTarget : HDSubTarget, ILegacyTarget, IRequiresData<DecalData>
{
static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Decal/ShaderGraph/DecalPass.template";

Expand Down Expand Up @@ -48,7 +48,7 @@ protected override IEnumerable<SubShaderDescriptor> EnumerateSubShaders()

public override void GetFields(ref TargetFieldContext context)
{
// Material
// Decal properties
context.AddField(HDFields.AffectsAlbedo, decalData.affectsAlbedo);
context.AddField(HDFields.AffectsNormal, decalData.affectsNormal);
context.AddField(HDFields.AffectsEmission, decalData.affectsEmission);
Expand Down Expand Up @@ -79,10 +79,9 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context)
context.AddBlock(BlockFields.SurfaceDescription.Emission);
}

public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo)
protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList)
{
// SystemDataPropertiesGUI.AddProperties(ref context, onChange, registerUndo);
// DecalDataPropertiesGUI.
blockList.AddPropertyBlock(new DecalPropertyBlock(decalData));
}

protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Lit;
Expand All @@ -106,62 +105,6 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera
collector.AddShaderProperty(decalMeshDepthBias);
}

public override void ProcessPreviewMaterial(Material material)
{
}

public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<BlockFieldDescriptor, int> blockMap)
{
blockMap = null;
if(!(masterNode is DecalMasterNode1 decalMasterNode))
return false;

// Set data
systemData.surfaceType = (SurfaceType)decalMasterNode.m_SurfaceType;
systemData.dotsInstancing = decalMasterNode.m_DOTSInstancing;
decalData.affectsMetal = decalMasterNode.m_AffectsMetal;
decalData.affectsAO = decalMasterNode.m_AffectsAO;
decalData.affectsSmoothness = decalMasterNode.m_AffectsSmoothness;
decalData.affectsAlbedo = decalMasterNode.m_AffectsAlbedo;
decalData.affectsNormal = decalMasterNode.m_AffectsNormal;
decalData.affectsEmission = decalMasterNode.m_AffectsEmission;
decalData.drawOrder = decalMasterNode.m_DrawOrder;
target.customEditorGUI = decalMasterNode.m_OverrideEnabled ? decalMasterNode.m_ShaderGUIOverride : "";

// Convert SlotMask to BlockMap entries
var blockMapLookup = new Dictionary<DecalMasterNode1.SlotMask, BlockFieldDescriptor>()
{
{ DecalMasterNode1.SlotMask.Position, BlockFields.VertexDescription.Position },
{ DecalMasterNode1.SlotMask.VertexNormal, BlockFields.VertexDescription.Normal },
{ DecalMasterNode1.SlotMask.VertexTangent, BlockFields.VertexDescription.Tangent },
{ DecalMasterNode1.SlotMask.Albedo, BlockFields.SurfaceDescription.BaseColor },
{ DecalMasterNode1.SlotMask.AlphaAlbedo, BlockFields.SurfaceDescription.Alpha },
{ DecalMasterNode1.SlotMask.Normal, BlockFields.SurfaceDescription.NormalTS },
{ DecalMasterNode1.SlotMask.AlphaNormal, HDBlockFields.SurfaceDescription.NormalAlpha },
{ DecalMasterNode1.SlotMask.Metallic, BlockFields.SurfaceDescription.Metallic },
{ DecalMasterNode1.SlotMask.Occlusion, BlockFields.SurfaceDescription.Occlusion },
{ DecalMasterNode1.SlotMask.Smoothness, BlockFields.SurfaceDescription.Smoothness },
{ DecalMasterNode1.SlotMask.AlphaMAOS, HDBlockFields.SurfaceDescription.MAOSAlpha },
{ DecalMasterNode1.SlotMask.Emission, BlockFields.SurfaceDescription.Emission },
};

// Set blockmap
blockMap = new Dictionary<BlockFieldDescriptor, int>();
foreach(DecalMasterNode1.SlotMask slotMask in Enum.GetValues(typeof(DecalMasterNode1.SlotMask)))
{
if(decalMasterNode.MaterialTypeUsesSlotMask(slotMask))
{
if(!blockMapLookup.TryGetValue(slotMask, out var blockFieldDescriptor))
continue;

var slotId = Mathf.Log((int)slotMask, 2);
blockMap.Add(blockFieldDescriptor, (int)slotId);
}
}

return true;
}

#region SubShaders
static class SubShaders
{
Expand Down
Loading