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,189 @@
using UnityEditor.ShaderGraph;
using UnityEngine;
using static UnityEditor.Rendering.BuiltIn.ShaderUtils;
using UnityEditor.Rendering.BuiltIn;
using System;
using UnityEditor.ShaderGraph.Serialization;
using UnityEngine.Rendering;
using BlendMode = UnityEngine.Rendering.BlendMode;
using BlendOp = UnityEditor.ShaderGraph.BlendOp;
namespace UnityEditor.Rendering.Fullscreen.ShaderGraph
{
internal class FullscreenData : JsonObject
{
public enum Version
{
Initial,
}
[SerializeField]
Version m_Version = Version.Initial;
public Version version
{
get => m_Version;
set => m_Version = value;
}
[SerializeField]
FullscreenMode m_fullscreenMode;
public FullscreenMode fullscreenMode
{
get => m_fullscreenMode;
set => m_fullscreenMode = value;
}
[SerializeField]
FullscreenBlendMode m_BlendMode = FullscreenBlendMode.Disabled;
public FullscreenBlendMode blendMode
{
get => m_BlendMode;
set => m_BlendMode = value;
}
[SerializeField]
BlendMode m_SrcColorBlendMode = BlendMode.Zero;
public BlendMode srcColorBlendMode
{
get => m_SrcColorBlendMode;
set => m_SrcColorBlendMode = value;
}
[SerializeField]
BlendMode m_DstColorBlendMode = BlendMode.One;
public BlendMode dstColorBlendMode
{
get => m_DstColorBlendMode;
set => m_DstColorBlendMode = value;
}
[SerializeField]
BlendOp m_ColorBlendOperation = BlendOp.Add;
public BlendOp colorBlendOperation
{
get => m_ColorBlendOperation;
set => m_ColorBlendOperation = value;
}
[SerializeField]
BlendMode m_SrcAlphaBlendMode = BlendMode.Zero;
public BlendMode srcAlphaBlendMode
{
get => m_SrcAlphaBlendMode;
set => m_SrcAlphaBlendMode = value;
}
[SerializeField]
BlendMode m_DstAlphaBlendMode = BlendMode.One;
public BlendMode dstAlphaBlendMode
{
get => m_DstAlphaBlendMode;
set => m_DstAlphaBlendMode = value;
}
[SerializeField]
BlendOp m_AlphaBlendOperation = BlendOp.Add;
public BlendOp alphaBlendOperation
{
get => m_AlphaBlendOperation;
set => m_AlphaBlendOperation = value;
}
[SerializeField]
bool m_EnableStencil = false;
public bool enableStencil
{
get => m_EnableStencil;
set => m_EnableStencil = value;
}
[SerializeField]
int m_StencilReference = 0;
public int stencilReference
{
get => m_StencilReference;
set => m_StencilReference = Mathf.Clamp(value, 0, 255);
}
[SerializeField]
int m_StencilReadMask = 255;
public int stencilReadMask
{
get => m_StencilReadMask;
set => m_StencilReadMask = Mathf.Clamp(value, 0, 255);
}
[SerializeField]
int m_StencilWriteMask = 255;
public int stencilWriteMask
{
get => m_StencilWriteMask;
set => m_StencilWriteMask = Mathf.Clamp(value, 0, 255);
}
[SerializeField]
CompareFunction m_StencilCompareFunction = CompareFunction.Always;
public CompareFunction stencilCompareFunction
{
get => m_StencilCompareFunction;
set => m_StencilCompareFunction = value;
}
[SerializeField]
StencilOp m_StencilPassOperation = StencilOp.Keep;
public StencilOp stencilPassOperation
{
get => m_StencilPassOperation;
set => m_StencilPassOperation = value;
}
[SerializeField]
StencilOp m_StencilFailOperation = StencilOp.Keep;
public StencilOp stencilFailOperation
{
get => m_StencilFailOperation;
set => m_StencilFailOperation = value;
}
[SerializeField]
StencilOp m_StencilDepthFailOperation = StencilOp.Keep;
public StencilOp stencilDepthTestFailOperation
{
get => m_StencilDepthFailOperation;
set => m_StencilDepthFailOperation = value;
}
[SerializeField]
bool m_DepthWrite = false;
public bool depthWrite
{
get => m_DepthWrite;
set => m_DepthWrite = value;
}
[SerializeField]
FullscreenDepthWriteMode m_depthWriteMode = FullscreenDepthWriteMode.LinearEye;
public FullscreenDepthWriteMode depthWriteMode
{
get => m_depthWriteMode;
set => m_depthWriteMode = value;
}
// When checked, allows the material to control ALL surface settings (uber shader style)
[SerializeField]
bool m_AllowMaterialOverride = false;
public bool allowMaterialOverride
{
get => m_AllowMaterialOverride;
set => m_AllowMaterialOverride = value;
}
[SerializeField]
CompareFunction m_DepthTestMode = CompareFunction.Disabled;
public CompareFunction depthTestMode
{
get => m_DepthTestMode;
set => m_DepthTestMode = value;
}
}
}

View File

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

View File

@@ -0,0 +1,19 @@
using System;
using UnityEngine;
using UnityEditor.Rendering.BuiltIn;
namespace UnityEditor.Rendering.Fullscreen.ShaderGraph
{
[Serializable]
sealed class FullscreenMetaData : ScriptableObject
{
[SerializeField]
FullscreenMode m_FullscreenMode;
public FullscreenMode fullscreenMode
{
get => m_FullscreenMode;
set => m_FullscreenMode = value;
}
}
}

View File

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

View File

