]> git.mcshandy.xyz Git - barrow_crawler/commitdiff
Small updates to visuals, but mostly barrow generation improvements
authorRandy McShandy <randy@mcshandy.xyz>
Fri, 17 May 2024 02:53:21 +0000 (21:53 -0500)
committerRandy McShandy <randy@mcshandy.xyz>
Fri, 17 May 2024 02:53:21 +0000 (21:53 -0500)
src/main.c
src/render_raylib.c
src/shaders/lighting.fs
src/utils.c

index 456c15ee604ecb517f54d3363243710906c57fcc..eb6dbc7f52681559ac4e73e78d1b901343ec4068 100755 (executable)
@@ -22,7 +22,7 @@ int main(int argc, char** argv)
        }
        barrow.max_iterations *= 1;
 
-#define ENABLE_BARROWGEN 0
+#define ENABLE_BARROWGEN 1
 #if ENABLE_BARROWGEN
        generate_rd(8, barrow, grid, grid_size);
 #endif
index 41750d49dbb87b41c346d49fe310c4a771acf7c7..72f52e54da7f2f6011ce82277f72b2124de58f65 100644 (file)
@@ -154,7 +154,7 @@ void initialize_renderer()
        map_center = barrow_scale;
        map_center.x /= 2.0f;
        map_center.z /= -2.0f;
-       map_center.y = -2.0f;
+       map_center.y = -3.0f;
 
        while(!IsImageReady(barrow_image)){}
        barrow_texture = LoadTextureFromImage(barrow_image);
@@ -164,12 +164,14 @@ void initialize_renderer()
 
        floor_image = LoadImage("./floor.png");
        floor_albedo = LoadTexture("./floor_albedo.png");
-       floor_scale = (Vector3){floor_image.width/6.0f, 1.0f, floor_image.height/6.0f};
+       floor_scale = (Vector3){floor_image.width/6.0f, 3.0f, floor_image.height/6.0f};
        floor_position = (Vector3){0.0f, -3.0f, -floor_scale.z};
        floor_rotation_axis = (Vector3){0.0f, 0.0f, floor_image.width};
        floor_rotation = 0.0f;
 
        while(!IsImageReady(floor_image)){}
+       floor_texture = LoadTextureFromImage(floor_image);
+       while(!IsTextureReady(floor_texture)){}
        while(!IsTextureReady(floor_albedo)){}
 
        /* Might want to replace barrow_scale with just img dimensions. */
@@ -227,7 +229,6 @@ void start_render_loop()
                Matrix mat_rot = MatrixRotate(barrow_rotation_axis, DEG2RAD * barrow_rotation);
                Matrix mat_scale = MatrixScale(barrow_scale.x, barrow_scale.y, barrow_scale.z);
                barrow_mat = MatrixMultiply(MatrixMultiply(mat_trans, mat_scale), mat_rot);
-               barrow_model.transform = barrow_mat;
 
                SetShaderValue(shader, cam_position_shader_loc, &cam.position, SHADER_UNIFORM_VEC3);
                SetShaderValue(shader, screen_dims_shader_loc, &fscreen_dims, SHADER_UNIFORM_VEC2);
@@ -240,14 +241,13 @@ void start_render_loop()
                        BeginMode3D(cam);
                        BeginShaderMode(shader);
                                DrawModelEx(coffin_model, coffin_position, coffin_rotation_axis, coffin_rotation, coffin_scale, DARKGRAY);
-                               //DrawModelEx(barrow_model, barrow_position, barrow_rotation_axis, barrow_rotation, barrow_scale, DARKGRAY);
+                               DrawModelEx(barrow_model, barrow_position, barrow_rotation_axis, barrow_rotation, barrow_scale, DARKGRAY);
                                DrawModelEx(floor_model, floor_position, floor_rotation_axis, floor_rotation, floor_scale, DARKGRAY);
-                               DrawMesh(barrow_model.meshes[0], barrow_model.materials[0], barrow_mat);
                                DrawRay(player_collide_ray, WHITE);
                        EndShaderMode();
                        EndMode3D();
 
-                       DrawTexturePro(barrow_texture, minimap_src, minimap_dest, (Vector2){0.0f, 0.0f}, 0.0f, RAYWHITE);
+                       DrawTexturePro(floor_texture, minimap_src, minimap_dest, (Vector2){0.0f, 0.0f}, 0.0f, RAYWHITE);
                        DrawFPS(fscreen_dims.x - 80, 10);
                        DrawText(TextFormat("cam x %f\ncam y %f\ncam z %f", cam.position.x, cam.position.y, cam.position.z), 0, 128, 16, GREEN);
                        DrawText(TextFormat("ray hit %d\nlength %f", player_collision.hit, player_collision.distance), 0, 256, 16, GREEN);
index c744bc65ce78bcab61944142554edba58b8829e5..7da0f8a3891b4de6194483dbfa75a76f748b8d51 100644 (file)
@@ -17,9 +17,8 @@ out vec4 finalColor;
 
 const vec3 v3_unit = vec3(1.0f, 1.0f, 1.0f);
 const float max_lum = 0.8f;
-const float max_lit_distance = 6.5f;
+const float max_lit_distance = 7.5f;
 const float max_center_distance = 8.0f;
