fix glsl rand() issue on iOS

This commit is contained in:
2018-05-09 17:53:40 +02:00
parent c4f304f7bc
commit 2379679913

View File

@@ -322,7 +322,17 @@ void App::initShaders()
#else
"out mediump vec4 frag;\n"
#endif
"mediump float rand(mediump vec2 co) { return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); }\n"
// http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/
"highp float rand(mediump vec2 co)\n"
"{\n"
" highp float a = 12.9898;\n"
" highp float b = 78.233;\n"
" highp float c = 43758.5453;\n"
" highp float dt= dot(co.xy ,vec2(a,b));\n"
" highp float sn= mod(dt,3.14);\n"
" return fract(sin(sn) * c);\n"
"}\n"
//"highp float rand(mediump vec2 co) { return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); }\n"
"void main(){\n"
" mediump vec2 uv2 = gl_FragCoord.st / resolution;\n"
" mediump float stencil = 1.0 - (texture(tex_stencil, (uv2+stencil_offset) * 2.0).r * 0.9) * stencil_alpha;\n"