Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[URP] Fullscreen ShaderGraph feature #6142

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
397ab27
Initial fullscreen target files
alelievr Sep 16, 2021
b5e9ddf
Added blend modes + depth output option
alelievr Sep 17, 2021
d197e65
Added read mask in stencil descriptor
alelievr Sep 20, 2021
2a70be5
Added Blit support
alelievr Sep 20, 2021
97047c2
Fixed ShaderGraph default shader generator outputing 2 CustomEditor l…
alelievr Sep 21, 2021
50f8621
Added Fullscreen SG material GUI
alelievr Sep 21, 2021
e7ffca3
Add ability to disable stencil and blend in shadergraph (for material)
alelievr Sep 22, 2021
28f538c
refactor to have one sub-target per pipeline + working position compu…
alelievr Sep 23, 2021
5258060
Add URP fullscreen pass implementation
alelievr Sep 24, 2021
a0ab151
Added IsNodeAllowedBySubTarget API
alelievr Sep 29, 2021
851792f
Added node filtering for the fulscreen sub-target + fix scene color n…
alelievr Sep 29, 2021
82cdcfc
Add create callback + separate colorRGBA into color RGB + A
alelievr Sep 29, 2021
18c821a
Move shadergraph fullscreen create menu
alelievr Sep 30, 2021
baf754a
Fix camera color buffer sampling in all HDRP custom pass injection po…
alelievr Sep 30, 2021
da7674d
Added HD scene depth node
alelievr Oct 1, 2021
dbc1e1c
Fix default custom editor in ShaderGraph being only applied if target…
alelievr Oct 1, 2021
648fc95
Fix alpha block by default
alelievr Oct 8, 2021
9b60865
Implemented builtin fullscreen pass (compatible with PPV2)
alelievr Oct 8, 2021
0b0b799
HD Sample depth node now sample the depth instead of loading it
alelievr Oct 8, 2021
57ca8e0
Fixed color LOD sampling
alelievr Oct 11, 2021
f503acd
Use BaseColor instead of Color block
alelievr Oct 11, 2021
4dc9cb7
Add the HD Sample buffer node
alelievr Oct 12, 2021
0b0998f
started to add the draw fullscreen render feature in URP
alelievr Oct 12, 2021
e5abaf6
Fix todo
alelievr Oct 12, 2021
5a8d654
Fix custom post process file creating in HDRP
alelievr Oct 12, 2021
07d459b
Fix render feature debug name + subgraphs in Fullscreen SGs
alelievr Oct 13, 2021
7eb0b01
Added options to bind normal and motion vectors in URP
alelievr Oct 14, 2021
a33cdb7
Normal sampling in Universal sample buffer node
alelievr Oct 14, 2021
cc4314a
Merge remote-tracking branch 'origin/master' into sg/fullscreen-target
alelievr Oct 14, 2021
17997a0
Fix depth test compilation
alelievr Oct 14, 2021
9d002da
Fix custom post process template
alelievr Oct 14, 2021
60a85f6
Started to add GLES2 support + finish URP integration
alelievr Oct 15, 2021
cdb4e33
FIx missing only_renderers
alelievr Oct 18, 2021
bcaadca
Finished fullscreen draw render feature in URP + Fix scene color node…
alelievr Oct 18, 2021
0b7ae6a
Fix rendering pass ignored
alelievr Oct 18, 2021
f893acd
Added sample buffer nodes preview in ShaderGraph
alelievr Oct 18, 2021
8514ef0
Started to add stencil support to custom passes
alelievr Oct 19, 2021
a63c2b3
Finish HDRP stencil integration
alelievr Oct 19, 2021
7e1cbb2
update node preview
alelievr Oct 19, 2021
e563dbd
Fix custom pass UI update
alelievr Oct 19, 2021
a66a418
Fix stencil disabled because of default value
alelievr Oct 20, 2021
e32b9a4
Added HDRP graphic test for fullscreen shader graph
alelievr Oct 20, 2021
aab5e0c
Added custom render texture support
alelievr Oct 20, 2021
a11dd34
Fix wrong stencil keyword generation
alelievr Oct 20, 2021
0dd896a
Fixes
alelievr Oct 20, 2021
8d3cf69
Fix custom pass editor not selecting correctt pass name when a new ma…
alelievr Oct 21, 2021
dd1f6a1
Add simple fullscreen graphic test for ShaderGraph
alelievr Oct 21, 2021
23117c7
Added CRT sub target filter on nodes
alelievr Oct 22, 2021
63247bc
Fix motion vector and blit source in Universal Sample buffer node
alelievr Oct 22, 2021
65c82d9
Add camera color as input
alelievr Oct 22, 2021
4c97c9c
Merge remote-tracking branch 'origin/master' into sg/fullscreen-target
alelievr Oct 26, 2021
f90918b
Fixed HD scene depth node
alelievr Oct 26, 2021
904019d
Cleanup for URP PR
alelievr Oct 26, 2021
c0d4c22
Cleanup for URP PR
alelievr Oct 26, 2021
d4cbd34
Fix function name conflict in URP sample buffer node
alelievr Oct 28, 2021
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
Prev Previous commit
Next Next commit
Started to add stencil support to custom passes
  • Loading branch information
alelievr committed Oct 19, 2021
commit 8514ef0a93df9d9dc708268e069e14b5e9f6a518
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ private class Styles
public static GUIContent depthWrite = new GUIContent("Write Depth", "Choose to write depth to the screen.");
public static GUIContent depthCompareFunction = new GUIContent("Depth Test", "Choose a new test setting for the depth.");

//Stencil Settings
public static GUIContent overrideStencil = new GUIContent("Override Stencil", "Override stencil state of the objects rendered.");
public static GUIContent stencilReferenceValue = new GUIContent("Reference", ".");
public static GUIContent stencilWriteMask = new GUIContent("Write Mask", ".");
public static GUIContent stencilReadMask = new GUIContent("Read Mask", ".");
public static GUIContent stencilCompareFunction = new GUIContent("Compare Function", ".");
public static GUIContent stencilPassOperation = new GUIContent("Pass", ".");
public static GUIContent stencilFailOperation = new GUIContent("Fail", ".");
public static GUIContent stencilDepthFailOperation = new GUIContent("Depth Fail", ".");

//Camera Settings
public static GUIContent overrideCamera = new GUIContent("Camera", "Override camera projections.");
public static GUIContent cameraFOV = new GUIContent("Field Of View", "Field Of View to render this pass in.");
Expand Down Expand Up @@ -85,6 +95,15 @@ private class Styles
SerializedProperty m_DepthCompareFunction;
SerializedProperty m_DepthWrite;

// Override stencil state
SerializedProperty m_OverrideStencilState;
SerializedProperty m_StencilReferenceValue;
SerializedProperty m_StencilWriteMask;
SerializedProperty m_StencilReadMask;
SerializedProperty m_StencilPassOperation;
SerializedProperty m_StencilFailOperation;
SerializedProperty m_StencilDepthFailOperation;

ReorderableList m_ShaderPassesList;

CustomPassVolume m_Volume;
Expand Down Expand Up @@ -268,6 +287,7 @@ void DoMaterialOverride(ref Rect rect)
rect.y += Styles.defaultLineSpace;
}

// Depth properties
EditorGUI.BeginProperty(rect, Styles.overrideDepth, m_OverrideDepthState);
{
if (customDepthIsNone)
Expand All @@ -291,6 +311,52 @@ void DoMaterialOverride(ref Rect rect)
EditorGUI.PropertyField(rect, m_DepthWrite, Styles.depthWrite);
EditorGUI.indentLevel--;
}

// Stencil properties
EditorGUI.BeginProperty(rect, Styles.overrideStencil, m_OverrideStencilState);
{
if (customDepthIsNone)
{
using (new EditorGUI.DisabledScope(true))
EditorGUI.Toggle(rect, Styles.overrideStencil, false);
}
else
{
EditorGUI.PropertyField(rect, m_OverrideStencilState, Styles.overrideStencil);
}
}
EditorGUI.EndProperty();

if (m_OverrideStencilState.boolValue && !customDepthIsNone)
{
EditorGUI.indentLevel++;
rect.y += Styles.defaultLineSpace;
EditorGUI.PropertyField(rect, m_StencilReferenceValue, Styles.stencilReferenceValue);
rect.y += Styles.defaultLineSpace;
EditorGUI.PropertyField(rect, m_StencilReadMask, Styles.stencilReadMask);
rect.y += Styles.defaultLineSpace;
EditorGUI.PropertyField(rect, m_StencilReadMask, Styles.stencilReadMask);
rect.y += Styles.defaultLineSpace;
EditorGUI.PropertyField(rect, m_StencilReadMask, Styles.stencilReadMask);
rect.y += Styles.defaultLineSpace;
EditorGUI.PropertyField(rect, m_StencilReadMask, Styles.stencilReadMask);
rect.y += Styles.defaultLineSpace;
EditorGUI.PropertyField(rect, m_StencilReadMask, Styles.stencilReadMask);
rect.y += Styles.defaultLineSpace;
EditorGUI.PropertyField(rect, m_StencilReadMask, Styles.stencilReadMask);
rect.y += Styles.defaultLineSpace;
EditorGUI.PropertyField(rect, m_StencilReadMask, Styles.stencilReadMask);

// SerializedProperty m_StencilWriteMask;
// SerializedProperty m_StencilReadMask;
// SerializedProperty m_StencilPassOperation;
// SerializedProperty m_StencilFailOperation;
// SerializedProperty m_StencilDepthFailOperation;


EditorGUI.indentLevel--;

}
}

void DoShaderPassesList(ref Rect rect)
Expand Down Expand Up @@ -349,6 +415,7 @@ protected override float GetPassHeight(SerializedProperty customPass)
if (showMaterialOverride)
height += Styles.defaultLineSpace * m_MaterialLines;
height += Styles.defaultLineSpace * (m_OverrideDepthState.boolValue && !customDepthIsNone ? 3 : 1);
height += Styles.defaultLineSpace * (m_OverrideStencilState.boolValue && !customDepthIsNone ? 6 : 1);
var mat = m_OverrideMaterial.objectReferenceValue as Material;

#if SHOW_PASS_NAMES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private class Styles
public static GUIContent fetchColorBuffer = new GUIContent("Fetch Color Buffer", "Tick this if your effect sample/fetch the camera color buffer");

public readonly static string writeAndFetchColorBufferWarning = "Fetching and Writing to the camera color buffer at the same time is not supported on most platforms.";
public readonly static string stencilWriteOverReservedBits = "The Stencil Write Mask of your material overwrites the bits reserved by HDRP. To avoid rendering errors, set the Write Mask to " + (int)(UserStencilUsage.UserBit0 | UserStencilUsage.UserBit1);
}

// Fullscreen pass
Expand Down Expand Up @@ -72,16 +73,56 @@ protected override void DoPassGUI(SerializedProperty customPass, Rect rect)
m_MaterialPassName.stringValue = mat.GetPassName(index);
}
EditorGUI.EndProperty();
rect.y += Styles.defaultLineSpace;

if (DoesWriteMaskContainsReservedBits(mat))
{
Rect helpBoxRect = rect;
helpBoxRect.height = Styles.helpBoxHeight;
EditorGUI.HelpBox(helpBoxRect, Styles.stencilWriteOverReservedBits, MessageType.Warning);
rect.y += Styles.helpBoxHeight;
}
// TODO: get the material stencil property and show a warning if writing to HDRP bits
}
}
}

bool DoesWriteMaskContainsReservedBits(Material material)
{
int writeMask = GetStencilWriteMask(material);
return ((writeMask & (int)~(UserStencilUsage.UserBit0 | UserStencilUsage.UserBit1)) != 0);
}

int GetStencilWriteMask(Material material)
{
if (material.shader == null)
return 0;

var serializedShader = new SerializedObject(material.shader);
var parsed = serializedShader.FindProperty("m_ParsedForm");
var subShaders = parsed.FindPropertyRelative("m_SubShaders");
var subShader = subShaders.GetArrayElementAtIndex(0);
var passes = subShader.FindPropertyRelative("m_Passes");
var pass = passes.GetArrayElementAtIndex(0);
var state = pass.FindPropertyRelative("m_State");
var writeMask = state.FindPropertyRelative("stencilWriteMask");
var writeMaskFloatValue = writeMask.FindPropertyRelative("val");
var writeMaskPropertyName = writeMask.FindPropertyRelative("name");

if (material.HasProperty(writeMaskPropertyName.stringValue))
return (int)material.GetFloat(writeMaskPropertyName.stringValue);
else
return (int)writeMaskFloatValue.floatValue;
}

protected override float GetPassHeight(SerializedProperty customPass)
{
int lineCount = (m_FullScreenPassMaterial.objectReferenceValue is Material ? 3 : 2);
int height = (int)(Styles.defaultLineSpace * lineCount);

height += (m_FetchColorBuffer.boolValue && targetColorBuffer == CustomPass.TargetBuffer.Camera) ? (int)Styles.helpBoxHeight : 0;
if (m_FullScreenPassMaterial.objectReferenceValue is Material mat)
height += (DoesWriteMaskContainsReservedBits(mat)) ? (int)Styles.helpBoxHeight : 0;

return height;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
Expand Down Expand Up @@ -52,6 +53,7 @@ internal enum StencilUsage
/// Comp Always
/// Pass Replace
/// </summary>
[Flags]
public enum UserStencilUsage
{
/// <summary>User stencil bit 0.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,46 @@ public enum ShaderPass
/// </summary>
public bool depthWrite = true;

/// <summary>
/// Override the stencil state of the objects.
/// </summary>
public bool overrideStencil = false;

/// <summary>
/// Stencil reference value.
/// </summary>
public int stencilReferenceValue;

/// <summary>
/// Write mask of the stencil.
/// </summary>
public int stencilWriteMask;

/// <summary>
/// Read mask of the stencil
/// </summary>
public int stencilReadMask;

/// <summary>
/// Comparison operation between the stencil buffer and the reference value.
/// </summary>
public CompareFunction stencilCompareFunction;

/// <summary>
/// Operation to execute if the stencil test passes.
/// </summary>
public StencilOp stencilPassOperation;

/// <summary>
/// Operation to execute if the stencil test fails.
/// </summary>
public StencilOp stencilFailOperation;

/// <summary>
/// Operation to execute if the depth test fails.
/// </summary>
public StencilOp stencilDepthFailOperation;

/// <summary>
/// Set the shader pass to use when the override material is null
/// </summary>
Expand Down