Weird android shader problem

I have a shader which works on both XNA and MonoGame in Windows and I’m trying to port it to Android. But something very weird happens. The geometry just disappears.

I started with the working shader and kept removing code until it still rendered something. Then adding an extra line breaks the shader (not every line break it, in example, adding “result.Diffuse.b=0.2f;” does not break the shader but “result.Diffuse.b+=0.2+lightDiffuseColor.r*10;” breaks it).

Sometimes the geometry does not disappear, it just deforms / translates /scales all geometry. It looks like somehow the world matrix would be overwritten by some other values. I fear that this could be some MojoShader bug (or whatever MG is using now) combined with the register optimization.

The bug happens in 4 androids with different GPUs I’ve tested and they produce the same results (which actually is a feat in android XD) so that’s why I’m inclined to think the problem may reside in MojoShader.

So, is there any way to get an intermediate output from mojoshader or some kind of data to analize the final glsl shader?

Thanks,
Kak

You can open the .xnb file with a text editor and check if you can find issues in the glsl. It contains some metadata, but is mostly plain glsl. That said, MojoShader does not keep variable names, so it will be hard to read.

Could you share some more code from the shader? That might help figuring out what triggers the issue exactly.

We would need a small sample that demonstrates the issue. This does not appear to be something we can work out from the description of it.

thanks for the answers.

@Jjagg I totally forgot the shader was embedded as text in the mgfxo file. I’m getting too old for this… :joy:

@KonajuGames I wanted to check the shader and discard that it was an error of mine first. If I can’t find the solution I’ll try to post a minimal sample which shows the problem.

1 Like

well, I’m unable to find a solution by myself.

I’v tried to make a minimal example showing the problem. There are two projects, one for Windows DX and another one for Android:

http://online.ru-zero.com/files/shaderTest.zip

Drawing functions and setup are at common/GameFuncs.cs

Shader is inside the shader folder. The original shader is in PointLight_DXY.fx, while FaultyFunc.fx contains the functions for a test shader in order to make the shader fail commenting one line (technique #4)
I am compiling it directly with 2mgfx (there’s a batch script in the shader folder)

Basically the point light vertex shader works on Windows but not on android. The Faulty file contains a function which still works on Windows DX (it has several instructions removed so it’s not making what it should do) but it does not work on android. However, if you comment the line after “COMMENT THIS”, the shader works. (by “not working” I mean that the geometry disappears,showing just a CornflowerBlue screen)

Thanks in advance.

p.s. My shader knowledge is very limited. Sorry if the code hurts your eyes :slight_smile:

I’ve been able to test the same shaders with latest iOS MG version and it also exhibits the same behaviour. Not working with the full version (geometry disappears) but removing instructions make the shader work.

I’m wondering if the problem would also happen in OpenGL. If it’s a problem of mojoshader it should also fail in OpenGL and should be easier to test. However for some reason I’m unable to get a working project in OpenGL in my rig.