Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ericksr · May 28, 2020 at 12:37 PM · errormobilerendertexture

Custom Render Texture appears black on mobile

Hello,

I'm trying to set the texture of my Custom Render Texture (called crtDebug) to my RenderCamera.targetTexture, which is one of the cameras I have active on my project, and show it on a Raw Image.

It works fine on my computer when I run on the Unity Editor, but the moment I run it on my Android device the texture appears to be black. Any Ideas about why this is happening?


This is my code:

 using UnityEngine;
 using UnityEngine.UI;
 
 public class RC_Get_Texture : MonoBehaviour
 {
     public Camera  RenderCamera;
     public GameObject debugObject;
 
     CustomRenderTexture crtDebug;
 
     void Start()
     {
         crtDebug = (CustomRenderTexture)debugObject.GetComponent<RawImage>().texture;
     }
 
     void Update()
     {
         UpdateVideoTextureDebug();
     }
 
     void UpdateVideoTextureDebug()
     {
         crtDebug.material.SetTexture("_Tex", RenderCamera.targetTexture);
         crtDebug.Update();
     }
 }
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 Tudor-Nita · Jul 22, 2020 at 07:17 PM 0
Share

Leaving this comment here because this is a really common issue. One I'm still debugging right now. We've dropped custom render textures on our (fairly big) project for exactly this reason. It was just simpler to bake into the actual shader ( and fewer worries about it breaking on devices we have not tested ).

Initialization on mobile ( both android and IOS ) just does not work reliably.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Tudor-Nita · Jul 22, 2020 at 08:07 PM

Better late than never.

Either Custom render textures have an undocumented initialization step you need to do on mobile or ( more likely ) it's just broken. I have rarely had them work on the first try.

This post describes a fairly inane workaround that works in 2019.4 as of writing this: https://forum.unity.com/threads/why-does-rendertexture-never-work-on-android-build-oculus-go.630559/

TLDR: set init and update to ondemand, build an initialization shader and call initialize from script on update.

This is an initialization shader for reference.

 Shader "Custom/CRTShaderInit"
 {
     Properties{
 
         [Gamma]_color("Color", Color) = (1.0,1.0,1.0)
 
     }
 
     SubShader
     {
        Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
        Lighting Off
        Blend One Zero
          
        Pass
        {
            CGPROGRAM
            #include "UnityCustomRenderTexture.cginc"
            #pragma vertex InitCustomRenderTextureVertexShader
            #pragma fragment frag
            #pragma target 3.0
 
            
             uniform float4 _color;
 
             float4 frag(v2f_init_customrendertexture IN) : COLOR
             {
 
                 return _color;
            }
            ENDCG
         }
     }
 }
 
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

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

Related Questions

Problem with Texture Scaling for Mobile Resolutions 1 Answer

Render texture errors on OSX 0 Answers

App not installed android bug 0 Answers

Error to install game made in Unity on mobile. Android 1 Answer

Crashing after placing terrain 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