Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Euromastyx · Jul 01, 2020 at 05:23 PM · renderingshaderspost processingpost-process-effectpostprocess

How to properly use RTHandles in HDRP for post effects

I've been trying to write a post-process volume component for HDRP (Unity 2019.4.1, HDRP 7.3.1) to replicate the Clear Flags: None effect (setting the background type to "none" on the camera doesn't seem to work the same way in HDRP). I'd like to achieve the effect of having "trails" after the image, where every frame is drawn on top of the previous.


The method I'm hoping to use for this is a separate camera with a custom volume component added to it that takes the output of the previous frame and uses a shader to add the current frame to it. However, I can't quite seem to get RTHandles to work with this.


What I'm trying to replicate Reference 1 and 2

Relevant volume component code:

     private GraphicsFormat RTFormat;
     private RTHandle rth;
 
 
     public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination)
     {
         //Validate
         if (m_Material == null)    return;
         if (rth == null) rth = CreateRTH(camera);
 
         m_Material.SetTexture("_MainTex", source);
         m_Material.SetTexture("_PrevFrame", rth);
 
         //Draw the frame itself
         HDUtils.DrawFullScreen(cmd, m_Material, destination);
         HDUtils.DrawFullScreen(cmd, m_Material, rth);
     }
 
     private RTHandle CreateRTH(HDCamera camera)
     {
         return RTHandles.Alloc(camera.actualWidth, camera.actualHeight, 2, DepthBits.Depth16, colorFormat: RTFormat, FilterMode.Bilinear, TextureWrapMode.Clamp, TextureDimension.Tex2D, false, false, false, false, 2, 0, MSAASamples.None, true, true, RenderTextureMemoryless.None, "rth");
     }


Shader function:

     float _Intensity;
     TEXTURE2D_X(_MainTex);
     TEXTURE2D_X(_PrevFrame);
 
 
     float4 CustomPostProcess(Varyings input) : SV_Target
     {
         UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
 
         uint2 positionSS = input.texcoord * _ScreenSize.xy;
         float3 outColor = LOAD_TEXTURE2D_X(_MainTex, positionSS).xyz;
         outColor.xy = 0;
         float3 acc =  LOAD_TEXTURE2D_X(_PrevFrame, positionSS).xyz;
         acc.yz = 0;
         outColor += acc; 
 
         return float4(outColor, 1);
     }

However, I can't seem to get the generated RTHandle and RenderTexture to output anything other than black. I've researched this as thoroughly as possible and my method seems to be correct from what I understand. Any ideas?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

160 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get quality Depth Of Field effect with Post Processing Stack V2? 1 Answer

HDRP Edge Detection FullScreen Custom Pass 0 Answers

Curved Screen Post Processing Effect 1 Answer

URP Custom volume overrides 0 Answers

How to disable post-processing in the editor view? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges