Skip to content

Commit 1244625

Browse files
authored
Update pi.glsl
1 parent 0084260 commit 1244625

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pi.glsl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// https://www.shadertoy.com/view/XsyyzW
1+
// https://www.shadertoy.com/view/wsjyDV
2+
// Inspired from https://www.shadertoy.com/view/XsyyzW
23
// Pi by Plouffe spigot algorithm:
34
// See also (en & fr) https://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula
45
// Adapted from C code: http://www.experimentalmath.info/bbp-codes/piqpr8.c
56
// Another PI method (not parallel): https://www.shadertoy.com/view/MdtXWj
7+
// See also https://github.com/voidstarHQ/voidstar
68

79
#define double float
810
#define pow16(x) exp2(4.*(x))
@@ -78,12 +80,12 @@ float digit(int id) {
7880
return fract(pid);// NB: pid always <0 ?
7981
}
8082

81-
vec2 S = 32./vec2(2,1); // character size
82-
#define W ivec2(iResolution.xy/S) // size of display char matrix
8383

8484
void mainImage( out vec4 O, vec2 U ) {
85-
ivec2 iU = ivec2(U); // cell index
86-
if ( iU.x>=W.x || iU.y>=W.y ) return;
85+
O -= O;
86+
ivec2 iU = ivec2(U/8.);
87+
ivec2 iW = ivec2(iResolution.xy/32.);
88+
if (iU.x>=iW.x || iU.y>=iW.y) return;
8789

8890
// Since only the fractional part is accurate,
8991
// extracting the wanted digit requires that one removes
@@ -92,7 +94,7 @@ void mainImage( out vec4 O, vec2 U ) {
9294
// (in theory, the next few digits up to the accuracy of
9395
// the calculations used would also be accurate).
9496
//float r = 16. * digit(0 + iU.x + W.x*iU.y);
95-
float r = digit(0 + iU.x + W.x*iU.y);
97+
float r = digit(0 + iU.x + iW.x*iU.y);
9698
float g = fract(100. * r);
9799
float b = fract(100. * g);
98100

0 commit comments

Comments
 (0)