Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 whatphilipmakes · Feb 22 at 12:09 AM · transparencyrendertexturecompute shader

RenderTexture transparency working in editor becomes solid color in build

alt text alt text
top: in editor, bottom: in build

I am currently trying to get my growth algorithm to work on a texture.

When running in the editor everything works as expected, however once I build the project, the whole RenderTexture becomes a solid color (red, green or blue [R8G8B8A8_UNORM] depending on the color format) with the simulation on top.

I have already tried to use an HDRP unlit texture shader instead of my custom transparency shader, which produced the same issue leading me to believe that my mistake lies somewhere within the compute shader drawing onto the texture. Also, I rebuilt the project using URP which unfortunately also produced the same result.

One other thing, I recently noticed that minimizing and maximizing the game window on runtime in the editor more than once crashes unity although I can't image how this has anything to do with the issue at hand.

EDIT: Just built the same project for windows (DX11) which works perfectly. This therefore seems to be an issue with the Metal API.

Interestingly, the maximizing/minimizing problem appears only if vsync is enabled and the touchpad gesture is used.

Unity Version 2021.2.12f1 using the HDRP on MacOS Monterey 12.2.1.

GitHub if you would like to reproduce the error: https://github.com/whatphilipcodes/seed

Compute Shader Code below.

 // mean filter code (DrawTrails) courtesy of https://github.com/DenizBicer/Physarum
 // (Modified)
 
 // Each #kernel tells which function to compile; you can have many kernels
 #pragma kernel DrawPoints
 #pragma kernel DrawTrails
 
 // Create a RenderTexture with enableRandomWrite flag and set it
 // with cs.SetTexture
 
 // texture
 shared RWTexture2D<float4> Result;
 //RWTexture2D<float> TrailBuffer;
 int _texres;
 int _colres;
 float4 _pcol;
 
 // testing
 float _decay;
 
 // buffer
 StructuredBuffer<float2> pointsBuffer;
 StructuredBuffer<float4> colorsBuffer;
 
 [numthreads(64,1,1)]
 void DrawPoints (uint3 id : SV_DispatchThreadID)
 {
     if ((pointsBuffer[id.x].x * pointsBuffer[id.x].y) > 0) Result[pointsBuffer[id.x].xy] = colorsBuffer[id.x % _colres];
 }
 
 [numthreads(16,16,1)]
 void DrawTrails (uint3 id : SV_DispatchThreadID)
 {
     float3 value;
 
     value = Result[id.xy].rgb;
 
     float3 d = float3(1, -1, 0.0);
 
     //mean filter red
     value.r = value.r;
     value.r += Result[id.xy - d.xx].r; // -1,-1
     value.r += Result[id.xy - d.zx].r; // 0, -1
     value.r += Result[id.xy - d.yx].r; // +1, -1
     value.r += Result[id.xy - d.xz].r; // -1, 0
     value.r += Result[id.xy + d.xz].r; // +1, 0
     value.r += Result[id.xy + d.yx].r; // -1, +1
     value.r += Result[id.xy + d.zx].r; // 0, +1
     value.r += Result[id.xy + d.xx].r; // +1, +1
 
     value.x = (value.x / 9) * (1 - _decay);
     
     //mean filter green
     value.g = value.g;
     value.g += Result[id.xy - d.xx].g; // -1,-1
     value.g += Result[id.xy - d.zx].g; // 0, -1
     value.g += Result[id.xy - d.yx].g; // +1, -1
     value.g += Result[id.xy - d.xz].g; // -1, 0
     value.g += Result[id.xy + d.xz].g; // +1, 0
     value.g += Result[id.xy + d.yx].g; // -1, +1
     value.g += Result[id.xy + d.zx].g; // 0, +1
     value.g += Result[id.xy + d.xx].g; // +1, +1
 
     value.g = (value.g / 9) * (1 - _decay);
 
     //mean filter blue
     value.b = value.z;
     value.b += Result[id.xy - d.xx].b; // -1,-1
     value.b += Result[id.xy - d.zx].b; // 0, -1
     value.b += Result[id.xy - d.yx].b; // +1, -1
     value.b += Result[id.xy - d.xz].b; // -1, 0
     value.b += Result[id.xy + d.xz].b; // +1, 0
     value.b += Result[id.xy + d.yx].b; // -1, +1
     value.b += Result[id.xy + d.zx].b; // 0, +1
     value.b += Result[id.xy + d.xx].b; // +1, +1
     
     value.b = (value.b / 9) * (1 - _decay);
     
     Result[id.xy] = float4(value.r, value.g, value.b, 0.0);
 }


bildschirmfoto-2022-02-21-um-001240.jpg (246.0 kB)
bildschirmfoto-2022-02-21-um-001023.png (234.3 kB)
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
Best Answer

Answer by whatphilipmakes · Feb 23 at 01:08 PM

The way I ended up solving my issue was to add a kernel that sets all pixels to black, dispatched from the start() method.

 [numthreads(16,16,1)]
 void SetTexture (uint3 id : SV_DispatchThreadID)
 {
     Result[id.xy] = float4(0.0, 0.0, 0.0, 0.0);
 }


I'm pretty sure that there are far more elegant solutions but for now this will have to do.

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

135 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

Related Questions

RenderTextureFormat.R8 0 Answers

[HDRP] Render Texture Alpha Channel 2 Answers

RenderTexture being wiped/changed on play or undo. 0 Answers

why does my temp camera only renders transparent objects ? 1 Answer

Alpha Problems With Render Textures 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