This commit is contained in:
2021-06-13 10:28:03 +02:00
parent eb70603c85
commit df2d24cbd3
7487 changed files with 943244 additions and 0 deletions

View File

@@ -0,0 +1,141 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph
{
sealed class PreviewTarget : Target
{
static readonly GUID kSourceCodeGuid = new GUID("7464b9fcde08e5645a16b9b8ae1e573c"); // PreviewTarget.cs
public PreviewTarget()
{
displayName = "Preview";
isHidden = true;
}
public override bool IsActive() => false;
public override void Setup(ref TargetSetupContext context)
{
context.AddAssetDependency(kSourceCodeGuid, AssetCollection.Flags.SourceDependency);
context.AddSubShader(SubShaders.Preview);
}
public override void GetFields(ref TargetFieldContext context)
{
}
public override void GetActiveBlocks(ref TargetActiveBlockContext context)
{
}
public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo)
{
}
public override bool WorksWithSRP(RenderPipelineAsset scriptableRenderPipeline) => true;
static class SubShaders
{
public static SubShaderDescriptor Preview = new SubShaderDescriptor()
{
renderQueue = "Geometry",
renderType = "Opaque",
generatesPreview = true,
passes = new PassCollection { Passes.Preview },
};
}
static class Passes
{
public static PassDescriptor Preview = new PassDescriptor()
{
// Definition
referenceName = "SHADERPASS_PREVIEW",
useInPreview = true,
// Templates
passTemplatePath = GenerationUtils.GetDefaultTemplatePath("PassMesh.template"),
sharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories(),
// Collections
structs = new StructCollection
{
{ Structs.Attributes },
{ StructDescriptors.PreviewVaryings },
{ Structs.SurfaceDescriptionInputs },
{ Structs.VertexDescriptionInputs },
},
fieldDependencies = FieldDependencies.Default,
pragmas = new PragmaCollection
{
{ Pragma.Vertex("vert") },
{ Pragma.Fragment("frag") },
},
defines = new DefineCollection
{
{ KeywordDescriptors.PreviewKeyword, 1 },
},
includes = new IncludeCollection
{
// Pre-graph
{ "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl", IncludeLocation.Pregraph },
{ "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl", IncludeLocation.Pregraph },
{ "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl", IncludeLocation.Pregraph }, // TODO: put this on a conditional
{ "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl", IncludeLocation.Pregraph },
{ "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl", IncludeLocation.Pregraph },
{ "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl", IncludeLocation.Pregraph },
{ "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl", IncludeLocation.Pregraph },
{ "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl", IncludeLocation.Pregraph },
{ "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariables.hlsl", IncludeLocation.Pregraph },
{ "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl", IncludeLocation.Pregraph },
{ "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl", IncludeLocation.Pregraph },
// Post-graph
{ "Packages/com.unity.shadergraph/ShaderGraphLibrary/PreviewVaryings.hlsl", IncludeLocation.Postgraph },
{ "Packages/com.unity.shadergraph/ShaderGraphLibrary/PreviewPass.hlsl", IncludeLocation.Postgraph },
}
};
}
static class StructDescriptors
{
public static StructDescriptor PreviewVaryings = new StructDescriptor()
{
name = "Varyings",
packFields = true,
fields = new[]
{
StructFields.Varyings.positionCS,
StructFields.Varyings.positionWS,
StructFields.Varyings.normalWS,
StructFields.Varyings.tangentWS,
StructFields.Varyings.texCoord0,
StructFields.Varyings.texCoord1,
StructFields.Varyings.texCoord2,
StructFields.Varyings.texCoord3,
StructFields.Varyings.color,
StructFields.Varyings.viewDirectionWS,
StructFields.Varyings.screenPosition,
StructFields.Varyings.instanceID,
StructFields.Varyings.cullFace,
}
};
}
static class KeywordDescriptors
{
public static KeywordDescriptor PreviewKeyword = new KeywordDescriptor()
{
displayName = "Preview",
referenceName = "SHADERGRAPH_PREVIEW",
type = KeywordType.Boolean,
definition = KeywordDefinition.MultiCompile,
scope = KeywordScope.Global,
};
}
}
}

View File

