fix bizarre issue with web perf and other stuff

This commit is contained in:
Tuomas Katajisto 2025-11-01 23:15:30 +02:00
parent 1667107e85
commit 2fd38144bb
16 changed files with 257 additions and 94 deletions

1
build_web.sh Executable file
View File

@ -0,0 +1 @@
jai first.jai - wasm release && rm -rf dist/packs/ && cp -r packs/ dist/ && rm dist/main.o

View File

@ -27,10 +27,16 @@ Iprof :: #import "Iprof"(IMPORT_MODE = .METAPROGRAM);
doWasmBuild := false;
hasTacoma := false;
releaseBuild := false;
iprof := false;
uncap_frames := false;
for arg : args {
if arg == "wasm" then doWasmBuild = true;
if arg == "tacoma" then hasTacoma = true;
if arg == "release" then releaseBuild = true;
if arg == "iprof" then iprof = true;
if arg == "iprof" then iprof = true;
if arg == "uncap_frames" then uncap_frames = true;
}
if doWasmBuild {
@ -81,6 +87,13 @@ 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_build_string("UNCAPPED_FRAMES :: false;", w);
if releaseBuild {
add_build_string("RELEASE_BUILD :: true;", w);
} else {
add_build_string("RELEASE_BUILD :: false;", w);
}
if is_directory("./game") {
add_build_string("USE_SAMPLE_GAME :: false;", w);
@ -149,7 +162,7 @@ Iprof :: #import "Iprof"(IMPORT_MODE = .METAPROGRAM);
set_build_options(opts, w);
iprof_plugin: *Iprof.My_Plugin;
profile := !releaseBuild;
profile := iprof;
if profile {
iprof_plugin = cast(*Iprof.My_Plugin) Iprof.get_plugin();
@ -174,6 +187,18 @@ Iprof :: #import "Iprof"(IMPORT_MODE = .METAPROGRAM);
add_build_string("USE_SAMPLE_GAME :: true;", w);
}
if uncap_frames {
add_build_string("UNCAPPED_FRAMES :: true;", w);
} else {
add_build_string("UNCAPPED_FRAMES :: false;", w);
}
if releaseBuild {
add_build_string("RELEASE_BUILD :: true;", w);
} else {
add_build_string("RELEASE_BUILD :: false;", w);
}
if profile {
add_build_string("HAS_IPROF :: true;", w);
iprof_plugin.add_source(iprof_plugin);

View File

@ -24,7 +24,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -51,7 +51,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -78,7 +78,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -105,7 +105,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -132,7 +132,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -159,7 +159,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -186,7 +186,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -213,7 +213,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -240,7 +240,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -267,7 +267,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -294,7 +294,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -321,7 +321,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -348,7 +348,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -375,7 +375,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -402,7 +402,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -429,7 +429,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -456,7 +456,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -483,7 +483,7 @@ VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller)
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)
_______________
Vulkan Version:
- available: 1.4.309
@ -509,3 +509,113 @@ Used Device Extensions :
VK_KHR_deferred_host_operations
VK_KHR_acceleration_structure
VK_KHR_ray_query
BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% 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: 1.0MB -> 0.3MB (0.6MB saved, 66.2% 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: 1.0MB -> 0.3MB (0.6MB saved, 66.2% 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: 1.0MB -> 0.3MB (0.6MB saved, 66.2% 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: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller)

3
mise.toml Normal file
View File

@ -0,0 +1,3 @@
[tasks]
build_web = "$HOME/bin/jai/bin/jai-linux first.jai - wasm release && rm -rf dist/packs/ && cp -r packs/ dist/ && rm dist/main.o"
ship_web = ""

View File

@ -1435,6 +1435,10 @@ sapp_html5_ask_leave_site :: (ask: bool) -> void #foreign sokol_app_clib;
sapp_html5_get_dropped_file_size :: (index: s32) -> u32 #foreign sokol_app_clib;
// HTML5: asynchronously load the content of a dropped file
sapp_html5_fetch_dropped_file :: (request: *sapp_html5_fetch_request) -> void #foreign sokol_app_clib;
// DEBUG DISABLE VSYNC:
sapp_glx_swapinterval :: (interval: s32) -> void #foreign sokol_app_clib;
// Metal: get bridged pointer to Metal device object
sapp_metal_get_device :: () -> *void #foreign sokol_app_clib;
// Metal: get bridged pointer to MTKView's current drawable of type CAMetalDrawable

View File

@ -5,7 +5,7 @@ build_lib_wasm_release() {
dst=$2
backend=$3
echo $dst
emcc -c -O2 -DNDEBUG -sMEMORY64 -sSHARED_MEMORY -DIMPL -D$backend c/$src.c
emcc -c -O2 -DNDEBUG -DSKIP_ERROR_CHECK -sMEMORY64 -sSHARED_MEMORY -DIMPL -D$backend c/$src.c
emar rcs $dst.a $src.o
}

View File

@ -10475,7 +10475,7 @@ _SOKOL_PRIVATE void _sapp_glx_swap_buffers(void) {
_sapp.glx.SwapBuffers(_sapp.x11.display, _sapp.glx.window);
}
_SOKOL_PRIVATE void _sapp_glx_swapinterval(int interval) {
void sapp_glx_swapinterval(int interval) {
if (_sapp.glx.EXT_swap_control) {
_sapp.glx.SwapIntervalEXT(_sapp.x11.display, _sapp.glx.window, interval);
}
@ -11731,7 +11731,7 @@ _SOKOL_PRIVATE void _sapp_linux_run(const sapp_desc* desc) {
_sapp_glx_choose_visual(&visual, &depth);
_sapp_x11_create_window(visual, depth);
_sapp_glx_create_context();
_sapp_glx_swapinterval(_sapp.swap_interval);
sapp_glx_swapinterval(_sapp.swap_interval);
#else
_sapp_egl_init();
#endif

View File

@ -5350,8 +5350,15 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_
#ifndef GL_COMPUTE_SHADER
#define GL_COMPUTE_SHADER 0x91B9
#endif
#ifndef SKIP_ERROR_CHECK
#ifndef _SG_GL_CHECK_ERROR
#define _SG_GL_CHECK_ERROR() { SOKOL_ASSERT(glGetError() == GL_NO_ERROR); }
#define _SG_GL_CHECK_ERROR() { }
#endif
#endif
#ifdef SKIP_ERROR_CHECK
#ifndef _SG_GL_CHECK_ERROR
#define _SG_GL_CHECK_ERROR() { }
#endif
#endif
#endif

View File

@ -32,9 +32,11 @@ stbi :: #import "stb_image";
#load "../game/game.jai";
}
last_frame_time : float64;
last_frame_time : float64; // timestamp of the last frame
delta\ _time : float64;
latest_frametime : float64; // latest frame generation duration
V_MAJOR :: 0;
V_MINOR :: 6;
@ -70,6 +72,7 @@ round_pow2 :: (v: float) -> s32 {
return cast(s32) (vi + 1);
}
debug_font : *Font;
init :: () {
sg_setup(*(sg_desc.{
@ -98,7 +101,8 @@ init :: () {
state.pass_action.colors[0] = .{ load_action = .LOAD };
init_asset_pack_load();
useless_mem : [1]u8;
debug_font = get_font_at_size(useless_mem, 15);
}
init_after_asset_pack :: () {
@ -127,6 +131,8 @@ init_after_asset_pack :: () {
// We want to do this last.
game_init();
#if UNCAPPED_FRAMES then sapp_glx_swapinterval(0);
}
is_in_reflection_pass : bool = false;
@ -138,6 +144,7 @@ frame :: () {
delta_time = get_time() - last_frame_time;
last_frame_time = get_time();
sfetch_dowork();
if mandatory_loads_done() && !init_after_mandatory_done {
@ -148,6 +155,8 @@ frame :: () {
if !mandatory_loads_done() then return;
fonsClearState(state.fons);
frame_start_time := get_time();
dpis := state.dpi_scale;
#if OS != .WASM { tick_profiler(); }
@ -173,6 +182,8 @@ frame :: () {
ui_clear_mouse_occluders();
ui_pass();
prepare_text(debug_font, tprint("frametime: % ms", latest_frametime * 1000));
draw_prepared_text(debug_font, 10, 10, .{0.0, 1.0, 0.0, 1.0});
draw_editor();
render();
input_per_frame_event_and_flag_update();
@ -182,6 +193,8 @@ frame :: () {
#if OS != .WASM { profiler_update(); }
reset_temporary_storage();
frame_end_time := get_time();
latest_frametime = frame_end_time - frame_start_time;
}
cleanup :: () {

View File

@ -1,12 +1,12 @@
#import,dir "../../modules/sokol-jai/sokol/app"(DEBUG = true);
#import,dir "../../modules/sokol-jai/sokol/gfx"(DEBUG = true);
#import,dir "../../modules/sokol-jai/sokol/gl"(DEBUG = true);
#import,dir "../../modules/sokol-jai/sokol/glue"(DEBUG = true);
#import,dir "../../modules/sokol-jai/sokol/shape"(DEBUG = true);
#import,dir "../../modules/sokol-jai/sokol/app"(DEBUG = RELEASE_BUILD);
#import,dir "../../modules/sokol-jai/sokol/gfx"(DEBUG = RELEASE_BUILD);
#import,dir "../../modules/sokol-jai/sokol/gl"(DEBUG = RELEASE_BUILD);
#import,dir "../../modules/sokol-jai/sokol/glue"(DEBUG = RELEASE_BUILD);
#import,dir "../../modules/sokol-jai/sokol/shape"(DEBUG = RELEASE_BUILD);
#import,dir "../../modules/sokol-jai/sokol/fontstash";
#import,dir "../../modules/sokol-jai/sokol/log"(DEBUG = true);
#import,dir "../../modules/sokol-jai/sokol/time"(DEBUG = true);
#import,dir "../../modules/sokol-jai/sokol/fetch"(DEBUG = true);
#import,dir "../../modules/sokol-jai/sokol/log"(DEBUG = RELEASE_BUILD);
#import,dir "../../modules/sokol-jai/sokol/time"(DEBUG = RELEASE_BUILD);
#import,dir "../../modules/sokol-jai/sokol/fetch"(DEBUG = RELEASE_BUILD);
#load "../main.jai";
@ -38,6 +38,7 @@ sapp_init :: () {
window_title = wi.title,
// icon = .{ sokol_default = true },
logger = .{ func = slog_func },
swap_interval = 0,
sample_count = 1, // I think I'll end up pixelifying the whole thing, so I don't think we need MSAA.
}));
}

View File

@ -55,6 +55,7 @@ body {
<body style="background:black">
<canvas class="game" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
<script type="text/javascript">
window.focus()
var Module = {
onRuntimeInitialized: function () {
const originalSet = HEAPU8.set.bind(HEAPU8);

View File

@ -167,7 +167,14 @@ backend_draw_trile_positions_main :: (trile : string, amount : s32, worldConf: *
bindings.images[0] = trilegfx.trixel_colors;
bindings.images[1] = g_ssaobuf;
bindings.samplers[2] = g_shadowmap_sampler;
if !in_shadowmap_pass {
bindings.images[2] = g_shadowmap;
} else {
// Just put something in this slot instead of the shadowmap
// so we don't have a circular shadowmap drawing situation.
// The texture is not used in shadowmap pass.
bindings.images[2] = g_rendertex_depth;
}
fs_params : Trile_Fs_Params;
fs_params.mvp_shadow = shadow_mvp.floats;
@ -218,8 +225,8 @@ backend_draw_ground :: (wc: *World_Config) {
vs_params.mvp = mvp.floats;
vs_params.planeHeight = wc.planeHeight;
sg_apply_pipeline(gPipelines.plane.pipeline);
gPipelines.plane.bind.samplers[2] = g_shadowmap_sampler;
gPipelines.plane.bind.images[2] = g_shadowmap;
gPipelines.plane.bind.samplers[1] = g_shadowmap_sampler;
gPipelines.plane.bind.images[1] = g_shadowmap;
sg_apply_bindings(*gPipelines.plane.bind);
sg_apply_uniforms(UB_plane_vs_params, *(sg_range.{ ptr = *vs_params, size = size_of(type_of(vs_params)) }));
sg_apply_uniforms(UB_plane_fs_params, *(sg_range.{ ptr = *fs_params, size = size_of(type_of(fs_params)) }));
@ -309,14 +316,14 @@ backend_process_command_buckets :: () {
current_trile_offset_index = 0; // This is not optimal, but it is nice and simple.
// 4. G-Buffer pass
in_gbuffer_pass = true;
sg_begin_pass(*(sg_pass.{ action = state.pass_action_clear_gbuf, attachments = g_gbuf_attachments}));
for render_command_buckets.gbuffer {
backend_handle_command(it);
}
sg_end_pass();
in_gbuffer_pass = false;
current_trile_offset_index = 0; // This is not optimal, but it is nice and simple.
// in_gbuffer_pass = true;
// sg_begin_pass(*(sg_pass.{ action = state.pass_action_clear_gbuf, attachments = g_gbuf_attachments}));
// for render_command_buckets.gbuffer {
// backend_handle_command(it);
// }
// sg_end_pass();
// in_gbuffer_pass = false;
// current_trile_offset_index = 0; // This is not optimal, but it is nice and simple.
sg_begin_pass(*(sg_pass.{ action = state.pass_action_clear, attachments = g_postprocess_attach_a }));
sg_apply_pipeline(gPipelines.ssao.pipeline);

View File

@ -1,4 +1,4 @@
SHADOWMAP_SIZE :: 2000;
SHADOWMAP_SIZE :: 1000;
Pipeline_Binding :: struct {
pipeline : sg_pipeline;
@ -580,14 +580,9 @@ create_plane_pipeline :: () {
compare = .LESS,
}));
gPipelines.plane.bind.samplers[1] = sg_make_sampler(*(sg_sampler_desc.{
wrap_u = .CLAMP_TO_EDGE,
wrap_v = .CLAMP_TO_EDGE,
min_filter = .NEAREST,
mag_filter = .NEAREST,
}));
gPipelines.plane.bind.samplers[1] = g_shadowmap_sampler;
gPipelines.plane.bind.samplers[3] = sg_make_sampler(*(sg_sampler_desc.{
gPipelines.plane.bind.samplers[2] = sg_make_sampler(*(sg_sampler_desc.{
wrap_u = .REPEAT,
wrap_v = .REPEAT,
min_filter = .LINEAR,
@ -602,8 +597,6 @@ create_plane_pipeline :: () {
sample_count = 1,
usage = .DYNAMIC,
};
gPipelines.plane.bind.images[1] = sg_make_image(*ground_img_desc);
}
create_arbtri_pipeline :: () {
@ -1008,7 +1001,7 @@ create_ssao_pipeline :: () {
}
init_plane_textures :: () {
gPipelines.plane.bind.images[3] = create_texture_from_pack("./resources/utiltex/water_small.png");
gPipelines.plane.bind.images[2] = create_texture_from_pack("./resources/utiltex/water_small.png");
}
g_plane_gbuffer_vertex_buffer : sg_buffer;

View File

@ -71,8 +71,8 @@ create_shadow_viewproj :: (cam: *Camera, conf: *World_Config) -> Matrix4 {
max_v.y = max(max_v.y, transformed_corner.y);
max_v.z = max(max_v.z, transformed_corner.z);
}
max_v.xy = avg.xy + Vector2.{50, 50};
min_v.xy = avg.xy - Vector2.{50, 50};
max_v.xy = avg.xy + Vector2.{20, 20};
min_v.xy = avg.xy - Vector2.{20, 20};
proj := matrix_ortho(min_v.x, max_v.x, min_v.y, max_v.y, -max_v.z-100, -min_v.z);
return view*proj;

View File

@ -31,7 +31,7 @@
Image type: ._2D
Sample type: .FLOAT
Multisampled: false
Bind slot: IMG_normal_map => 3
Bind slot: IMG_normal_map => 2
Image 'reftex':
Image type: ._2D
Sample type: .FLOAT
@ -39,7 +39,7 @@
Bind slot: IMG_reftex => 0
Sampler 'normalsmp':
Type: .FILTERING
Bind slot: SMP_normalsmp => 3
Bind slot: SMP_normalsmp => 2
Sampler 'refsmp':
Type: .FILTERING
Bind slot: SMP_refsmp => 0
@ -49,9 +49,9 @@ UB_plane_vs_params :: 0;
UB_plane_world_config :: 1;
UB_plane_data :: 2;
UB_plane_fs_params :: 3;
IMG_normal_map :: 3;
IMG_normal_map :: 2;
IMG_reftex :: 0;
SMP_normalsmp :: 3;
SMP_normalsmp :: 2;
SMP_refsmp :: 0;
Plane_Vs_Params :: struct {
mvp: [16]float;
@ -1594,17 +1594,17 @@ plane_shader_desc :: (backend: sg_backend) -> sg_shader_desc {
desc.images[0].multisampled = false;
desc.images[0].image_type = ._2D;
desc.images[0].sample_type = .FLOAT;
desc.images[3].stage = .FRAGMENT;
desc.images[3].multisampled = false;
desc.images[3].image_type = ._2D;
desc.images[3].sample_type = .FLOAT;
desc.images[2].stage = .FRAGMENT;
desc.images[2].multisampled = false;
desc.images[2].image_type = ._2D;
desc.images[2].sample_type = .FLOAT;
desc.samplers[0].stage = .FRAGMENT;
desc.samplers[0].sampler_type = .FILTERING;
desc.samplers[3].stage = .FRAGMENT;
desc.samplers[3].sampler_type = .FILTERING;
desc.samplers[2].stage = .FRAGMENT;
desc.samplers[2].sampler_type = .FILTERING;
desc.image_sampler_pairs[0].stage = .FRAGMENT;
desc.image_sampler_pairs[0].image_slot = 3;
desc.image_sampler_pairs[0].sampler_slot = 3;
desc.image_sampler_pairs[0].image_slot = 2;
desc.image_sampler_pairs[0].sampler_slot = 2;
desc.image_sampler_pairs[0].glsl_name = "normal_map_normalsmp";
desc.image_sampler_pairs[1].stage = .FRAGMENT;
desc.image_sampler_pairs[1].image_slot = 0;
@ -1705,17 +1705,17 @@ plane_shader_desc :: (backend: sg_backend) -> sg_shader_desc {
desc.images[0].multisampled = false;
desc.images[0].image_type = ._2D;
desc.images[0].sample_type = .FLOAT;
desc.images[3].stage = .FRAGMENT;
desc.images[3].multisampled = false;
desc.images[3].image_type = ._2D;
desc.images[3].sample_type = .FLOAT;
desc.images[2].stage = .FRAGMENT;
desc.images[2].multisampled = false;
desc.images[2].image_type = ._2D;
desc.images[2].sample_type = .FLOAT;
desc.samplers[0].stage = .FRAGMENT;
desc.samplers[0].sampler_type = .FILTERING;
desc.samplers[3].stage = .FRAGMENT;
desc.samplers[3].sampler_type = .FILTERING;
desc.samplers[2].stage = .FRAGMENT;
desc.samplers[2].sampler_type = .FILTERING;
desc.image_sampler_pairs[0].stage = .FRAGMENT;
desc.image_sampler_pairs[0].image_slot = 3;
desc.image_sampler_pairs[0].sampler_slot = 3;
desc.image_sampler_pairs[0].image_slot = 2;
desc.image_sampler_pairs[0].sampler_slot = 2;
desc.image_sampler_pairs[0].glsl_name = "normal_map_normalsmp";
desc.image_sampler_pairs[1].stage = .FRAGMENT;
desc.image_sampler_pairs[1].image_slot = 0;
@ -1748,20 +1748,20 @@ plane_shader_desc :: (backend: sg_backend) -> sg_shader_desc {
desc.images[0].image_type = ._2D;
desc.images[0].sample_type = .FLOAT;
desc.images[0].msl_texture_n = 1;
desc.images[3].stage = .FRAGMENT;
desc.images[3].multisampled = false;
desc.images[3].image_type = ._2D;
desc.images[3].sample_type = .FLOAT;
desc.images[3].msl_texture_n = 0;
desc.images[2].stage = .FRAGMENT;
desc.images[2].multisampled = false;
desc.images[2].image_type = ._2D;
desc.images[2].sample_type = .FLOAT;
desc.images[2].msl_texture_n = 0;
desc.samplers[0].stage = .FRAGMENT;
desc.samplers[0].sampler_type = .FILTERING;
desc.samplers[0].msl_sampler_n = 1;
desc.samplers[3].stage = .FRAGMENT;
desc.samplers[3].sampler_type = .FILTERING;
desc.samplers[3].msl_sampler_n = 0;
desc.samplers[2].stage = .FRAGMENT;
desc.samplers[2].sampler_type = .FILTERING;
desc.samplers[2].msl_sampler_n = 0;
desc.image_sampler_pairs[0].stage = .FRAGMENT;
desc.image_sampler_pairs[0].image_slot = 3;
desc.image_sampler_pairs[0].sampler_slot = 3;
desc.image_sampler_pairs[0].image_slot = 2;
desc.image_sampler_pairs[0].sampler_slot = 2;
desc.image_sampler_pairs[1].stage = .FRAGMENT;
desc.image_sampler_pairs[1].image_slot = 0;
desc.image_sampler_pairs[1].sampler_slot = 0;

View File

@ -64,15 +64,13 @@ layout(binding=2) uniform plane_data {
// Texture bindings
layout(binding = 0) uniform texture2D reftex;
layout(binding = 1) uniform texture2D groundtex;
layout(binding = 2) uniform texture2D shadow;
layout(binding = 3) uniform texture2D normal_map;
layout(binding = 1) uniform texture2D shadow;
layout(binding = 2) uniform texture2D normal_map;
// Sampler bindings
layout(binding = 0) uniform sampler refsmp;
layout(binding = 1) uniform sampler groundsmp;
layout(binding = 2) uniform sampler shadowsmp;
layout(binding = 3) uniform sampler normalsmp;
layout(binding = 1) uniform sampler shadowsmp;
layout(binding = 2) uniform sampler normalsmp;
vec3 fresnelSchlick(float cosTheta) {
vec3 F0 = vec3(0.02);