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 /
  • Help Room /
avatar image
0
Question by Krstn · Nov 22, 2018 at 07:33 AM · shaderblit

Why is Graphics.Blit with material not working consistently?

Hi

I am in need of creating a quick background blur below some popups in my UI project. After investigating a while, I have settled on using the AsyncGPUReadbackRequest to get the data into the texture and a Frosted Glass shader (Unlit).

Because the background is going to be static anyway, I wanted to push it into the RenderTexture, apply shader while doing Graphics.Blit.

Unfortunately, most of the time it looks like the shader does not use the input texture of Graphics.Blit at all. My render texture looks like only some grey layer was applied to it. I've tried with different Unlit shaders, always the same - output looks like the main texture in shader was empty.

What strikes me, is that in a moment of frustration, I kept mashing the button i have created for testing the effect and.... once in a while it actually works and produces the desired output!

I am not sure why, the effect is not consistent at all. I'm using Unity 2018.2.16, I have also tried on .15 with the same effect.

I've searched for the answers online already, I came up with a lot mentioning that the shader has to be unlint (checked) and that it could be due to different formats of texture and the expected format of the shader. I think i am sure this is ok in my case, especially that once in a while it works just fine.

https://forum.unity.com/threads/graphics-blit-with-material-resulting-in-corrupted-output.41164/

The script I use for testing is super easy, maybe someone could have a look and point me to what I do wrong, I will be forever grateful.

The script has to be attached to the camera, and I just redirect the render texture to some output RawImage.

Thanks

 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Rendering;
 using UnityEngine.UI;
 
 public class ProcessImage : MonoBehaviour {
     public bool willProcess = false;
 
     public RawImage _outputImage;
 
     public Material _shaderMaterial;
     public Texture2D _texture;
    
     
     Queue<AsyncGPUReadbackRequest> _requests = new Queue<AsyncGPUReadbackRequest>();
     
     
     /// <summary>
     /// Instantiate the textures
     /// </summary>
     void Start() {
         _texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGBA32, false);
     }
     
     /// <summary>
     /// Check if any request is complete and if so process the texutre
     /// </summary>
     void Update() {
         while (_requests.Count > 0) {
             var req = _requests.Peek();
 
             if  (req.hasError) {
                 Debug.Log("GPU readback error detected.");
                 _requests.Dequeue();
                 
             } else if (req.done) {
                 
                 // retrieve the buffer and direct it into the texture
                 var buffer = req.GetData<Color32>();
                 _texture.LoadRawTextureData(buffer);
                 _texture.Apply();
                 _requests.Dequeue();
                 
                 // create a new Render Texture (this is testing only, in the end it will reuse existing one)
                 RenderTexture renderTexture = new RenderTexture(_texture.width, _texture.height, 1, RenderTextureFormat.ARGB32);
                 
                 // copy the content of the texture to RenderTexture using shader
                 Graphics.Blit(_texture, renderTexture, _shaderMaterial);
                 
                 // assign texture to the right place in the output image
                 _outputImage.texture = renderTexture;
 
                 Debug.Log("DONE");
 
             } else {
                 break;
             }
         }
     }
 
     
     /// <summary>
     /// Detect that processing should be performed
     /// </summary>
     /// <param name="src"></param>
     /// <param name="dest"></param>
     void OnRenderImage(RenderTexture src, RenderTexture dest) {
        
         if (willProcess) {
             Debug.Log("OnRenderImage");
             willProcess = false;
             
             // request the screen data
             _requests.Enqueue(AsyncGPUReadback.Request(src));
 
         }
         
         Graphics.Blit(src, dest);
 
     }
 }

Comment
Add comment · Show 1
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
avatar image UNSEENWorks · Jul 07, 2019 at 06:13 AM 0
Share

I have the same problem, did you found the solution? @$$anonymous$$rstn

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

217 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Is it possible to set the 'ForceNoShadowCasting' SubShader Tag via shader properties or a custom material editor? 1 Answer

How to access to a variable in shader from a script ? 1 Answer

Meshes appears very dark than expectation 0 Answers

how to hide objects inside an invisible object? 0 Answers

Real-time Mesh deformation / animation / shader 0 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