merged latest changes from origin/master

Commit 3852c94182ad · silentevermore · 2026-10-09 09:36 +0300

Changeset
3852c94182ad46e379037094047805941cb1f1d7

View source at this commit

Comments

No comments yet.

Log in to comment

Diff

diff --git a/shaders/frag.glsl b/shaders/frag.glsl
--- a/shaders/frag.glsl
+++ b/shaders/frag.glsl
@@ -6,61 +6,10 @@
 
 uniform sampler2D texture0;
 
-uniform float ambient;
-uniform vec3 lightDir;
-uniform vec3 lightColor;
-
 out vec4 finalColor;
 
-const mat4 bayerMatrix = mat4(
-		0.0/16.0, 12.0/16.0,  3.0/16.0, 15.0/16.0,
-		8.0/16.0,  4.0/16.0, 11.0/16.0,  7.0/16.0,
-		2.0/16.0, 14.0/16.0,  1.0/16.0, 13.0/16.0,
-		10.0/16.0,  6.0/16.0,  9.0/16.0,  5.0/16.0
-);
-
-float pixel_size = 1.0;
-float contrast = 1.5;
-float levels = 32.0;
-vec2 gamma = vec2(0.5, 1.5);
-
 void main() {
-	// pixelization
-	vec2 texsize = textureSize(texture0, 0);
-	vec2 pixel_c = texsize / (pixel_size * 2.0);
-	vec2 pixel_uv = floor(fragTexCoord * pixel_c) / pixel_c;
-
-	vec2 p = pixel_uv - vec2(0.5);
-	float r = length(p);
-	vec2 dist = p / (1.0 + 0.25 * r);
-	pixel_uv = dist * 0.5 + vec2(0.5);
-
-	vec4 color = texture(texture0, pixel_uv);
-
-	// dither
-	{
-		float lum = dot(color.rgb, vec3(0.299, 0.587, 0.114));
-		int x = int(mod(gl_FragCoord.x, 4.0));
-		int y = int(mod(gl_FragCoord.y, 4.0));
-		float thres = bayerMatrix[x][y];
-		color.rgb = (lum > thres) ? color.rgb * 2.0 : vec3(0.0);
-	}
-
-	// gamma + posterization
-	color.rgb = pow(color.rgb, vec3(gamma.x));
-	{
-		float gray = max(color.r, max(color.g, color.b));
-		float low = floor(gray * levels) / levels;
-		float high = ceil(gray * levels) / levels;
-		float level = abs(low - gray) < abs(high - gray) ? low : high;
-		float adj = level / gray;
-		color.rgb *= adj;
-	}
-	color.rgb = pow(color.rgb, vec3(gamma.y));
-
-	// vignette
-	float diff = length(fragTexCoord - vec2(0.5));
-	color.rgb *= 1.0 - diff;
+	vec4 color = texture(texture0, fragTexCoord);
 
 	finalColor = color;
 }
diff --git a/shaders/frag.glsl b/shaders/post.glsl
copy from shaders/frag.glsl
copy to shaders/post.glsl
--- a/shaders/frag.glsl
+++ b/shaders/post.glsl
@@ -6,10 +6,6 @@
 
 uniform sampler2D texture0;
 
-uniform float ambient;
-uniform vec3 lightDir;
-uniform vec3 lightColor;
-
 out vec4 finalColor;
 
 const mat4 bayerMatrix = mat4(
diff --git a/src/chunk/mod.rs b/src/chunk/mod.rs
new file mode 100644
--- /dev/null
+++ b/src/chunk/mod.rs
@@ -0,0 +1,20 @@
+pub use super::voxel::Voxel;
+use super::rlb::core::math::Vector3;
+
+pub const CHUNK_SIZE: usize = 32;
+
+pub struct Chunk {
+    pub chunk_pos: Vector3,
+    pub voxels: [Voxel; CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE],
+    pub dirty: bool,
+} // pending: add events stack
+
+impl Chunk {
+    pub fn new(pos: Vector3) -> Self {
+        Self {
+            chunk_pos: pos,
+            voxels: [Voxel::Stone; CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE],
+            dirty: false,
+        }
+    }
+}
diff --git a/src/main.rs b/src/main.rs
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,15 +1,13 @@
+mod chunk;
+mod voxel;
+
 use sola_raylib::{self as rlb, ffi::Rectangle};
 use rlb::{
     prelude::*,
     core::*,
     consts::*,
 };
-
-struct LightingData {
-    ambient: f32,
-    light_dir: Vector3,
-    light_col: Vector3
-}
+use chunk::*;
 
 fn main() {
     let (mut rl, rl_thd) = rlb::init()
@@ -27,39 +25,19 @@
 
     // shader stuff
     let mut shader = rl.load_shader(&rl_thd, None, Some("shaders/frag.glsl")).unwrap();
-
-    let ambient_pos = shader.get_shader_location("ambient");
-    let light_pos = shader.get_shader_location("lightPosition");
-    let light_color = shader.get_shader_location("lightColor");
+    let mut post_shader = rl.load_shader(&rl_thd, None, Some("shaders/post.glsl")).unwrap();
+    let mut rend_tex = rl.load_render_texture(&rl_thd, rl.get_render_width() as u32, rl.get_render_height() as u32).unwrap();
 
-    let mut lighting_data = LightingData {
-        ambient: 0.1,
-        light_dir: Vector3::new(0.0, 1.0, 0.0),
-        light_col: Vector3::new(1.0, 1.0, 1.0)
-    };
-
-    let suzanne = rl.load_model(&rl_thd, "res/obj/suzanne.obj").unwrap();
+    // chunks
+    let mut test_chunk = Chunk::new(Vector3::zero());
 
     rl.hide_cursor();
     rl.disable_cursor();
 
     while !rl.window_should_close() {
-        let mut rend_tex = rl.load_render_texture(&rl_thd, rl.get_render_width() as u32, rl.get_render_height() as u32).unwrap();
-
-        // update shader data
-        lighting_data.light_dir = Vector3::new(1.0, 1.0, 1.0);
-        shader.set_shader_value(
-            ambient_pos,
-            lighting_data.ambient
-        );
-        shader.set_shader_value(
-            light_pos,
-            lighting_data.light_dir
-        );
-        shader.set_shader_value(
-            light_color,
-            lighting_data.light_col
-        );
+        if rend_tex.width() != rl.get_render_width() || rend_tex.height() != rl.get_render_height() {
+            rend_tex = rl.load_render_texture(&rl_thd, rl.get_render_width() as u32, rl.get_render_height() as u32).unwrap();
+        }
 
         rl.update_camera(&mut cam, CameraMode::CAMERA_FREE);
         rl.draw(&rl_thd, |mut d| {
@@ -67,10 +45,9 @@
                 tx.clear_background(Color::new(30, 30, 30, 255));
                 tx.draw_mode3D(cam, |mut d3, _| {
                     d3.draw_grid(100, 1.0);
-                    d3.draw_model(&suzanne, Vector3::zero(), 1.0, Color::BLUEVIOLET);
                 });
             });
-            d.draw_shader_mode(&mut shader, |mut shd| {
+            d.draw_shader_mode(&mut post_shader, |mut shd| {
                 shd.draw_texture_rec(&rend_tex, Rectangle{
                     x: 0.0,
                     y: 0.0,
diff --git a/src/voxel/mod.rs b/src/voxel/mod.rs
new file mode 100644
--- /dev/null
+++ b/src/voxel/mod.rs
@@ -0,0 +1,6 @@
+#[derive(Clone)]
+#[derive(Copy)]
+pub enum Voxel {
+    Air,
+    Stone,
+}