- Home /
RWTexture2D in Compute Shader on Android?
I am trying to use this asset to test out a compute shader on android, that allows texture modification. I'm new to shaders, I could have misunderstood or not realizing some kind of limitation on mobile. I had assumed since the editor (while under android platform) worked that it would just work on android. I have tested this in the editor, on android platform, with opengl 3.1 as min graphics API, disabled the graphics emulation, and the asset works as expected. Player settings like this:
When testing it on android, the asset caused a force close on Unity 5.4, and on 5.5, it would complain about "Kernel at index 0 is invalid" when I ran the code the same as in the editor. If I modify the shader code by commenting out a section where it assigns to a RWTexture2D, then the error goes away, but obviously nothing is drawn to the screen.
This is a snippet of code to describe the problem area (cannot share complete code, its asset from asset store):
#pragma kernel pixelCalc
RWTexture2D<float4> textureOut;
[numthreads(32,32,1)]
void pixelCalc (uint3 id : SV_DispatchThreadID){
// some stuff happens here...
while (itn < 255 && d < 4){
// calculations and stuff...
itn++;
}
if (itn == 256) // if this line and 3 below it are commented out, runs on android!
textureOut[id.xy] = float4(0, 0, 0, 1);
else
textureOut[id.xy] = colors[itn];
}
Hope somebody can confirm that RWTexture2D on a compute shader should work or not on android? Has anybody had this error and found a way to make it work on android?
Answer by MD_Reptile · Dec 11, 2016 at 06:08 AM
I cracked away at it for days and days (remember, I know jack about shaders), and finally got a compute shader working that uses RWTexture2D running on android! I couldn't get that asset working as it does in the editor, but instead learned a good bit about shader coding and followed a variety of tutorials before I found one that helped me with this problem, so if future readers need help getting RWTexture2D working on android, have a look at this tutorial page to get you going in the right direction:
http://cheneyshen.com/directcompute-tutorial-for-unity-textures/
Answer by asa989 · May 04, 2018 at 03:45 AM
I was wondering if you have found a way to use Texture2D on Android?