From 92e93928ff07eb768b4b013ab5dff16f0e4f55d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Tue, 20 Oct 2026 16:28:58 +0300 Subject: [PATCH] reorder --- game/ver-mac/bridge/raylib_bridge.c | 171 +++++++++++++++------------- 1 file changed, 89 insertions(+), 82 deletions(-) diff --git a/game/ver-mac/bridge/raylib_bridge.c b/game/ver-mac/bridge/raylib_bridge.c index fb597ae..95054b6 100644 --- a/game/ver-mac/bridge/raylib_bridge.c +++ b/game/ver-mac/bridge/raylib_bridge.c @@ -217,6 +217,94 @@ static Matrix sr_cube_transform(void) return sr_transform((Vector3){ 0.0f, 1.1f, 0.0f }, 1.0f, sr_rot_x, sr_rot_y, sr_rot_z); } +static void sr_draw_object(Model model, Material material, Matrix model_mat, + Texture2D normal, float is_ground, float emissive); + +static void sr_render_main_pass(void) +{ + // --- Main pass: camera --- + rlViewport(0, 0, sr_width, sr_height); + rlSetFramebufferWidth(sr_width); + rlSetFramebufferHeight(sr_height); + + rlClearColor(24, 26, 34, 255); + rlClearScreenBuffers(); + + rlMatrixMode(RL_PROJECTION); + rlPushMatrix(); + rlLoadIdentity(); + + float aspect = (float)sr_width / (float)sr_height; + double top = (double)sr_cfg.near_plane * tan((double)sr_cfg.fov_y * 0.5 * DEG2RAD); + double right = top * (double)aspect; + rlFrustum(-right, right, -top, top, (double)sr_cfg.near_plane, (double)sr_cfg.far_plane); + + rlMatrixMode(RL_MODELVIEW); + rlLoadIdentity(); + + Vector3 eye = { 0.0f, 2.6f, 5.6f }; + Vector3 target = { 0.0f, 1.0f, 0.0f }; + Vector3 up = { 0.0f, 1.0f, 0.0f }; + + Matrix view = MatrixLookAt(eye, target, up); + rlMultMatrixf(MatrixToFloat(view)); + + rlEnableDepthTest(); + rlEnableBackfaceCulling(); + rlSetCullFace(RL_CULL_FACE_BACK); + + rlEnableShader(sr_main_shader.id); + + Vector3 light_color = { 1.15f, 1.08f, 0.98f }; + Vector3 ambient = { 0.30f, 0.32f, 0.38f }; + Vector3 grid_color = { 0.45f, 0.62f, 0.95f }; + Vector3 fog_color = { 24.0f / 255.0f, 26.0f / 255.0f, 34.0f / 255.0f }; + float light_amount = 1.0f; + float shadow_bias = 0.0025f; + float shadow_softness = 4.0f; + float fog_start = 10.0f; + float fog_end = 34.0f; + + SetShaderValue(sr_main_shader, loc_light_pos, &sr_light_pos, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_light_color, &light_color, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_ambient, &ambient, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_light_enabled, &light_amount, SHADER_UNIFORM_FLOAT); + SetShaderValue(sr_main_shader, loc_shadow_bias, &shadow_bias, SHADER_UNIFORM_FLOAT); + SetShaderValue(sr_main_shader, loc_shadow_softness, &shadow_softness, SHADER_UNIFORM_FLOAT); + SetShaderValue(sr_main_shader, loc_grid_color, &grid_color, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_camera_pos, &eye, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_fog_color, &fog_color, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_fog_start, &fog_start, SHADER_UNIFORM_FLOAT); + SetShaderValue(sr_main_shader, loc_fog_end, &fog_end, SHADER_UNIFORM_FLOAT); + + int shadow_unit = 1; + SetShaderValue(sr_main_shader, loc_shadow_map, &shadow_unit, SHADER_UNIFORM_INT); + rlActiveTextureSlot(1); + rlEnableTexture(sr_shadow_depth); + rlActiveTextureSlot(0); + + // --- Ground (procedural grid floor) --- + sr_draw_object(sr_ground_model, sr_ground_material, MatrixTranslate(0.0f, 0.0f, 0.0f), (Texture2D){ 0 }, 1.0f, 0.0f); + + // --- Cubes --- + if (sr_has_model) + { + sr_draw_object(sr_model, sr_cube_material, sr_cube_transform(), sr_cube_normal, 0.0f, 0.0f); + } + + // Flush while the projection/modelview matrices are still active, otherwise + // rlgl draws the pending batch with the restored (2D) projection. + rlDrawRenderBatchActive(); + + // --- Restore matrices (equivalent to raylib's EndMode3D) --- + rlMatrixMode(RL_PROJECTION); + rlPopMatrix(); + rlMatrixMode(RL_MODELVIEW); + rlLoadIdentity(); + rlDisableDepthTest(); + rlDisableBackfaceCulling(); +} + static void sr_render_shadow_pass(void) { rlViewport(0, 0, sr_cfg.shadow_size, sr_cfg.shadow_size); @@ -306,88 +394,7 @@ void sr_render(void) sr_light_proj = MatrixPerspective(90.0 * DEG2RAD, 1.0, 1.5, 16.0); sr_render_shadow_pass(); - - // --- Main pass: camera --- - rlViewport(0, 0, sr_width, sr_height); - rlSetFramebufferWidth(sr_width); - rlSetFramebufferHeight(sr_height); - - rlClearColor(24, 26, 34, 255); - rlClearScreenBuffers(); - - rlMatrixMode(RL_PROJECTION); - rlPushMatrix(); - rlLoadIdentity(); - - float aspect = (float)sr_width / (float)sr_height; - double top = (double)sr_cfg.near_plane * tan((double)sr_cfg.fov_y * 0.5 * DEG2RAD); - double right = top * (double)aspect; - rlFrustum(-right, right, -top, top, (double)sr_cfg.near_plane, (double)sr_cfg.far_plane); - - rlMatrixMode(RL_MODELVIEW); - rlLoadIdentity(); - - Vector3 eye = { 0.0f, 2.6f, 5.6f }; - Vector3 target = { 0.0f, 1.0f, 0.0f }; - Vector3 up = { 0.0f, 1.0f, 0.0f }; - - Matrix view = MatrixLookAt(eye, target, up); - rlMultMatrixf(MatrixToFloat(view)); - - rlEnableDepthTest(); - rlEnableBackfaceCulling(); - rlSetCullFace(RL_CULL_FACE_BACK); - - rlEnableShader(sr_main_shader.id); - - Vector3 light_color = { 1.15f, 1.08f, 0.98f }; - Vector3 ambient = { 0.30f, 0.32f, 0.38f }; - Vector3 grid_color = { 0.45f, 0.62f, 0.95f }; - Vector3 fog_color = { 24.0f / 255.0f, 26.0f / 255.0f, 34.0f / 255.0f }; - float light_amount = 1.0f; - float shadow_bias = 0.0025f; - float shadow_softness = 4.0f; - float fog_start = 10.0f; - float fog_end = 34.0f; - - SetShaderValue(sr_main_shader, loc_light_pos, &sr_light_pos, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_light_color, &light_color, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_ambient, &ambient, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_light_enabled, &light_amount, SHADER_UNIFORM_FLOAT); - SetShaderValue(sr_main_shader, loc_shadow_bias, &shadow_bias, SHADER_UNIFORM_FLOAT); - SetShaderValue(sr_main_shader, loc_shadow_softness, &shadow_softness, SHADER_UNIFORM_FLOAT); - SetShaderValue(sr_main_shader, loc_grid_color, &grid_color, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_camera_pos, &eye, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_fog_color, &fog_color, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_fog_start, &fog_start, SHADER_UNIFORM_FLOAT); - SetShaderValue(sr_main_shader, loc_fog_end, &fog_end, SHADER_UNIFORM_FLOAT); - - int shadow_unit = 1; - SetShaderValue(sr_main_shader, loc_shadow_map, &shadow_unit, SHADER_UNIFORM_INT); - rlActiveTextureSlot(1); - rlEnableTexture(sr_shadow_depth); - rlActiveTextureSlot(0); - - // --- Ground (procedural grid floor) --- - sr_draw_object(sr_ground_model, sr_ground_material, MatrixTranslate(0.0f, 0.0f, 0.0f), (Texture2D){ 0 }, 1.0f, 0.0f); - - // --- Cubes --- - if (sr_has_model) - { - sr_draw_object(sr_model, sr_cube_material, sr_cube_transform(), sr_cube_normal, 0.0f, 0.0f); - } - - // Flush while the projection/modelview matrices are still active, otherwise - // rlgl draws the pending batch with the restored (2D) projection. - rlDrawRenderBatchActive(); - - // --- Restore matrices (equivalent to raylib's EndMode3D) --- - rlMatrixMode(RL_PROJECTION); - rlPopMatrix(); - rlMatrixMode(RL_MODELVIEW); - rlLoadIdentity(); - rlDisableDepthTest(); - rlDisableBackfaceCulling(); + sr_render_main_pass(); } void sr_shutdown(void)