-//const vec4 candle_color = vec4(255.0f/255.0f, 0.001f/255.0f, 0.001f/255.0f, 255.0f/255.0f);
 const vec4 candle_color = vec4(228.0f/255.0f, 103.0f/255.0f, 1.0f/255.0f, 255.0f/255.0f);
 float lumWeight = 0.0f;
 
@@ -132,6 +131,6 @@ void main()
 
                // All single color channel variations with this looks cool as FUCK
                // turns this into three levels going b-r-g
-               finalColor.b = 0.0f;
+               //finalColor.b = 0.0f;
 
 }
index 61989a37a0a6f1d11d5094b3a366f4bddc2a5cbb..5ab0e65e70c64b8ebd1c78381ddc8573f95b8187 100644 (file)
@@ -3,7 +3,8 @@
 #include <stdint.h>
 #include <math.h>
 
-#warning "TODO: I think this header is only posix, check for alt platform replacements"
+#warning "TODO: I think these are only posix, check for alt platform replacements"
+#include <sys/param.h>
 #include <time.h>
 
 #include "structs.h"
@@ -25,6 +26,11 @@ FVec2 ** grid_prime;
 FVec2 ** grid_temp;
 IVec2 grid_size;
 
+float iv2_inverse_sqrt(IVec2 a, IVec2 b)
+{
+       return 1.0f/sqrt(pow(a.x-b.x, 2) + pow(a.y-b.y, 2));
+}
+
 float kernel_sum(Mat3 kernel, Mat3 source) {
   float result = 0.0f;
 
@@ -116,7 +122,10 @@ int initialize(int worker_count, RD_Opts active_opt)
                        {
                                grid[x][y].c = 1.0f;
                        }
-                       if ((sqrtf(((x-center_x)*(x-center_x))+((y-center_y)*(y-center_y))) < central_chamber_radius))
+
+                       const float distance_from_center = sqrtf(((x-center_x)*(x-center_x))+((y-center_y)*(y-center_y)));
+                       if ((distance_from_center < central_chamber_radius) ||
+                                       ((abs(x-center_x) < 1.0f) && (abs(y-center_y) < (central_chamber_radius*1.5f))))
                        {
                                grid[x][y].c = 1.0f;
                        }
@@ -124,31 +133,38 @@ int initialize(int worker_count, RD_Opts active_opt)
        }
 
        /* Set up seed-points to create connected rooms */
-       const int seed_count = 10;//sqrt(grid_size.x) * 2;
-       const int width = 12 * (grid_size.x/128);
-       const int height = width * 1;
-       const float small_room_radius = 16.0f;
+       const int seed_count = 7;//sqrt(grid_size.x) * 2;
+       const float small_room_radius = 10.0f;
+       const float phase = ((rand() % 360)/(float)360) * (M_PI*2);
 
-       float phase = ((rand() % 360)/(float)360) * (M_PI*2);
        for (int n = 0; n < seed_count; n++)
        {
                /* Generate n seeds at even radial points, random phase offset */
                float angle = ((float)n/(float)seed_count) * (M_PI * 2);
+               float dist_offset = ((rand() % 14)+1);
                angle += phase;
 
-               int seed_x = ((cosf(angle) * (grid_size.x/4.0f)) + (grid_size.x/2.0f));
-               int seed_y = ((sinf(angle) * (grid_size.y/4.0f)) + (grid_size.y/2.0f));
+               int seed_x = ((cosf(angle) * (dist_offset + (grid_size.x/4.0f))) + (grid_size.x/2.0f));
+               int seed_y = ((sinf(angle) * (dist_offset + (grid_size.y/4.0f))) + (grid_size.y/2.0f));
 
                grid[seed_x][seed_y].b = 1.0f;
                grid[seed_x][seed_y].c = 0.0f;
 
-               for (int x = seed_x-(width/2); x < seed_x+(width/2); x++)
+               const float x_start = (seed_x-((small_room_radius)));
+               const float y_start = (seed_y-((small_room_radius)));
+               const float x_end       = (seed_x+((small_room_radius)));
+               const float y_end       = (seed_y+((small_room_radius)));
+               const float distance_seed_to_center = sqrtf(pow(seed_x - center_x, 2) + pow(seed_y - center_y, 2));
+
+               for (int x = x_start; x < x_end; x++)
                {
-                       for (int y = seed_y-(height/2); y < seed_y+(height/2); y++)
+                       for (int y = y_start; y < y_end; y++)
                        {
-                               if ((sqrtf(((x-seed_x)*(x-seed_x))+((y-seed_y)*(y-seed_y))) < small_room_radius))
-                                       // Third parameter for permanent presence of B chemicals (black)
+                               const float distance_from_center = sqrtf(((x-center_x)*(x-center_x))+((y-center_y)*(y-center_y)));
+                               if (distance_from_center >= distance_seed_to_center)
+                               {
                                        grid[x][y].c = 1.0f;
+                               }
                        }
                }
        }
@@ -183,7 +199,7 @@ int generate_rd(int worker_count, RD_Opts active_opt, FVec2 **grid_buffer, IVec2
                {
                        float a = round(-0.05f + grid_buffer[x][y].a);
                        barrow_mesh_buffer[x][y] = (uint8_t)(255.0f * a);
-                       floor_mesh_buffer[x][y] = 0.0f;
+                       floor_mesh_buffer[x][y] = barrow_mesh_buffer[x][y];
 
                        /* Generate different materials
                        */