Skip to content

Commit a7c5e3c

Browse files
committed
Updating julia set example.
Now dividing by the zoom instead of multiplying (in the shader), so zoom works as expected. Also zoom increase/decrease is now scaled depending on the current zoom.
1 parent 998b418 commit a7c5e3c

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

examples/shaders/resources/shaders/glsl330/julia_shader.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ const int MAX_ITERATIONS = 255; // Max iterations to do.
1515
// Square a complex number
1616
vec2 complexSquare(vec2 z)
1717
{
18-
return vec2(
19-
z.x * z.x - z.y * z.y,
20-
z.x * z.y * 2.0
21-
);
18+
return vec2(
19+
z.x * z.x - z.y * z.y,
20+
z.x * z.y * 2.0
21+
);
2222
}
2323

2424
// Convert Hue Saturation Value color into RGB
@@ -33,8 +33,8 @@ vec3 hsv2rgb(vec3 c)
3333
void main()
3434
{
3535
// The pixel coordinates scaled so they are on the mandelbrot scale.
36-
vec2 z = vec2(((gl_FragCoord.x + offset.x)/screenDims.x) * 2.5 * zoom,
37-
((screenDims.y - gl_FragCoord.y + offset.y)/screenDims.y) * 1.5 * zoom); // y also flipped due to opengl
36+
vec2 z = vec2((((gl_FragCoord.x + offset.x)/screenDims.x) * 2.5)/zoom,
37+
(((screenDims.y - gl_FragCoord.y + offset.y)/screenDims.y) * 1.5)/zoom); // y also flipped due to opengl
3838
int iterations = 0;
3939

4040
/*

examples/shaders/shaders_julia_set.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ int main()
4040

4141
// Load julia set shader
4242
// NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
43-
Shader shader = LoadShader(0, "resources/shaders/glsl330/julia_shader.fs");
43+
Shader shader = LoadShader(0, "julia_shader.fs");
4444

4545
// c constant to use in z^2 + c
4646
float c[2] = { POINTS_OF_INTEREST[0][0], POINTS_OF_INTEREST[0][1] };
4747

4848
// Offset and zoom to draw the julia set at. (centered on screen and 1.6 times smaller)
4949
float offset[2] = { -(float)screenWidth/2, -(float)screenHeight/2 };
50-
float zoom = 1.6f;
50+
float zoom = 1.0f;
5151

5252
Vector2 offsetSpeed = { 0.0f, 0.0f };
5353

@@ -111,8 +111,8 @@ int main()
111111
// Probably offset movement should be proportional to zoom level
112112
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) || IsMouseButtonDown(MOUSE_RIGHT_BUTTON))
113113
{
114-
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) zoom -= 0.003f;
115-
if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) zoom += 0.003f;
114+
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) zoom += zoom * 0.003f;
115+
if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) zoom -= zoom * 0.003f;
116116

117117
Vector2 mousePos = GetMousePosition();
118118

0 commit comments

Comments
 (0)