Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Question Blit Pass not working on URP and Unity +2021 versions (it does in older ones)

Discussion in 'Graphics Experimental Previews' started by Extrys, Jul 19, 2021.

  1. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    345
    Hello i have been having ome troubles with porting the Sobel Filter shader to SingleInstanced for VR
    I actually got it working but only in 2020.1.0f1

    im currently on 2021.1.5f1
    And seems that the shader or the pass is not longer working on SingleInstanced rendering

    It seems like this currently:
    Left eye: Gray
    Right Eye: Black

    Im not sure what is the cause of the problem, but i have reduced the Sobel Filter script to just a testing Color Inversion postprocessing shader to test, and it doesnt work, if someone knows about this it would be pretty nice to know what the problem is and how to solve it

    i will attach here the current color inversion filter and the Blit Pass

    Im sure-ish this is some kind of deprecation or something new should be used instead

    Mi goal at all is to have a working Fade system that doesnt depends of the postprocessing stacks
    and it paints all the screen, also i wanted to avoid using meshesh arround the player head, so i wanted to make like a way to multiply the final screen processed color in order to do a decent VR fade out platform agnostic



    The filter:
    Code (hlsl):
    1. Shader "Unlit/ScreenFadeSinglePass"
    2. {
    3.     Properties
    4.     {
    5.         [HideInInspector] _MainTex("Base (RGB)", 2D) = "white" {}
    6.     }
    7.         SubShader
    8.         {
    9.             Tags { "RenderType" = "Opaque" }
    10.             LOD 200
    11.  
    12.             Pass
    13.             {
    14.                 HLSLPROGRAM
    15.                 #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
    16.                 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
    17.  
    18.                 #pragma prefer_hlslcc gles
    19.                 #pragma exclude_renderers d3d11_9x
    20.                 #pragma target 2.0
    21.  
    22.  
    23.                 TEXTURE2D_X(_MainTex);
    24.                 SAMPLER(sampler_MainTex);
    25.  
    26.                 float _Delta;
    27.                 half4 _MainTex_ST;
    28.  
    29.                 struct Attributes
    30.                 {
    31.                     float4 positionOS       : POSITION;
    32.                     float2 uv               : TEXCOORD0;
    33.                     UNITY_VERTEX_INPUT_INSTANCE_ID //insert
    34.                 };
    35.  
    36.                 struct Varyings
    37.                 {
    38.                     float2 uv        : TEXCOORD0;
    39.                     float4 vertex : SV_POSITION;
    40.                     UNITY_VERTEX_OUTPUT_STEREO //insert
    41.                 };
    42.  
    43.                 float2 UnityStereoScreenSpaceUVAdjust(float2 uv, float4 scaleAndOffset)
    44.                 {
    45.                     return uv.xy * scaleAndOffset.xy + scaleAndOffset.zw;
    46.                 }
    47.  
    48.                 Varyings vert(Attributes input)
    49.                 {
    50.                     Varyings o = (Varyings)0;
    51.  
    52.                     UNITY_SETUP_INSTANCE_ID(input);
    53.                     UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    54.  
    55.                     VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
    56.                     o.vertex = vertexInput.positionCS;
    57.                     o.uv = input.uv;
    58.  
    59.                     return o;
    60.                 }
    61.  
    62.                 half4 frag(Varyings i) : SV_Target
    63.                 {
    64.                     UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
    65.  
    66.                     float2 uv = UnityStereoTransformScreenSpaceTex(i.uv);
    67.                     //float2 uv = UnityStereoScreenSpaceUVAdjust(i.uv, _MainTex_ST);
    68.  
    69.                     half4 col = SAMPLE_TEXTURE2D_X(_MainTex, sampler_MainTex, uv);
    70.  
    71.                     return 1-col;
    72.                 }
    73.  
    74.                 #pragma vertex vert
    75.                 #pragma fragment frag
    76.  
    77.                 ENDHLSL
    78.             }
    79.         }
    80.         FallBack "Diffuse"
    81. }
    82.  

    The Blit pass:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3. using UnityEngine.Rendering.Universal;
    4. // this was used on https://gamedevbill.com, but originally taken from https://cyangamedev.wordpress.com/2020/06/22/urp-post-processing/
    5. // Saved in Blit.cs
    6. public class Blit : ScriptableRendererFeature
    7. {
    8.  
    9.     public class BlitPass : ScriptableRenderPass
    10.     {
    11.         public enum RenderTarget
    12.         {
    13.             Color,
    14.             RenderTexture,
    15.         }
    16.  
    17.         public Material blitMaterial = null;
    18.         public int blitShaderPassIndex = 0;
    19.         public FilterMode filterMode { get; set; }
    20.  
    21.         private RenderTargetIdentifier source { get; set; }
    22.         private RenderTargetHandle destination { get; set; }
    23.  
    24.         RenderTargetHandle m_TemporaryColorTexture;
    25.         string m_ProfilerTag;
    26.  
    27.         public BlitPass(RenderPassEvent renderPassEvent, Material blitMaterial, int blitShaderPassIndex, string tag)
    28.         {
    29.             this.renderPassEvent = renderPassEvent;
    30.             this.blitMaterial = blitMaterial;
    31.             this.blitShaderPassIndex = blitShaderPassIndex;
    32.             m_ProfilerTag = tag;
    33.             m_TemporaryColorTexture.Init("_TemporaryColorTexture");
    34.         }
    35.  
    36.         public void Setup(RenderTargetIdentifier source, RenderTargetHandle destination)
    37.         {
    38.             this.source = source;
    39.             this.destination = destination;
    40.         }
    41.  
    42.         public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    43.         {
    44.             CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);
    45.  
    46.             RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;
    47.  
    48.             opaqueDesc.depthBufferBits = 0;
    49.  
    50.             if (destination == RenderTargetHandle.CameraTarget)
    51.             {
    52.                 cmd.GetTemporaryRT(m_TemporaryColorTexture.id, opaqueDesc, filterMode);
    53.  
    54.                 cmd.Blit(source, m_TemporaryColorTexture.Identifier());
    55.                 cmd.Blit(m_TemporaryColorTexture.Identifier(), source, blitMaterial);
    56.             }
    57.             else
    58.             {
    59.                 Blit(cmd, source, destination.Identifier(), blitMaterial, blitShaderPassIndex);
    60.             }
    61.  
    62.             context.ExecuteCommandBuffer(cmd);
    63.             CommandBufferPool.Release(cmd);
    64.         }
    65.  
    66.         public override void FrameCleanup(CommandBuffer cmd)
    67.         {
    68.             if (destination == RenderTargetHandle.CameraTarget)
    69.                 cmd.ReleaseTemporaryRT(m_TemporaryColorTexture.id);
    70.         }
    71.     }
    72.  
    73.     [System.Serializable]
    74.     public class BlitSettings
    75.     {
    76.         public RenderPassEvent Event = RenderPassEvent.AfterRenderingOpaques;
    77.  
    78.         public Material blitMaterial = null;
    79.         public int blitMaterialPassIndex = 0;
    80.         public Target destination = Target.Color;
    81.         public string textureId = "_BlitPassTexture";
    82.     }
    83.  
    84.     public enum Target
    85.     {
    86.         Color,
    87.         Texture
    88.     }
    89.  
    90.     public BlitSettings settings = new BlitSettings();
    91.     RenderTargetHandle m_RenderTextureHandle;
    92.  
    93.     BlitPass blitPass;
    94.  
    95.     public override void Create()
    96.     {
    97.         var passIndex = settings.blitMaterial != null ? settings.blitMaterial.passCount - 1 : 1;
    98.         settings.blitMaterialPassIndex = Mathf.Clamp(settings.blitMaterialPassIndex, -1, passIndex);
    99.         blitPass = new BlitPass(settings.Event, settings.blitMaterial, settings.blitMaterialPassIndex, name);
    100.         m_RenderTextureHandle.Init(settings.textureId);
    101.     }
    102.  
    103.     public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    104.     {
    105.         var src = renderer.cameraColorTarget;
    106.         var dest = (settings.destination == Target.Color) ? RenderTargetHandle.CameraTarget : m_RenderTextureHandle;
    107.  
    108.         if (settings.blitMaterial == null)
    109.         {
    110.             Debug.LogWarningFormat("Missing Blit Material. {0} blit pass will not execute. Check for missing reference in the assigned renderer.", GetType().Name);
    111.             return;
    112.         }
    113.  
    114.         blitPass.Setup(src, dest);
    115.         renderer.EnqueuePass(blitPass);
    116.     }
    117. }
     
  2. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    345
    Bumping this post! for visibility
     
  3. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,266
    rz_0lento likes this.
  4. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    345
    Hey thanks for answering, i set that shader but it also doesnt work with 2 eyes, is like something is wrong with the blitz pass, or how should i use this shader in order to make it work?
     
  5. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    345
    I still needing a bit of help over here, this shader stills not working , not sure if it has something to do with the forward passes, but i dont know how to use this shader to make it work, any help?
     
  6. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    345
    ¡ upload_2021-8-4_19-0-50.png

    I got this, but I don't know why there is only half screen is affected by the shader, this is super weird

    I'm not sure what more should I do

    the only thing I want to do is a Sobel filter for single-pass instanced rendering
    i have used cmd.DrawMesh in the pass feature
     

    Attached Files:

  7. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    345
    I dont get it working get, currently testing in Unity 2020.3.15f2
    Please could someone help me with this?
    upload_2021-8-6_19-8-45.png
    I dont know why they touched how the passes or instanced rendering works

    Since Blit is broken since URP 10 i have to try doing it with the method i have been told up, but al i get working is this,
    i dont get whats wrong could someone give me sources on this?
     
  8. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    345
    Bumping this thread
     
  9. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Extrys likes this.
  10. Chaiker

    Chaiker

    Joined:
    Apr 14, 2014
    Posts:
    63
  11. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,363
    Is the new Blitter function rendering a single triangle ?

    Blitter.BlitTexture one seems to return uint vertexID : SV_VertexID;

    only with 0, 1 and 2 values

    Thanks