This commit is contained in:
2024-09-20 20:30:10 +02:00
commit 4fabf1a6fd
29169 changed files with 1706941 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
using System.Collections.Generic;
namespace UnityEditor.ShaderGraph
{
[GenerationAPI]
internal class TargetActiveBlockContext
{
public List<BlockFieldDescriptor> activeBlocks { get; private set; }
public List<BlockFieldDescriptor> currentBlocks { get; private set; }
public PassDescriptor? pass { get; private set; }
public TargetActiveBlockContext(List<BlockFieldDescriptor> currentBlocks, PassDescriptor? pass)
{
activeBlocks = new List<BlockFieldDescriptor>();
this.currentBlocks = currentBlocks;
this.pass = pass;
}
public void AddBlock(BlockFieldDescriptor block, bool conditional = true)
{
if (conditional == true)
{
activeBlocks.Add(block);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 860eceef9d9eeb64789007e44a1935fe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
using System.Collections.Generic;
namespace UnityEditor.ShaderGraph
{
[GenerationAPI]
internal class TargetFieldContext
{
public List<ConditionalField> conditionalFields { get; private set; }
public PassDescriptor pass { get; private set; }
public List<(BlockFieldDescriptor descriptor, bool isDefaultValue)> blocks { get; private set; }
public List<BlockFieldDescriptor> connectedBlocks { get; private set; }
public bool hasDotsProperties { get; private set; }
// NOTE: active blocks (and connectedBlocks) do not include temporarily added default blocks
public TargetFieldContext(PassDescriptor pass, List<(BlockFieldDescriptor descriptor, bool isDefaultValue)> activeBlocks, List<BlockFieldDescriptor> connectedBlocks, bool hasDotsProperties)
{
conditionalFields = new List<ConditionalField>();
this.pass = pass;
this.blocks = activeBlocks;
this.connectedBlocks = connectedBlocks;
this.hasDotsProperties = hasDotsProperties;
}
public void AddField(FieldDescriptor field, bool conditional = true)
{
conditionalFields.Add(new ConditionalField(field, conditional));
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1b72eab244c7bf14cabec1afc06beebb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
using UnityEditor.Graphing.Util;
using UnityEditor.ShaderGraph.Drawing;
namespace UnityEditor.ShaderGraph
{
[GenerationAPI]
internal class TargetPropertyGUIContext : VisualElement
{
const int kIndentWidthInPixel = 15;
public int globalIndentLevel { get; set; } = 0;
public readonly Action graphValidation;
public TargetPropertyGUIContext(Action graphValidationCallback)
{
graphValidation = graphValidationCallback;
}
public void AddProperty<T>(string label, BaseField<T> field, bool condition, EventCallback<ChangeEvent<T>> evt)
{
if (condition == true)
{
AddProperty<T>(label, field, evt);
}
}
public void AddProperty<T>(string label, int indentLevel, BaseField<T> field, bool condition, EventCallback<ChangeEvent<T>> evt)
{
if (condition == true)
{
AddProperty<T>(label, indentLevel, field, evt);
}
}
public void AddProperty<T>(string label, BaseField<T> field, EventCallback<ChangeEvent<T>> evt)
{
AddProperty<T>(label, 0, field, evt);
}
public void AddProperty<T>(string label, int indentLevel, BaseField<T> field, EventCallback<ChangeEvent<T>> evt)
{
AddProperty<T>(label, string.Empty, indentLevel, field, evt);
}
public void AddProperty<T>(string label, string tooltip, int indentLevel, BaseField<T> field, EventCallback<ChangeEvent<T>> evt)
{
if (field is INotifyValueChanged<T> notifyValueChanged)
{
notifyValueChanged.RegisterValueChangedCallback(evt);
}
var propertyLabel = new Label(label);
propertyLabel.tooltip = tooltip;
var propertyRow = new PropertyRow(propertyLabel);
ApplyPadding(propertyRow, indentLevel);
propertyRow.Add(field);
this.hierarchy.Add(propertyRow);
}
public void AddLabel(string label, int indentLevel)
{
var propertyRow = new PropertyRow(new Label(label));
ApplyPadding(propertyRow, indentLevel);
this.hierarchy.Add(propertyRow);
}
public void AddHelpBox(MessageType messageType, string messageText)
{
var helpBox = new HelpBoxRow(messageType);
helpBox.Add(new Label(messageText));
this.hierarchy.Add(helpBox);
}
void ApplyPadding(PropertyRow row, int indentLevel)
{
row.Q(className: "unity-label").style.marginLeft = (globalIndentLevel + indentLevel) * kIndentWidthInPixel;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5b0e9f1f7df8dc34a984c30b56cf998b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,97 @@
using System;
using System.Linq;
using System.Collections.Generic;
namespace UnityEditor.ShaderGraph
{
[GenerationAPI]
internal class TargetSetupContext
{
public List<SubShaderDescriptor> subShaders { get; private set; }
public KernelCollection kernels { get; private set; }
public AssetCollection assetCollection { get; private set; }
// these are data that are now stored in the subshaders.
// but for backwards compatibility with the existing Targets,
// we store the values provided directly by the Target,
// and apply them to all of the subShaders provided by the Target (that don't have their own setting)
// the Targets are free to switch to specifying these values per SubShaderDescriptor instead,
// if they want to specify different values for each subshader.
private List<ShaderCustomEditor> customEditorForRenderPipelines;
private string defaultShaderGUI;
// assetCollection is used to gather asset dependencies
public TargetSetupContext(AssetCollection assetCollection = null)
{
subShaders = new List<SubShaderDescriptor>();
kernels = new KernelCollection();
this.assetCollection = assetCollection;
}
public void SetupFinalize()
{
// copy custom editors to each subshader, if they don't have their own specification
if (subShaders == null)
return;
for (int i = 0; i < subShaders.Count; i++)
{
var subShader = subShaders[i];
if ((subShader.shaderCustomEditors == null) && (customEditorForRenderPipelines != null))
subShader.shaderCustomEditors = new List<ShaderCustomEditor>(customEditorForRenderPipelines);
if (subShader.shaderCustomEditor == null)
subShader.shaderCustomEditor = defaultShaderGUI;
subShaders[i] = subShader; // yay C# structs
}
}
public void AddSubShader(SubShaderDescriptor subShader)
{
subShaders.Add(subShader);
}
public void AddKernel(KernelDescriptor kernel)
{
kernels.Add(kernel);
}
public void AddAssetDependency(GUID guid, AssetCollection.Flags flags)
{
assetCollection?.AddAssetDependency(guid, flags);
}
public void SetDefaultShaderGUI(string defaultShaderGUI)
{
this.defaultShaderGUI = defaultShaderGUI;
}
public void AddCustomEditorForRenderPipeline(string shaderGUI, Type renderPipelineAssetType)
=> AddCustomEditorForRenderPipeline(shaderGUI, renderPipelineAssetType.FullName);
public void AddCustomEditorForRenderPipeline(string shaderGUI, string renderPipelineAssetTypeFullName)
{
if (customEditorForRenderPipelines == null)
customEditorForRenderPipelines = new List<ShaderCustomEditor>();
customEditorForRenderPipelines.Add(
new ShaderCustomEditor()
{
shaderGUI = shaderGUI,
renderPipelineAssetType = renderPipelineAssetTypeFullName
});
}
public bool HasCustomEditorForRenderPipeline<RPT>()
=> HasCustomEditorForRenderPipeline(typeof(RPT).FullName);
public bool HasCustomEditorForRenderPipeline(Type renderPipelineAssetType)
=> HasCustomEditorForRenderPipeline(renderPipelineAssetType.FullName);
public bool HasCustomEditorForRenderPipeline(string renderPipelineAssetTypeFullName)
=> customEditorForRenderPipelines?.Any(c => c.renderPipelineAssetType == renderPipelineAssetTypeFullName) ?? false;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b681d2c61f5433e4e9be20bfb43db249
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: