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 GLES2 support + finish URP integration
  • Loading branch information
alelievr committed Oct 15, 2021
commit 60a85f65ac8fd90f5b7f3d9e087ac286c02b2e6e
16 changes: 16 additions & 0 deletions com.unity.render-pipelines.core/Runtime/Utilities/Blitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,22 @@ public static void BlitTexture(CommandBuffer cmd, RTHandle source, Vector4 scale
DrawTriangle(cmd, material, pass);
}

/// <summary>
/// Blit a Texture with a specified material. The reference name "_BlitTexture" will be used to bind the input texture.
/// </summary>
/// <param name="cmd">Command Buffer used for rendering.</param>
/// <param name="source">Source render target.</param>
/// <param name="destination">Destination render target.</param>
/// <param name="material">Material to invoke when blitting.</param>
/// <param name="pass">Pass idx within the material to invoke.</param>
public static void BlitTexture(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier destination, Material material, int pass)
{
// Unfortunately there is no function bind a RenderTargetIdentifier with a property block so we have to bind it globally.
cmd.SetGlobalTexture(BlitShaderIDs._BlitTexture, source);
cmd.SetRenderTarget(destination);
DrawTriangle(cmd, material, pass);
}

/// <summary>
/// Blit a RTHandle to another RTHandle.
/// This will properly account for partial usage (in term of resolution) of the texture for the current viewport.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ void RecordRenderGraph(RenderRequest renderRequest,
hdCamera.depthBufferMipChainInfo.ComputePackedMipChainInfo(RTHandles.rtHandleProperties.currentRenderTargetSize);

// Bind the depth pyramid offset info for the HDSceneDepth node in ShaderGraph. This can be used by users in custom passes.
Shader.SetGlobalBuffer(HDShaderIDs._DepthPyramidMipLevelOffsets, m_DepthBufferMipChainInfo.GetOffsetBufferData(m_DepthPyramidMipLevelOffsetsBuffer));
Shader.SetGlobalVector(HDShaderIDs._DepthPyramidBufferSize, new Vector4(m_DepthBufferMipChainInfo.textureSize.x, m_DepthBufferMipChainInfo.textureSize.y, 1.0f / m_DepthBufferMipChainInfo.textureSize.x, 1.0f / m_DepthBufferMipChainInfo.textureSize.y));
Shader.SetGlobalBuffer(HDShaderIDs._DepthPyramidMipLevelOffsets, hdCamera.depthBufferMipChainInfo.GetOffsetBufferData(m_DepthPyramidMipLevelOffsetsBuffer));
Shader.SetGlobalVector(HDShaderIDs._DepthPyramidBufferSize, new Vector4(hdCamera.depthBufferMipChainInfo.textureSize.x, hdCamera.depthBufferMipChainInfo.textureSize.y, 1.0f / hdCamera.depthBufferMipChainInfo.textureSize.x, 1.0f / hdCamera.depthBufferMipChainInfo.textureSize.y));

#if UNITY_EDITOR
var showGizmos = camera.cameraType == CameraType.Game
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ private struct Styles
public static GUIContent RequiresMotionVectorTexture = EditorGUIUtility.TrTextContent("Requires Motion Texture", "Specifies whether the shader needs the motion texture. Keeping this option disabled will avoid the motion texture to be computed.");
public static GUIContent BlitMaterial = new GUIContent("Material", "The material used to perform the fullscreen draw.");
public static GUIContent BlitMaterialPassIndex = EditorGUIUtility.TrTextContent("Pass Name", "Name of the material pass to use for the fullscreen draw.");
public static GUIContent Source = EditorGUIUtility.TrTextContent("Source", "Specifies the source texture for the blit. You can sample it from");
public static GUIContent Destination = EditorGUIUtility.TrTextContent("Destination", ".");
public static GUIContent Source = EditorGUIUtility.TrTextContent("Source", "Specifies the source texture for the fullscreen pass. You can sample it from");
public static GUIContent Destination = EditorGUIUtility.TrTextContent("Destination", "Specifies the destination texture for the fullscreen pass.");
}

