Scene picking, shadow mapping adjustments
This commit is contained in:
@@ -69,69 +69,6 @@ if _scene == null {
|
||||
_scene = current_scene; }
|
||||
p, locator := find_and_occupy_empty_slot(*_scene.by_type._Item); p._locator = locator; register_entity(_scene, p); p.transform = create_identity_transform(); init_entity(p); return p; }
|
||||
|
||||
//
|
||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||
//
|
||||
serialize_entity :: (e: *Item, builder: *String_Builder) {
|
||||
print_to_builder(builder, "type: Item\n");
|
||||
print_to_builder(builder, "entity.enabled: %\n", e.entity.enabled);
|
||||
print_to_builder(builder, "entity.flags: %\n", e.entity.flags);
|
||||
print_to_builder(builder, "entity.transform.position.x: %\n", e.entity.transform.position.x);
|
||||
print_to_builder(builder, "entity.transform.position.y: %\n", e.entity.transform.position.y);
|
||||
print_to_builder(builder, "entity.transform.position.z: %\n", e.entity.transform.position.z);
|
||||
print_to_builder(builder, "entity.transform.orientation.x: %\n", e.entity.transform.orientation.x);
|
||||
print_to_builder(builder, "entity.transform.orientation.y: %\n", e.entity.transform.orientation.y);
|
||||
print_to_builder(builder, "entity.transform.orientation.z: %\n", e.entity.transform.orientation.z);
|
||||
print_to_builder(builder, "entity.transform.orientation.w: %\n", e.entity.transform.orientation.w);
|
||||
print_to_builder(builder, "entity.transform.scale.x: %\n", e.entity.transform.scale.x);
|
||||
print_to_builder(builder, "entity.transform.scale.y: %\n", e.entity.transform.scale.y);
|
||||
print_to_builder(builder, "entity.transform.scale.z: %\n", e.entity.transform.scale.z);
|
||||
print_to_builder(builder, "entity.snap_offset.x: %\n", e.entity.snap_offset.x);
|
||||
print_to_builder(builder, "entity.snap_offset.y: %\n", e.entity.snap_offset.y);
|
||||
print_to_builder(builder, "entity.snap_offset.z: %\n", e.entity.snap_offset.z);
|
||||
}
|
||||
|
||||
//
|
||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||
//
|
||||
deserialize_entity :: (scene: *Scene, lines: [] string, e: *Item) {
|
||||
for line: lines {
|
||||
values := split(line, ":");
|
||||
if values.count == 2 {
|
||||
if trim(values[0], " ") == {
|
||||
case "entity.enabled";
|
||||
scan2(values[1], "%", *e.entity.enabled);
|
||||
case "entity.transform.position.x";
|
||||
scan2(values[1], "%", *e.entity.transform.position.x);
|
||||
case "entity.transform.position.y";
|
||||
scan2(values[1], "%", *e.entity.transform.position.y);
|
||||
case "entity.transform.position.z";
|
||||
scan2(values[1], "%", *e.entity.transform.position.z);
|
||||
case "entity.transform.orientation.x";
|
||||
scan2(values[1], "%", *e.entity.transform.orientation.x);
|
||||
case "entity.transform.orientation.y";
|
||||
scan2(values[1], "%", *e.entity.transform.orientation.y);
|
||||
case "entity.transform.orientation.z";
|
||||
scan2(values[1], "%", *e.entity.transform.orientation.z);
|
||||
case "entity.transform.orientation.w";
|
||||
scan2(values[1], "%", *e.entity.transform.orientation.w);
|
||||
case "entity.transform.scale.x";
|
||||
scan2(values[1], "%", *e.entity.transform.scale.x);
|
||||
case "entity.transform.scale.y";
|
||||
scan2(values[1], "%", *e.entity.transform.scale.y);
|
||||
case "entity.transform.scale.z";
|
||||
scan2(values[1], "%", *e.entity.transform.scale.z);
|
||||
case "entity.snap_offset.x";
|
||||
scan2(values[1], "%", *e.entity.snap_offset.x);
|
||||
case "entity.snap_offset.y";
|
||||
scan2(values[1], "%", *e.entity.snap_offset.y);
|
||||
case "entity.snap_offset.z";
|
||||
scan2(values[1], "%", *e.entity.snap_offset.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||
//
|
||||
@@ -199,6 +136,69 @@ deserialize_entity :: (scene: *Scene, lines: [] string, e: *Block) {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||
//
|
||||
serialize_entity :: (e: *Item, builder: *String_Builder) {
|
||||
print_to_builder(builder, "type: Item\n");
|
||||
print_to_builder(builder, "entity.enabled: %\n", e.entity.enabled);
|
||||
print_to_builder(builder, "entity.flags: %\n", e.entity.flags);
|
||||
print_to_builder(builder, "entity.transform.position.x: %\n", e.entity.transform.position.x);
|
||||
print_to_builder(builder, "entity.transform.position.y: %\n", e.entity.transform.position.y);
|
||||
print_to_builder(builder, "entity.transform.position.z: %\n", e.entity.transform.position.z);
|
||||
print_to_builder(builder, "entity.transform.orientation.x: %\n", e.entity.transform.orientation.x);
|
||||
print_to_builder(builder, "entity.transform.orientation.y: %\n", e.entity.transform.orientation.y);
|
||||
print_to_builder(builder, "entity.transform.orientation.z: %\n", e.entity.transform.orientation.z);
|
||||
print_to_builder(builder, "entity.transform.orientation.w: %\n", e.entity.transform.orientation.w);
|
||||
print_to_builder(builder, "entity.transform.scale.x: %\n", e.entity.transform.scale.x);
|
||||
print_to_builder(builder, "entity.transform.scale.y: %\n", e.entity.transform.scale.y);
|
||||
print_to_builder(builder, "entity.transform.scale.z: %\n", e.entity.transform.scale.z);
|
||||
print_to_builder(builder, "entity.snap_offset.x: %\n", e.entity.snap_offset.x);
|
||||
print_to_builder(builder, "entity.snap_offset.y: %\n", e.entity.snap_offset.y);
|
||||
print_to_builder(builder, "entity.snap_offset.z: %\n", e.entity.snap_offset.z);
|
||||
}
|
||||
|
||||
//
|
||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||
//
|
||||
deserialize_entity :: (scene: *Scene, lines: [] string, e: *Item) {
|
||||
for line: lines {
|
||||
values := split(line, ":");
|
||||
if values.count == 2 {
|
||||
if trim(values[0], " ") == {
|
||||
case "entity.enabled";
|
||||
scan2(values[1], "%", *e.entity.enabled);
|
||||
case "entity.transform.position.x";
|
||||
scan2(values[1], "%", *e.entity.transform.position.x);
|
||||
case "entity.transform.position.y";
|
||||
scan2(values[1], "%", *e.entity.transform.position.y);
|
||||
case "entity.transform.position.z";
|
||||
scan2(values[1], "%", *e.entity.transform.position.z);
|
||||
case "entity.transform.orientation.x";
|
||||
scan2(values[1], "%", *e.entity.transform.orientation.x);
|
||||
case "entity.transform.orientation.y";
|
||||
scan2(values[1], "%", *e.entity.transform.orientation.y);
|
||||
case "entity.transform.orientation.z";
|
||||
scan2(values[1], "%", *e.entity.transform.orientation.z);
|
||||
case "entity.transform.orientation.w";
|
||||
scan2(values[1], "%", *e.entity.transform.orientation.w);
|
||||
case "entity.transform.scale.x";
|
||||
scan2(values[1], "%", *e.entity.transform.scale.x);
|
||||
case "entity.transform.scale.y";
|
||||
scan2(values[1], "%", *e.entity.transform.scale.y);
|
||||
case "entity.transform.scale.z";
|
||||
scan2(values[1], "%", *e.entity.transform.scale.z);
|
||||
case "entity.snap_offset.x";
|
||||
scan2(values[1], "%", *e.entity.snap_offset.x);
|
||||
case "entity.snap_offset.y";
|
||||
scan2(values[1], "%", *e.entity.snap_offset.y);
|
||||
case "entity.snap_offset.z";
|
||||
scan2(values[1], "%", *e.entity.snap_offset.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// String added via add_build_string() from c:/Personal/games/onegameamonth/oct24/modules/Coven/metaprogram.jai:272.
|
||||
//
|
||||
|
||||
@@ -35,7 +35,7 @@ Camera :: struct {
|
||||
dirty : bool;
|
||||
}
|
||||
|
||||
create_perspective_camera :: (position: Vector3 = .{}, fov: float, aspect: float, yaw: float = 0.0, pitch: float = 0.0, roll: float = 0.0, z_near: float = 0.1, z_far: float = 200.0) -> Camera {
|
||||
create_perspective_camera :: (position: Vector3 = .{}, fov: float, aspect: float, yaw: float = 0.0, pitch: float = 0.0, roll: float = 0.0, z_near: float = 0.1, z_far: float = 100.0) -> Camera {
|
||||
camera : Camera;
|
||||
camera.type = .PERSPECTIVE;
|
||||
camera.world_up = .{0,1,0};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#load "../ui/widgets.jai";
|
||||
|
||||
pick_scene_view_at :: (coordinates: Vector2) {
|
||||
ray := normalized_screen_to_ray_v2(*editor.camera, coordinates);
|
||||
ray := normalized_screen_to_ray_v2(*current_scene.camera, coordinates);
|
||||
|
||||
if editor.should_check_entities {
|
||||
hit_entity : *Entity;
|
||||
@@ -126,7 +126,7 @@ editor_ui :: () {
|
||||
|
||||
state := ui_interactable_texture(get_texture_from_pass("UI Blend Pass"));
|
||||
if state.left_mouse_down {
|
||||
//pick_scene_view_at(.{state.normalized_local_mouse_coordinates.x, 1.0 - state.normalized_local_mouse_coordinates.y});
|
||||
pick_scene_view_at(.{state.normalized_local_mouse_coordinates.x, 1.0-state.normalized_local_mouse_coordinates.y});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ calc_tight_light_projection :: (camera: Camera, light_direction: Vector3) -> Mat
|
||||
inv_camera_view := inverse(camera.view_matrix);
|
||||
view_frustum_in_world_space := transform(frustum, inv_camera_view);
|
||||
|
||||
// Transform world space camera frustum to light space (with origin in 0,0,0)
|
||||
light_view := look_at_lh(.{0,0,0}, light_direction, .{0,1,0});
|
||||
light_space_frustum := transform(view_frustum_in_world_space, light_view);
|
||||
|
||||
@@ -23,7 +22,22 @@ calc_tight_light_projection :: (camera: Camera, light_direction: Vector3) -> Mat
|
||||
light_space_frustum = transform(view_frustum_in_world_space, light_view);
|
||||
|
||||
final_aabb := get_frustum_aabb(light_space_frustum);
|
||||
// @Incomplete: Padding
|
||||
|
||||
// Texel size calculation based on shadow map resolution (e.g., 2048x2048)
|
||||
texel_size_x := (final_aabb.max.x - final_aabb.min.x) / 4096.0;
|
||||
texel_size_y := (final_aabb.max.y - final_aabb.min.y) / 4096.0;
|
||||
|
||||
// Snap the minimum bounds of the AABB to the nearest texel
|
||||
final_aabb.min.x = floor(final_aabb.min.x / texel_size_x) * texel_size_x;
|
||||
final_aabb.min.y = floor(final_aabb.min.y / texel_size_y) * texel_size_y;
|
||||
|
||||
// Recalculate the max bounds based on snapped min
|
||||
final_aabb.max.x = final_aabb.min.x + (texel_size_x * 4096.0);
|
||||
final_aabb.max.y = final_aabb.min.y + (texel_size_y * 4096.0);
|
||||
|
||||
// Padding
|
||||
final_aabb.min -= .{8,5,8};
|
||||
final_aabb.max += .{8,50, 8};
|
||||
|
||||
light_projection := orthographic_lh_projection_matrix(final_aabb.min.x, final_aabb.max.x, final_aabb.min.y, final_aabb.max.y, final_aabb.min.z, final_aabb.max.z);
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ ui_box_make :: (flags: UI_Box_Flags, hash: u32) -> *UI_Box {
|
||||
|
||||
if parent != null {
|
||||
parent.num_children += 1;
|
||||
//actual_hash += parent.hash;
|
||||
actual_hash += parent.hash * xx parent.num_children;
|
||||
//actual_hash += xx (parent.num_children*2);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ ui_toolbar_button :: (text: string, identifier: s64 = 0, loc := #caller_location
|
||||
return box.interaction.clicked, box.interaction;
|
||||
}
|
||||
|
||||
ui_label :: (text: string, text_color: Color = .{1,1,1,1}, identifier: s64 = 0, loc := #caller_location) {
|
||||
ui_label_animated :: (text: string, text_color: Color = .{1,1,1,1}, identifier: s64 = 0, loc := #caller_location) {
|
||||
ui_set_next_text(text);
|
||||
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
|
||||
ui_set_next_text_color(text_color);
|
||||
@@ -78,6 +78,16 @@ ui_label :: (text: string, text_color: Color = .{1,1,1,1}, identifier: s64 = 0,
|
||||
box := ui_box_make(.DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
|
||||
}
|
||||
|
||||
ui_label :: (text: string, text_color: Color = .{1,1,1,1}, identifier: s64 = 0, loc := #caller_location) {
|
||||
ui_set_next_text(text);
|
||||
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
|
||||
ui_set_next_text_color(text_color);
|
||||
ui_set_next_size_x(.TEXT_DIM);
|
||||
ui_set_next_size_y(.TEXT_DIM);
|
||||
ui_set_next_padding(5);
|
||||
box := ui_box_make(.DRAW_TEXT, get_hash(loc, identifier));
|
||||
}
|
||||
|
||||
ui_label_fill_parent_x :: (text: string, identifier: s64 = 0, loc := #caller_location) {
|
||||
ui_set_next_text(text);
|
||||
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
|
||||
|
||||
Reference in New Issue
Block a user