From 55d96209836bec3c097a62cf5b92f01c8f4ed0b6 Mon Sep 17 00:00:00 2001 From: Cat Flynn Date: Sun, 26 Feb 2023 03:26:42 +0000 Subject: [PATCH] add upper spheres --- shader/include/scene.glsl | 28 ++++++++++++++++++++++++++++ src/main.c | 2 +- src/sphere.c | 4 ++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/shader/include/scene.glsl b/shader/include/scene.glsl index c9a20ec..79c5c4f 100644 --- a/shader/include/scene.glsl +++ b/shader/include/scene.glsl @@ -11,6 +11,34 @@ RayHit trace(inout Ray ray) intersectSphere(ray, hit, _spheres[i]); } + int sphereCount = 10; + for (int i = 0; i < sphereCount; i++) + { + Sphere s; + float a = i/float(sphereCount)*2.0*PI; + float d = 17.0 + cos((1.3+a)*3.0) * 3.0; + float r = 4.0 + sin(a*3.0)*2.0; + s.cr = vec4(sin(a)*d,2.0*r+cos(a*5.0),cos(a)*d, r); + s.albedo = vec3(.2); + s.material = i % 3 == 0 ? MAT_CHROME : MAT_LAMBERT; + + intersectSphere(ray, hit, s); + } + + sphereCount = 3; + for (int i = 0; i < sphereCount; i++) + { + Sphere s; + float a = i/float(sphereCount)*2.0*PI; + float d = 5.0 + cos((5.34+a)*5.0) * 3.0; + float r = 3.0 + sin(a*2.0)*1.5; + s.cr = vec4(sin(a)*d,4.0*r+cos(a*5.0),cos(a)*d, r); + s.albedo = vec3(.2); + s.material = i % 3 == 0 ? MAT_CHROME : MAT_LAMBERT; + + intersectSphere(ray, hit, s); + } + ray.distance += hit.distance * float(hit.distance < INF); return hit; diff --git a/src/main.c b/src/main.c index 4a8ba8c..737c485 100644 --- a/src/main.c +++ b/src/main.c @@ -135,7 +135,7 @@ void updateUniforms(GLuint shaderProgram, float t) updateCameraUniforms(shaderProgram, aspect, t); // make and update spheres - const int sphereCount = 41; + const int sphereCount = 25; struct Sphere spheres[sphereCount]; makeSpheres(spheres, sphereCount, t); updateSphereUniforms(shaderProgram, spheres, sphereCount); diff --git a/src/sphere.c b/src/sphere.c index e3daa97..df6ac98 100644 --- a/src/sphere.c +++ b/src/sphere.c @@ -30,13 +30,13 @@ void makeSpheres(struct Sphere *spheres, int count, float t) int rainbowSpheres = count - middleSpheres; // distance from center float d = 6.0; - radius = 0.5; + radius = 0.7; float x; for (int i = 0; i < rainbowSpheres; i++) { x = 2.0*CGLM_PI * (float)i/(float)rainbowSpheres; sc[0] = sin(x)*d; - sc[1] = sin(x*3.0-5.0*sin(t)); + sc[1] = radius*sin(x*3.0-5.0*sin(t)); sc[2] = cos(x)*d; float ic = i/(float)rainbowSpheres*CGLM_PI*2.0;