@@ -0,0 +1,148 @@
#if VFX_GRAPH_10_0_0_OR_NEWER
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UIElements;
using UnityEditor.UIElements;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.Graphing.Util;
using UnityEditor.ShaderGraph.Internal;
using UnityEditor.ShaderGraph.Legacy;
namespace UnityEditor.ShaderGraph
{
sealed class VFXTarget : Target, ILegacyTarget
{
[SerializeField]
bool m_Lit;
[SerializeField]
bool m_AlphaTest = false;
public VFXTarget()
{
displayName = "Visual Effect";
}
public bool lit
{
get => m_Lit;
set => m_Lit = value;
}
public bool alphaTest
{
get => m_AlphaTest;
set => m_AlphaTest = value;
}
public override bool IsActive() => true;
public override void Setup(ref TargetSetupContext context)
{
}
public override void GetFields(ref TargetFieldContext context)
{
}
public override bool IsNodeAllowedByTarget(Type nodeType)
{
return base.IsNodeAllowedByTarget(nodeType);
}
public override void GetActiveBlocks(ref TargetActiveBlockContext context)
{
context.AddBlock(BlockFields.SurfaceDescription.BaseColor);
context.AddBlock(BlockFields.SurfaceDescription.Alpha);
context.AddBlock(BlockFields.SurfaceDescription.Metallic, lit);
context.AddBlock(BlockFields.SurfaceDescription.Smoothness, lit);
context.AddBlock(BlockFields.SurfaceDescription.NormalTS, lit);
context.AddBlock(BlockFields.SurfaceDescription.Emission);
context.AddBlock(BlockFields.SurfaceDescription.AlphaClipThreshold, alphaTest);
}
enum MaterialMode
{
Unlit,
Lit
}
public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo)
{
context.AddProperty("Material", new EnumField(MaterialMode.Unlit) { value = m_Lit ? MaterialMode.Lit : MaterialMode.Unlit }, evt =>
{
var newLit = (MaterialMode)evt.newValue == MaterialMode.Lit;
if (Equals(m_Lit, newLit))
return;
registerUndo("Change Material Lit");
m_Lit = newLit;
onChange();
});
context.AddProperty("Alpha Clipping", new Toggle() { value = m_AlphaTest }, (evt) =>
{
if (Equals(m_AlphaTest, evt.newValue))
return;
registerUndo("Change Alpha Test");
m_AlphaTest = evt.newValue;
onChange();
});
}
public static Dictionary<BlockFieldDescriptor, int> s_BlockMap = new Dictionary<BlockFieldDescriptor, int>()
{
{ BlockFields.SurfaceDescription.BaseColor, ShaderGraphVfxAsset.ColorSlotId },
{ BlockFields.SurfaceDescription.Metallic, ShaderGraphVfxAsset.MetallicSlotId },
{ BlockFields.SurfaceDescription.Smoothness, ShaderGraphVfxAsset.SmoothnessSlotId },
{ BlockFields.SurfaceDescription.NormalTS, ShaderGraphVfxAsset.NormalSlotId },
{ BlockFields.SurfaceDescription.Emission, ShaderGraphVfxAsset.EmissiveSlotId },
{ BlockFields.SurfaceDescription.Alpha, ShaderGraphVfxAsset.AlphaSlotId },
{ BlockFields.SurfaceDescription.AlphaClipThreshold, ShaderGraphVfxAsset.AlphaThresholdSlotId },
};
public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<BlockFieldDescriptor, int> blockMap)
{
blockMap = null;
if (!(masterNode is VisualEffectMasterNode1 vfxMasterNode))
return false;
lit = vfxMasterNode.m_Lit;
alphaTest = vfxMasterNode.m_AlphaTest;
blockMap = new Dictionary<BlockFieldDescriptor, int>();
if (lit)
{
blockMap.Add(BlockFields.SurfaceDescription.BaseColor, ShaderGraphVfxAsset.BaseColorSlotId);
blockMap.Add(BlockFields.SurfaceDescription.Metallic, ShaderGraphVfxAsset.MetallicSlotId);
blockMap.Add(BlockFields.SurfaceDescription.Smoothness, ShaderGraphVfxAsset.SmoothnessSlotId);
blockMap.Add(BlockFields.SurfaceDescription.NormalTS, ShaderGraphVfxAsset.NormalSlotId);
blockMap.Add(BlockFields.SurfaceDescription.Emission, ShaderGraphVfxAsset.EmissiveSlotId);
}
else
{
blockMap.Add(BlockFields.SurfaceDescription.BaseColor, ShaderGraphVfxAsset.ColorSlotId);
}
blockMap.Add(BlockFields.SurfaceDescription.Alpha, ShaderGraphVfxAsset.AlphaSlotId);
if (alphaTest)
{
blockMap.Add(BlockFields.SurfaceDescription.AlphaClipThreshold, ShaderGraphVfxAsset.AlphaThresholdSlotId);
}
return true;
}
public override bool WorksWithSRP(RenderPipelineAsset scriptableRenderPipeline)
{
return GraphicsSettings.currentRenderPipeline != null && scriptableRenderPipeline?.GetType() == GraphicsSettings.currentRenderPipeline.GetType();
}
}
}
#endif