aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2018-03-11 13:13:38 +0100
committerAndreas Grois <andi@grois.info>2018-03-11 13:13:38 +0100
commit6842d96a7ec31d3ec192c715fee45e895ed01a48 (patch)
tree37ee507667a7be6791e3988574aa8b41116699d3
parente15f1717aa9d58623113585c1d25473bdf793f11 (diff)
Decouple y and x value based on iteration. Should approximately square
teh available randomness!
-rw-r--r--BuddhaTest/Shaders/BuddhaCompute.glsl32
-rw-r--r--BuddhaTest/src/BuddhaTest.cpp11
2 files changed, 22 insertions, 21 deletions
diff --git a/BuddhaTest/Shaders/BuddhaCompute.glsl b/BuddhaTest/Shaders/BuddhaCompute.glsl
index 458a4e3..85d0cae 100644
--- a/BuddhaTest/Shaders/BuddhaCompute.glsl
+++ b/BuddhaTest/Shaders/BuddhaCompute.glsl
@@ -33,30 +33,17 @@ void addToColorAt(vec2 complex, uvec3 toAdd)
addToColorOfCell(cell,toAdd);
}
-/*
-vec2 hash2( uint n, out uint hash )
-{
- // integer hash copied from Hugo Elias
- n = (n << 13U) ^ n;
- n = n * (n * n * 15731U + 789221U) + 1376312589U;
- hash = n*n;
- uvec2 k = n * uvec2(n,n*16807U);
- return vec2( k & uvec2(0x7fffffffU))/float(0x7fffffff);
-}
-*/
-
uint intHash(uint x) {
x = ((x >> 16) ^ x) * 0x45d9f3bU;
x = ((x >> 16) ^ x) * 0x45d9f3bU;
x = (x >> 16) ^ x;
return x;
}
-vec2 hash2(uint n, out uint hash)
+
+float hash1(uint seed, out uint hash)
{
- uint ih =intHash(n);
- hash = intHash(ih);
- uvec2 k = uvec2(ih,hash);
- return vec2(k & uvec2(0x7fffffffU))/float(0x7fffffff);
+ hash = intHash(seed);
+ return float(hash)/float(0xffffffffU);
}
vec2 compSqr(in vec2 v)
@@ -139,14 +126,17 @@ float isInMainBulb(vec2 v)
return step(sqrRadius,0.062499999);
}
-vec2 getStartValue(uint seed)
+vec2 getStartValue(uint seed, uint yDecoupler)
{
uint hash = seed;
vec2 retval = vec2(0);
for(int i = 0; i < 5; ++i)
{
- vec2 random = hash2(hash,hash);
+ float x = hash1(hash,hash);
+ hash = (hash ^ yDecoupler);
+ float y = hash1(hash,hash);
+ vec2 random = vec2(x,y);
vec2 point = vec2(random.x * 3.5-2.5,random.y*1.55);
float useThisPoint =1.0-(isInMainBulb(point) + isInMainCardioid(point));
retval = mix(retval,point,useThisPoint);
@@ -197,8 +187,8 @@ void main() {
//TODO: Check this once I've had some sleep. Anyhow, I'm using 1D, so y and z components globalInfocationID should be zero anyhow.
uint seed = iterationCount * totalWorkers + gl_GlobalInvocationID.x + gl_GlobalInvocationID.y*totalWorkersPerDimension.x + gl_GlobalInvocationID.z*(totalWorkersPerDimension.x + totalWorkersPerDimension.y);
-
- vec2 offset = getStartValue(seed);
+ uint yDecoupler = iterationCount;
+ vec2 offset = getStartValue(seed, yDecoupler);
if(!isGoingToBeDrawn(offset))
return;
diff --git a/BuddhaTest/src/BuddhaTest.cpp b/BuddhaTest/src/BuddhaTest.cpp
index c29a220..a03e8e8 100644
--- a/BuddhaTest/src/BuddhaTest.cpp
+++ b/BuddhaTest/src/BuddhaTest.cpp
@@ -126,9 +126,20 @@ int main(int argc, char * argv[])
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
+ //uint32_t iterationsPerFrame = settings.globalWorkGroupSizeX*settings.globalWorkGroupSizeY*settings.globalWorkGroupSizeZ*settings.localWorkgroupSizeX*settings.localWorkgroupSizeY*settings.localWorkgroupSizeZ;
+ //bool bWarningShown{false};
+
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
+ //commented out, as with the new y-decoupling we will get more points in 2D even after we had all integer values for x.
+ //check if we are "done"
+ //if(iterationsPerFrame * iterationCount <= iterationsPerFrame && iterationCount > 1 && !bWarningShown)
+ //{
+ // std::cout << "The program covered all possible integer values for starting point computation. Leaving it running will not improve the image any more." << std::endl;
+ // bWarningShown = true;
+ //}
+
//let the compute shader do something
glUseProgram(ComputeShader);
//increase iterationCount, which is used for pseudo random generation