Style conventions

This commit is contained in:
Josh Colclough 2023-10-27 18:14:15 +01:00
parent bcc51a2e79
commit f9b3f1a623
3 changed files with 21 additions and 22 deletions

View File

@ -13,24 +13,23 @@ uniform float zoom; // Zoom of the scale.
// NOTE: Maximum number of shader for-loop iterations depend on GPU,
// for example, on RasperryPi for this examply only supports up to 60
const int MAX_ITERATIONS = 48; // Max iterations to do.
const float COLOR_CYCLES = 1; // Number of times the palette repeats.
const float COLOR_CYCLES = 1; // Number of times the color palette repeats.
// Square a complex number
vec2 ComplexSquare(vec2 z)
{
return vec2(
z.x * z.x - z.y * z.y,
z.x * z.y * 2.0
z.x*z.x - z.y*z.y,
z.x*z.y*2.0
);
}
// Convert Hue Saturation Value (HSV) color into RGB
vec3 Hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
vec4 K = vec4(1.0, 2.0/3.0, 1.0/3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz)*6.0 - K.www);
return c.z*mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void main()
@ -56,7 +55,7 @@ void main()
// The pixel coordinates are scaled so they are on the mandelbrot scale
// NOTE: fragTexCoord already comes as normalized screen coordinates but offset must be normalized before scaling and zoom
vec2 z = vec2((fragTexCoord.x - 0.5) * 2.5, (fragTexCoord.y - 0.5) * 1.5) / zoom;
vec2 z = vec2((fragTexCoord.x - 0.5)*2.5, (fragTexCoord.y - 0.5)*1.5)/zoom;
z.x += offset.x;
z.y += offset.y;
@ -82,5 +81,5 @@ void main()
// If in set, color black. 0.999 allows for some float accuracy error.
if (norm > 0.999) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
else gl_FragColor = vec4(Hsv2rgb(vec3(norm * COLOR_CYCLES, 1.0, 1.0)), 1.0);
else gl_FragColor = vec4(Hsv2rgb(vec3(norm*COLOR_CYCLES, 1.0, 1.0)), 1.0);
}

View File

@ -12,23 +12,23 @@ uniform vec2 offset; // Offset of the scale.
uniform float zoom; // Zoom of the scale.
const int MAX_ITERATIONS = 255; // Max iterations to do.
const float COLOR_CYCLES = 2; // Number of times the palette repeats. Can show higher detail for higher iteration numbers.
const float COLOR_CYCLES = 2; // Number of times the color palette repeats. Can show higher detail for higher iteration numbers.
// Square a complex number
vec2 ComplexSquare(vec2 z)
{
return vec2(
z.x * z.x - z.y * z.y,
z.x * z.y * 2.0
z.x*z.x - z.y*z.y,
z.x*z.y*2.0
);
}
// Convert Hue Saturation Value (HSV) color into RGB
vec3 Hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
vec4 K = vec4(1.0, 2.0/3.0, 1.0/3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz)*6.0 - K.www);
return c.z*mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void main()
@ -54,7 +54,7 @@ void main()
// The pixel coordinates are scaled so they are on the mandelbrot scale
// NOTE: fragTexCoord already comes as normalized screen coordinates but offset must be normalized before scaling and zoom
vec2 z = vec2((fragTexCoord.x - 0.5) * 2.5, (fragTexCoord.y - 0.5) * 1.5) / zoom;
vec2 z = vec2((fragTexCoord.x - 0.5)*2.5, (fragTexCoord.y - 0.5)*1.5)/zoom;
z.x += offset.x;
z.y += offset.y;
@ -79,5 +79,5 @@ void main()
// If in set, color black. 0.999 allows for some float accuracy error.
if (norm > 0.999) finalColor = vec4(0.0, 0.0, 0.0, 1.0);
else finalColor = vec4(Hsv2rgb(vec3(norm * COLOR_CYCLES, 1.0, 1.0)), 1.0);
else finalColor = vec4(Hsv2rgb(vec3(norm*COLOR_CYCLES, 1.0, 1.0)), 1.0);
}

View File

@ -134,12 +134,12 @@ int main(void)
// Find the velocity at which to change the camera. Take the distance of the mouse
// from the center of the screen as the direction, and adjust magnitude based on
// the current zoom.
offsetVelocity.x = (mousePos.x/(float)screenWidth - 0.5) * offsetSpeedMul / zoom;
offsetVelocity.y = (mousePos.y/(float)screenHeight - 0.5) * offsetSpeedMul / zoom;
offsetVelocity.x = (mousePos.x/(float)screenWidth - 0.5)*offsetSpeedMul/zoom;
offsetVelocity.y = (mousePos.y/(float)screenHeight - 0.5)*offsetSpeedMul/zoom;
// Apply move velocity to camera
offset[0] += GetFrameTime() * offsetVelocity.x;
offset[1] += GetFrameTime() * offsetVelocity.y;
offset[0] += GetFrameTime()*offsetVelocity.x;
offset[1] += GetFrameTime()*offsetVelocity.y;
// Update the shader uniform values!
SetShaderValue(shader, zoomLoc, &zoom, SHADER_UNIFORM_FLOAT);
@ -147,7 +147,7 @@ int main(void)
}
// Increment c value with time
const float dc = GetFrameTime() * (float)incrementSpeed * 0.0005f;
const float dc = GetFrameTime()*(float)incrementSpeed*0.0005f;
c[0] += dc;
c[1] += dc;
SetShaderValue(shader, cLoc, c, SHADER_UNIFORM_VEC2);