Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frustum culling #1642

Merged
merged 32 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ad6a870
Fixed bug with opening files with \r on windows
nikhilghosh75 Apr 26, 2024
07e7c62
Implemented frustum culling
nikhilghosh75 Apr 26, 2024
e463962
Implemented stresstest 1
nikhilghosh75 Apr 26, 2024
84fa57b
Added additional comments to the frustum culling logic
nikhilghosh75 Apr 26, 2024
94f9a46
Fixed styling
nikhilghosh75 Apr 26, 2024
e62b1b9
Fixed various checks
nikhilghosh75 Apr 26, 2024
d70ae7f
Added name to mailmap
nikhilghosh75 Apr 26, 2024
03da156
Added name to copying.md
nikhilghosh75 Apr 26, 2024
87a21a8
renderer: Fix imports and windows settings.
heinezen Jul 13, 2024
c3805cd
Fix name parsing in copying.md
heinezen Jul 13, 2024
9446165
renderer: Fix camera unifs for stresstest 1.
heinezen Jul 13, 2024
acc9c96
renderer: Get frustum from camera.
heinezen Jul 13, 2024
34cc059
renderer: Fix object position fetching.
heinezen Jul 14, 2024
5f95f21
renderer: Fix position curve in stresstest 1.
heinezen Jul 14, 2024
69841ad
etc: Fix time pretty print for Keyframe.
heinezen Jul 14, 2024
0df247c
renderer: Resize frustum to exact camera boundaries.
heinezen Jul 14, 2024
189d916
renderer: Fetch updates before checking that object is in frustrum.
heinezen Jul 14, 2024
f114994
renderer: Move camera constants to different file.
heinezen Jul 14, 2024
f3365cf
renderer: Construct frustum with parameters.
heinezen Jul 14, 2024
d88fb47
renderer: Rename Frustum class to Frustum3d.
heinezen Jul 15, 2024
6926049
renderer: 2D Frustum implementation.
heinezen Jul 16, 2024
0c0efa6
renderer: Get max bounds for animations.
heinezen Jul 18, 2024
7391bc2
renderer: Create 2D frustum for sprites.
heinezen Jul 18, 2024
769154b
renderer: Replace 3D frustum with 2D frustum in world renderer.
heinezen Jul 18, 2024
d7a8e5b
renderer: Use correct zoom value for 2D frustum.
heinezen Jul 18, 2024
33021dc
renderer: Zig-zag movement in and out of camera view in stressttest 1.
heinezen Jul 18, 2024
04bf89e
renderer: Construct camera frustumson the fly.
heinezen Jul 18, 2024
8edeb9d
renderer: Skip scaled vector creation in frustum.
heinezen Jul 18, 2024
b457b87
renderer: Inclide model matrix in 2D frustum check.
heinezen Jul 19, 2024
e97a944
renderer: Enable frustum culling with flag in world stage.
heinezen Jul 19, 2024
a608d26
renderer: Enable GL_LINE_LOOP vertex primitive.
heinezen Jul 21, 2024
8ba6a75
renderer: Frustum culling demo.
heinezen Jul 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ Tobias Feldballe <tobias@osandweb.dk> <tobi.fp@gmail.com>
Tobias Feldballe <tobias@osandweb.dk> <tf@jumpstory.com>
Jonas Borchelt <jonas.borchelt@connected.link>
Derek Frogget <fro22003@byui.edu> <114030121+derekfrogget@users.noreply.github.com>
Nikhil Ghosh <nghosh606@gmail.com>
37 changes: 37 additions & 0 deletions assets/test/shaders/demo_6_2d.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#version 330

in vec2 vert_uv;

layout(location=0) out vec4 col;

uniform sampler2D tex;

// position (top left corner) and size: (x, y, width, height)
uniform vec4 tile_params;

vec2 uv = vec2(
vert_uv.x * tile_params.z + tile_params.x,
vert_uv.y * tile_params.w + tile_params.y
);

void main() {
vec4 tex_val = texture(tex, uv);
int alpha = int(round(tex_val.a * 255));
switch (alpha) {
case 0:
col = tex_val;
discard;
case 254:
col = vec4(1.0f, 0.0f, 0.0f, 1.0f);
break;
case 252:
col = vec4(0.0f, 1.0f, 0.0f, 1.0f);
break;
case 250:
col = vec4(0.0f, 0.0f, 1.0f, 1.0f);
break;
default:
col = tex_val;
break;
}
}
83 changes: 83 additions & 0 deletions assets/test/shaders/demo_6_2d.vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#version 330

layout(location=0) in vec2 v_position;
layout(location=1) in vec2 uv;

out vec2 vert_uv;

