Author Topic: Different shader behaviour on different GPUs  (Read 1242 times)

Offline christian

  • byte
  • *
  • Posts: 8
    • View Profile
Different shader behaviour on different GPUs
« on: March 04, 2013, 08:52:32 pm »
I'm new to the forum, so... Hello everyone!
First of all, I would like to congratulate and thank Egon for this wonderful library!

Now to the point: I have a problem with a custom shader.
I am developing a simple application with a dice simulation, in which the user can (obviously) throw dices.
I wanted to use a bump mapping shader for the dices, and I took the bump shader from the wiki and converted it for GLSL with OpenGL ES2 (substituted the "gl_Something" with the uniforms and attributes provided by JPCT-AE).

I was developing on a Tegra3 device and with the emulator, and I achived the same result, so I was happy :D

When I tried the app on a Adreno320 powered device, I noticed that the dices were much whiter, and when I tried it on a Galaxy Note II (Mali GPU) the dices were almost black (except for some bright spots)!!!

After a lot of tests, I wrote a much more simple shader that isolate the problem.
The shader is:

Code: [Select]
-------------------------------VERTEX:
varying vec3 tmpVec;
uniform mat4 modelViewMatrix;
uniform mat4 modelViewProjectionMatrix;
attribute vec4 position;

void main(void)
{
gl_Position = modelViewProjectionMatrix * position;
tmpVec = vec3(modelViewMatrix * position);
}

-------------------------------FRAGMENT:
precision mediump float;
varying vec3 tmpVec;

void main (void)
{
gl_FragColor = vec4(normalize(tmpVec), 1.0);
}

In this shader I take the vertex position, convert it in camera space and pass it to the fragment, in which I normalize and put the vertex position in the fragment color.
If I use the position for the color, the result is the same both on the One X and the Mi2, but if I use the position converted in camera space, I obtain a different result (as the attachment to the post shows).

My question is: how is it possible?
Could the same code and the same shader lead to so much different results? The shader is very simple, and I cannot see the error.
Am I missing something?

Thank you in advance! :)

Christian

[attachment deleted by admin]

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Different shader behaviour on different GPUs
« Reply #1 on: March 04, 2013, 09:01:45 pm »
Have you tried to use highp in the fragment shader? I'm just guessing here...i actually don't think that it should make a difference, but you never know. I'm used to the general problem because a) Adreno is crap and b) Mali can't handle values larger than 65536 (that's usually the reason for black bump mapping shaders on Mali). But in this case, the shader is really simple... ???

Offline christian

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Different shader behaviour on different GPUs
« Reply #2 on: March 05, 2013, 09:16:18 am »
Thank you for the answer!

Have you tried to use highp in the fragment shader? I'm just guessing here...i actually don't think that it should make a difference, but you never know.
I tried, but the result seems to be the same...

Could it be world dimensions? The camera is 500 units far from the wood plane, and the dices BB are 75 units big... Could it lead to precision problems in the shader?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Different shader behaviour on different GPUs
« Reply #3 on: March 05, 2013, 09:19:13 am »
Maybe...at least Mali can't handle calculations with higher values. Maybe the same is true for Acrapno chips. Try to limit the tmpVec values and see what happens.

Offline christian

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Different shader behaviour on different GPUs
« Reply #4 on: March 05, 2013, 10:48:52 am »
Well, I tried to scale down the world by 10, and now the behaviour on Tegra3 and on Adreno320 is similar, so I guess that the problem was related to number precision...
ASAP I'll try again on the Mali, I'll let you know  :)

Offline christian

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Different shader behaviour on different GPUs
« Reply #5 on: March 14, 2013, 05:11:37 pm »
Well, I tried to scale down the world by 10, and now the behaviour on Tegra3 and on Adreno320 is similar, so I guess that the problem was related to number precision...
ASAP I'll try again on the Mali, I'll let you know  :)

Now it also works on Mali (Galaxy Note II), so the problem was definitely the scene size.
As a rule of thumb, you should always keep the scene bounding box size under a hundred units side...

PS: Egon, thank you for putting DnDice inside Projects page! :)