private void Init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ public override void CollectShaderProperties(PropertyCollector properties, Gener
{
properties.AddShaderProperty(new Texture2DArrayShaderProperty
{
overrideReferenceName = "_MainTex",
displayName = "_MainTex",
// Make it compatible with Blitter.cs calls
overrideReferenceName = "_BlitTexture",
displayName = "_BlitTexture",
hidden = true,
generatePropertyBlock = true,
isMainTexture = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,24 @@ public UniversalFullscreenSubTarget()
{
displayName = "Fullscreen";
}

protected override KeywordCollection GetPassKeywords(FullscreenCompatibility compatibility)
{
return new KeywordCollection
{
useDrawProcedural
};
}

// For GLES 2 support
static KeywordDescriptor useDrawProcedural = new KeywordDescriptor
{
displayName = "Use Draw Procedural",
referenceName = "_USE_DRAW_PROCEDURAL",
type = KeywordType.Boolean,
definition = KeywordDefinition.MultiCompile,
scope = KeywordScope.Global,
stages = KeywordShaderStage.Vertex,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderin
var renderer = renderingData.cameraData.renderer;

if (m_Settings.source == DrawFullscreenBufferType.Custom || m_Settings.destination == DrawFullscreenBufferType.Custom)
{
cmd.GetTemporaryRT(k_CustomRTId, blitTargetDescriptor, FilterMode.Bilinear);
}

if (m_Settings.source == DrawFullscreenBufferType.CameraColor)
m_Source = renderer.cameraColorTarget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ public virtual IncludeCollection GetPostGraphIncludes()
protected virtual DefineCollection GetPassDefines(FullscreenCompatibility compatibility)
=> new DefineCollection();

protected virtual KeywordCollection GetPassKeywords(FullscreenCompatibility compatibility)
=> new KeywordCollection();

public virtual PassDescriptor GenerateFullscreenPass(FullscreenCompatibility compatibility)
{
var fullscreenPass = new PassDescriptor
Expand Down Expand Up @@ -337,6 +340,7 @@ public virtual PassDescriptor GenerateFullscreenPass(FullscreenCompatibility com
requiredFields = new FieldCollection
{
StructFields.Attributes.uv0, // Always need uv0 to calculate the other properties in fullscreen node code
StructFields.Attributes.positionOS,
StructFields.Varyings.texCoord0,
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
Expand All @@ -355,7 +359,7 @@ public virtual PassDescriptor GenerateFullscreenPass(FullscreenCompatibility com
{depthWriteKeywork, 1, new FieldCondition(FullscreenFields.depth, true)},
GetPassDefines(compatibility),
},
keywords = new KeywordCollection(),
keywords = GetPassKeywords(compatibility),
includes = new IncludeCollection
{
// Pre-graph
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ void BuildVaryings(Attributes input, inout Varyings output)
output.texCoord0 = output.positionCS * 0.5 + 0.5;
output.texCoord0.y = 1 - output.texCoord0.y;

float3 p = ComputeWorldSpacePosition(output.positionCS, UNITY_MATRIX_I_VP);

// Encode view direction in texCoord1
float3 worldPos = mul(UNITY_MATRIX_I_VP, float4(output.positionCS.xyz, 1)).xyz;
output.texCoord1.xyz = worldPos;
output.texCoord1.xyz = GetWorldSpaceViewDir(p);// - float3(0, 2, 0);
}

float4 GetDrawProceduralVertexPosition(uint vertexID)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
PackedVaryings vert(Attributes input)
{
Varyings output = (Varyings)0;
#if SHADER_API_GLES
output.positionCS = float4(input.positionOS.xyz, 1);
#else
output.positionCS = GetDrawProceduralVertexPosition(input.vertexID);
#endif
BuildVaryings(input, output);
PackedVaryings packedOutput = PackVaryings(output);
return packedOutput;
Expand Down