Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Mr_Admirals · Dec 11, 2018 at 06:15 PM · shaderrendertextureblurblit

Blit isn't writing to render texture

Hello,

I found a nice Gaussian Blur shader online and am attempting to use it to blur a render texture using blit(). However, the render texture remains unblurred. I know for a fact the blur shader works as I've used it to blur the main camera, but it just doesn't seem to want to blit() my render texture.

C# Blur Script:

 void Update()
 {
         if (_material == null)
         {
             _material = new Material(_shader);
             _material.hideFlags = HideFlags.HideAndDontSave;
         }
 
         RenderTexture rt1, rt2;
 
         if (_downSampleMode == DownSampleMode.Half)
         {
             rt1 = RenderTexture.GetTemporary(source.width / 2, source.height / 2);
             rt2 = RenderTexture.GetTemporary(source.width / 2, source.height / 2);
             Graphics.Blit(source, rt1);
         }
         else if (_downSampleMode == DownSampleMode.Quarter)
         {
             rt1 = RenderTexture.GetTemporary(source.width / 4, source.height / 4);
             rt2 = RenderTexture.GetTemporary(source.width / 4, source.height / 4);
             Graphics.Blit(source, rt1, _material, 0);
         }
         else
         {
             rt1 = RenderTexture.GetTemporary(source.width, source.height);
             rt2 = RenderTexture.GetTemporary(source.width, source.height);
             Graphics.Blit(source, rt1);
         }
 
         for (var i = 0; i < _iteration; i++)
         {
             Graphics.Blit(rt1, rt2, _material, 1);
             Graphics.Blit(rt2, rt1, _material, 2);
         }
 
         Graphics.Blit(rt1, source);
 
         RenderTexture.ReleaseTemporary(rt1);
         RenderTexture.ReleaseTemporary(rt2);
 }

Potentially Useful information:

The render texture is being used as a depth map

it is constantly being written to

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Namey5 · Jan 09, 2019 at 10:15 AM

I'm assuming 'source' is just a global variable that you assign in the inspector. If that is the case, I would recommend having a separate RenderTexture as an output. I'm not entirely sure of the outcome of blurring recursively into the same texture. I'm also not sure how well Graphics.Blit () works in Update. It is generally meant to be used in OnRenderImage (which would be how you blurred the camera output before). If the script is attached to the camera, you could probably get away with;

  void OnRenderImage(RenderTexture src, RenderTexture dest)
  {
          if (_material == null)
          {
              _material = new Material(_shader);
              _material.hideFlags = HideFlags.HideAndDontSave;
          }
  
          RenderTexture rt1, rt2;
  
          if (_downSampleMode == DownSampleMode.Half)
          {
              rt1 = RenderTexture.GetTemporary(source.width / 2, source.height / 2);
              rt2 = RenderTexture.GetTemporary(source.width / 2, source.height / 2);
              Graphics.Blit(source, rt1);
          }
          else if (_downSampleMode == DownSampleMode.Quarter)
          {
              rt1 = RenderTexture.GetTemporary(source.width / 4, source.height / 4);
              rt2 = RenderTexture.GetTemporary(source.width / 4, source.height / 4);
              Graphics.Blit(source, rt1, _material, 0);
          }
          else
          {
              rt1 = RenderTexture.GetTemporary(source.width, source.height);
              rt2 = RenderTexture.GetTemporary(source.width, source.height);
              Graphics.Blit(source, rt1);
          }
  
          for (var i = 0; i < _iteration; i++)
          {
              Graphics.Blit(rt1, rt2, _material, 1);
              Graphics.Blit(rt2, rt1, _material, 2);
          }
  
          Graphics.Blit(rt1, source);
 
          Graphics.Blit (src, dest);
  
          RenderTexture.ReleaseTemporary(rt1);
          RenderTexture.ReleaseTemporary(rt2);
  }
Comment
Add comment · Share
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

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

155 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

Related Questions

Blit shader to RenderTexture results in solid black 0 Answers

Prevent Render Texture clearing 1 Answer

How to alter/modify a RenderTexture with a shader,How can I modify/"post process" a RenderTexture using a shader 0 Answers

I have a problem with updating a RenderTexture being used in combination with a shader. 0 Answers

How to use Graphics.Blit with custom input textures 3 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