From d63261a5b4067aff3f2b633e691e1e7cb098c6f5 Mon Sep 17 00:00:00 2001 From: Katajisto Date: Mon, 28 Jul 2025 16:51:01 +0300 Subject: [PATCH] work on asset packing and console logging --- .gitignore | 1 + first.jai | 54 ++-- log_nvprosample.txt | 172 ++++++++++++ .../examples/example.jai | 73 +++++ modules/Simple_Package_Reader/module.jai | 242 ++++++++++++++++ resources/{ => utiltex}/lut.png | Bin src/editor/console.jai | 3 + src/editor/trile_editor.jai | 6 +- src/load.jai | 61 +++- src/main.jai | 16 +- src/meta/lint.jai | 4 + src/meta/meta.jai | 2 + src/meta/pack.jai | 27 ++ src/meta/shaderload.jai | 16 ++ src/pipelines.jai | 5 - src/shaders/jai/shader_sky.jai | 260 +++++++++--------- src/shaders/shader_sky.glsl | 8 +- 17 files changed, 774 insertions(+), 176 deletions(-) create mode 100644 modules/Simple_Package_Reader/examples/example.jai create mode 100644 modules/Simple_Package_Reader/module.jai rename resources/{ => utiltex}/lut.png (100%) create mode 100644 src/meta/pack.jai create mode 100644 src/meta/shaderload.jai diff --git a/.gitignore b/.gitignore index 4c9a658..2648e1f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .build/ dist/ first +packs/* diff --git a/first.jai b/first.jai index d08a55c..e2f1005 100644 --- a/first.jai +++ b/first.jai @@ -1,26 +1,35 @@ #load "./src/meta/meta.jai"; + Iprof :: #import "Iprof"(IMPORT_MODE = .METAPROGRAM); #run { print("%\n", ascii_car); - // @ToDo: Fix this so that we are using the freshly compiled Jai files instead of the old ones. - // { - // process_result, output, error := run_command("bash", "./compile_shaders.sh", working_directory=tprint("%/src/shaders", #filepath)); - // if process_result.exit_code != 0 { - // log_error("Shader compilation failed."); - // if output { - // log_error(output,, logger = runtime_support_default_logger); - // } - // exit(1); - // } - // } + + // Step 1. Compile shaders. + { + print("--- Shader Compile Step ---\n"); + process_result, output, error := run_command("bash", "./compile_shaders.sh", working_directory=tprint("%/src/shaders", #filepath)); + if process_result.exit_code != 0 { + log_error("Shader compilation failed."); + if output { + log_error(output,, logger = runtime_support_default_logger); + } + exit(1); + } + } + + // Step 2. Create a pack file for all of the assets in ./resources. + create_pack(); + opt := get_build_options(); args := opt.compile_time_command_line; doWasmBuild := false; hasTacoma := false; + releaseBuild := false; for arg : args { if arg == "wasm" then doWasmBuild = true; if arg == "tacoma" then hasTacoma = true; + if arg == "release" then releaseBuild = true; } if doWasmBuild { @@ -74,6 +83,7 @@ Iprof :: #import "Iprof"(IMPORT_MODE = .METAPROGRAM); add_build_file("src/platform_specific/main_web.jai", w); add_build_string("HAS_TACOMA :: false;", w); add_build_string("HAS_IPROF :: false;", w); + add_shaders_to_workspace(w); while true { message := compiler_wait_for_message(); @@ -123,13 +133,16 @@ Iprof :: #import "Iprof"(IMPORT_MODE = .METAPROGRAM); w := compiler_create_workspace("Target"); opts := get_build_options(w); copy_commonly_propagated_fields(*opts, *root_opts); + opts.cpu_target = root_opts.cpu_target; opts.os_target = root_opts.os_target; + opts.backend = ifx releaseBuild then .LLVM else .X64; opts.output_executable_name = root_opts.output_executable_name; + set_build_options(opts, w); iprof_plugin: *Iprof.My_Plugin; - profile :: true; + profile := !releaseBuild; if profile { iprof_plugin = cast(*Iprof.My_Plugin) Iprof.get_plugin(); @@ -147,19 +160,26 @@ Iprof :: #import "Iprof"(IMPORT_MODE = .METAPROGRAM); } else { add_build_string("HAS_TACOMA :: false;", w); } - add_build_string("HAS_IPROF :: true;", w); - iprof_plugin.add_source(iprof_plugin); + if profile { + add_build_string("HAS_IPROF :: true;", w); + iprof_plugin.add_source(iprof_plugin); + } else { + add_build_string("HAS_IPROF :: false;", w); + } add_build_file("src/platform_specific/main_native.jai", w); + add_shaders_to_workspace(w); while true { message := compiler_wait_for_message(); - iprof_plugin.message(iprof_plugin, message); + if profile then iprof_plugin.message(iprof_plugin, message); custom_message_handler(message, *w); if message.kind == .COMPLETE then break; } compiler_end_intercept(w); - iprof_plugin.finish(iprof_plugin); - iprof_plugin.shutdown(iprof_plugin); + if profile { + iprof_plugin.finish(iprof_plugin); + iprof_plugin.shutdown(iprof_plugin); + } } } diff --git a/log_nvprosample.txt b/log_nvprosample.txt index e69de29..9782aff 100644 --- a/log_nvprosample.txt +++ b/log_nvprosample.txt @@ -0,0 +1,172 @@ +_______________ +Vulkan Version: + - available: 1.4.309 + - requesting: 1.3.0 +______________________ +Used Instance Layers : +VK_LAYER_KHRONOS_validation + +Used Instance Extensions : +____________________ +Devices : 1 +0: AMD Radeon RX 6950 XT + - Compatible +Compatible physical devices found : 1 +Using Device: + - Device Name : AMD Radeon RX 6950 XT + - Vendor : AMD + - Driver Version : 2.0.341 + - API Version : 1.4.308 + - Device Type : Discrete GPU +________________________ +Used Device Extensions : +VK_KHR_deferred_host_operations +VK_KHR_acceleration_structure +VK_KHR_ray_query + +BLAS Compaction: 0.0MB -> 0.0MB (0.0MB saved, 41.3% smaller) +_______________ +Vulkan Version: + - available: 1.4.309 + - requesting: 1.3.0 +______________________ +Used Instance Layers : +VK_LAYER_KHRONOS_validation + +Used Instance Extensions : +____________________ +Devices : 1 +0: AMD Radeon RX 6950 XT + - Compatible +Compatible physical devices found : 1 +Using Device: + - Device Name : AMD Radeon RX 6950 XT + - Vendor : AMD + - Driver Version : 2.0.341 + - API Version : 1.4.308 + - Device Type : Discrete GPU +________________________ +Used Device Extensions : +VK_KHR_deferred_host_operations +VK_KHR_acceleration_structure +VK_KHR_ray_query + +BLAS Compaction: 0.0MB -> 0.0MB (0.0MB saved, 41.3% smaller) +_______________ +Vulkan Version: + - available: 1.4.309 + - requesting: 1.3.0 +______________________ +Used Instance Layers : +VK_LAYER_KHRONOS_validation + +Used Instance Extensions : +____________________ +Devices : 1 +0: AMD Radeon RX 6950 XT + - Compatible +Compatible physical devices found : 1 +Using Device: + - Device Name : AMD Radeon RX 6950 XT + - Vendor : AMD + - Driver Version : 2.0.341 + - API Version : 1.4.308 + - Device Type : Discrete GPU +________________________ +Used Device Extensions : +VK_KHR_deferred_host_operations +VK_KHR_acceleration_structure +VK_KHR_ray_query + +BLAS Compaction: 0.0MB -> 0.0MB (0.0MB saved, 41.3% smaller) +_______________ +Vulkan Version: + - available: 1.4.309 + - requesting: 1.3.0 +______________________ +Used Instance Layers : +VK_LAYER_KHRONOS_validation + +Used Instance Extensions : +____________________ +Devices : 1 +0: AMD Radeon RX 6950 XT + - Compatible +Compatible physical devices found : 1 +Using Device: + - Device Name : AMD Radeon RX 6950 XT + - Vendor : AMD + - Driver Version : 2.0.341 + - API Version : 1.4.308 + - Device Type : Discrete GPU +________________________ +Used Device Extensions : +VK_KHR_deferred_host_operations +VK_KHR_acceleration_structure +VK_KHR_ray_query + +BLAS Compaction: 0.0MB -> 0.0MB (0.0MB saved, 41.3% smaller) +_______________ +Vulkan Version: + - available: 1.4.309 + - requesting: 1.3.0 +______________________ +Used Instance Layers : +VK_LAYER_KHRONOS_validation + +Used Instance Extensions : +____________________ +Devices : 1 +0: AMD Radeon RX 6950 XT + - Compatible +Compatible physical devices found : 1 +Using Device: + - Device Name : AMD Radeon RX 6950 XT + - Vendor : AMD + - Driver Version : 2.0.341 + - API Version : 1.4.308 + - Device Type : Discrete GPU +________________________ +Used Device Extensions : +VK_KHR_deferred_host_operations +VK_KHR_acceleration_structure +VK_KHR_ray_query + +BLAS Compaction: 0.0MB -> 0.0MB (0.0MB saved, 41.3% smaller) +_______________ +Vulkan Version: + - available: 1.4.309 + - requesting: 1.3.0 +______________________ +Used Instance Layers : +VK_LAYER_KHRONOS_validation + +Used Instance Extensions : +____________________ +Devices : 1 +0: AMD Radeon RX 6950 XT + - Compatible +Compatible physical devices found : 1 +Using Device: + - Device Name : AMD Radeon RX 6950 XT + - Vendor : AMD + - Driver Version : 2.0.341 + - API Version : 1.4.308 + - Device Type : Discrete GPU +________________________ +Used Device Extensions : +VK_KHR_deferred_host_operations +VK_KHR_acceleration_structure +VK_KHR_ray_query + +BLAS Compaction: 0.0MB -> 0.0MB (0.0MB saved, 41.3% smaller) +_______________ +Vulkan Version: + - available: 1.4.309 + - requesting: 1.3.0 +______________________ +Used Instance Layers : +VK_LAYER_KHRONOS_validation + +Used Instance Extensions : +__________________ \ No newline at end of file diff --git a/modules/Simple_Package_Reader/examples/example.jai b/modules/Simple_Package_Reader/examples/example.jai new file mode 100644 index 0000000..50a0e75 --- /dev/null +++ b/modules/Simple_Package_Reader/examples/example.jai @@ -0,0 +1,73 @@ +#import "Simple_Package"; +#import "Basic"; +#import "File"; +#import "Hash_Table"; + +write_package :: (filename: string) { + item1 := "Hello, Sailor!"; + + item2: [100] u8; + for 0..item2.count-1 item2[it] = xx it; + + item3: [10] float; + for 0..item3.count-1 item3[it] = cast(float)(it*it); + + + package: Create_Package; + defer deinit(*package); + + init(*package); + + add(*package, "run_tree/data/item1", xx item1); + + add(*package, "this is item2", xx item2); + + item3_data: [] u8; + item3_data.data = xx item3.data; + item3_data.count = item3.count * size_of(type_of(item3[0])); + add(*package, "item3, unimaginatively", item3_data); + + write(*package, filename); +} + +read_package :: (filename: string) -> (success: bool, package: Load_Package) { + package: Load_Package; + + success := init_from_file(*package, filename); + if !success return false, package; + + print("package has % entries:\n", package.entries.count); + + for package.entries { + print("[%] %\n", it_index, it); + } + + return true, package; +} + +main :: () { + filename :: "test.package"; + + write_package(filename); + success, package := read_package(filename); + + print("\n"); + print("read_package returned success == %.\n", success); + print("\n"); + + if success { + found, entry := table_find_new(*package.lookup, "this is item2"); + + if found { + print("Found the entry!: %\n", entry.*); + } else { + print("Did not find the entry! Oops!\n"); + assert(false); + } + } else { + assert(false); + } + + print("\n"); +} + diff --git a/modules/Simple_Package_Reader/module.jai b/modules/Simple_Package_Reader/module.jai new file mode 100644 index 0000000..7cf2025 --- /dev/null +++ b/modules/Simple_Package_Reader/module.jai @@ -0,0 +1,242 @@ +// create_*... + +Create_Package :: struct { + data: String_Builder; + + entries: [..] Entry_Info; + pool: Pool; // Stores entry names and user data. +} + +Entry_Info :: struct { + name: string; + data: [] u8; + offset_from_start_of_file: s64; + size_of_entry: s64; // Equal to data.count if we hae the data, but we might not have the data if loading Table_Of_Contents only! +} + +deinit :: (using package: *Create_Package) { + free_buffers(*data); + array_reset(*entries); + release(*pool); +} + + +KNOWN_HEADER_SIZE :: 64; +#assert size_of(Package_Header) == KNOWN_HEADER_SIZE; + +Package_Header :: struct { + magic: u32; + version: u32; + flags: u32; + reserved0: u32; + + table_of_contents_offset: s64; + + reserved: [5] u64; +} + +Load_Package :: struct { + header: Package_Header; + data: [] u8; + + table_of_contents: Table_Of_Contents; + + entries: [] Entry_Info; + + lookup: Table(string, *Entry_Info); +} + +KNOWN_TABLE_OF_CONTENTS_SIZE :: 64; +#assert size_of(Table_Of_Contents) == KNOWN_TABLE_OF_CONTENTS_SIZE; + +Table_Of_Contents :: struct { + table_of_contents_magic: u32; + reserved0: u32; + + number_of_entries: s64; + + reserved: [6] u64; +} + +append_struct :: (builder: *String_Builder, to_append: *$T) { + append(builder, cast(*u8) to_append, size_of(T)); +} + + +init_from_memory :: (package: *Load_Package, data: [] u8, name_for_debugging := "") -> bool { + #assert(TARGET_IS_LITTLE_ENDIAN); // We can endian-swap the header later. + + if data.count < KNOWN_HEADER_SIZE { + log_error("Package '%' is too small to even contain a header! (It's % bytes).\n", name_for_debugging, data.count); + return false; // Too small! + } + + _header := cast(*Package_Header) data.data; + package.header = << _header; + + header_success := check_header(*package.header, name_for_debugging, data.count); + if !header_success return false; + + offset := package.header.table_of_contents_offset; + toc_start := data; + toc_start.data += offset; + toc_start.count -= offset; + assert(toc_start.count >= 0); + + toc_success := load_table_of_contents(package, toc_start, data.data, name_for_debugging, offset); + + return toc_success; +} + + +load_table_of_contents :: (package: *Load_Package, data: [] u8, base_file_data_if_file_is_loaded: *u8, name_for_debugging: string, offset_for_debugging: s64) -> bool { + toc := cast(*Table_Of_Contents) data.data; + if toc.table_of_contents_magic != TABLE_OF_CONTENTS_MAGIC { + log_error("In package '%', we skipped to the supposed table_of_contents at offset %, but did not find the magic number there that we expected to find. (We wanted %, but got %).\n", name_for_debugging, offset_for_debugging, formatInt(TABLE_OF_CONTENTS_MAGIC, base=16), formatInt(toc.table_of_contents_magic, base=16)); + return false; + } + + entries: [..] Entry_Info; + array_resize(*entries, toc.number_of_entries); + + s: string; + s.data = data.data + KNOWN_TABLE_OF_CONTENTS_SIZE; + s.count = data.count - KNOWN_TABLE_OF_CONTENTS_SIZE; + + assert(s.count >= 0); + + for 0..toc.number_of_entries-1 { + entry := *entries[it]; + + if s.count < 4 { + log_error("Table_Of_Contents Entry % is too short!\n", it+1); + return false; + } + + name_length: u32; + get(*s, *name_length); + + entry.name.data = s.data; + entry.name.count = name_length; + + if s.count < name_length + 1 + 16 { // The 16 is for the chunk size and offset. + log_error("Table_Of_Contents Entry % is too short!\n", it+1); + return false; + } + + advance(*s, name_length + 1); + + chunk_size: s64; + chunk_offset: s64; + + get(*s, *chunk_size); + get(*s, *chunk_offset); + + if chunk_offset >= package.header.table_of_contents_offset { + log_error("The offset_from_start_of_file for Entry % is out of range; it must be before the table_of_contents, which starts at %, but it was %.\n", it+1, package.header.table_of_contents_offset, chunk_offset); + return false; + } + + base := base_file_data_if_file_is_loaded; + if base { + entry.data.data = base + chunk_offset; + entry.data.count = chunk_size; + } + + entry.size_of_entry = chunk_size; + entry.offset_from_start_of_file = chunk_offset; + + table_add(*package.lookup, entry.name, entry); + } + + package.entries = entries; + + return true; +} + +#scope_file + +MAGIC :: #run << cast(*u32) "simp".data; +TABLE_OF_CONTENTS_MAGIC :: #run << cast(*u32) "toc!".data; + +FILE_VERSION :: 1; +TARGET_IS_LITTLE_ENDIAN :: true; // @Endian: Need a way to change this based on target CPU! + +// @Copypasta from the game! +put :: (builder: *String_Builder, x: $T) +#modify { + using Type_Info_Tag; + + ti := cast(*Type_Info) T; + if ti.type == INTEGER return true; // Accept integers. + if ti.type == FLOAT return true; // Accept floats. + if ti.type == BOOL return true; // Accept bools. + if ti.type == ENUM return true; // Accept enums. + + return false; // Reject anything else. +} +{ + ensure_contiguous_space(builder, size_of(T)); + + #if TARGET_IS_LITTLE_ENDIAN { + // @Speed: Just write the target type! + simple_memcpy(builder, x); + } else { + // @Incomplete: Do a slow-path if we know we are not little-endian. This can be generated by #run_and_insert? + assert(false); + } +} + +get :: (s: *string, x: *$T) +#modify { // @Cutnpaste from put + using Type_Info_Tag; + + ti := cast(*Type_Info) T; + if ti.type == INTEGER return true; // Accept integers. + if ti.type == FLOAT return true; // Accept floats. + if ti.type == BOOL return true; // Accept bools. + if ti.type == ENUM return true; // Accept enums. + + return false; // Reject anything else. +} +{ + assert(s.count >= size_of(T)); + + if TARGET_IS_LITTLE_ENDIAN { + memcpy(x, s.data, size_of(T)); + } else { + // @Incomplete: Do a slow-path if we know we are not little-endian. This can be generated by #run_and_insert? + assert(false); + } + + s.data += size_of(T); + s.count -= size_of(T); +} + +check_header :: (header: *Package_Header, name: string, file_size_in_bytes_or_minus_1: s64) -> bool { + using header; + + if magic != MAGIC { + log_error("Package '%' has an incorrect magic number! (Wanted %, got %).\n", name, formatInt(MAGIC, base=16), formatInt(magic, base=16)); + return false; + } + + if version > FILE_VERSION { // 'version' is unsigned, so, don't check < 0. + log_error("Package '%' has an invalid version number, or a version created by code that is newer than we are, so we don't understand the format. (Its version is %; our highest known version is %).\n", name, version, FILE_VERSION); + return false; + } + + if file_size_in_bytes_or_minus_1 >= 0 { + size := file_size_in_bytes_or_minus_1; + if table_of_contents_offset + KNOWN_TABLE_OF_CONTENTS_SIZE >= size { + log_error("Package '%' has an invalid table_of_contents_offset; it claims to be %, but the file is only % bytes long.\n", name, table_of_contents_offset, size); + return false; + } + } + + return true; +} + +#import "Basic"; +#import "Hash_Table"; +#import "Pool"; diff --git a/resources/lut.png b/resources/utiltex/lut.png similarity index 100% rename from resources/lut.png rename to resources/utiltex/lut.png diff --git a/src/editor/console.jai b/src/editor/console.jai index cff2600..ee09175 100644 --- a/src/editor/console.jai +++ b/src/editor/console.jai @@ -120,6 +120,9 @@ tick_console :: () { } } +console_add_output_line :: (s: string) { + array_add(*console_report, s); +} draw_console :: (theme: *GR.Overall_Theme) { if console_h < 1 then return; diff --git a/src/editor/trile_editor.jai b/src/editor/trile_editor.jai index 7041c1b..513a302 100644 --- a/src/editor/trile_editor.jai +++ b/src/editor/trile_editor.jai @@ -108,8 +108,10 @@ handle_tool_click :: () { current_color : Vector3 = .{1.0, 0.0, 0.0}; -reset_trile :: (a: bool = false) { - print("Reset called, with arg: %!\n", a); +reset_trile :: () { + newt : Trile; + set_trile("test", newt); + current_trile = get_trile("test"); } @Command tick_trile_editor :: () { diff --git a/src/load.jai b/src/load.jai index 34e3389..99462ca 100644 --- a/src/load.jai +++ b/src/load.jai @@ -1,18 +1,36 @@ +#scope_file + MAX_FILE_SIZE :: 200_000; buf : [MAX_FILE_SIZE]u8; +g_asset_pack : Load_Package; + mandatory_loads_left : s32 = 0; + +packcb :: (res: *sfetch_response_t) #c_call { + push_context,defer_pop default_context; + mem : []u8; + mem.count = res.data.size.(s64); + mem.data = res.data.ptr; + + success := init_from_memory(*g_asset_pack, mem, "main_asset_pack"); + print("Succesfully loaded main asset pack!\n"); + mandatory_loads_left -= 1; +} + +#scope_export + init_after_mandatory_done : bool = false; mandatory_loads_done :: () -> bool { return mandatory_loads_left <= 0; } -init_font_loads :: () { +init_asset_pack_load :: () { mandatory_loads_left += 1; sfetch_send(*(sfetch_request_t.{ - path = "./resources/DroidSerif-Regular.ttf".data, - callback = fontcb, + path = "./packs/assets.pack".data, + callback = packcb, buffer = .{ ptr = buf.data, size = buf.count @@ -20,9 +38,36 @@ init_font_loads :: () { })); } -fontcb :: (res: *sfetch_response_t) #c_call { - push_context,defer_pop default_context; - state.font_default.fons_font = fonsAddFontMem(state.fons, "sans", res.data.ptr, xx res.data.size, 0); - ui_init_font_fields(*state.font_default); - mandatory_loads_left -= 1; +add_font_from_pack :: (path: string) { + ok, entry := table_find_new(*g_asset_pack.lookup, path); + if !ok { + print("Failed to find font % from pack...\n", path); + return; + } + state.font_default.fons_font = fonsAddFontMem(state.fons, "sans", entry.data.data, xx entry.data.count, 0); +} + +asset_list :: () -> string #expand { + count := 0; + for v : g_asset_pack.lookup { + console_add_output_line(sprint("% (%)", v.name, format_size(v.size_of_entry))); + count += 1; + } + return tprint("> A total of % assets.", count); +} @Command + +// Returns tprinted pointer, please copy it somewhere. +format_size :: (bytes: int) -> string { + bytes_counter := bytes; + bytes_float := cast(float) bytes; + names : []string = .["b", "kb", "mb", "gb", "tb"]; + name_index := 0; + while bytes_counter / 1000 > 0 { + name_index += 1; + bytes_counter /= 1000; + bytes_float /= 1000.0; + if name_index > 4 then break; + } + return tprint("% %", bytes_float, names[name_index]); + } diff --git a/src/main.jai b/src/main.jai index f64b1c8..8e6316c 100644 --- a/src/main.jai +++ b/src/main.jai @@ -9,6 +9,7 @@ MEM_DEBUG :: false; #import "Input"; #import "Hash_Table"; #import "Hash"; +#import "Simple_Package_Reader"; stbi :: #import "stb_image"; #load "trile.jai"; @@ -87,16 +88,19 @@ init :: () { state.pass_action_clear.colors[0] = .{ load_action = .CLEAR, clear_value = .{ r = 0.6, g = 0.7, b = 1.0, a = 1 } }; state.pass_action.colors[0] = .{ load_action = .LOAD }; - init_font_loads(); - // Add empty trile. - set_trile("test", Trile.{}); + init_asset_pack_load(); - init_editor(); } -init_after_mandatory_loads :: () { +init_after_asset_pack :: () { + + add_font_from_pack("./resources/DroidSerif-Regular.ttf"); + ui_init_font_fields(*state.font_default); + init_ui(); + set_trile("test", Trile.{}); + init_editor(); } cam : Camera; @@ -108,7 +112,7 @@ frame :: () { sfetch_dowork(); if mandatory_loads_done() && !init_after_mandatory_done { - init_after_mandatory_loads(); + init_after_asset_pack(); init_after_mandatory_done = true; } diff --git a/src/meta/lint.jai b/src/meta/lint.jai index 5f205e7..80dfedf 100644 --- a/src/meta/lint.jai +++ b/src/meta/lint.jai @@ -38,6 +38,10 @@ lint_procedure_name :: (name: string, node: Code_Node) -> bool { for name { if it >= #char "a" && it <= #char "z" then continue; if it == #char "_" then continue; + if it == #char "+" then continue; + if it == #char "=" then continue; + if it == #char "<" then continue; + if it == #char ">" then continue; if it >= #char "0" && it <= #char "9" then continue; name_ok = false; wrong_char = it; diff --git a/src/meta/meta.jai b/src/meta/meta.jai index 8b4667e..6190fdb 100644 --- a/src/meta/meta.jai +++ b/src/meta/meta.jai @@ -1,6 +1,8 @@ #load "ascii.jai"; +#load "pack.jai"; #load "lint.jai"; #load "console_commands.jai"; +#load "shaderload.jai"; custom_message_handler :: (message: *Message, w: *Workspace) { lint_checks(message); diff --git a/src/meta/pack.jai b/src/meta/pack.jai new file mode 100644 index 0000000..4b598bd --- /dev/null +++ b/src/meta/pack.jai @@ -0,0 +1,27 @@ +create_pack :: () { + #import "Simple_Package"; + #import "File"; + util :: #import "File_Utilities"; + + files_to_pack := util.file_list("./resources", true); + + package: Create_Package; + defer deinit(*package); + init(*package); + + print("Packing % files -> ./packs/assets.pack\n", files_to_pack.count); + + for files_to_pack { + file, ok := read_entire_file(it); + if !ok { + print("Failed in loading file to pack: %\n", it); + continue; + } + filedata : []u8; + filedata.count = file.count; + filedata.data = file.data; + add(*package, it, filedata); + } + + write(*package, "./packs/assets.pack"); +} diff --git a/src/meta/shaderload.jai b/src/meta/shaderload.jai new file mode 100644 index 0000000..cfb66a5 --- /dev/null +++ b/src/meta/shaderload.jai @@ -0,0 +1,16 @@ +#scope_file + +get_shader_paths :: () -> []string { + util :: #import "File_Utilities"; + return util.file_list("./src/shaders/jai"); +} + +#scope_export + +add_shaders_to_workspace :: (w: Workspace) { + file :: #import "File"; + paths := get_shader_paths(); + for paths { + add_build_file(file.get_absolute_path(it), w); + } +} diff --git a/src/pipelines.jai b/src/pipelines.jai index 22467ff..ffd92eb 100644 --- a/src/pipelines.jai +++ b/src/pipelines.jai @@ -1,8 +1,3 @@ -#load "./shaders/jai/shader_triangle.jai"; -#load "./shaders/jai/shader_trixel.jai"; -#load "./shaders/jai/shader_sky.jai"; -#load "./shaders/jai/shader_trile.jai"; - Pipeline_Binding :: struct { pipeline : sg_pipeline; bind : sg_bindings; diff --git a/src/shaders/jai/shader_sky.jai b/src/shaders/jai/shader_sky.jai index 1fdb25f..05afd07 100644 --- a/src/shaders/jai/shader_sky.jai +++ b/src/shaders/jai/shader_sky.jai @@ -165,18 +165,19 @@ vs_sky_source_glsl430 := u8.[ } float _240 = _199.y; final += (mix(_178.horizonHalo, vec3(0.0), vec3(clamp(abs(_240) * 80.0, 0.0, 1.0))) * 0.100000001490116119384765625); - vec3 param = ((_199 / vec3(_240)) * 2.0) + vec3(_178.time * 0.0500000007450580596923828125); - float _269 = fbm(param); - vec3 _273 = final; - vec3 _282 = mix(_273, vec3(1.0), vec3((max(0.0, _240) * (smoothstep(0.5, 1.0, _269) * 0.300000011920928955078125)) * 2.0)); - final = _282; - return _282; + if (_178.hasClouds == 1) + { + vec3 param = ((_199 / vec3(_240)) * 2.0) + vec3(_178.time * 0.0500000007450580596923828125); + float _276 = fbm(param); + final = mix(final, vec3(1.0), vec3((max(0.0, _240) * (smoothstep(0.5, 1.0, _276) * 0.300000011920928955078125)) * 2.0)); + } + return final; } void main() { vec3 param = normalize(pos.xyz); - vec3 param_1 = vec3(0.485071241855621337890625, 0.72760689258575439453125, 0.485071241855621337890625); + vec3 param_1 = _178.sunPosition; frag_color = vec4(sky(param, param_1), 1.0); } @@ -389,40 +390,36 @@ fs_sky_source_glsl430 := u8.[ 0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x29, 0x20,0x2a,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39, 0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x20,0x3d,0x20,0x28,0x28,0x5f,0x31,0x39,0x39,0x20,0x2f,0x20,0x76,0x65,0x63, - 0x33,0x28,0x5f,0x32,0x34,0x30,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20, - 0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x37,0x38,0x2e,0x74,0x69,0x6d,0x65, - 0x20,0x2a,0x20,0x30,0x2e,0x30,0x35,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x37,0x34, - 0x35,0x30,0x35,0x38,0x30,0x35,0x39,0x36,0x39,0x32,0x33,0x38,0x32,0x38,0x31,0x32, - 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32, - 0x36,0x39,0x20,0x3d,0x20,0x66,0x62,0x6d,0x28,0x70,0x61,0x72,0x61,0x6d,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x37,0x33,0x20,0x3d, - 0x20,0x66,0x69,0x6e,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, - 0x20,0x5f,0x32,0x38,0x32,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x32,0x37,0x33, - 0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x2c,0x20,0x76,0x65,0x63, - 0x33,0x28,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x5f,0x32,0x34,0x30, - 0x29,0x20,0x2a,0x20,0x28,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28, - 0x30,0x2e,0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x5f,0x32,0x36,0x39,0x29,0x20, - 0x2a,0x20,0x30,0x2e,0x33,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30, - 0x39,0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x29,0x29,0x20,0x2a, - 0x20,0x32,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x69,0x6e,0x61, - 0x6c,0x20,0x3d,0x20,0x5f,0x32,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x20,0x5f,0x32,0x38,0x32,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f, - 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6e,0x6f,0x72, - 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x38,0x35,0x30,0x37, - 0x31,0x32,0x34,0x31,0x38,0x35,0x35,0x36,0x32,0x31,0x33,0x33,0x37,0x38,0x39,0x30, - 0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x37,0x32,0x37,0x36,0x30,0x36,0x38,0x39,0x32, - 0x35,0x38,0x35,0x37,0x35,0x34,0x33,0x39,0x34,0x35,0x33,0x31,0x32,0x35,0x2c,0x20, - 0x30,0x2e,0x34,0x38,0x35,0x30,0x37,0x31,0x32,0x34,0x31,0x38,0x35,0x35,0x36,0x32, - 0x31,0x33,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65, - 0x63,0x34,0x28,0x73,0x6b,0x79,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x00, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x37,0x38,0x2e, + 0x68,0x61,0x73,0x43,0x6c,0x6f,0x75,0x64,0x73,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x28,0x28,0x5f,0x31,0x39, + 0x39,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x32,0x34,0x30,0x29,0x29,0x20, + 0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31, + 0x37,0x38,0x2e,0x74,0x69,0x6d,0x65,0x20,0x2a,0x20,0x30,0x2e,0x30,0x35,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x37,0x34,0x35,0x30,0x35,0x38,0x30,0x35,0x39,0x36,0x39, + 0x32,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x37,0x36,0x20,0x3d,0x20, + 0x66,0x62,0x6d,0x28,0x70,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x69,0x6e,0x61,0x6c,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x66,0x69,0x6e,0x61,0x6c,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29, + 0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c, + 0x20,0x5f,0x32,0x34,0x30,0x29,0x20,0x2a,0x20,0x28,0x73,0x6d,0x6f,0x6f,0x74,0x68, + 0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x5f, + 0x32,0x37,0x36,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x30,0x30,0x30,0x30,0x30,0x30, + 0x31,0x31,0x39,0x32,0x30,0x39,0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32, + 0x35,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x69, + 0x6e,0x61,0x6c,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69, + 0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65, + 0x28,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31, + 0x37,0x38,0x2e,0x73,0x75,0x6e,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x76,0x65,0x63,0x34,0x28,0x73,0x6b,0x79,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x00, ]; /* #version 300 es @@ -539,18 +536,19 @@ vs_sky_source_glsl300es := u8.[ } highp float _240 = _199.y; final += (mix(_178.horizonHalo, vec3(0.0), vec3(clamp(abs(_240) * 80.0, 0.0, 1.0))) * 0.100000001490116119384765625); - highp vec3 param = ((_199 / vec3(_240)) * 2.0) + vec3(_178.time * 0.0500000007450580596923828125); - highp float _269 = fbm(param); - highp vec3 _273 = final; - highp vec3 _282 = mix(_273, vec3(1.0), vec3((max(0.0, _240) * (smoothstep(0.5, 1.0, _269) * 0.300000011920928955078125)) * 2.0)); - final = _282; - return _282; + if (_178.hasClouds == 1) + { + highp vec3 param = ((_199 / vec3(_240)) * 2.0) + vec3(_178.time * 0.0500000007450580596923828125); + highp float _276 = fbm(param); + final = mix(final, vec3(1.0), vec3((max(0.0, _240) * (smoothstep(0.5, 1.0, _276) * 0.300000011920928955078125)) * 2.0)); + } + return final; } void main() { highp vec3 param = normalize(pos.xyz); - highp vec3 param_1 = vec3(0.485071241855621337890625, 0.72760689258575439453125, 0.485071241855621337890625); + highp vec3 param_1 = _178.sunPosition; frag_color = vec4(sky(param, param_1), 1.0); } @@ -782,42 +780,37 @@ fs_sky_source_glsl300es := u8.[ 0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x31, 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31, 0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x20,0x3d,0x20,0x28,0x28,0x5f,0x31,0x39,0x39,0x20,0x2f,0x20,0x76,0x65,0x63, - 0x33,0x28,0x5f,0x32,0x34,0x30,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20, - 0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x37,0x38,0x2e,0x74,0x69,0x6d,0x65, - 0x20,0x2a,0x20,0x30,0x2e,0x30,0x35,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x37,0x34, - 0x35,0x30,0x35,0x38,0x30,0x35,0x39,0x36,0x39,0x32,0x33,0x38,0x32,0x38,0x31,0x32, - 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x32,0x36,0x39,0x20,0x3d,0x20,0x66,0x62,0x6d,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x68,0x69,0x67,0x68,0x70, - 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x37,0x33,0x20,0x3d,0x20,0x66,0x69,0x6e, - 0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65, - 0x63,0x33,0x20,0x5f,0x32,0x38,0x32,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x32, - 0x37,0x33,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x2c,0x20,0x76, - 0x65,0x63,0x33,0x28,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x5f,0x32, - 0x34,0x30,0x29,0x20,0x2a,0x20,0x28,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65, - 0x70,0x28,0x30,0x2e,0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x5f,0x32,0x36,0x39, - 0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x39, - 0x32,0x30,0x39,0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x29,0x29, - 0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x69, - 0x6e,0x61,0x6c,0x20,0x3d,0x20,0x5f,0x32,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x32,0x38,0x32,0x3b,0x0a,0x7d,0x0a,0x0a, - 0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x70, - 0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x68,0x69,0x67, - 0x68,0x70,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, - 0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x38,0x35,0x30,0x37,0x31,0x32, - 0x34,0x31,0x38,0x35,0x35,0x36,0x32,0x31,0x33,0x33,0x37,0x38,0x39,0x30,0x36,0x32, - 0x35,0x2c,0x20,0x30,0x2e,0x37,0x32,0x37,0x36,0x30,0x36,0x38,0x39,0x32,0x35,0x38, - 0x35,0x37,0x35,0x34,0x33,0x39,0x34,0x35,0x33,0x31,0x32,0x35,0x2c,0x20,0x30,0x2e, - 0x34,0x38,0x35,0x30,0x37,0x31,0x32,0x34,0x31,0x38,0x35,0x35,0x36,0x32,0x31,0x33, - 0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34, - 0x28,0x73,0x6b,0x79,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, - + 0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x37,0x38,0x2e,0x68,0x61,0x73,0x43,0x6c,0x6f, + 0x75,0x64,0x73,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x28,0x28,0x5f,0x31,0x39, + 0x39,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x32,0x34,0x30,0x29,0x29,0x20, + 0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31, + 0x37,0x38,0x2e,0x74,0x69,0x6d,0x65,0x20,0x2a,0x20,0x30,0x2e,0x30,0x35,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x37,0x34,0x35,0x30,0x35,0x38,0x30,0x35,0x39,0x36,0x39, + 0x32,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x32,0x37,0x36,0x20,0x3d,0x20,0x66,0x62,0x6d,0x28,0x70,0x61,0x72,0x61,0x6d,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x69,0x6e,0x61,0x6c,0x20, + 0x3d,0x20,0x6d,0x69,0x78,0x28,0x66,0x69,0x6e,0x61,0x6c,0x2c,0x20,0x76,0x65,0x63, + 0x33,0x28,0x31,0x2e,0x30,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x6d,0x61, + 0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x5f,0x32,0x34,0x30,0x29,0x20,0x2a,0x20,0x28, + 0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x35,0x2c,0x20, + 0x31,0x2e,0x30,0x2c,0x20,0x5f,0x32,0x37,0x36,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33, + 0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30,0x39,0x32,0x38,0x39,0x35, + 0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x66,0x69,0x6e,0x61,0x6c,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x70,0x6f,0x73, + 0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x68,0x69,0x67,0x68,0x70, + 0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, + 0x5f,0x31,0x37,0x38,0x2e,0x73,0x75,0x6e,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x73,0x6b,0x79,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; /* #include @@ -978,19 +971,20 @@ vs_sky_source_metal_macos := u8.[ } float _240 = _199.y; final += (mix(_178.horizonHalo, float3(0.0), float3(fast::clamp(abs(_240) * 80.0, 0.0, 1.0))) * 0.100000001490116119384765625); - float3 param = ((_199 / float3(_240)) * 2.0) + float3(_178.time * 0.0500000007450580596923828125); - float _269 = fbm(param); - float3 _273 = final; - float3 _282 = mix(_273, float3(1.0), float3((fast::max(0.0, _240) * (smoothstep(0.5, 1.0, _269) * 0.300000011920928955078125)) * 2.0)); - final = _282; - return _282; + if (_178.hasClouds == 1) + { + float3 param = ((_199 / float3(_240)) * 2.0) + float3(_178.time * 0.0500000007450580596923828125); + float _276 = fbm(param); + final = mix(final, float3(1.0), float3((fast::max(0.0, _240) * (smoothstep(0.5, 1.0, _276) * 0.300000011920928955078125)) * 2.0)); + } + return final; } fragment main0_out main0(main0_in in [[stage_in]], constant sky_world_config& _178 [[buffer(0)]]) { main0_out out = {}; float3 param = fast::normalize(in.pos.xyz); - float3 param_1 = float3(0.485071241855621337890625, 0.72760689258575439453125, 0.485071241855621337890625); + float3 param_1 = float3(_178.sunPosition); out.frag_color = float4(sky(param, param_1, _178), 1.0); return out; } @@ -1237,50 +1231,46 @@ fs_sky_source_metal_macos := u8.[ 0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x31,0x30, 0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39, 0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x28, - 0x28,0x5f,0x31,0x39,0x39,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f, - 0x32,0x34,0x30,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2b,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x37,0x38,0x2e,0x74,0x69,0x6d,0x65,0x20, - 0x2a,0x20,0x30,0x2e,0x30,0x35,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x37,0x34,0x35, - 0x30,0x35,0x38,0x30,0x35,0x39,0x36,0x39,0x32,0x33,0x38,0x32,0x38,0x31,0x32,0x35, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x36, - 0x39,0x20,0x3d,0x20,0x66,0x62,0x6d,0x28,0x70,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x37,0x33,0x20, - 0x3d,0x20,0x66,0x69,0x6e,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x5f,0x32,0x38,0x32,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f, - 0x32,0x37,0x33,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a, - 0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x5f,0x32,0x34,0x30,0x29,0x20,0x2a, - 0x20,0x28,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x35, - 0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x5f,0x32,0x36,0x39,0x29,0x20,0x2a,0x20,0x30, - 0x2e,0x33,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30,0x39,0x32,0x38, - 0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x29,0x29,0x20,0x2a,0x20,0x32,0x2e, - 0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x69,0x6e,0x61,0x6c,0x20,0x3d, - 0x20,0x5f,0x32,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x5f,0x32,0x38,0x32,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d, - 0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61, - 0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20, - 0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f, - 0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x73,0x6b,0x79,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x5f,0x63,0x6f,0x6e,0x66,0x69,0x67,0x26,0x20,0x5f,0x31,0x37,0x38,0x20,0x5b,0x5b, - 0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74, - 0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, - 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x69,0x6e,0x2e,0x70,0x6f,0x73, - 0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x28,0x30,0x2e,0x34,0x38,0x35,0x30,0x37,0x31,0x32,0x34,0x31,0x38,0x35, - 0x35,0x36,0x32,0x31,0x33,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30, - 0x2e,0x37,0x32,0x37,0x36,0x30,0x36,0x38,0x39,0x32,0x35,0x38,0x35,0x37,0x35,0x34, - 0x33,0x39,0x34,0x35,0x33,0x31,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x38,0x35,0x30, - 0x37,0x31,0x32,0x34,0x31,0x38,0x35,0x35,0x36,0x32,0x31,0x33,0x33,0x37,0x38,0x39, - 0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x66, - 0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x28,0x73,0x6b,0x79,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x5f,0x31,0x37,0x38,0x29,0x2c,0x20,0x31,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, - 0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x69,0x66,0x20,0x28,0x5f,0x31,0x37,0x38,0x2e,0x68,0x61,0x73,0x43,0x6c,0x6f,0x75, + 0x64,0x73,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x20,0x3d,0x20,0x28,0x28,0x5f,0x31,0x39,0x39,0x20,0x2f,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x32,0x34,0x30,0x29,0x29,0x20,0x2a,0x20,0x32, + 0x2e,0x30,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x37, + 0x38,0x2e,0x74,0x69,0x6d,0x65,0x20,0x2a,0x20,0x30,0x2e,0x30,0x35,0x30,0x30,0x30, + 0x30,0x30,0x30,0x30,0x37,0x34,0x35,0x30,0x35,0x38,0x30,0x35,0x39,0x36,0x39,0x32, + 0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x37,0x36,0x20,0x3d,0x20,0x66, + 0x62,0x6d,0x28,0x70,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x69,0x6e,0x61,0x6c,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x66, + 0x69,0x6e,0x61,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30, + 0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x66,0x61,0x73,0x74,0x3a, + 0x3a,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x5f,0x32,0x34,0x30,0x29,0x20, + 0x2a,0x20,0x28,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e, + 0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x5f,0x32,0x37,0x36,0x29,0x20,0x2a,0x20, + 0x30,0x2e,0x33,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30,0x39,0x32, + 0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x29,0x29,0x20,0x2a,0x20,0x32, + 0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x69,0x6e,0x61,0x6c,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x73,0x6b,0x79, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x63,0x6f,0x6e,0x66,0x69,0x67,0x26,0x20,0x5f, + 0x31,0x37,0x38,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d, + 0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f, + 0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20, + 0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28, + 0x69,0x6e,0x2e,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x37,0x38,0x2e,0x73,0x75, + 0x6e,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x2e,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x73,0x6b,0x79,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x5f,0x31,0x37,0x38, + 0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, ]; sky_shader_desc :: (backend: sg_backend) -> sg_shader_desc { desc: sg_shader_desc; diff --git a/src/shaders/shader_sky.glsl b/src/shaders/shader_sky.glsl index f4a25e7..72ccf6d 100644 --- a/src/shaders/shader_sky.glsl +++ b/src/shaders/shader_sky.glsl @@ -113,8 +113,10 @@ vec3 sky(vec3 skypos, vec3 sunpos) { final = vec3(final); // Cirrus Clouds - float density = smoothstep(1.0 - cirrus, 1.0, fbm(npos.xyz / npos.y * 2.0 + time * 0.05)) * 0.3; - final.rgb = mix(final.rgb, vec3(1.0, 1.0, 1.0), max(0.0, npos.y) * density * 2.0); + if(hasClouds == 1) { + float density = smoothstep(1.0 - cirrus, 1.0, fbm(npos.xyz / npos.y * 2.0 + time * 0.05)) * 0.3; + final.rgb = mix(final.rgb, vec3(1.0, 1.0, 1.0), max(0.0, npos.y) * density * 2.0); + } return final; } @@ -123,7 +125,7 @@ vec3 sky(vec3 skypos, vec3 sunpos) { void main() { vec3 dir = normalize(pos.xyz); - vec3 color = sky(dir, normalize(vec3(0.6,0.9,0.6))); + vec3 color = sky(dir, sunPosition); frag_color = vec4(color, 1.0); } @end