// camera parameters for transforming the object position
// and scaling the subtex to the correct size
layout (std140) uniform camera {
// view matrix (world to view space)
mat4 view;
// projection matrix (view to clip space)
mat4 proj;
// inverse zoom factor (1.0 / zoom)
// high zoom = upscale subtex
// low zoom = downscale subtex
float inv_zoom;
// inverse viewport size (1.0 / viewport size)
vec2 inv_viewport_size;
};

// position of the object in world space
uniform vec3 obj_world_position;

// parameters for scaling and moving the subtex
// to the correct position in clip space

// animation scalefactor
// scales the vertex positions so that they
// match the subtex dimensions
//
// high animation scale = downscale subtex
// low animation scale = upscale subtex
uniform float scale;

// size of the subtex (in pixels)
uniform vec2 subtex_size;

// offset of the subtex anchor point
// from the subtex center (in pixels)
// used to move the subtex so that the anchor point
// is at the object position
uniform vec2 anchor_offset;

void main() {
// translate the position of the object from world space to clip space
// this is the position where we want to draw the subtex in 2D
vec4 obj_clip_pos = proj * view * vec4(obj_world_position, 1.0);

// subtex has to be scaled to account for the zoom factor
// and the animation scale factor. essentially this is (animation scale / zoom).
float zoom_scale = scale * inv_zoom;

// Scale the subtex vertices
// we have to account for the viewport size to get the correct dimensions
// and then scale the subtex to the zoom factor to get the correct size
vec2 vert_scale = zoom_scale * subtex_size * inv_viewport_size;

// Scale the anchor offset with the same method as above
// to get the correct anchor position in the viewport
vec2 anchor_scale = zoom_scale * anchor_offset * inv_viewport_size;

// offset the clip position by the offset of the subtex anchor
// imagine this as pinning the subtex to the object position at the subtex anchor point
obj_clip_pos += vec4(anchor_scale.x, anchor_scale.y, 0.0, 0.0);

// create a move matrix for positioning the vertices
// uses the vert scale and the transformed object position in clip space
mat4 move = mat4(vert_scale.x, 0.0, 0.0, 0.0,
0.0, vert_scale.y, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
obj_clip_pos.x, obj_clip_pos.y, obj_clip_pos.z, 1.0);

// calculate the final vertex position
gl_Position = move * vec4(v_position, 0.0, 1.0);

// flip y axis because OpenGL uses bottom-left as its origin
float uv_x = uv.x;
float uv_y = 1.0 - uv.y;

vert_uv = vec2(uv_x, uv_y);
}
7 changes: 7 additions & 0 deletions assets/test/shaders/demo_6_2d_frame.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#version 330

out vec4 col;

void main() {
col = vec4(1.0, 0.0, 0.0, 0.8);
}
58 changes: 58 additions & 0 deletions assets/test/shaders/demo_6_2d_frame.vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#version 330

layout(location=0) in vec2 v_position;

// camera parameters for transforming the object position
// and scaling the subtex to the correct size
layout (std140) uniform camera {
// view matrix (world to view space)
mat4 view;
// projection matrix (view to clip space)
mat4 proj;
// inverse zoom factor (1.0 / zoom)
float inv_zoom;
// inverse viewport size (1.0 / viewport size)
vec2 inv_viewport_size;
};

// position of the object in world space
uniform vec3 obj_world_position;

// parameters for scaling and moving the subtex
// to the correct position in clip space

// animation scalefactor
// scales the vertex positions so that they
// match the subtex dimensions
//
// high animation scale = downscale subtex
// low animation scale = upscale subtex
uniform float scale;

// size of the frame (in pixels)
uniform vec2 frame_size;

void main() {
// translate the position of the object from world space to clip space
// this is the position where we want to draw the subtex in 2D
vec4 obj_clip_pos = proj * view * vec4(obj_world_position, 1.0);

// subtex has to be scaled to account for the zoom factor
// and the animation scale factor. essentially this is (animation scale / zoom).
float zoom_scale = scale * inv_zoom;

// Scale the subtex vertices
// we have to account for the viewport size to get the correct dimensions
// and then scale the frame to the zoom factor to get the correct size
vec2 vert_scale = zoom_scale * frame_size * inv_viewport_size;

// create a move matrix for positioning the vertices
// uses the vert scale and the transformed object position in clip space
mat4 move = mat4(vert_scale.x, 0.0, 0.0, 0.0,
0.0, vert_scale.y, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
obj_clip_pos.x, obj_clip_pos.y, obj_clip_pos.z, 1.0);

// calculate the final vertex position
gl_Position = move * vec4(v_position, 0.0, 1.0);
}
13 changes: 13 additions & 0 deletions assets/test/shaders/demo_6_3d.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#version 330

in vec2 tex_pos;

layout(location=0) out vec4 out_col;

uniform sampler2D tex;

void main()
{
vec4 tex_val = texture(tex, tex_pos);
out_col = tex_val;
}
24 changes: 24 additions & 0 deletions assets/test/shaders/demo_6_3d.vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#version 330

