added button to enable/disable the busy loop to be able to count fps
authorEleni Maria Stea <estea@igalia.com>
Tue, 30 Apr 2019 21:06:54 +0000 (00:06 +0300)
committerEleni Maria Stea <estea@igalia.com>
Tue, 30 Apr 2019 21:07:55 +0000 (00:07 +0300)
added more things to the example => TOO SLOW

examples/mushroom.shader_test
src/main.cc

index 0f6ad39..9ca6657 100644 (file)
@@ -15,10 +15,10 @@ uniform mat4 cam_xform;
 #endif
 
 #define T 0.0001
-#define STEP 0.01
+#define STEP 0.02
 #define FOV 45.0
 #define M_PI 3.14159
-#define MAX_STEPS 2000
+#define MAX_STEPS 1500
 #define GRAD_DELTA (STEP / 2.0)
 
 #define OBJ_NULL 0
@@ -32,22 +32,36 @@ const vec2 res = vec2(800.0, 600.0);
 float pnoise(vec2 P, vec2 rep);
 float cnoise(vec2 P);
 
-float ground_height(vec3 point)
+float ground_height(vec2 point)
 {
-       return cnoise(point.xz * 0.85);
+       return cnoise(point * 0.1) * 3.0;
 }
 
 /* dist from nearest object */
 float calc_dist_mushroom(in vec3 point, out int obj_id)
 {
-       const float sep = 4.0;
-       const float hsep = sep / 2.0;
-       vec3 p = vec3(mod(point.x + hsep, sep) - hsep, point.y, mod(point.z + hsep, sep) - hsep);
-       vec3 cap_pt = p * vec3(1.0, 1.5, 1.0);
-
        const float sph_radius = 1.0;
        const float bigsph_radius = 50.0;
 
+       const float sep = 5.6; //dist between 2 mushrooms
+       const float hsep = sep / 2.0;
+       vec2 cell_pt = floor((point.xz + vec2(hsep, hsep)) / sep) * sep;
+
+       vec2 cell_pt2 = cell_pt * 7.32;
+       vec2 cell_noise = vec2(cnoise(cell_pt2 + 3.48),
+                       cnoise(cell_pt2 + 25.72));
+       vec3 scale = vec3(1.0, 1.0, 1.0);//vec3(cell_noise.x, cell_noise.y, cell_noise.x) *
+       //      vec3(0.4, 0.6, 0.4) + vec3(1.0, 1.0, 1.0);
+       vec2 xzoffs = cell_noise * (hsep - sph_radius * max(scale.x, scale.z));
+
+       vec3 p = vec3(mod(point.x + hsep, sep) - hsep, point.y,
+                       mod(point.z + hsep, sep) - hsep) * scale;
+       p.x += xzoffs.x;
+       p.z += xzoffs.y;
+       p.y -= ground_height(cell_pt - xzoffs);
+
+       vec3 cap_pt = p * vec3(1.0, 1.5, 1.0);
+
        float dsph_small = sqrt(dot(cap_pt, cap_pt)) - sph_radius;
        vec3 bigsph_center = vec3(0.0, bigsph_radius - 0.2, 0.0);
        vec3 dvec = bigsph_center - cap_pt;
@@ -82,7 +96,7 @@ float calc_dist_ground(in vec3 point, out int obj_id)
 {
        obj_id = OBJ_GROUND;
 
-       const float ground_height = -0.9 + ground_height(point); 
+       const float ground_height = -0.9 + ground_height(point.xz); 
        return point.y - ground_height;
 }
 
index 502ad7d..1237966 100644 (file)
@@ -35,7 +35,9 @@ static float cam_phi, cam_theta, cam_dist = 10;
 static unsigned int sdrprog;
 static int uloc_cam_xform = -1;
 
+static float sensitivity = 0.5;
 static bool quit;
+static bool busy_loop;
 
 int main(int argc, char **argv)
 {
@@ -62,6 +64,10 @@ int main(int argc, char **argv)
        int xfd = ConnectionNumber(dpy);
 
        while(!quit) {
+               if(busy_loop) {
+                       post_redisplay();
+               }
+
                if(!redraw_pending) {
                        int num_rfds;
                        int *rfds = resman_get_wait_fds(sdrman, &num_rfds);
@@ -141,9 +147,6 @@ static void display()
                        float cam_mat[16];
                        glGetFloatv(GL_MODELVIEW_MATRIX, cam_mat);
                        glUniformMatrix4fv(uloc_cam_xform, 1, 0, cam_mat);
-
-                       /* busy loop until the libresman bug gets fixed... */
-                       post_redisplay();
                }
 
                glLoadIdentity();
@@ -170,6 +173,21 @@ static void keyboard(unsigned char key, int x, int y)
        case 27:
                quit = true;
                break;
+       case '`':
+       case '\n':
+               post_redisplay();
+               break;
+       case '=':
+               sensitivity *= 2;
+               printf("sensitivity: %f\n", sensitivity);
+               break;
+       case '-':
+               sensitivity *= 0.5;
+               printf("sensitivity: %f\n", sensitivity);
+               break;
+       case 'b':
+               busy_loop = !busy_loop;
+               break;
        default:
                break;
        }
@@ -271,8 +289,8 @@ static void motion(int x, int y)
                return;
 
        if(bnstate[0]) {
-               cam_theta += dx * 0.5;
-               cam_phi += dy * 0.5;
+               cam_theta += dx * sensitivity;
+               cam_phi += dy * sensitivity;
 
                if(cam_phi < -90) cam_phi = -90;
                if(cam_phi > 90) cam_phi = 90;
@@ -281,7 +299,7 @@ static void motion(int x, int y)
        }
 
        if(bnstate[2]) {
-               cam_dist += dy * 0.1;
+               cam_dist += dy * sensitivity / 5.0;
 
                if(cam_dist < 0) cam_dist = 0;