From: Randy McShandy Date: Mon, 20 May 2024 02:22:58 +0000 (-0500) Subject: lol orbs X-Git-Url: http://git.mcshandy.xyz/gitweb.cgi?a=commitdiff_plain;h=c42f332afa9290ec11801ae3e2150415c4dbfcf0;p=barrow_crawler lol orbs --- diff --git a/assets/hand_1.jpg b/assets/hand_1.jpg new file mode 100644 index 0000000..b50b223 Binary files /dev/null and b/assets/hand_1.jpg differ diff --git a/assets/hand_1.png b/assets/hand_1.png new file mode 100644 index 0000000..d1b7769 Binary files /dev/null and b/assets/hand_1.png differ diff --git a/src/main.c b/src/main.c index 407d277..dfafb6c 100755 --- a/src/main.c +++ b/src/main.c @@ -16,7 +16,7 @@ int main(int argc, char** argv) { /* TODO: Clean this up and integrate into platform system. */ -#define ENABLE_BARROWGEN 1 +#define ENABLE_BARROWGEN 0 #if ENABLE_BARROWGEN barrow.max_iterations *= 1; IVec2 grid_size = {.x = GRID_X*1.5, .y = GRID_Y * 1.5}; @@ -35,13 +35,15 @@ int main(int argc, char** argv) pthread_t generator_thread; pthread_create(&generator_thread, NULL, generate_rd, (void*)&gargs); + start_render_loop(); + pthread_join(generator_thread, NULL); #else resource_generation_finished = 1; + start_render_loop(); #endif /* ENABLE_BARROWGEN */ - start_render_loop(); - pthread_join(generator_thread, NULL); + return 0; } diff --git a/src/platforms/platform_posix.c b/src/platforms/platform_posix.c index 4383304..d488be8 100644 --- a/src/platforms/platform_posix.c +++ b/src/platforms/platform_posix.c @@ -5,6 +5,7 @@ worker_arg warg; int waiting_workers; +int should_quit = 0; extern FVec2 ** grid; extern FVec2 ** grid_prime; diff --git a/src/render_raylib.c b/src/render_raylib.c index 01a7db0..0398812 100644 --- a/src/render_raylib.c +++ b/src/render_raylib.c @@ -34,18 +34,28 @@ Vector3 coffin_position; Vector3 coffin_scale; Vector3 coffin_rotation_axis; float coffin_rotation; -int coffin_material_count; +int coffin_material_count; + +Image hand_01_image; +Texture hand_01_texture; +Vector2 hand_position; +float hand_rotation; +float hand_scale; Shader shader; int cam_position_shader_loc; int screen_dims_shader_loc; int map_center_shader_loc; +int orb_color_shader_loc; +int orb_intensity_shader_loc; +int orb_directionality_shader_loc; Vector3 player_collide_point; Ray player_collide_ray; RayCollision player_collision; Vector3 player_velocity; Vector3 player_rotation; +Vector3 player_angles; Vector3 map_center; float forward_speed = 0.015f; @@ -58,6 +68,11 @@ Vector3 vec3_010 = {0.0f, 1.0f, 0.0f}; Vector3 vec3_up = {0.0f, 1.0f, 0.0f}; Vector3 vec3_down = {0.0f, -1.0f, 0.0f}; +Color orb_color = BLUE; +Vector4 orb_normal_color; +float orb_intensity = 1.0f; /* TODO: normalized distance from center, but lighting shader already has this. */ +Vector3 orb_directionality = {1.0f, 1.0f, 1.0f}; + typedef void(*renderfunc)(); typedef void(*controlfunc)(); #define MAX_RENDERFUNCS 2U @@ -69,19 +84,31 @@ NOTE: Only call inside a Raylib BeginDrawing() block! */ void drawing_game_mode() { + Vector2 from_center_coords = (Vector2){cam.position.x, cam.position.z}; + from_center_coords.x -= barrow_scale.x/2; + from_center_coords.y += barrow_scale.z/2; + /* -PI, PI */ + player_angles.y = Vector2Angle(Vector2Normalize(from_center_coords), (Vector2){1.0f, 0.0f}); + ClearBackground(BLACK); BeginMode3D(cam); BeginShaderMode(shader); - DrawModelEx(coffin_model, coffin_position, coffin_rotation_axis, coffin_rotation, coffin_scale, DARKGRAY); + // 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(floor_model, floor_position, floor_rotation_axis, floor_rotation, floor_scale, DARKGRAY); - DrawRay(player_collide_ray, WHITE); + // DrawRay(player_collide_ray, WHITE); EndShaderMode(); EndMode3D(); + orb_normal_color = ColorNormalize(orb_color); + orb_intensity = 64.0f; /* TODO: normalized distance from center, but lighting shader already has this. */ + orb_directionality = player_angles; + + DrawTextureEx(hand_01_texture, hand_position, hand_rotation, hand_scale, orb_color); + #define DEBUG_GAME_INFO 1 #if DEBUG_GAME_INFO==1 Rectangle minimap_dest = {.width = 64.0f*img_export_scale.x, .height = 64.0f*img_export_scale.y, .x = 0.0f, .y = 0.0f}; @@ -91,7 +118,8 @@ void drawing_game_mode() 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("tgt x %f\ntgt y %f\ntgt z %f", cam.target.x, cam.target.y, cam.target.z), 0, 128+64, 16, GREEN); - DrawText(TextFormat("ray hit %d\nlength %f", player_collision.hit, player_collision.distance), 0, 256, 16, GREEN); + DrawText(TextFormat("rot x %f\nrot y %f\nrot z %f", player_angles.x, player_angles.y, player_angles.z), 0, 128+(64*2), 16, GREEN); + DrawText(TextFormat("ray hit %d\nlength %f", player_collision.hit, player_collision.distance), 0, 128+(64*3), 16, GREEN); #endif /* DEBUG_GAME_INFO */ } @@ -162,6 +190,13 @@ void control_game_mode() cam.target.y -= DEG2RAD * 20.0; } + if (IsKeyReleased(KEY_ONE)) + orb_color = RED; + if (IsKeyReleased(KEY_TWO)) + orb_color = BLUE; + if (IsKeyReleased(KEY_THREE)) + orb_color = GREEN; + /* Collision test */ /* Cast straight up */ player_collide_ray = (Ray){cam.position, vec3_up}; @@ -199,6 +234,9 @@ void wait_initialize_shaders() cam_position_shader_loc = GetShaderLocation(shader, "cam_position"); screen_dims_shader_loc = GetShaderLocation(shader, "screen_dims"); map_center_shader_loc = GetShaderLocation(shader, "map_center"); + orb_color_shader_loc = GetShaderLocation(shader, "orb_color"); + orb_intensity_shader_loc = GetShaderLocation(shader, "orb_intensity"); + orb_directionality_shader_loc = GetShaderLocation(shader, "orb_directionality"); } void wait_initialize_resources() @@ -257,6 +295,14 @@ void wait_initialize_resources() coffin_model = LoadModel("./assets/coffin_1.glb"); while(!IsModelReady(coffin_model)){} coffin_model.materials[0].shader = shader; + + hand_01_image = LoadImage("./assets/hand_1.png"); + while(!IsImageReady(hand_01_image)){} + hand_01_texture = LoadTextureFromImage(hand_01_image); + while(!IsTextureReady(hand_01_texture)){} + hand_scale = 4.0f; + hand_position = (Vector2){0, fscreen_dims.y - (hand_01_image.height * hand_scale)}; + hand_rotation = 0.0f; } /* Mode handler setup */ @@ -286,7 +332,7 @@ void initialize_renderer() cam.position = barrow_position; cam.position.y -= 0.5f; cam.position.x = barrow_scale.x/2.0f; - cam.position.z = (-barrow_scale.z/2.0f) - 4.0f; + cam.position.z = (-barrow_scale.z/2.0f); cam.target = (Vector3){barrow_scale.x/2.0f, cam.position.y - 7.0f, cam.position.z/2.0f}; cam.up = (Vector3){0.0f, 1.0f, 0.0f}; cam.fovy = 90.0f; @@ -299,6 +345,7 @@ void initialize_renderer() void start_render_loop() { initialize_prerenderer(); + SetTraceLogLevel(LOG_ALL); InitWindow(fscreen_dims.x, fscreen_dims.y, screen_title); wait_initialize_shaders(); @@ -320,6 +367,9 @@ void start_render_loop() SetShaderValue(shader, cam_position_shader_loc, &cam.position, SHADER_UNIFORM_VEC3); SetShaderValue(shader, screen_dims_shader_loc, &fscreen_dims, SHADER_UNIFORM_VEC2); SetShaderValue(shader, map_center_shader_loc, &map_center, SHADER_UNIFORM_VEC3); + SetShaderValue(shader, orb_color_shader_loc, &orb_normal_color, SHADER_UNIFORM_VEC4); + SetShaderValue(shader, orb_intensity_shader_loc, &orb_intensity, SHADER_UNIFORM_FLOAT); + SetShaderValue(shader, orb_directionality_shader_loc, &orb_directionality, SHADER_UNIFORM_VEC3); UpdateCameraPro(&cam, player_velocity, player_rotation, 0.0f); BeginDrawing(); diff --git a/src/shaders/lighting.fs b/src/shaders/lighting.fs index d5e98f1..946a863 100644 --- a/src/shaders/lighting.fs +++ b/src/shaders/lighting.fs @@ -4,6 +4,7 @@ in vec2 fragTexCoord; in vec4 fragColor; in vec3 fragPosition; +layout(pixel_center_integer) in vec4 gl_FragCoord; // Input uniform values uniform sampler2D texture0; @@ -11,6 +12,9 @@ uniform vec4 colDiffuse; uniform vec3 cam_position; uniform vec2 screen_dims; uniform vec3 map_center; +uniform vec4 orb_color; +uniform float orb_intensity; +uniform vec3 orb_directionality; // Output fragment color out vec4 finalColor; @@ -19,10 +23,11 @@ const vec3 v3_unit = vec3(1.0f, 1.0f, 1.0f); const float max_lum = 1.0f; const float max_lit_distance = 7.5f; const float max_center_distance = 8.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; +vec4 candle_color = vec4(228.0f/255.0f, 103.0f/255.0f, 1.0f/255.0f, 255.0f/255.0f); + +vec2 orb_pos = vec2(3.0 * (screen_dims.x/16), 8 * (screen_dims.y/16)); -const vec2 candle_pos = vec2(0.5, 0.5); +float lumWeight = 0.0f; // A single iteration of Bob Jenkins' One-At-A-Time hashing algorithm. uint hash( uint x ) { @@ -122,11 +127,20 @@ void main() candle_weight = 1.0f - normalized_lit_distance; } + float normal_distance_from_orb = distance(orb_pos, gl_FragCoord.xy)/orb_intensity; + if(normal_distance_from_orb < 1.0f) + { + lumWeight = 3.0f; + finalColor *= (orb_color * lumWeight); + finalColor.a = 1.5 - easeOutExpo(normal_distance_from_orb); + } + lumWeight = min(lumWeight, max_lum); lumWeights = vec4(1.0f) * lumWeight; lumWeights *= dot(finalColor, lumWeights); - lighting_color = vec4(mix(candle_color.rgb * candle_weight, lumWeights.rgb, 0.4f), 1.0f); + lighting_color = vec4(mix(orb_color.rgb * candle_weight, lumWeights.rgb, 0.4f), 1.0f); + //lighting_color = vec4(mix(candle_color.rgb * candle_weight, lumWeights.rgb, 0.4f), 1.0f); finalColor = finalColor * lighting_color; // All single color channel variations with this looks cool as FUCK diff --git a/src/structs.c b/src/structs.c index ae3eaa3..95885b8 100644 --- a/src/structs.c +++ b/src/structs.c @@ -69,12 +69,10 @@ const Mat3 laplacian_kernel = } }; -int should_quit = 0; - const char chars[6] = {' ', ' ', ' ', '+', '#', '@'}; const int max_chars = sizeof(chars) / sizeof(chars[0]) - 1; -const IVec2 screen_dims = {.x = 1800, .y = 1200}; +const IVec2 screen_dims = {.x = 1600, .y = 900}; const char* screen_title = "Barrow Crawler"; const int target_fps = 60; diff --git a/src/utils.c b/src/utils.c index daee66c..7dcff1d 100644 --- a/src/utils.c +++ b/src/utils.c @@ -20,7 +20,6 @@ #define printf(a,...) #endif -extern int should_quit; FVec2 ** grid; FVec2 ** grid_prime; FVec2 ** grid_temp;