]> zoso.dev Git - libnemo.git/commitdiff
Assign bytes in loop. Assign frag color with multiplication instead of branching...
authorChris Duncan <chris@zoso.dev>
Sun, 15 Dec 2024 08:38:44 +0000 (00:38 -0800)
committerChris Duncan <chris@zoso.dev>
Sun, 15 Dec 2024 08:38:44 +0000 (00:38 -0800)
src/lib/workers/pow.ts

index a5f658862d1523f42e2cf4de7743cd8bacfbe37b..7c7ee1ea2b1d16420fc45f1075f8213e07f5339f 100644 (file)
@@ -168,14 +168,9 @@ void main() {
        m[1] = (u_work1.r ^ (u_work1.g << 8) ^ (u_work1.b << 16) ^ (u_work1.a << 24));
 
        // Block hash
-       m[2] = blockHash[0];
-       m[3] = blockHash[1];
-       m[4] = blockHash[2];
-       m[5] = blockHash[3];
-       m[6] = blockHash[4];
-       m[7] = blockHash[5];
-       m[8] = blockHash[6];
-       m[9] = blockHash[7];
+       for (i=0;i<8;i++) {
+               m[i+2] = blockHash[i];
+       }
 
        // twelve rounds of mixing
        for(i=0;i<12;i++) {
@@ -191,15 +186,19 @@ void main() {
 
        // Threshold test, first 4 bytes not significant,
        //  only calculate digest of the second 4 bytes
-       if((BLAKE2B_IV32_1 ^ v[1] ^ v[17]) > threshold) {
-               // Success found, return pixel data so work value can be constructed
-               fragColor = vec4(
-                       float(x_index + 1u)/255., // +1 to distinguish from 0 (unsuccessful) pixels
-                       float(y_index + 1u)/255., // Same as previous
-                       float(x_pos)/255., // Return the 2 custom bytes used in work value
-                       float(y_pos)/255.  // Second custom byte
+       //if((BLAKE2B_IV32_1 ^ v[1] ^ v[17]) > threshold) {
+               // Success found, set pixel data so work value can be constructed
+               fragColor = mix(
+                       fragColor,
+                       vec4(
+                               float(x_index + 1u)/255., // +1 to distinguish from 0 (unsuccessful) pixels
+                               float(y_index + 1u)/255., // Same as previous
+                               float(x_pos)/255., // Return the 2 custom bytes used in work value
+                               float(y_pos)/255.  // Second custom byte
+                       ),
+                       float((BLAKE2B_IV32_1 ^ v[1] ^ v[17]) > threshold)
                );
-       }
+       //}
 }`
 
        /** Used to set canvas size. Must be a multiple of 256. */