layout (location = 0) in vec3 position;
layout (location = 1) in vec2 uv;

out vec2 tex_pos;

// camera parameters for transforming the object position
// and scaling the subtex to the correct size
layout (std140) uniform camera {
// view matrix (world to view space)
mat4 view;
// projection matrix (view to clip space)
mat4 proj;
// inverse zoom factor (1.0 / zoom)
float inv_zoom;
// inverse viewport size (1.0 / viewport size)
vec2 inv_viewport_size;
};

void main() {
gl_Position = proj * view * vec4(position, 1.0);
tex_pos = vec2(uv.x, 1.0 - uv.y);
}
10 changes: 10 additions & 0 deletions assets/test/shaders/demo_6_display.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 330

uniform sampler2D color_texture;

in vec2 v_uv;
out vec4 col;

void main() {
col = texture(color_texture, v_uv);
}
10 changes: 10 additions & 0 deletions assets/test/shaders/demo_6_display.vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 330

layout(location=0) in vec2 position;
layout(location=1) in vec2 uv;
out vec2 v_uv;

void main() {
gl_Position = vec4(position, 0.0, 1.0);
v_uv = uv;
}
4 changes: 2 additions & 2 deletions buildsystem/codecompliance/authors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2023 the openage authors. See copying.md for legal info.
# Copyright 2014-2024 the openage authors. See copying.md for legal info.

"""
Checks whether all authors are properly listed in copying.md.
Expand Down Expand Up @@ -39,7 +39,7 @@ def get_author_emails_copying_md():
"""
with open("copying.md", encoding='utf8') as fobj:
for line in fobj:
match = re.match("^.*\\|[^|]*\\|[^|]*\\|([^|]+)\\|.*$", line)
match = re.match(r"^.*\|[^|]*\|[^|]*\|([^|]+)\|.*$", line)
if not match:
continue

Expand Down
1 change: 1 addition & 0 deletions copying.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ _the openage authors_ are:
| Astitva Kamble | askastitva | astitvakamble5 à gmail dawt com |
| Haoyang Bi | AyiStar | ayistar à outlook dawt com |
| Michael Seibt | RoboSchmied | github à roboschmie dawt de |
| Nikhil Ghosh | NikhilGhosh75 | nghosh606 à gmail dawt com |

If you're a first-time committer, add yourself to the above list. This is not
just for legal reasons, but also to keep an overview of all those nicknames.
Expand Down
2 changes: 1 addition & 1 deletion etc/gdb_pretty/printers.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def children(self):
"""
Get the displayed children of the keyframe.
"""
yield ('time', self.__val['time'])
yield ('time', self.__val['timestamp'])
yield ('value', self.__val['value'])


Expand Down
6 changes: 4 additions & 2 deletions libopenage/coord/pixel.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright 2016-2023 the openage authors. See copying.md for legal info.
// Copyright 2016-2024 the openage authors. See copying.md for legal info.

#include "pixel.h"

#include "coord/phys.h"
#include "renderer/camera/camera.h"
#include "renderer/camera/definitions.h"


namespace openage {
namespace coord {
Expand Down Expand Up @@ -54,7 +56,7 @@ phys3 input::to_phys3(const std::shared_ptr<renderer::camera::Camera> &camera) c
scene3 input::to_scene3(const std::shared_ptr<renderer::camera::Camera> &camera) const {
// Use raycasting to find the position
// Direction and origin point are fetched from the camera
auto cam_dir = renderer::camera::cam_direction;
auto cam_dir = renderer::camera::CAM_DIRECTION;
auto ray_origin = camera->get_input_pos(*this);

// xz plane that we want to intersect with
Expand Down
3 changes: 2 additions & 1 deletion libopenage/pathfinding/demo/demo_0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "pathfinding/flow_field.h"
#include "pathfinding/integration_field.h"
#include "renderer/camera/camera.h"
#include "renderer/camera/definitions.h"
#include "renderer/gui/integration/public/gui_application_with_logger.h"
#include "renderer/opengl/window.h"
#include "renderer/render_pass.h"
Expand Down Expand Up @@ -313,7 +314,7 @@ void RenderManager0::hide_vectors() {
std::pair<int, int> RenderManager0::select_tile(double x, double y) {
auto grid_plane_normal = Eigen::Vector3f{0, 1, 0};
auto grid_plane_point = Eigen::Vector3f{0, 0, 0};
auto camera_direction = renderer::camera::cam_direction;
auto camera_direction = renderer::camera::CAM_DIRECTION;
auto camera_position = camera->get_input_pos(
coord::input(x, y));

Expand Down
3 changes: 3 additions & 0 deletions libopenage/renderer/camera/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
add_sources(libopenage
camera.cpp
definitions.cpp
frustum_2d.cpp
frustum_3d.cpp
)
Loading
Loading