Search Unity

Blit not using scale or offset?

Discussion in 'Universal Render Pipeline' started by ahriman, Oct 23, 2020.

  1. ahriman

    ahriman

    Joined:
    Jun 11, 2014
    Posts:
    5
    Hey, trying to basically recreate the PixelBoy effect in URP using a render pass. Here's my code.


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3. using UnityEngine.Rendering.Universal;
    4. public class PixelBlitFeature : ScriptableRendererFeature
    5. {
    6.     class PixelBlit : ScriptableRenderPass
    7.     {
    8.  
    9.         private RenderTargetHandle tempTexture;
    10.         int width = 384;
    11.         int height = 216;
    12.         int lowResRT = 200;
    13.         // This method is called before executing the render pass.
    14.         // It can be used to configure render targets and their clear state. Also to create temporary render target textures.
    15.         // When empty this render pass will render to the active camera render target.
    16.         // You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
    17.         // The render pipeline will ensure target setup and clearing happens in an performance manner.
    18.         public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
    19.         {
    20.  
    21.         }
    22.  
    23.         // Here you can implement the rendering logic.
    24.         // Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers
    25.         // https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html
    26.         // You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline.
    27.         public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    28.         {
    29.             CommandBuffer cmd = CommandBufferPool.Get("PixelBoy Blit");
    30.  
    31.             RenderTargetIdentifier src = BuiltinRenderTextureType.CameraTarget;
    32.             RenderTargetIdentifier dst = BuiltinRenderTextureType.CurrentActive;
    33.             cmd.GetTemporaryRT(lowResRT, width, height, -1, FilterMode.Point);
    34.             cmd.Blit(src, lowResRT, new Vector2(5,5), new Vector2(0,0));
    35.             cmd.Blit(lowResRT, dst);
    36.             context.ExecuteCommandBuffer(cmd);
    37.             CommandBufferPool.Release(cmd);
    38.             Debug.Log("Executed.");
    39.         }
    40.  
    41.         /// Cleanup any allocated resources that were created during the execution of this render pass.
    42.         public override void FrameCleanup(CommandBuffer cmd)
    43.         {
    44.             cmd.ReleaseTemporaryRT(lowResRT);
    45.         }
    46.     }
    47.  
    48.     PixelBlit m_ScriptablePass;
    49.  
    50.     public override void Create()
    51.     {
    52.         m_ScriptablePass = new PixelBlit();
    53.  
    54.         // Configures where the render pass should be injected.
    55.         m_ScriptablePass.renderPassEvent = RenderPassEvent.AfterRendering;
    56.     }
    57.  
    58.     // Here you can inject one or multiple render passes in the renderer.
    59.     // This method is called when setting up the renderer once per-camera.
    60.     public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    61.     {
    62.         renderer.EnqueuePass(m_ScriptablePass);
    63.     }
    64. }
    65.  
    66.  
    67.  
    This blits the top left corner of the image only. I figured using the Blit overload with scale and offset parameters would cause it to write every fifth source pixel to the temporary render texture, but alas, no dice. It's the same result as simply blitting. Any assistance? Thanks!
     
  2. LB_Chris

    LB_Chris

    Joined:
    Jan 29, 2020
    Posts:
    33
    Hey, sadly I cannot help you with your problem since I have the same problem. Have you had any success since that you could share?
     
  3. Frog556fb2

    Frog556fb2

    Joined:
    Apr 27, 2019
    Posts:
    14
    I have the same problem
     
  4. Tdisi

    Tdisi

    Joined:
    Jan 7, 2019
    Posts:
    2
    same problem