Question

I made a shader in GLSL for an android game. In this shader I have to compute the length between the current pixel and the center of the FX

This shader contain these lines :

//compute distance between current pixel and the center of the fx
highp vec2 tc = MCPosition - center;
int dist = int(length(tc));

if (length(tc) < 720.)
{
    ...

MCPosition is a highp vec2 which contains the coordinate of the current pixel. center is a highp vec2 which contains the center of the FX

This shader works well on many devices (Galaxy Nexus, kindle fire, ...) but on samsung galaxy S3, length(tc) returns an incorrect value when the expected result is over 256, like if it manages all float value as mediump.

Can someone explain me why ?

Was it helpful?

Solution

The Galaxy S3 uses a Mali 400 gpu. Unfortunately fragment shaders on these gpus only support lowp and mediump precision in the fragment shader. Although the expected result of length(tc) is less than the maximum value for a mediump float, the intermediate results will be greater.

Perhaps you could scale your vector before finding its length:

if (length((1./720.)*tc) < 1.)
{
  ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top