@@ -0,0 +1,298 @@
using System;
using UnityEngine;
using UnityEngine.Rendering;
using RenderQueue = UnityEngine.Rendering.RenderQueue;
using UnityEditor.ShaderGraph.Drawing;
namespace UnityEditor.Rendering.Fullscreen.ShaderGraph
{
/// <summary>
/// The base class to implement the fullscreen Material GUI in a render pipeline.
/// </summary>
public class FullscreenShaderGUI : ShaderGUI
{
/// <summary>Enum used to store the expanded state of the drawer in the material GUI</summary>
[Flags]
protected enum Expandable
{
/// <summary>Surface Option key for the MaterialHeaderScopeList.RegisterHeaderScope call</summary>
SurfaceOptions = 1 << 0,
/// <summary>Surface Inputs key for the MaterialHeaderScopeList.RegisterHeaderScope call</summary>
SurfaceInputs = 1 << 1,
}
protected class Styles
{
// Categories
/// <summary>Surface Option header name</summary>
public static readonly GUIContent SurfaceOptions =
EditorGUIUtility.TrTextContent("Surface Options", "Controls the rendering states of the fullscreen material.");
/// <summary>Surface Inputs header name</summary>
public static readonly GUIContent SurfaceInputs = EditorGUIUtility.TrTextContent("Surface Inputs",
"These settings describe the look and feel of the surface itself.");
/// <summary>Name and tooltip for the blending mode property in the material GUI</summary>
public static readonly GUIContent blendingMode = EditorGUIUtility.TrTextContent("Blending Mode",
"Controls how the color of the Transparent surface blends with the Material color in the background.");
/// <summary>Name and tooltip for the source color blend mode property in the material GUI</summary>
public static readonly GUIContent srcColorBlendMode = EditorGUIUtility.TrTextContent("Src Color",
"Describes how the input color will be blended.");
/// <summary>Name and tooltip for the destination color blend mode property in the material GUI</summary>
public static readonly GUIContent dstColorBlendMode = EditorGUIUtility.TrTextContent("Dst Color",
"Describes how the destination color will be blended.");
/// <summary>Name and tooltip for the color blend operation property in the material GUI</summary>
public static readonly GUIContent colorBlendOperation = EditorGUIUtility.TrTextContent("Color Blend Op",
"Tell which operation to use when blending the colors. Default is Add.");
/// <summary>Name and tooltip for the source alpha blend mode property in the material GUI</summary>
public static readonly GUIContent srcAlphaBlendMode = EditorGUIUtility.TrTextContent("Src Alpha",
"Describes how the input alpha will be blended.");
/// <summary>Name and tooltip for the destination alpha blend mode property in the material GUI</summary>
public static readonly GUIContent dstAlphaBlendMode = EditorGUIUtility.TrTextContent("Dst Alpha",
"Describes how the input alpha will be blended.");
/// <summary>Name and tooltip for the alpha blend operation property in the material GUI</summary>
public static readonly GUIContent alphaBlendOperation = EditorGUIUtility.TrTextContent("Alpha Blend Op",
"Tell which operation to use when blending the alpha channel. Default is Add.");
/// <summary>Name and tooltip for the depth write property in the material GUI</summary>
public static readonly GUIContent depthWrite = EditorGUIUtility.TrTextContent("Depth Write",
"Controls whether the shader writes depth.");
/// <summary>Name and tooltip for the depth test property in the material GUI</summary>
public static readonly GUIContent depthTest = EditorGUIUtility.TrTextContent("Depth Test",
"Specifies the depth test mode. The default is Always.");
/// <summary>Name and tooltip for the stencil override property in the material GUI</summary>
public static readonly GUIContent stencil = EditorGUIUtility.TrTextContent("Stencil Override", "Enable the stencil block in the shader.");
/// <summary>Name and tooltip for the stencil reference property in the material GUI</summary>
public static readonly GUIContent stencilRef = EditorGUIUtility.TrTextContent("Reference", "Reference value use for comparison and operations.");
/// <summary>Name and tooltip for the stencil read mask property in the material GUI</summary>
public static readonly GUIContent stencilReadMask = EditorGUIUtility.TrTextContent("Read Mask", "Tells which bit are allowed to be read during the stencil test.");
/// <summary>Name and tooltip for the stencil write mask property in the material GUI</summary>
public static readonly GUIContent stencilWriteMask = EditorGUIUtility.TrTextContent("Write Mask", "Tells which bit are allowed to be written during the stencil test.");
/// <summary>Name and tooltip for the stencil comparison property in the material GUI</summary>
public static readonly GUIContent stencilComparison = EditorGUIUtility.TrTextContent("Comparison", "Tells which function to use when doing the stencil test.");
/// <summary>Name and tooltip for the stencil pass operation property in the material GUI</summary>
public static readonly GUIContent stencilPass = EditorGUIUtility.TrTextContent("Pass", "Tells what to do when the stencil test succeed.");
/// <summary>Name and tooltip for the stencil fail operation property in the material GUI</summary>
public static readonly GUIContent stencilFail = EditorGUIUtility.TrTextContent("Fail", "Tells what to do when the stencil test fails.");
/// <summary>Name and tooltip for the stencil depth fail operation property in the material GUI</summary>
public static readonly GUIContent stencilDepthFail = EditorGUIUtility.TrTextContent("Depth Fail", "Tells what to do when the depth test fails.");
}
bool m_FirstTimeApply = true;
// By default, everything is expanded
readonly MaterialHeaderScopeList m_MaterialScopeList = new MaterialHeaderScopeList(uint.MaxValue);
// These have to be stored due to how MaterialHeaderScopeList callbacks work (they don't provide this data in the callbacks)
MaterialEditor m_MaterialEditor;
MaterialProperty[] m_Properties;
private const int queueOffsetRange = 50;
/// <summary>
/// Unity calls this function when it displays the GUI. To implement your custom GUI, override this function..
/// </summary>
/// <param name="materialEditor">Material editor instance.</param>
/// <param name="properties">The list of properties in the inspected material(s).</param>
override public void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{
m_MaterialEditor = materialEditor;
m_Properties = properties;
Material targetMat = materialEditor.target as Material;
if (m_FirstTimeApply)
{
OnOpenGUI(targetMat, materialEditor, properties);
m_FirstTimeApply = false;
}
ShaderPropertiesGUI(materialEditor, targetMat, properties);
}
/// <summary>
/// Unity calls this function when it displays the GUI. To implement your custom GUI, override this function..
/// </summary>
/// <param name="materialEditor">Material editor instance.</param>
/// <param name="properties">The list of properties in the inspected material(s).</param>
/// <param name="material">The target materials for this GUI.</param>
public virtual void OnOpenGUI(Material material, MaterialEditor materialEditor, MaterialProperty[] properties)
{
// Generate the foldouts
m_MaterialScopeList.RegisterHeaderScope(Styles.SurfaceOptions, (uint)Expandable.SurfaceOptions, DrawSurfaceOptions);
m_MaterialScopeList.RegisterHeaderScope(Styles.SurfaceInputs, (uint)Expandable.SurfaceInputs, DrawSurfaceInputs);
}
/// <summary>
/// Assign a new FullscreenShader to the target material.
/// </summary>
/// <param name="material">A valid material using a Fullscreen Shader Graph.</param>
/// <param name="oldShader"></param>
/// <param name="newShader"></param>
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
{
// Clear all keywords for fresh start
// Note: this will nuke user-selected custom keywords when they change shaders
material.shaderKeywords = null;
base.AssignNewShaderToMaterial(material, oldShader, newShader);
// Setup keywords based on the new shader
ValidateMaterial(material);
}
void ShaderPropertiesGUI(MaterialEditor materialEditor, Material material, MaterialProperty[] properties)
{
m_MaterialScopeList.DrawHeaders(materialEditor, material);
}
/// <summary>
/// Draw the Surface Options section of the fullscreen shader GUI.
/// </summary>
/// <param name="material">A valid material using a Fullscreen Shader Graph.</param>
protected virtual void DrawSurfaceOptions(Material material)
{
var materialEditor = m_MaterialEditor;
var properties = m_Properties;
var blendMode = FindProperty(FullscreenUniforms.blendModeProperty, properties, false);
var srcColorBlend = FindProperty(FullscreenUniforms.srcColorBlendProperty, properties, false);
var dstColorBlend = FindProperty(FullscreenUniforms.dstColorBlendProperty, properties, false);
var srcAlphaBlend = FindProperty(FullscreenUniforms.srcAlphaBlendProperty, properties, false);
var dstAlphaBlend = FindProperty(FullscreenUniforms.dstAlphaBlendProperty, properties, false);
var colorBlendOp = FindProperty(FullscreenUniforms.colorBlendOperationProperty, properties, false);
var alphaBlendOp = FindProperty(FullscreenUniforms.alphaBlendOperationProperty, properties, false);
var depthWrite = FindProperty(FullscreenUniforms.depthWriteProperty, properties, false);
var depthTest = FindProperty(FullscreenUniforms.depthTestProperty, properties, false);
var stencilEnable = FindProperty(FullscreenUniforms.stencilEnableProperty, properties, false);
var stencilRef = FindProperty(FullscreenUniforms.stencilReferenceProperty, properties, false);
var stencilReadMask = FindProperty(FullscreenUniforms.stencilReadMaskProperty, properties, false);
var stencilWriteMask = FindProperty(FullscreenUniforms.stencilWriteMaskProperty, properties, false);
var stencilComp = FindProperty(FullscreenUniforms.stencilComparisonProperty, properties, false);
var stencilPass = FindProperty(FullscreenUniforms.stencilPassProperty, properties, false);
var stencilFail = FindProperty(FullscreenUniforms.stencilFailProperty, properties, false);
var stencilDepthFail = FindProperty(FullscreenUniforms.stencilDepthFailProperty, properties, false);
if (material.HasProperty(FullscreenUniforms.blendModeProperty))
{
EditorGUI.BeginChangeCheck();
m_MaterialEditor.ShaderProperty(blendMode, Styles.blendingMode);
FullscreenBlendMode blendModeValue = (FullscreenBlendMode)blendMode.floatValue;
if (EditorGUI.EndChangeCheck())
SetBlendMode(blendModeValue);
if (blendModeValue == FullscreenBlendMode.Custom)
{
m_MaterialEditor.ShaderProperty(srcColorBlend, Styles.srcColorBlendMode, 1);
m_MaterialEditor.ShaderProperty(dstColorBlend, Styles.dstColorBlendMode, 1);
m_MaterialEditor.ShaderProperty(colorBlendOp, Styles.colorBlendOperation, 1);
m_MaterialEditor.ShaderProperty(srcAlphaBlend, Styles.srcAlphaBlendMode, 1);
m_MaterialEditor.ShaderProperty(dstAlphaBlend, Styles.dstAlphaBlendMode, 1);
m_MaterialEditor.ShaderProperty(alphaBlendOp, Styles.alphaBlendOperation, 1);
}
}
if (material.HasProperty(FullscreenUniforms.depthWriteProperty))
m_MaterialEditor.ShaderProperty(depthWrite, Styles.depthWrite);
if (material.HasProperty(FullscreenUniforms.depthTestProperty))
m_MaterialEditor.ShaderProperty(depthTest, Styles.depthTest);
if (material.HasProperty(FullscreenUniforms.stencilEnableProperty))
{
EditorGUI.BeginChangeCheck();
m_MaterialEditor.ShaderProperty(stencilEnable, Styles.stencil);
bool stencilEnableValue = stencilEnable.floatValue > 0.5f;
if (EditorGUI.EndChangeCheck())
SetStencilEnable(stencilEnableValue);
if (stencilEnableValue)
{
m_MaterialEditor.ShaderProperty(stencilRef, Styles.stencilRef, 1);
m_MaterialEditor.ShaderProperty(stencilReadMask, Styles.stencilReadMask, 1);
m_MaterialEditor.ShaderProperty(stencilWriteMask, Styles.stencilWriteMask, 1);
m_MaterialEditor.ShaderProperty(stencilComp, Styles.stencilComparison, 1);
m_MaterialEditor.ShaderProperty(stencilPass, Styles.stencilPass, 1);
m_MaterialEditor.ShaderProperty(stencilFail, Styles.stencilFail, 1);
m_MaterialEditor.ShaderProperty(stencilDepthFail, Styles.stencilDepthFail, 1);
}
}
void SetStencilEnable(bool enabled)
{
if (!enabled)
{
stencilComp.floatValue = (float)CompareFunction.Always;
stencilPass.floatValue = (float)StencilOp.Keep;
stencilFail.floatValue = (float)StencilOp.Keep;
stencilDepthFail.floatValue = (float)StencilOp.Keep;
}
}
void SetBlendMode(FullscreenBlendMode blendMode)
{
// Note that we can't disable the blend mode from here
if (blendMode == FullscreenBlendMode.Alpha || blendMode == FullscreenBlendMode.Disabled)
{
srcColorBlend.floatValue = (float)BlendMode.SrcAlpha;
dstColorBlend.floatValue = (float)BlendMode.OneMinusSrcAlpha;
srcAlphaBlend.floatValue = (float)BlendMode.One;
dstAlphaBlend.floatValue = (float)BlendMode.OneMinusSrcAlpha;
}
else if (blendMode == FullscreenBlendMode.Premultiply)
{
srcColorBlend.floatValue = (float)BlendMode.One;
dstColorBlend.floatValue = (float)BlendMode.OneMinusSrcAlpha;
srcAlphaBlend.floatValue = (float)BlendMode.One;
dstAlphaBlend.floatValue = (float)BlendMode.OneMinusSrcAlpha;
}
else if (blendMode == FullscreenBlendMode.Additive)
{
srcColorBlend.floatValue = (float)BlendMode.SrcAlpha;
dstColorBlend.floatValue = (float)BlendMode.One;
srcAlphaBlend.floatValue = (float)BlendMode.One;
dstAlphaBlend.floatValue = (float)BlendMode.One;
}
else if (blendMode == FullscreenBlendMode.Multiply)
{
srcColorBlend.floatValue = (float)BlendMode.DstColor;
dstColorBlend.floatValue = (float)BlendMode.Zero;
srcAlphaBlend.floatValue = (float)BlendMode.One;
dstAlphaBlend.floatValue = (float)BlendMode.OneMinusSrcAlpha;
}
colorBlendOp.floatValue = (float)BlendOp.Add;
alphaBlendOp.floatValue = (float)BlendOp.Add;
}
}
/// <summary>
/// Draw the Surface Inputs section of the fullscreen shader GUI.
/// </summary>
/// <param name="material">A valid material using a Fullscreen Shader Graph.</param>
protected virtual void DrawSurfaceInputs(Material material)
{
DrawShaderGraphProperties(m_MaterialEditor, material, m_Properties);
}
static void DrawShaderGraphProperties(MaterialEditor materialEditor, Material material, MaterialProperty[] properties)
{
if (properties == null)
return;
ShaderGraphPropertyDrawers.DrawShaderGraphGUI(materialEditor, properties);
}
/// <summary>
/// Ensures that the material is correctly setup.
/// </summary>
/// <param name="material">A valid material using a Fullscreen Shader Graph.</param>
public override void ValidateMaterial(Material material) => SetupSurface(material);
/// <summary>
/// Setup the fullscreen shader keywords from the material properties.
/// </summary>
/// <param name="material">A valid material using a Fullscreen Shader Graph.</param>
public static void SetupSurface(Material material)
{
// For now there is no keyword in FullScreenShader.
}
}
}

