rnc-archive / react-native-webgl

DEPRECATED: use expo-gl – Implements WebGL for react-native
295 stars 73 forks source link

How to achieve randomness for 2D noise function #60

Closed zdenham closed 6 years ago

zdenham commented 6 years ago

Hello! Thanks for the wonderful library!

I am implementing a film grain image effect, and it involves a noise function and the below 2D random function (taken from book of shaders). I was able to implement the effect nicely in webgl, but when using react-native-webgl, the randomness and noise functions both had unexpected and very different outputs than webgl. The following shader:

float random(vec2 co){
  return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}

void main() {
  float rnd = random(v_position);

  gl_FragColor = vec4(vec3(rnd), 1.0);
}

Outputed:

webgl

In webgl, but in react-native-webgl outputed: rnwebgl (which does not appear very random). I am wondering why the output is so inconsistent between the two platforms, if the difference can be remedied, or if it is a hardware problem... Any advice would be greatly appreciated!

zdenham commented 6 years ago

Update: this function outputs correctly on simulator (that is the same as webgl), but if built to any real iOS device it outputs something similar to the second image above.

gre commented 6 years ago

have you tried to define a precision ? like precision highp float;

zdenham commented 6 years ago

ahhh yes, I had been using mediump. This did the trick! Thank you for your help!