Skip to content

Commit

Permalink
Clean up raycasting code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
bfeldpw committed Aug 8, 2024
1 parent 12159ca commit c5e6288
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 113 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ Simple Raycaster to learn Zig
*Teaser, further screenshots see below*

## Introduction
My first steps in Zig, importing native C with Glfw and OpenGL for learning purposes. Code might be hacky in some places, hopefully improving while learning. OpenGL fixed function pipeline is used purely out of lazyness and the fact, that a simple vertical line (maybe textured) is all that is needed for a raycasting algorithm in its most simplistic form. Might switch to core profile later, but that's secondary. Same applies for parameters and resources, for now, the map is hardcoded as are parameters (nevertheless there are parameters and not some magic numbers ;-)). Later, a map, its features, and configuration should be loaded from files, of course.
My first steps in Zig, importing native C with Glfw and OpenGL for learning purposes. Code might be hacky in some places, hopefully improving while learning. ~~OpenGL fixed function pipeline is used purely out of lazyness and the fact, that a simple vertical line (maybe textured) is all that is needed for a raycasting algorithm in its most simplistic form. Might switch to core profile later, but that's secondary.~~ OpenGL core profile is used to be able to do optimisations and effects such as ambient occlusion using shaders. For now, the map is hardcoded as are parameters (nevertheless there are parameters and not some magic numbers ;-)). Later, a map, its features, and configuration should be loaded from files, of course.

## News
**Next up** The next thing to tackle will most probably be something internal again. Since a lot of vertices are dynamically updated and send to the GPU in each frame, optimisation might be possible by using glStorageBuffer and persistent mapping via glMapBufferRange with persistence and coherence bits set.
**2024-08-08** There was some time off due to another pet project. Nevertheless, several internal adjustments were made. This includes cleaning up the ray casting code structures to be prepared for further additions (floor casting, lights,...).
**2023-12-09** OpenGL core profile has been merged to main branch. After a lot of work, the main functionality has been moved to modern OpenGL, this includes:
* Ambient occlusion has been re-introduced (better, shader-based)
* Framebuffer objects (FBO) have been implemented and are used for
Expand Down
3 changes: 3 additions & 0 deletions resource/shader/pxy_tuv_f32_base.vert
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#version 330 core

layout (location = 0) in vec2 pos;
layout (location = 2) in vec2 uv;

Expand All @@ -10,4 +11,6 @@ void main()
{
v_uv = uv;
gl_Position = vec4(pos.x * t.x + t.z, pos.y * t.y + t.w, 0.0, 1.0);
// float z = 1 + 10*uv.x;
// gl_Position = vec4((pos.x * t.x + t.z) * z, (pos.y * t.y + t.w) * z, -2 * -z - 2.0, z);
}
4 changes: 2 additions & 2 deletions src/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ pub const multithreading = true;
/// verbose output
pub const debug_allocator = false;

pub var sub_sampling_base: u32 = 2;
pub var sub_sampling_base: u32 = 3;
pub const sub_sampling_blocky = false;

pub const sub = struct {
/// Enables auto-subsampling. Based on raycasting and
/// render time, the number of rays will be reduced in
/// case of high load
pub const auto = true;
pub const auto = false;
/// Upper threshold in [ms] for raycasting and rendering
/// If exceeded, number of rays will be reduced
pub const th_high = 6.0;
Expand Down
Loading

0 comments on commit c5e6288

Please sign in to comment.