View File

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

View File

@@ -0,0 +1,904 @@
using UnityEditor.ShaderGraph;
using UnityEngine;
using System;
using UnityEditor.ShaderGraph.Internal;
using System.Linq;
using BlendMode = UnityEngine.Rendering.BlendMode;
using BlendOp = UnityEditor.ShaderGraph.BlendOp;
using UnityEngine.UIElements;
using UnityEditor.UIElements;
using UnityEngine.Rendering;
namespace UnityEditor.Rendering.Fullscreen.ShaderGraph
{
[GenerateBlocks("Fullscreen")]
internal struct FullscreenBlocks
{
public static BlockFieldDescriptor color = new BlockFieldDescriptor(BlockFields.SurfaceDescription.name, "FullscreenColor", "Color",
"SURFACEDESCRIPTION_COLOR", new ColorControl(UnityEngine.Color.grey, true), ShaderStage.Fragment);
public static BlockFieldDescriptor eyeDepth = new BlockFieldDescriptor(BlockFields.SurfaceDescription.name, "FullscreenEyeDepth", "Eye Depth",
"SURFACEDESCRIPTION_EYE_DEPTH", new FloatControl(0), ShaderStage.Fragment);
public static BlockFieldDescriptor linear01Depth = new BlockFieldDescriptor(BlockFields.SurfaceDescription.name, "FullscreenLinear01Depth", "Linear01 Depth",
"SURFACEDESCRIPTION_LINEAR01_DEPTH", new FloatControl(0), ShaderStage.Fragment);
public static BlockFieldDescriptor rawDepth = new BlockFieldDescriptor(BlockFields.SurfaceDescription.name, "FullscreenRawDepth", "Raw Depth",
"SURFACEDESCRIPTION_RAW_DEPTH", new FloatControl(0), ShaderStage.Fragment);
}
[GenerationAPI]
internal struct FullscreenFields
{
public static FieldDescriptor depth = new FieldDescriptor("OUTPUT", "depth", "OUTPUT_DEPTH");
}
internal enum FullscreenMode
{
FullScreen,
CustomRenderTexture,
}
internal enum FullscreenCompatibility
{
Blit,
DrawProcedural,
}
internal enum FullscreenBlendMode
{
Disabled,
Alpha,
Premultiply,
Additive,
Multiply,
Custom,
}
internal enum FullscreenDepthWriteMode
{
LinearEye,
Linear01,
Raw,
}
internal static class FullscreenUniforms
{
public static readonly string blendModeProperty = "_Fullscreen_BlendMode";
public static readonly string srcColorBlendProperty = "_Fullscreen_SrcColorBlend";
public static readonly string dstColorBlendProperty = "_Fullscreen_DstColorBlend";
public static readonly string srcAlphaBlendProperty = "_Fullscreen_SrcAlphaBlend";
public static readonly string dstAlphaBlendProperty = "_Fullscreen_DstAlphaBlend";
public static readonly string colorBlendOperationProperty = "_Fullscreen_ColorBlendOperation";
public static readonly string alphaBlendOperationProperty = "_Fullscreen_AlphaBlendOperation";
public static readonly string depthWriteProperty = "_Fullscreen_DepthWrite";
public static readonly string depthTestProperty = "_Fullscreen_DepthTest";
public static readonly string stencilEnableProperty = "_Fullscreen_Stencil";
public static readonly string stencilReferenceProperty = "_Fullscreen_StencilReference";
public static readonly string stencilReadMaskProperty = "_Fullscreen_StencilReadMask";
public static readonly string stencilWriteMaskProperty = "_Fullscreen_StencilWriteMask";
public static readonly string stencilComparisonProperty = "_Fullscreen_StencilComparison";
public static readonly string stencilPassProperty = "_Fullscreen_StencilPass";
public static readonly string stencilFailProperty = "_Fullscreen_StencilFail";
public static readonly string stencilDepthFailProperty = "_Fullscreen_StencilDepthFail";
public static readonly string srcColorBlend = "[" + srcColorBlendProperty + "]";
public static readonly string dstColorBlend = "[" + dstColorBlendProperty + "]";
public static readonly string srcAlphaBlend = "[" + srcAlphaBlendProperty + "]";
public static readonly string dstAlphaBlend = "[" + dstAlphaBlendProperty + "]";
public static readonly string colorBlendOperation = "[" + colorBlendOperationProperty + "]";
public static readonly string alphaBlendOperation = "[" + alphaBlendOperationProperty + "]";
public static readonly string depthWrite = "[" + depthWriteProperty + "]";
public static readonly string depthTest = "[" + depthTestProperty + "]";
public static readonly string stencilReference = "[" + stencilReferenceProperty + "]";
public static readonly string stencilReadMask = "[" + stencilReadMaskProperty + "]";
public static readonly string stencilWriteMask = "[" + stencilWriteMaskProperty + "]";
public static readonly string stencilComparison = "[" + stencilComparisonProperty + "]";
public static readonly string stencilPass = "[" + stencilPassProperty + "]";
public static readonly string stencilFail = "[" + stencilFailProperty + "]";
public static readonly string stencilDepthFail = "[" + stencilDepthFailProperty + "]";
}
internal abstract class FullscreenSubTarget<T> : SubTarget<T>, IRequiresData<FullscreenData>, IHasMetadata where T : Target
{
static readonly GUID kSourceCodeGuid = new GUID("1cfc804c75474e144be5d4158b9522ed"); // FullscreenSubTarget.cs // TODO
static readonly string[] kSharedTemplateDirectories = GenerationUtils.GetDefaultSharedTemplateDirectories().Union(new string[] { "Packages/com.unity.shadergraph/Editor/Generation/Targets/Fullscreen/Templates" }).ToArray();
// HLSL includes
protected static readonly string kFullscreenCommon = "Packages/com.unity.shadergraph/Editor/Generation/Targets/Fullscreen/Includes/FullscreenCommon.hlsl";
protected static readonly string kTemplatePath = "Packages/com.unity.shadergraph/Editor/Generation/Targets/Fullscreen/Templates/ShaderPass.template";
protected static readonly string kCommon = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl";
protected static readonly string kColor = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl";
protected static readonly string kTexture = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl";
protected static readonly string kInstancing = "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl";
protected static readonly string kFullscreenShaderPass = "Packages/com.unity.shadergraph/Editor/Generation/Targets/Fullscreen/Includes/FullscreenShaderPass.cs.hlsl";
protected static readonly string kSpaceTransforms = "Packages/com.unity.render-pipelines.core/ShaderLibrary/SpaceTransforms.hlsl";
protected static readonly string kFunctions = "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl";
protected static readonly string kTextureStack = "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl";
protected virtual string fullscreenDrawProceduralInclude => "Packages/com.unity.shadergraph/Editor/Generation/Targets/Fullscreen/Includes/FullscreenDrawProcedural.hlsl";
protected virtual string fullscreenBlitInclude => "Packages/com.unity.shadergraph/Editor/Generation/Targets/Fullscreen/Includes/FullscreenBlit.hlsl";
FullscreenData m_FullscreenData;
FullscreenData IRequiresData<FullscreenData>.data
{
get => m_FullscreenData;
set => m_FullscreenData = value;
}
public FullscreenData fullscreenData
{
get => m_FullscreenData;
set => m_FullscreenData = value;
}
public override void Setup(ref TargetSetupContext context)
{
context.AddAssetDependency(kSourceCodeGuid, AssetCollection.Flags.SourceDependency);
context.SetDefaultShaderGUI(GetDefaultShaderGUI().FullName);
context.AddSubShader(GenerateSubShader());
}
protected virtual IncludeCollection pregraphIncludes => new IncludeCollection();
protected abstract string pipelineTag { get; }
protected virtual Type GetDefaultShaderGUI() => typeof(FullscreenShaderGUI);
public virtual string identifier => GetType().Name;
public virtual ScriptableObject GetMetadataObject(GraphDataReadOnly graph)
{
var bultInMetadata = ScriptableObject.CreateInstance<FullscreenMetaData>();
bultInMetadata.fullscreenMode = fullscreenData.fullscreenMode;
return bultInMetadata;
}
public RenderStateCollection GetRenderState()
{
var result = new RenderStateCollection();
if (fullscreenData.allowMaterialOverride)
{
if (fullscreenData.depthTestMode != CompareFunction.Disabled)
result.Add(RenderState.ZTest(FullscreenUniforms.depthTest));
else
result.Add(RenderState.ZTest("Off"));
result.Add(RenderState.ZWrite(FullscreenUniforms.depthWrite));
if (fullscreenData.blendMode != FullscreenBlendMode.Disabled)
{
result.Add(RenderState.Blend(FullscreenUniforms.srcColorBlend, FullscreenUniforms.dstColorBlend, FullscreenUniforms.srcAlphaBlend, FullscreenUniforms.dstAlphaBlend));
result.Add(RenderState.BlendOp(FullscreenUniforms.colorBlendOperation, FullscreenUniforms.alphaBlendOperation));
}
else
{
result.Add(RenderState.Blend("Blend Off"));
}
if (fullscreenData.enableStencil)
{
result.Add(RenderState.Stencil(new StencilDescriptor { Ref = FullscreenUniforms.stencilReference, ReadMask = FullscreenUniforms.stencilReadMask, WriteMask = FullscreenUniforms.stencilWriteMask, Comp = FullscreenUniforms.stencilComparison, ZFail = FullscreenUniforms.stencilDepthFail, Fail = FullscreenUniforms.stencilFail, Pass = FullscreenUniforms.stencilPass }));
}
}
else
{
if (fullscreenData.depthTestMode == CompareFunction.Disabled)
result.Add(RenderState.ZTest("Off"));
else
result.Add(RenderState.ZTest(CompareFunctionToZTest(fullscreenData.depthTestMode).ToString()));
result.Add(RenderState.ZWrite(fullscreenData.depthWrite ? ZWrite.On.ToString() : ZWrite.Off.ToString()));
// Blend mode
if (fullscreenData.blendMode == FullscreenBlendMode.Alpha)
result.Add(RenderState.Blend(Blend.SrcAlpha, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha));
else if (fullscreenData.blendMode == FullscreenBlendMode.Premultiply)
result.Add(RenderState.Blend(Blend.One, Blend.OneMinusSrcAlpha, Blend.One, Blend.OneMinusSrcAlpha));
else if (fullscreenData.blendMode == FullscreenBlendMode.Additive)
result.Add(RenderState.Blend(Blend.SrcAlpha, Blend.One, Blend.One, Blend.One));
else if (fullscreenData.blendMode == FullscreenBlendMode.Multiply)
result.Add(RenderState.Blend(Blend.DstColor, Blend.Zero));
else if (fullscreenData.blendMode == FullscreenBlendMode.Disabled)
result.Add(RenderState.Blend("Blend Off"));
else
{
result.Add(RenderState.Blend(BlendModeToBlend(fullscreenData.srcColorBlendMode), BlendModeToBlend(fullscreenData.dstColorBlendMode), BlendModeToBlend(fullscreenData.srcAlphaBlendMode), BlendModeToBlend(fullscreenData.dstAlphaBlendMode)));
result.Add(RenderState.BlendOp(fullscreenData.colorBlendOperation, fullscreenData.alphaBlendOperation));
}
if (fullscreenData.enableStencil)
{
result.Add(RenderState.Stencil(new StencilDescriptor
{
Ref = fullscreenData.stencilReference.ToString(),
ReadMask = fullscreenData.stencilReadMask.ToString(),
WriteMask = fullscreenData.stencilWriteMask.ToString(),
Comp = CompareFunctionToStencilString(fullscreenData.stencilCompareFunction),
ZFail = StencilOpToStencilString(fullscreenData.stencilDepthTestFailOperation),
Fail = StencilOpToStencilString(fullscreenData.stencilFailOperation),
Pass = StencilOpToStencilString(fullscreenData.stencilPassOperation),
}));
}
}
result.Add(RenderState.Cull(UnityEditor.ShaderGraph.Cull.Off));
return result;
}
public static Blend BlendModeToBlend(BlendMode mode)
{
switch (mode)
{
case BlendMode.Zero: return Blend.Zero;
case BlendMode.One: return Blend.One;
case BlendMode.DstColor: return Blend.DstColor;
case BlendMode.SrcColor: return Blend.SrcColor;
case BlendMode.OneMinusDstColor: return Blend.OneMinusDstColor;
case BlendMode.SrcAlpha: return Blend.SrcAlpha;
case BlendMode.OneMinusSrcColor: return Blend.OneMinusSrcColor;
case BlendMode.DstAlpha: return Blend.DstAlpha;
case BlendMode.OneMinusDstAlpha: return Blend.OneMinusDstAlpha;
case BlendMode.SrcAlphaSaturate: return Blend.SrcAlpha;
case BlendMode.OneMinusSrcAlpha: return Blend.OneMinusSrcAlpha;
default: return Blend.Zero;
}
;
}
public static ZTest CompareFunctionToZTest(CompareFunction mode)
{
switch (mode)
{
case CompareFunction.Equal: return ZTest.Equal;
case CompareFunction.NotEqual: return ZTest.NotEqual;
case CompareFunction.Greater: return ZTest.Greater;
case CompareFunction.Less: return ZTest.Less;
case CompareFunction.GreaterEqual: return ZTest.GEqual;
case CompareFunction.LessEqual: return ZTest.LEqual;
case CompareFunction.Always: return ZTest.Always;
case CompareFunction.Disabled: return ZTest.Always;
default: return ZTest.Always;
}
;
}
public static string CompareFunctionToStencilString(CompareFunction compare)
{
switch (compare)
{
case CompareFunction.Never: return "Never";
case CompareFunction.Equal: return "Equal";
case CompareFunction.NotEqual: return "NotEqual";
case CompareFunction.Greater: return "Greater";
case CompareFunction.Less: return "Less";
case CompareFunction.GreaterEqual: return "GEqual";
case CompareFunction.LessEqual: return "LEqual";
case CompareFunction.Always: return "Always";
default: return "Always";
}
;
}
public static string StencilOpToStencilString(StencilOp op)
{
switch (op)
{
case StencilOp.Keep: return "Keep";
case StencilOp.Zero: return "Zero";
case StencilOp.Replace: return "Replace";
case StencilOp.IncrementSaturate: return "IncrSat";
case StencilOp.DecrementSaturate: return "DecrSat";
case StencilOp.Invert: return "Invert";
case StencilOp.IncrementWrap: return "IncrWrap";
case StencilOp.DecrementWrap: return "DecrWrap";
default: return "Keep";
}
;
}
public virtual SubShaderDescriptor GenerateSubShader()
{
var result = new SubShaderDescriptor()
{
generatesPreview = true,
passes = new PassCollection(),
pipelineTag = pipelineTag,
};
result.passes.Add(GenerateFullscreenPass(FullscreenCompatibility.DrawProcedural));
result.passes.Add(GenerateFullscreenPass(FullscreenCompatibility.Blit));
return result;
}
public virtual IncludeCollection GetPreGraphIncludes()
{
return new IncludeCollection
{
{ kCommon, IncludeLocation.Pregraph },
{ kColor, IncludeLocation.Pregraph },
{ kTexture, IncludeLocation.Pregraph },
{ kTextureStack, IncludeLocation.Pregraph },
{ kFullscreenShaderPass, IncludeLocation.Pregraph }, // For VR
{ pregraphIncludes },
{ kSpaceTransforms, IncludeLocation.Pregraph },
{ kFunctions, IncludeLocation.Pregraph },
};
}
public virtual IncludeCollection GetPostGraphIncludes()
{
return new IncludeCollection { { kFullscreenCommon, IncludeLocation.Postgraph } };
}
static readonly KeywordDescriptor depthWriteKeyword = new KeywordDescriptor
{
displayName = "Depth Write",
referenceName = "DEPTH_WRITE",
type = KeywordType.Boolean,
definition = KeywordDefinition.ShaderFeature,
stages = KeywordShaderStage.Fragment,
};
static readonly KeywordDescriptor depthWriteModeKeyword = new KeywordDescriptor
{
displayName = "Depth Write Mode",
referenceName = "DEPTH_WRITE_MODE",
type = KeywordType.Enum,
definition = KeywordDefinition.Predefined,
entries = new KeywordEntry[]
{
new KeywordEntry("Eye Depth", "EYE"),
new KeywordEntry("Eye Linear 01", "LINEAR01"),
new KeywordEntry("Eye Raw", "RAW"),
},
stages = KeywordShaderStage.Fragment,
};
public static StructDescriptor Varyings = new StructDescriptor()
{
name = "Varyings",
packFields = true,
populateWithCustomInterpolators = false,
fields = new FieldDescriptor[]
{
StructFields.Varyings.positionCS,
StructFields.Varyings.texCoord0,
StructFields.Varyings.texCoord1,
StructFields.Varyings.instanceID,
StructFields.Varyings.stereoTargetEyeIndexAsBlendIdx0,
StructFields.Varyings.stereoTargetEyeIndexAsRTArrayIdx,
}
};
protected virtual DefineCollection GetPassDefines(FullscreenCompatibility compatibility)
=> new DefineCollection();
protected virtual KeywordCollection GetPassKeywords(FullscreenCompatibility compatibility)
=> new KeywordCollection();
static StructDescriptor GetFullscreenAttributes(FullscreenCompatibility compatibility)
{
var desc = new StructDescriptor()
{
name = "Attributes",
packFields = false,
};
if (compatibility == FullscreenCompatibility.Blit)
{
desc.fields = new FieldDescriptor[]
{
StructFields.Attributes.instanceID,
StructFields.Attributes.vertexID,
StructFields.Attributes.positionOS,
};
}
else
{
desc.fields = new FieldDescriptor[]
{
StructFields.Attributes.instanceID,
StructFields.Attributes.vertexID,
};
}
return desc;
}
public virtual PassDescriptor GenerateFullscreenPass(FullscreenCompatibility compatibility)
{
var fullscreenPass = new PassDescriptor
{
// Definition
displayName = compatibility.ToString(),
referenceName = "SHADERPASS_" + compatibility.ToString().ToUpper(),
useInPreview = true,
// Template
passTemplatePath = kTemplatePath,
sharedTemplateDirectories = kSharedTemplateDirectories,
// Port Mask
validVertexBlocks = null,
validPixelBlocks = new BlockFieldDescriptor[]
{
BlockFields.SurfaceDescription.BaseColor,
BlockFields.SurfaceDescription.Alpha,
FullscreenBlocks.eyeDepth,
FullscreenBlocks.linear01Depth,
FullscreenBlocks.rawDepth,
},
// Fields
structs = new StructCollection
{
{ GetFullscreenAttributes(compatibility) },
{ Structs.SurfaceDescriptionInputs },
{ Varyings },
{ Structs.VertexDescriptionInputs },
},
fieldDependencies = FieldDependencies.Default,
requiredFields = new FieldCollection
{
StructFields.Varyings.texCoord0, // Always need texCoord0 to calculate the other properties in fullscreen node code
StructFields.Varyings.texCoord1, // We store the view direction computed in the vertex in the texCoord1
StructFields.Attributes.vertexID, // Need the vertex Id for the DrawProcedural case
},
// Conditional State
renderStates = GetRenderState(),
pragmas = new PragmaCollection
{
{ Pragma.Target(ShaderModel.Target30) },
{ Pragma.Vertex("vert") },
{ Pragma.Fragment("frag") },
},
defines = new DefineCollection
{
{depthWriteKeyword, 1, new FieldCondition(FullscreenFields.depth, true)},
{depthWriteModeKeyword, (int)fullscreenData.depthWriteMode, new FieldCondition(FullscreenFields.depth, true)},
GetPassDefines(compatibility),
},
keywords = GetPassKeywords(compatibility),
includes = new IncludeCollection
{
// Pre-graph
GetPreGraphIncludes(),
// Post-graph
GetPostGraphIncludes(),
},
};
switch (compatibility)
{
default:
case FullscreenCompatibility.Blit:
fullscreenPass.includes.Add(fullscreenBlitInclude, IncludeLocation.Postgraph);
break;
case FullscreenCompatibility.DrawProcedural:
fullscreenPass.includes.Add(fullscreenDrawProceduralInclude, IncludeLocation.Postgraph);
break;
}
return fullscreenPass;
}
// We don't need the save context / update materials for now
public override object saveContext => null;
public FullscreenSubTarget()
{
displayName = "Fullscreen";
}
public override bool IsNodeAllowedBySubTarget(Type nodeType)
{
var interfaces = nodeType.GetInterfaces();
bool allowed = true;
// Subgraph nodes inherits all the interfaces including vertex ones.
if (nodeType == typeof(SubGraphNode))
return true;
// There is no input in the vertex block for now
if (interfaces.Contains(typeof(IMayRequireVertexID)))
allowed = false;
if (interfaces.Contains(typeof(IMayRequireVertexSkinning)))
allowed = false;
return allowed;
}
public override bool IsActive() => true;
public override void GetFields(ref TargetFieldContext context)
{
context.AddField(UnityEditor.ShaderGraph.Fields.GraphPixel);
context.AddField(FullscreenFields.depth, fullscreenData.depthWrite || fullscreenData.depthTestMode != CompareFunction.Disabled);
}
public override void GetActiveBlocks(ref TargetActiveBlockContext context)
{
context.AddBlock(BlockFields.SurfaceDescription.BaseColor);
context.AddBlock(BlockFields.SurfaceDescription.Alpha);
var depthBlock = FullscreenBlocks.eyeDepth;
if (fullscreenData.depthWriteMode == FullscreenDepthWriteMode.Linear01)
depthBlock = FullscreenBlocks.linear01Depth;
if (fullscreenData.depthWriteMode == FullscreenDepthWriteMode.Raw)
depthBlock = FullscreenBlocks.rawDepth;
context.AddBlock(depthBlock, fullscreenData.depthWrite || fullscreenData.depthTestMode != CompareFunction.Disabled);
}
public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode)
{
if (fullscreenData.allowMaterialOverride)
{
base.CollectShaderProperties(collector, generationMode);
CollectRenderStateShaderProperties(collector, generationMode);
}
collector.AddFloatProperty("_FlipY", 0, HLSLDeclaration.Global, false);
}
public void CollectRenderStateShaderProperties(PropertyCollector collector, GenerationMode generationMode)
{
if (generationMode != GenerationMode.Preview && fullscreenData.allowMaterialOverride)
{
// When blend mode is disabled, we can't override
if (fullscreenData.blendMode != FullscreenBlendMode.Disabled)
{
BlendMode srcColorBlend = fullscreenData.srcColorBlendMode;
BlendMode srcAlphaBlend = fullscreenData.srcAlphaBlendMode;
BlendMode dstColorBlend = fullscreenData.dstColorBlendMode;
BlendMode dstAlphaBlend = fullscreenData.dstAlphaBlendMode;
BlendOp colorBlendOp = fullscreenData.colorBlendOperation;
BlendOp alphaBlendOp = fullscreenData.alphaBlendOperation;
// Patch the default blend values depending on the Blend Mode:
if (fullscreenData.blendMode != FullscreenBlendMode.Custom)
{
colorBlendOp = BlendOp.Add;
alphaBlendOp = BlendOp.Add;
}
if (fullscreenData.blendMode == FullscreenBlendMode.Alpha)
{
srcColorBlend = BlendMode.SrcAlpha;
dstColorBlend = BlendMode.OneMinusSrcAlpha;
srcAlphaBlend = BlendMode.One;
dstAlphaBlend = BlendMode.OneMinusSrcAlpha;
}
else if (fullscreenData.blendMode == FullscreenBlendMode.Premultiply)
{
srcColorBlend = BlendMode.One;
dstColorBlend = BlendMode.OneMinusSrcAlpha;
srcAlphaBlend = BlendMode.One;
dstAlphaBlend = BlendMode.OneMinusSrcAlpha;
}
else if (fullscreenData.blendMode == FullscreenBlendMode.Additive)
{
srcColorBlend = BlendMode.SrcAlpha;
dstColorBlend = BlendMode.One;
srcAlphaBlend = BlendMode.One;
dstAlphaBlend = BlendMode.One;
}
else if (fullscreenData.blendMode == FullscreenBlendMode.Multiply)
{
srcColorBlend = BlendMode.DstColor;
dstColorBlend = BlendMode.Zero;
srcAlphaBlend = BlendMode.One;
dstAlphaBlend = BlendMode.OneMinusSrcAlpha;
}
collector.AddEnumProperty(FullscreenUniforms.blendModeProperty, fullscreenData.blendMode);
collector.AddEnumProperty(FullscreenUniforms.srcColorBlendProperty, srcColorBlend);
collector.AddEnumProperty(FullscreenUniforms.dstColorBlendProperty, dstColorBlend);
collector.AddEnumProperty(FullscreenUniforms.srcAlphaBlendProperty, srcAlphaBlend);
collector.AddEnumProperty(FullscreenUniforms.dstAlphaBlendProperty, dstAlphaBlend);
collector.AddEnumProperty(FullscreenUniforms.colorBlendOperationProperty, colorBlendOp);
collector.AddEnumProperty(FullscreenUniforms.alphaBlendOperationProperty, alphaBlendOp);
}
collector.AddBoolProperty(FullscreenUniforms.depthWriteProperty, fullscreenData.depthWrite);
if (fullscreenData.depthTestMode != CompareFunction.Disabled)
collector.AddEnumProperty(FullscreenUniforms.depthTestProperty, fullscreenData.depthTestMode);
// When stencil is disabled, we can't override
if (fullscreenData.enableStencil)
{
collector.AddBoolProperty(FullscreenUniforms.stencilEnableProperty, fullscreenData.enableStencil);
collector.AddIntProperty(FullscreenUniforms.stencilReferenceProperty, fullscreenData.stencilReference);
collector.AddIntProperty(FullscreenUniforms.stencilReadMaskProperty, fullscreenData.stencilReadMask);
collector.AddIntProperty(FullscreenUniforms.stencilWriteMaskProperty, fullscreenData.stencilWriteMask);
collector.AddEnumProperty(FullscreenUniforms.stencilComparisonProperty, fullscreenData.stencilCompareFunction);
collector.AddEnumProperty(FullscreenUniforms.stencilPassProperty, fullscreenData.stencilPassOperation);
collector.AddEnumProperty(FullscreenUniforms.stencilFailProperty, fullscreenData.stencilFailOperation);
collector.AddEnumProperty(FullscreenUniforms.stencilDepthFailProperty, fullscreenData.stencilDepthTestFailOperation);
}
}
}
public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo)
{
context.AddProperty("Allow Material Override", new Toggle() { value = fullscreenData.allowMaterialOverride }, (evt) =>
{
if (Equals(fullscreenData.allowMaterialOverride, evt.newValue))
return;
registerUndo("Change Allow Material Override");
fullscreenData.allowMaterialOverride = evt.newValue;
onChange();
});
GetRenderStatePropertiesGUI(ref context, onChange, registerUndo);
}
protected virtual void GetRenderStatePropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo)
{
GetBlendingPropertiesGUI(ref context, onChange, registerUndo);
context.AddProperty("Depth Test", new EnumField(fullscreenData.depthTestMode) { value = fullscreenData.depthTestMode }, (evt) =>
{
if (Equals(fullscreenData.depthTestMode, evt.newValue))
return;
registerUndo("Change Depth Test");
fullscreenData.depthTestMode = (CompareFunction)evt.newValue;
onChange();
});
context.AddProperty("Depth Write", new Toggle { value = fullscreenData.depthWrite }, (evt) =>
{
if (Equals(fullscreenData.depthWrite, evt.newValue))
return;
registerUndo("Change Depth Write");
fullscreenData.depthWrite = evt.newValue;
onChange();
});
if (fullscreenData.depthWrite || fullscreenData.depthTestMode != CompareFunction.Disabled)
{
context.AddProperty("Depth Write Mode", new EnumField(fullscreenData.depthWriteMode) { value = fullscreenData.depthWriteMode }, (evt) =>
{
if (Equals(fullscreenData.depthWriteMode, evt.newValue))
return;
registerUndo("Change Depth Write Mode");
fullscreenData.depthWriteMode = (FullscreenDepthWriteMode)evt.newValue;
onChange();
});
}
GetStencilPropertiesGUI(ref context, onChange, registerUndo);
}
protected virtual void GetBlendingPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo)
{
context.AddProperty("Blend Mode", new EnumField(fullscreenData.blendMode) { value = fullscreenData.blendMode }, (evt) =>
{
if (Equals(fullscreenData.blendMode, evt.newValue))
return;
registerUndo("Change Blend Mode");
fullscreenData.blendMode = (FullscreenBlendMode)evt.newValue;
onChange();
});
if (fullscreenData.blendMode == FullscreenBlendMode.Custom)
{
context.globalIndentLevel++;
context.AddLabel("Color Blend Mode", 0);
context.AddProperty("Src Color", new EnumField(fullscreenData.srcColorBlendMode) { value = fullscreenData.srcColorBlendMode }, (evt) =>
{
if (Equals(fullscreenData.srcColorBlendMode, evt.newValue))
return;
registerUndo("Change Blend Mode");
fullscreenData.srcColorBlendMode = (BlendMode)evt.newValue;
onChange();
});
context.AddProperty("Dst Color", new EnumField(fullscreenData.dstColorBlendMode) { value = fullscreenData.dstColorBlendMode }, (evt) =>
{
if (Equals(fullscreenData.dstColorBlendMode, evt.newValue))
return;
registerUndo("Change Blend Mode");
fullscreenData.dstColorBlendMode = (BlendMode)evt.newValue;
onChange();
});
context.AddProperty("Color Operation", new EnumField(fullscreenData.colorBlendOperation) { value = fullscreenData.colorBlendOperation }, (evt) =>
{
if (Equals(fullscreenData.colorBlendOperation, evt.newValue))
return;
registerUndo("Change Blend Mode");
fullscreenData.colorBlendOperation = (BlendOp)evt.newValue;
onChange();
});
context.AddLabel("Alpha Blend Mode", 0);
context.AddProperty("Src", new EnumField(fullscreenData.srcAlphaBlendMode) { value = fullscreenData.srcAlphaBlendMode }, (evt) =>
{
if (Equals(fullscreenData.srcAlphaBlendMode, evt.newValue))
return;
registerUndo("Change Blend Mode");
fullscreenData.srcAlphaBlendMode = (BlendMode)evt.newValue;
onChange();
});
context.AddProperty("Dst", new EnumField(fullscreenData.dstAlphaBlendMode) { value = fullscreenData.dstAlphaBlendMode }, (evt) =>
{
if (Equals(fullscreenData.dstAlphaBlendMode, evt.newValue))
return;
registerUndo("Change Blend Mode");
fullscreenData.dstAlphaBlendMode = (BlendMode)evt.newValue;
onChange();
});
context.AddProperty("Blend Operation Alpha", new EnumField(fullscreenData.alphaBlendOperation) { value = fullscreenData.alphaBlendOperation }, (evt) =>
{
if (Equals(fullscreenData.alphaBlendOperation, evt.newValue))
return;
registerUndo("Change Blend Mode");
fullscreenData.alphaBlendOperation = (BlendOp)evt.newValue;
onChange();
});
context.globalIndentLevel--;
}
}
protected virtual void GetStencilPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action<String> registerUndo)
{
context.AddProperty("Enable Stencil", new Toggle { value = fullscreenData.enableStencil }, (evt) =>
{
if (Equals(fullscreenData.enableStencil, evt.newValue))
return;
registerUndo("Change Enable Stencil");
fullscreenData.enableStencil = evt.newValue;
onChange();
});
if (fullscreenData.enableStencil)
{
context.globalIndentLevel++;
context.AddProperty("Reference", new IntegerField { value = fullscreenData.stencilReference, isDelayed = true }, (evt) =>
{
if (Equals(fullscreenData.stencilReference, evt.newValue))
return;
registerUndo("Change Stencil Reference");
fullscreenData.stencilReference = evt.newValue;
onChange();
});
context.AddProperty("Read Mask", new IntegerField { value = fullscreenData.stencilReadMask, isDelayed = true }, (evt) =>
{
if (Equals(fullscreenData.stencilReadMask, evt.newValue))
return;
registerUndo("Change Stencil Read Mask");
fullscreenData.stencilReadMask = evt.newValue;
onChange();
});
context.AddProperty("Write Mask", new IntegerField { value = fullscreenData.stencilWriteMask, isDelayed = true }, (evt) =>
{
if (Equals(fullscreenData.stencilWriteMask, evt.newValue))
return;
registerUndo("Change Stencil Write Mask");
fullscreenData.stencilWriteMask = evt.newValue;
onChange();
});
context.AddProperty("Comparison", new EnumField(fullscreenData.stencilCompareFunction) { value = fullscreenData.stencilCompareFunction }, (evt) =>
{
if (Equals(fullscreenData.stencilCompareFunction, evt.newValue))
return;
registerUndo("Change Stencil Comparison");
fullscreenData.stencilCompareFunction = (CompareFunction)evt.newValue;
onChange();
});
context.AddProperty("Pass", new EnumField(fullscreenData.stencilPassOperation) { value = fullscreenData.stencilPassOperation }, (evt) =>
{
if (Equals(fullscreenData.stencilPassOperation, evt.newValue))
return;
registerUndo("Change Stencil Pass Operation");
fullscreenData.stencilPassOperation = (StencilOp)evt.newValue;
onChange();
});
context.AddProperty("Fail", new EnumField(fullscreenData.stencilFailOperation) { value = fullscreenData.stencilFailOperation }, (evt) =>
{
if (Equals(fullscreenData.stencilFailOperation, evt.newValue))
return;
registerUndo("Change Stencil Fail Operation");
fullscreenData.stencilFailOperation = (StencilOp)evt.newValue;
onChange();
});
context.AddProperty("Depth Fail", new EnumField(fullscreenData.stencilDepthTestFailOperation) { value = fullscreenData.stencilDepthTestFailOperation }, (evt) =>
{
if (Equals(fullscreenData.stencilDepthTestFailOperation, evt.newValue))
return;
registerUndo("Change Stencil Depth Fail Operation");
fullscreenData.stencilDepthTestFailOperation = (StencilOp)evt.newValue;
onChange();
});
context.globalIndentLevel--;
}
}
}
internal static class FullscreenPropertyCollectorExtension
{
public static void AddEnumProperty<T>(this PropertyCollector collector, string prop, T value, HLSLDeclaration hlslDeclaration = HLSLDeclaration.DoNotDeclare) where T : Enum
{
collector.AddShaderProperty(new Vector1ShaderProperty
{
floatType = FloatType.Enum,
enumType = EnumType.CSharpEnum,
cSharpEnumType = typeof(T),
hidden = true,
overrideHLSLDeclaration = true,
hlslDeclarationOverride = hlslDeclaration,
value = Convert.ToInt32(value),
overrideReferenceName = prop,
});
}
public static void AddIntProperty(this PropertyCollector collector, string prop, int value, HLSLDeclaration hlslDeclaration = HLSLDeclaration.DoNotDeclare)
{
collector.AddShaderProperty(new Vector1ShaderProperty
{
floatType = FloatType.Integer,
hidden = true,
overrideHLSLDeclaration = true,
hlslDeclarationOverride = hlslDeclaration,
value = value,
overrideReferenceName = prop,
});
}
public static void AddBoolProperty(this PropertyCollector collector, string prop, bool value, HLSLDeclaration hlslDeclaration = HLSLDeclaration.DoNotDeclare)
{
collector.AddShaderProperty(new BooleanShaderProperty
{
hidden = true,
overrideHLSLDeclaration = true,
hlslDeclarationOverride = hlslDeclaration,
value = value,
overrideReferenceName = prop,
});
}
public static void AddFloatProperty(this PropertyCollector collector, string referenceName, float defaultValue, HLSLDeclaration declarationType = HLSLDeclaration.DoNotDeclare, bool generatePropertyBlock = true)
{
collector.AddShaderProperty(new Vector1ShaderProperty
{
floatType = FloatType.Default,
hidden = true,
overrideHLSLDeclaration = true,
hlslDeclarationOverride = declarationType,
value = defaultValue,
generatePropertyBlock = generatePropertyBlock,
overrideReferenceName = referenceName,
});
}
}
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 67b87f1c65c508c429e1d957b33776b3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
PackedVaryings vert(Attributes input)
{
Varyings output = (Varyings)0;
output = BuildVaryings(input);
PackedVaryings packedOutput = PackVaryings(output);
return packedOutput;
}
float4 frag(PackedVaryings packedInput) : SV_TARGET
{
Varyings unpacked = UnpackVaryings(packedInput);
SurfaceDescriptionInputs surfaceDescriptionInputs = BuildSurfaceDescriptionInputs(unpacked);
SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
return surfaceDescription.Color;
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0de8792ff52727f44925b54be00b9f18
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
PackedVaryings vert(Attributes input)
{
Varyings output = (Varyings)0;
#if SHADER_API_GLES
output.positionCS = float4(input.positionOS.xyz, 1);
#else
output.positionCS = GetBlitVertexPosition(input.vertexID);
#endif
BuildVaryings(input, output);
PackedVaryings packedOutput = PackVaryings(output);
return packedOutput;
}
FragOutput frag(PackedVaryings packedInput)
{
return DefaultFullscreenFragmentShader(packedInput);
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c1931467a12255f489f3c72e4aa99ade
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,151 @@
// Provies missing variables for the FullScreen pass
#ifndef FULLSCREEN_COMMON_INCLUDED
#define FULLSCREEN_COMMON_INCLUDED
struct FragOutput
{
float4 color : SV_TARGET;
#ifdef DEPTH_WRITE
float depth : DEPTH_OFFSET_SEMANTIC;
#endif
};
float4x4 inverse(float4x4 m) {
float
a00 = m[0][0], a01 = m[0][1], a02 = m[0][2], a03 = m[0][3],
a10 = m[1][0], a11 = m[1][1], a12 = m[1][2], a13 = m[1][3],
a20 = m[2][0], a21 = m[2][1], a22 = m[2][2], a23 = m[2][3],
a30 = m[3][0], a31 = m[3][1], a32 = m[3][2], a33 = m[3][3],
b00 = a00 * a11 - a01 * a10,
b01 = a00 * a12 - a02 * a10,
b02 = a00 * a13 - a03 * a10,
b03 = a01 * a12 - a02 * a11,
b04 = a01 * a13 - a03 * a11,
b05 = a02 * a13 - a03 * a12,
b06 = a20 * a31 - a21 * a30,
b07 = a20 * a32 - a22 * a30,
b08 = a20 * a33 - a23 * a30,
b09 = a21 * a32 - a22 * a31,
b10 = a21 * a33 - a23 * a31,
b11 = a22 * a33 - a23 * a32,
det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
return float4x4(
a11 * b11 - a12 * b10 + a13 * b09,
a02 * b10 - a01 * b11 - a03 * b09,
a31 * b05 - a32 * b04 + a33 * b03,
a22 * b04 - a21 * b05 - a23 * b03,
a12 * b08 - a10 * b11 - a13 * b07,
a00 * b11 - a02 * b08 + a03 * b07,
a32 * b02 - a30 * b05 - a33 * b01,
a20 * b05 - a22 * b02 + a23 * b01,
a10 * b10 - a11 * b08 + a13 * b06,
a01 * b08 - a00 * b10 - a03 * b06,
a30 * b04 - a31 * b02 + a33 * b00,
a21 * b02 - a20 * b04 - a23 * b00,
a11 * b07 - a10 * b09 - a12 * b06,
a00 * b09 - a01 * b07 + a02 * b06,
a31 * b01 - a30 * b03 - a32 * b00,
a20 * b03 - a21 * b01 + a22 * b00) / det;
}
// Some render pipeline don't have access to the inverse view projection matrix
// It's okay to compute it in the vertex shader because we only have 3 to 4 vertices
void BuildVaryingsWithoutInverseProjection(Attributes input, inout Varyings output)
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
output.texCoord0 = output.positionCS * 0.5 + 0.5;
#if UNITY_UV_STARTS_AT_TOP
if (_FlipY < 0.5)
output.texCoord0.y = 1 - output.texCoord0.y;
#endif
float3x3 inverseView = (float3x3)inverse(UNITY_MATRIX_V);
float4x4 inverseProj = inverse(UNITY_MATRIX_P);
float4 viewDirectionEyeSpace = mul(inverseProj, float4(output.positionCS.xyz, 1));
float3 viewDirectionWS = mul(inverseView, viewDirectionEyeSpace.xyz).xyz;
// Encode view direction in texCoord1
output.texCoord1.xyz = viewDirectionWS;
}
void BuildVaryings(Attributes input, inout Varyings output)
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
output.texCoord0 = output.positionCS * 0.5 + 0.5;
#if UNITY_UV_STARTS_AT_TOP
if (_FlipY < 0.5)
output.texCoord0.y = 1 - output.texCoord0.y;
#endif
float3 p = ComputeWorldSpacePosition(output.positionCS, UNITY_MATRIX_I_VP);
// Encode view direction in texCoord1
output.texCoord1.xyz = GetWorldSpaceViewDir(p);
}
float4 GetDrawProceduralVertexPosition(uint vertexID)
{
return GetFullScreenTriangleVertexPosition(vertexID, UNITY_NEAR_CLIP_VALUE);
}
float4 GetBlitVertexPosition(uint vertexID)
{
float4 positionCS = GetQuadVertexPosition(vertexID);
positionCS.xy = positionCS.xy * 2 - 1;
return positionCS;
}
float4 GetBlitVertexPositionFromPositionOS(float3 positionOS)
{
return float4(positionOS.xy * 2 - 1, UNITY_NEAR_CLIP_VALUE, 1);
}
FragOutput DefaultFullscreenFragmentShader(PackedVaryings packedInput)
{
FragOutput output = (FragOutput)0;
Varyings unpacked = UnpackVaryings(packedInput);
UNITY_SETUP_INSTANCE_ID(unpacked);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked);
SurfaceDescriptionInputs surfaceDescriptionInputs = BuildSurfaceDescriptionInputs(unpacked);
SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
output.color.rgb = surfaceDescription.BaseColor;
output.color.a = surfaceDescription.Alpha;
#if defined(DEPTH_WRITE)
float n = _ProjectionParams.y;
float f = _ProjectionParams.z;
#if defined(DEPTH_WRITE_MODE_EYE)
// Reverse of LinearEyeDepth
float d = rcp(max(surfaceDescription.FullscreenEyeDepth, 0.000000001));
output.depth = (d - _ZBufferParams.w) / _ZBufferParams.z;
#endif
#if defined(DEPTH_WRITE_MODE_LINEAR01)
// Reverse of Linear01Depth
float d = rcp(max(surfaceDescription.FullscreenLinear01Depth, 0.000000001));
output.depth = (d - _ZBufferParams.y) / _ZBufferParams.x;
#endif
#if defined(DEPTH_WRITE_MODE_RAW)
output.depth = surfaceDescription.FullscreenRawDepth;
#endif
#endif
return output;
}
#endif // FULLSCREEN_COMMON_INCLUDED

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 54f14acd1960c2a459a0fcd6c959938d
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
PackedVaryings vert(Attributes input)
{
Varyings output = (Varyings)0;
output.positionCS = GetDrawProceduralVertexPosition(input.vertexID);
BuildVaryings(input, output);
PackedVaryings packedOutput = PackVaryings(output);
return packedOutput;
}
FragOutput frag(PackedVaryings packedInput)
{
return DefaultFullscreenFragmentShader(packedInput);
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: fa5319f2d61c4df44b77220af2406147
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,12 @@
//-----------------------------------------------------------------------------
// structure definition
//-----------------------------------------------------------------------------
namespace UnityEngine.Rendering.HighDefinition
{
[GenerateHLSL(PackingRules.Exact)]
enum FullscreenShaderPass
{
Blit,
DrawProcedural,
}
}

View File

@@ -0,0 +1,14 @@
//
// This file was automatically generated. Please don't edit by hand. Execute Editor command [ Edit > Rendering > Generate Shader Includes ] instead
//
#ifndef FULLSCREENSHADERPASS_CS_HLSL
#define FULLSCREENSHADERPASS_CS_HLSL
//
// UnityEngine.Rendering.HighDefinition.FullscreenShaderPass: static fields
//
#define FULLSCREENSHADERPASS_BLIT (0)
#define FULLSCREENSHADERPASS_DRAW_PROCEDURAL (1)
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: fa6980c25ec2f164ba4a6fcb040eb870
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c131f605e2f659045adf332f0f0f876f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,114 @@
Pass
{
$splice(PassName)
// Render State
$splice(RenderState)
// Debug
$splice(Debug)
// --------------------------------------------------
// Pass
HLSLPROGRAM
// Pragmas
$splice(PassPragmas)
// #pragma enable_d3d11_debug_symbols
$splice(DotsInstancingOptions)
$splice(HybridV1InjectedBuiltinProperties)
// Keywords
$splice(PassKeywords)
$splice(GraphKeywords)
#define FULLSCREEN_SHADERGRAPH
// Defines
$SurfaceType.Transparent: // UBER SHADER NOW: #define _SURFACE_TYPE_TRANSPARENT 1
$Attributes.normalOS: #define ATTRIBUTES_NEED_NORMAL
$Attributes.tangentOS: #define ATTRIBUTES_NEED_TANGENT
$Attributes.uv0: #define ATTRIBUTES_NEED_TEXCOORD0
$Attributes.uv1: #define ATTRIBUTES_NEED_TEXCOORD1
$Attributes.uv2: #define ATTRIBUTES_NEED_TEXCOORD2
$Attributes.uv3: #define ATTRIBUTES_NEED_TEXCOORD3
$Attributes.color: #define ATTRIBUTES_NEED_COLOR
$Attributes.vertexID: #define ATTRIBUTES_NEED_VERTEXID
$Varyings.positionWS: #define VARYINGS_NEED_POSITION_WS
$Varyings.normalWS: #define VARYINGS_NEED_NORMAL_WS
$Varyings.tangentWS: #define VARYINGS_NEED_TANGENT_WS
$Varyings.texCoord0: #define VARYINGS_NEED_TEXCOORD0
$Varyings.texCoord1: #define VARYINGS_NEED_TEXCOORD1
$Varyings.texCoord2: #define VARYINGS_NEED_TEXCOORD2
$Varyings.texCoord3: #define VARYINGS_NEED_TEXCOORD3
$Varyings.color: #define VARYINGS_NEED_COLOR
$Varyings.viewDirectionWS: #define VARYINGS_NEED_VIEWDIRECTION_WS
$Varyings.bitangentWS: #define VARYINGS_NEED_BITANGENT_WS
$Varyings.screenPosition: #define VARYINGS_NEED_SCREENPOSITION
$Varyings.fogFactorAndVertexLight: #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
$Varyings.cullFace: #define VARYINGS_NEED_CULLFACE
$features.graphVertex: #define FEATURES_GRAPH_VERTEX
// Force depth texture because we need it for almost every nodes
// TODO: dependency system that triggers this define from position or view direction usage
#define REQUIRE_DEPTH_TEXTURE
#define REQUIRE_NORMAL_TEXTURE
$splice(PassInstancing)
$splice(GraphDefines)
// custom interpolator pre-include
$splice(sgci_CustomInterpolatorPreInclude)
// Includes
$splice(PreGraphIncludes)
// --------------------------------------------------
// Structs and Packing
// custom interpolators pre packing
$splice(CustomInterpolatorPrePacking)
$splice(PassStructs)
$splice(InterpolatorPack)
// --------------------------------------------------
// Graph
// Graph Properties
$splice(GraphProperties)
// Graph Includes
$splice(GraphIncludes)
// Graph Functions
$splice(GraphFunctions)
// Custom interpolators pre vertex
$splice(CustomInterpolatorPreVertex)
// Graph Vertex
$splice(GraphVertex)
// Custom interpolators, pre surface
$splice(CustomInterpolatorPreSurface)
// Graph Pixel
$splice(GraphPixel)
// --------------------------------------------------
// Build Graph Inputs
$features.graphVertex: $include("BuildVertexDescriptionInputs.template.hlsl")
$features.graphPixel: $include("SharedCode.template.hlsl")
// --------------------------------------------------
// Main
$splice(PostGraphIncludes)
ENDHLSL
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0ed3a57e16f0259448e5b68a210e991a
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,70 @@
SurfaceDescriptionInputs BuildSurfaceDescriptionInputs(Varyings input)
{
SurfaceDescriptionInputs output;
ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
float3 normalWS = SHADERGRAPH_SAMPLE_SCENE_NORMAL(input.texCoord0.xy);
float4 tangentWS = float4(0, 1, 0, 0); // We can't access the tangent in screen space
$SurfaceDescriptionInputs.WorldSpaceBiTangent: // use bitangent on the fly like in hdrp
$SurfaceDescriptionInputs.WorldSpaceBiTangent: // IMPORTANT! If we ever support Flip on double sided materials ensure bitangent and tangent are NOT flipped.
$SurfaceDescriptionInputs.WorldSpaceBiTangent: float crossSign = (tangentWS.w > 0.0 ? 1.0 : -1.0) * GetOddNegativeScale();
$SurfaceDescriptionInputs.WorldSpaceBiTangent: float3 bitang = crossSign * cross(normalWS.xyz, tangentWS.xyz);
$SurfaceDescriptionInputs.WorldSpaceNormal: output.WorldSpaceNormal = normalWS.xyz; // we want a unit length Normal Vector node in shader graph
$SurfaceDescriptionInputs.ObjectSpaceNormal: output.ObjectSpaceNormal = normalize(mul(output.WorldSpaceNormal, (float3x3) UNITY_MATRIX_M)); // transposed multiplication by inverse matrix to handle normal scale
$SurfaceDescriptionInputs.ViewSpaceNormal: output.ViewSpaceNormal = mul(output.WorldSpaceNormal, (float3x3) UNITY_MATRIX_I_V); // transposed multiplication by inverse matrix to handle normal scale
$SurfaceDescriptionInputs.TangentSpaceNormal: output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f);
$SurfaceDescriptionInputs.WorldSpaceTangent: // to preserve mikktspace compliance we use same scale renormFactor as was used on the normal.
$SurfaceDescriptionInputs.WorldSpaceTangent: // This is explained in section 2.2 in "surface gradient based bump mapping framework"
$SurfaceDescriptionInputs.WorldSpaceTangent: output.WorldSpaceTangent = tangentWS.xyz;
$SurfaceDescriptionInputs.WorldSpaceBiTangent: output.WorldSpaceBiTangent = bitang;
float3 viewDirWS = normalize(input.texCoord1.xyz);
float linearDepth = LinearEyeDepth(SHADERGRAPH_SAMPLE_SCENE_DEPTH(input.texCoord0.xy), _ZBufferParams);
float3 cameraForward = -UNITY_MATRIX_V[2].xyz;
float camearDistance = linearDepth / dot(viewDirWS, cameraForward);
float3 positionWS = viewDirWS * camearDistance + GetCameraPositionWS();
$SurfaceDescriptionInputs.ObjectSpaceTangent: output.ObjectSpaceTangent = TransformWorldToObjectDir(output.WorldSpaceTangent);
$SurfaceDescriptionInputs.ViewSpaceTangent: output.ViewSpaceTangent = TransformWorldToViewDir(output.WorldSpaceTangent);
$SurfaceDescriptionInputs.TangentSpaceTangent: output.TangentSpaceTangent = float3(1.0f, 0.0f, 0.0f);
$SurfaceDescriptionInputs.ObjectSpaceBiTangent: output.ObjectSpaceBiTangent = TransformWorldToObjectDir(output.WorldSpaceBiTangent);
$SurfaceDescriptionInputs.ViewSpaceBiTangent: output.ViewSpaceBiTangent = TransformWorldToViewDir(output.WorldSpaceBiTangent);
$SurfaceDescriptionInputs.TangentSpaceBiTangent: output.TangentSpaceBiTangent = float3(0.0f, 1.0f, 0.0f);
$SurfaceDescriptionInputs.WorldSpaceViewDirection: output.WorldSpaceViewDirection = normalize(viewDirWS);
$SurfaceDescriptionInputs.ObjectSpaceViewDirection: output.ObjectSpaceViewDirection = TransformWorldToObjectDir(output.WorldSpaceViewDirection);
$SurfaceDescriptionInputs.ViewSpaceViewDirection: output.ViewSpaceViewDirection = TransformWorldToViewDir(output.WorldSpaceViewDirection);
$SurfaceDescriptionInputs.TangentSpaceViewDirection: float3x3 tangentSpaceTransform = float3x3(output.WorldSpaceTangent, output.WorldSpaceBiTangent, output.WorldSpaceNormal);
$SurfaceDescriptionInputs.TangentSpaceViewDirection: output.TangentSpaceViewDirection = mul(tangentSpaceTransform, output.WorldSpaceViewDirection);
$SurfaceDescriptionInputs.WorldSpacePosition: output.WorldSpacePosition = positionWS;
$SurfaceDescriptionInputs.ObjectSpacePosition: output.ObjectSpacePosition = TransformWorldToObject(positionWS);
$SurfaceDescriptionInputs.ViewSpacePosition: output.ViewSpacePosition = TransformWorldToView(positionWS);
$SurfaceDescriptionInputs.TangentSpacePosition: output.TangentSpacePosition = float3(0.0f, 0.0f, 0.0f);
$SurfaceDescriptionInputs.AbsoluteWorldSpacePosition: output.AbsoluteWorldSpacePosition = GetAbsolutePositionWS(positionWS);
$SurfaceDescriptionInputs.WorldSpacePositionPredisplacement: output.WorldSpacePositionPredisplacement = positionWS;
$SurfaceDescriptionInputs.ObjectSpacePositionPredisplacement: output.ObjectSpacePositionPredisplacement = TransformWorldToObject(positionWS);
$SurfaceDescriptionInputs.ViewSpacePositionPredisplacement: output.ViewSpacePositionPredisplacement = TransformWorldToView(positionWS);
$SurfaceDescriptionInputs.TangentSpacePositionPredisplacement: output.TangentSpacePositionPredisplacement = float3(0.0f, 0.0f, 0.0f);
$SurfaceDescriptionInputs.AbsoluteWorldSpacePositionPredisplacement:output.AbsoluteWorldSpacePositionPredisplacement = GetAbsolutePositionWS(positionWS);
$SurfaceDescriptionInputs.ScreenPosition: output.ScreenPosition = float4(input.texCoord0.xy, 0, 1);
$SurfaceDescriptionInputs.uv0: output.uv0 = input.texCoord0;
$SurfaceDescriptionInputs.uv1: output.uv1 = input.texCoord1;
$SurfaceDescriptionInputs.uv2: output.uv2 = input.texCoord2;
$SurfaceDescriptionInputs.uv3: output.uv3 = input.texCoord3;
$SurfaceDescriptionInputs.VertexColor: output.VertexColor = input.color;
$SurfaceDescriptionInputs.TimeParameters: output.TimeParameters = _TimeParameters.xyz; // This is mainly for LW as HD overwrite this value
$SurfaceDescriptionInputs.NDCPosition: output.NDCPosition = input.texCoord0.xy;
#if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
#define BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN output.FaceSign = IS_FRONT_VFACE(input.cullFace, true, false);
#else
#define BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN
#endif
$SurfaceDescriptionInputs.FaceSign: BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN
#undef BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN
return output;
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 16201fed0715efa48a8908fedb361bf0
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: