Water tweaks
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
import type { Client } from "$/client/client.ts";
|
||||
import { begin_mode_3d, clear_background, end_mode_3d, update_lightmap } from "$/client/renderer/mod.ts";
|
||||
import {
|
||||
begin_mode_3d,
|
||||
canvas,
|
||||
clear_background,
|
||||
draw_rect,
|
||||
end_mode_3d,
|
||||
update_lightmap,
|
||||
} from "$/client/renderer/mod.ts";
|
||||
import { daylight } from "$/common/time.ts";
|
||||
import { Hud } from "$/client/gui/hud.ts";
|
||||
import { DebugOverlay } from "$/client/gui/debug_overlay.ts";
|
||||
@@ -13,6 +20,8 @@ const DAY_SKY = [0.69, 0.8, 1];
|
||||
const NIGHT_SKY = [0.02, 0.03, 0.08];
|
||||
// minecraft's darkest sky: moonlight still lights things a little
|
||||
const NIGHT_SKY_LIGHT = 0.2;
|
||||
// how much of the screen is the water's color with the camera under water
|
||||
const UNDERWATER_ALPHA = 0.4;
|
||||
|
||||
// draws a frame, like minecraft's GameRenderer: the level from the camera, then the hud and screens on top
|
||||
export class GameRenderer {
|
||||
@@ -35,6 +44,21 @@ export class GameRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
// with the camera in water, the screen and the hand are washed in the biome's water color, like minecraft's
|
||||
// underwater overlay
|
||||
#render_underwater(client: Client) {
|
||||
const { x, y, z } = client.camera;
|
||||
const [bx, by, bz] = [Math.floor(x), Math.floor(y), Math.floor(z)];
|
||||
if (!client.level.is_liquid(bx, by, bz)) return;
|
||||
const color = client.level.water_color(bx, bz);
|
||||
draw_rect(0, 0, canvas.width, canvas.height, [
|
||||
(color >> 16) / 255,
|
||||
((color >> 8) & 0xff) / 255,
|
||||
(color & 0xff) / 255,
|
||||
UNDERWATER_ALPHA,
|
||||
]);
|
||||
}
|
||||
|
||||
// partial_tick is how far this frame is between the last tick and the next, entities are drawn in between
|
||||
render(client: Client, partial_tick: number) {
|
||||
const camera = client.camera;
|
||||
@@ -53,6 +77,7 @@ export class GameRenderer {
|
||||
profiler.section("nameplates", () => render_nameplates(client.level, camera, client.player, partial_tick));
|
||||
end_mode_3d();
|
||||
profiler.section("hand", () => this.hand.render(client.player, partial_tick));
|
||||
this.#render_underwater(client);
|
||||
|
||||
profiler.section("hud", () => {
|
||||
this.hud.render(client);
|
||||
|
||||
Reference in New Issue
Block a user