{"id":40,"date":"2014-10-05T06:57:18","date_gmt":"2014-10-05T06:57:18","guid":{"rendered":"http:\/\/betelge.wordpress.com\/?p=40"},"modified":"2014-10-05T06:57:18","modified_gmt":"2014-10-05T06:57:18","slug":"emulated-double-precision-in-opengl-es-shader","status":"publish","type":"post","link":"https:\/\/www.betelge.com\/blog\/2014\/10\/05\/emulated-double-precision-in-opengl-es-shader\/","title":{"rendered":"Emulated double precision in OpenGL ES shader"},"content":{"rendered":"<p>In the previous post,\u00a0<a title=\"Generating the Mandelbrot set in an OpenGL ES shader\" href=\"http:\/\/betelge.wordpress.com\/2014\/10\/04\/generating-the-mandelbrot-set-in-an-opengl-es-shader\/\">Generating the Mandelbrot set in an OpenGL ES shader<\/a>, there was blockiness\u00a0caused by the low precision of the fragment shader at a zoom level of just 100x. We would like to be able to\u00a0scale the fractal by factors of millions to explore it properly so this is totally inadequate.<\/p>\n<p>I found a <a title=\"Heavy computing with GLSL \u2013 Part 2: Emulated double precision\" href=\"https:\/\/thasler.com\/blog\/?p=93\">blog post<\/a>\u00a0about emulating double precision in GLSL by using two floats to represent a value. I recommend reading\u00a0it as the author gets some pretty nice results. I tried porting the code and making it work in OpenGL ES, but the my results where far from excellent.<\/p>\n<p><a href=\"https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-21\" src=\"https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot3.png?w=300\" alt=\"2014-9-4_mandelbrot3\" width=\"300\" height=\"180\" srcset=\"https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot3.png 800w, https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot3-300x180.png 300w, https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot3-768x461.png 768w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><a href=\"https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-41\" src=\"https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot4.png?w=300\" alt=\"2014-9-4_mandelbrot4\" width=\"300\" height=\"180\" srcset=\"https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot4.png 800w, https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot4-300x180.png 300w, https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot4-768x461.png 768w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>You can see that there is an actual improvement. The\u00a0emulation works!<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot61.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-43\" src=\"https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot61.png?w=300\" alt=\"2014-9-4_mandelbrot6\" width=\"300\" height=\"180\" srcset=\"https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot61.png 800w, https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot61-300x180.png 300w, https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot61-768x461.png 768w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><a href=\"https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot5-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-44\" src=\"https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot5-1.png?w=300\" alt=\"2014-9-4_mandelbrot5 (1)\" width=\"300\" height=\"180\" srcset=\"https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot5-1.png 800w, https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot5-1-300x180.png 300w, https:\/\/www.betelge.com\/blog\/wp-content\/uploads\/2014\/10\/2014-9-4_mandelbrot5-1-768x461.png 768w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>But\u00a0at a closer look the improvement is minimal.<\/p>\n<p>I modified\u00a0the code to account for the\u00a0lower float\u00a0precision\u00a0but it didn&#8217;t help. In the Android Emulator it worked much better, but the emulator has a much higher float precision even with single midiump floats.<\/p>\n<p>This is where I realised that even though OpenGL ES doesn&#8217;t\u00a0guarantee high precision floats in the fragment shader, it does in\u00a0the vertex shader!<\/p>\n<p>The next post in the series shows how to use the\u00a0precision of the vertex shader to greatly improve the details.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous post,\u00a0Generating the Mandelbrot set in an OpenGL ES shader, there was blockiness\u00a0caused by the low precision of the fragment shader at a zoom level of just 100x. We would like to be able to\u00a0scale the fractal by &hellip; <a href=\"https:\/\/www.betelge.com\/blog\/2014\/10\/05\/emulated-double-precision-in-opengl-es-shader\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.betelge.com\/blog\/wp-json\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.betelge.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.betelge.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.betelge.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.betelge.com\/blog\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":0,"href":"https:\/\/www.betelge.com\/blog\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.betelge.com\/blog\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.betelge.com\/blog\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.betelge.com\/blog\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}