在learnwebgl tutorial1中,我在片段着色器中发现了一条有趣的行.
precision mediump float;
Run Code Online (Sandbox Code Playgroud)
我在这里发现了一篇关于它的文章,但我仍然无法理解这是什么意思?
如果我删除这一行,没有任何变化.一切都是一样的.那precision mediump float意味着什么?
在玩弄一代时Mandelbrot set,WebGl我不可避免地发现了OpenGl32 位的小精度float。然而,当我发现这篇很棒的文章时,新的希望诞生了。
我小心翼翼地从上述源代码中获取了函数,并double 在 JS 端添加了解构。
据我了解,JSdoubles对于浮点数有 64 位,所以我的想法是在 JS 端计算一些准备数据,将其作为浮点数对发送到 GPU,然后继续进行 mandelbrot 循环。
可悲的是,最后我看到结果图像的差异几乎为零,而且我真的不知道我的失败点在哪里。
JS:
function doubleToFloat(d) {
return new Float32Array([d])[0];
};
function splitDouble(dbl) { //splits JS number to array of 2 32bit floats
var arr = [];
arr[0] = doubleToFloat(dbl);
arr[1] = doubleToFloat(dbl - arr[0]);
//console.log(dbl, arr);
arr = new Float32Array(arr);
dlog(dbl,arr);
return arr;
};
///Somewhere inside rendering function - binding data to webGl …Run Code Online (Sandbox Code Playgroud)