-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[glsl-in] Add collatz shader and test quad shader
- Loading branch information
Showing
2 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// AUTHOR: Unknown | ||
// ISSUE: #246 | ||
// NOTE: Taken from the wgpu repo | ||
#version 450 | ||
layout(local_size_x = 1) in; | ||
|
||
layout(set = 0, binding = 0) buffer PrimeIndices { | ||
uint[] indices; | ||
}; // this is used as both input and output for convenience | ||
|
||
// The Collatz Conjecture states that for any integer n: | ||
// If n is even, n = n/2 | ||
// If n is odd, n = 3n+1 | ||
// And repeat this process for each new n, you will always eventually reach 1. | ||
// Though the conjecture has not been proven, no counterexample has ever been found. | ||
// This function returns how many times this recurrence needs to be applied to reach 1. | ||
uint collatz_iterations(uint n) { | ||
uint i = 0; | ||
while(n != 1) { | ||
if (mod(n, 2) == 0) { | ||
n = n / 2; | ||
} | ||
else { | ||
n = (3 * n) + 1; | ||
} | ||
i++; | ||
} | ||
return i; | ||
} | ||
|
||
void main() { | ||
uint index = gl_GlobalInvocationID.x; | ||
indices[index] = collatz_iterations(indices[index]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters