Different shader behaviour on different GPUs

Started by christian, March 04, 2013, 08:52:32 PM

Previous topic - Next topic

christian

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:


-------------------------------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]

EgonOlsen

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... ???

christian

Thank you for the answer!

Quote from: EgonOlsen 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 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?

EgonOlsen

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.

christian

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  :)

christian

Quote from: christian 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  :)

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! :)