mgecumshooter/esotera
merged from silentevermore
Commit 02a429c5cdf5 · mgecumshooter · 2026-10-21 12:09 +0300
Comments
No comments yet.
Diff
diff --git a/shaders/post.glsl b/shaders/post.glsl
--- a/shaders/post.glsl
+++ b/shaders/post.glsl
@@ -3,12 +3,14 @@
in vec3 fragPosition;
in vec3 fragNormal;
in vec2 fragTexCoord;
+in vec4 fragColor;
uniform sampler2D texture0;
uniform sampler2D depth_tex;
out vec4 finalColor;
+// dither
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,
@@ -16,11 +18,25 @@
10.0/16.0, 6.0/16.0, 9.0/16.0, 5.0/16.0
);
+// ssao
+const vec2 OFFSETS[8] = vec2[8](
+ vec2( 1.0, 0.0),
+ vec2(-1.0, 0.0),
+ vec2( 0.0, 1.0),
+ vec2( 0.0, -1.0),
+ vec2( 0.707, 0.707),
+ vec2(-0.707, 0.707),
+ vec2( 0.707, -0.707),
+ vec2(-0.707, -0.707)
+);
+
+// pixelization + other
float pixel_size = 1.0;
float contrast = 1.5;
float levels = 32.0;
vec2 gamma = vec2(0.5, 1.5);
+// isoteric.
const float near_plane = 0.01;
const float far_plane = 1000.0;
const float fog_far = 150.0;
@@ -43,7 +59,7 @@
pixel_uv = dist * 0.5 + vec2(0.5);
float depth = texture(depth_tex, pixel_uv).r;
- vec4 color = texture(texture0, pixel_uv);
+ vec4 color = texture(texture0, pixel_uv) * fragColor;
// dither
{
@@ -71,6 +87,62 @@
color.rgb *= 1.0 - diff;
color.rgb *= pow(1.0 - linearize_depth(depth), 4.0);
- // finalColor = color;
+ if (depth < 1) {
+ float strength = 1.0;
+ float radius = 4.0;
+ int ao_idx = 1;
+
+ // ssao
+ if (ao_idx == 1) {
+ // simple
+ vec2 px = radius / texsize;
+ float ao = 0.0;
+
+ float d1 = texture(depth_tex, pixel_uv + vec2( px.x, 0.0)).r;
+ float d2 = texture(depth_tex, pixel_uv + vec2(-px.x, 0.0)).r;
+ float d3 = texture(depth_tex, pixel_uv + vec2(0.0, px.y)).r;
+ float d4 = texture(depth_tex, pixel_uv + vec2(0.0, -px.y)).r;
+
+ ao += smoothstep(0.001, 0.008, depth - d1);
+ ao += smoothstep(0.001, 0.008, depth - d2);
+ ao += smoothstep(0.001, 0.008, depth - d3);
+ ao += smoothstep(0.001, 0.008, depth - d4);
+ ao *= 0.25;
+
+ color.rgb *= 1.0 - ao * strength;
+ } else {
+ float occlusion = 0.0;
+ vec2 texelSize = 1.0 / texsize;
+
+ for (int i = 0; i < 8; i++) {
+ vec2 sampleUV =
+ pixel_uv + OFFSETS[i] * radius * texelSize;
+
+ if (any(lessThan(sampleUV, vec2(0.0))) ||
+ any(greaterThan(sampleUV, vec2(1.0)))) continue;
+
+ float sampleDepth = texture(depth_tex, sampleUV).r;
+
+ if (sampleDepth >= 0.99999) continue;
+
+ float difference = depth - sampleDepth;
+ float bias = max(0.0005, depth * 0.002);
+
+ occlusion += smoothstep(
+ bias,
+ bias * 4.0,
+ difference
+ );
+ }
+
+ float ao = clamp(
+ 1.0 - strength * (occlusion / 8.0),
+ 0.0,
+ 1.0
+ );
+
+ color.rgb *= ao;
+ }
+ }
finalColor = color;
}
diff --git a/src/main.rs b/src/main.rs
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,12 +1,12 @@
// external deps
+use rlb::prelude::*;
use sola_raylib as rlb;
-use rlb::prelude::*;
// modules declarations
mod chunk;
-mod voxel;
mod player;
mod util;
+mod voxel;
mod world;
// internal modules
@@ -15,19 +15,14 @@
use util::*;
use world::*;
-
fn main() {
- let (mut rl, rl_thd) = rlb::init()
- .size(800, 600)
- .title("ESOTERA")
- .vsync()
- .build();
+ let (mut rl, rl_thd) = rlb::init().size(800, 600).title("ESOTERA").vsync().build();
let mut cam = Camera3D::perspective(
Vector3::new(0f32, 1f32, 10f32),
Vector3::new(0f32, 0f32, 0f32),
Vector3::new(0f32, 1f32, 0f32),
- 90f32
+ 90f32,
);
rl.hide_cursor();
@@ -53,7 +48,6 @@
}
// chunk_material.set_shader(&shader);
-
// chunks
// let test_chunk = Chunk::new(Vector3::zero());
@@ -62,13 +56,10 @@
let mut world = World::new(4);
let mut plr = Player::new(
- Vector3::new(0f32, 10f32, 0f32),
- Cube::new(
- Vector3::new(5f32, 10f32, 5f32),
- ),
+ Vector3::new(0f32, 10f32, 0f32),
+ Cube::new(Vector3::new(5f32, 10f32, 5f32)),
);
-
// main game loop
while !rl.window_should_close() {
world.load_around_player(plr.get_eye_pos());
@@ -85,7 +76,7 @@
// (&rl_thd, rl.get_render_width() as u32, rl.get_render_height() as u32).unwrap();
}
- rl.draw(&rl_thd, |mut d| {
+ rl.draw(&rl_thd, |mut d| {
d.draw_texture_mode(&rl_thd, &mut rend_tex, |mut tx| {
tx.clear_background(Color::new(30, 30, 30, 255));
tx.draw_mode3D(cam, |mut d3, _| {
@@ -123,17 +114,18 @@
height: -rend_tex.texture().height as f32
}, Vector2::zero(), Color::WHITE);
});
- d.draw_text(
- &format!("x: {:.2}, y: {:.2}, z: {:.2}",
- plr.get_eye_pos().x,
- plr.get_eye_pos().y,
- plr.get_eye_pos().z,
- ),
- 0,
- 0,
- 20,
- Color::WHITE
- );
+ d.draw_text(
+ &format!(
+ "x: {:.2}, y: {:.2}, z: {:.2}",
+ plr.get_eye_pos().x,
+ plr.get_eye_pos().y,
+ plr.get_eye_pos().z,
+ ),
+ 0,
+ 0,
+ 20,
+ Color::WHITE,
+ );
});
}
}