feat: Add new shaders for floor, ceiling, and wall; update shader handling in cube creation

This commit is contained in:
2026-01-05 20:49:37 +00:00
parent 87d72e6e12
commit 3395572e90
9 changed files with 164 additions and 13 deletions

View File

@@ -208,6 +208,18 @@ local shader_variants = {
vertex = "shaders/solid.vert.spv",
fragment = "shaders/solid.frag.spv",
},
floor = {
vertex = "shaders/solid.vert.spv",
fragment = "shaders/floor.frag.spv",
},
wall = {
vertex = "shaders/solid.vert.spv",
fragment = "shaders/wall.frag.spv",
},
ceiling = {
vertex = "shaders/solid.vert.spv",
fragment = "shaders/ceiling.frag.spv",
},
pbr = {
vertex = "shaders/pbr.vert.spv",
fragment = "shaders/pbr.frag.spv",
@@ -514,19 +526,20 @@ local function apply_color_to_vertices(color)
return colored_vertices
end
local function create_static_cube(position, scale, color)
local function create_static_cube(position, scale, color, shader_key)
local model = build_static_model_matrix(position, scale)
local function compute_model_matrix()
return model
end
local vertices = color and apply_color_to_vertices(color) or cube_vertices
local resolved_shader = shader_key or "solid"
return {
vertices = vertices,
indices = cube_indices,
compute_model_matrix = compute_model_matrix,
shader_key = "solid", -- Use solid shader for room geometry
shader_key = resolved_shader,
}
end
@@ -563,23 +576,23 @@ local function create_room_objects()
local wall_outer_edge = wall_offset + room.wall_thickness
log_debug("Room walls: inner=%.2f outer=%.2f", wall_inner_edge, wall_outer_edge)
local floor_color = {0.14, 0.19, 0.26}
local wall_color = {0.52, 0.36, 0.22}
local ceiling_color = {0.78, 0.8, 0.86}
local floor_color = {0.08, 0.26, 0.55}
local wall_color = {0.78, 0.38, 0.18}
local ceiling_color = {0.72, 0.9, 0.96}
local objects = {
create_static_cube({0.0, floor_center_y, 0.0},
{room.half_size, room.floor_half_thickness, room.half_size}, floor_color),
{room.half_size, room.floor_half_thickness, room.half_size}, floor_color, "floor"),
create_static_cube({0.0, ceiling_y, 0.0},
{room.half_size, room.floor_half_thickness, room.half_size}, ceiling_color),
{room.half_size, room.floor_half_thickness, room.half_size}, ceiling_color, "ceiling"),
create_static_cube({0.0, wall_center_y, -wall_offset},
{room.half_size, room.wall_height, room.wall_thickness}, wall_color),
{room.half_size, room.wall_height, room.wall_thickness}, wall_color, "wall"),
create_static_cube({0.0, wall_center_y, wall_offset},
{room.half_size, room.wall_height, room.wall_thickness}, wall_color),
{room.half_size, room.wall_height, room.wall_thickness}, wall_color, "wall"),
create_static_cube({-wall_offset, wall_center_y, 0.0},
{room.wall_thickness, room.wall_height, room.half_size}, wall_color),
{room.wall_thickness, room.wall_height, room.half_size}, wall_color, "wall"),
create_static_cube({wall_offset, wall_center_y, 0.0},
{room.wall_thickness, room.wall_height, room.half_size}, wall_color),
{room.wall_thickness, room.wall_height, room.half_size}, wall_color, "wall"),
}
-- Add lanterns in the four corners (adjusted for bigger room)

46
shaders/ceiling.frag Normal file
View File

@@ -0,0 +1,46 @@
#version 450
layout(location = 0) in vec3 fragColor;
layout(location = 1) in vec3 fragWorldPos;
layout(location = 0) out vec4 outColor;
const vec3 LIGHT_POSITIONS[8] = vec3[8](
vec3(13.0, 4.5, 13.0),
vec3(-13.0, 4.5, 13.0),
vec3(13.0, 4.5, -13.0),
vec3(-13.0, 4.5, -13.0),
vec3(0.0, 4.5, 13.0),
vec3(0.0, 4.5, -13.0),
vec3(13.0, 4.5, 0.0),
vec3(-13.0, 4.5, 0.0)
);
const vec3 LIGHT_COLOR = vec3(0.92, 0.96, 1.0);
const float LIGHT_INTENSITY = 0.85;
const float AMBIENT_STRENGTH = 0.38;
float calculateAttenuation(float distance) {
const float kConstant = 1.0;
const float kLinear = 0.09;
const float kQuadratic = 0.032;
return 1.0 / (kConstant + kLinear * distance + kQuadratic * distance * distance);
}
void main() {
vec3 baseColor = clamp(fragColor * 1.15, 0.0, 1.0);
vec3 ambient = AMBIENT_STRENGTH * baseColor;
vec3 lighting = vec3(0.0);
for (int i = 0; i < 8; i++) {
vec3 lightDir = LIGHT_POSITIONS[i] - fragWorldPos;
float distance = length(lightDir);
lightDir = normalize(lightDir);
float attenuation = calculateAttenuation(distance);
lighting += LIGHT_COLOR * LIGHT_INTENSITY * attenuation;
}
vec3 finalColor = ambient + baseColor * lighting;
finalColor = clamp(finalColor, 0.0, 1.0);
outColor = vec4(finalColor, 1.0);
}

BIN
shaders/ceiling.frag.spv Normal file

Binary file not shown.

46
shaders/floor.frag Normal file
View File

@@ -0,0 +1,46 @@
#version 450
layout(location = 0) in vec3 fragColor;
layout(location = 1) in vec3 fragWorldPos;
layout(location = 0) out vec4 outColor;
const vec3 LIGHT_POSITIONS[8] = vec3[8](
vec3(13.0, 4.5, 13.0),
vec3(-13.0, 4.5, 13.0),
vec3(13.0, 4.5, -13.0),
vec3(-13.0, 4.5, -13.0),
vec3(0.0, 4.5, 13.0),
vec3(0.0, 4.5, -13.0),
vec3(13.0, 4.5, 0.0),
vec3(-13.0, 4.5, 0.0)
);
const vec3 LIGHT_COLOR = vec3(1.0, 0.92, 0.7);
const float LIGHT_INTENSITY = 1.0;
const float AMBIENT_STRENGTH = 0.3;
float calculateAttenuation(float distance) {
const float kConstant = 1.0;
const float kLinear = 0.09;
const float kQuadratic = 0.032;
return 1.0 / (kConstant + kLinear * distance + kQuadratic * distance * distance);
}
void main() {
vec3 baseColor = clamp(fragColor * 1.1, 0.0, 1.0);
vec3 ambient = AMBIENT_STRENGTH * baseColor;
vec3 lighting = vec3(0.0);
for (int i = 0; i < 8; i++) {
vec3 lightDir = LIGHT_POSITIONS[i] - fragWorldPos;
float distance = length(lightDir);
lightDir = normalize(lightDir);
float attenuation = calculateAttenuation(distance);
lighting += LIGHT_COLOR * LIGHT_INTENSITY * attenuation;
}
vec3 finalColor = ambient + baseColor * lighting;
finalColor = clamp(finalColor, 0.0, 1.0);
outColor = vec4(finalColor, 1.0);
}

BIN
shaders/floor.frag.spv Normal file

Binary file not shown.

View File

@@ -17,8 +17,8 @@ const vec3 LIGHT_POSITIONS[8] = vec3[8](
);
const vec3 LIGHT_COLOR = vec3(1.0, 0.9, 0.6); // Warm lantern color
const float LIGHT_INTENSITY = 0.8;
const float AMBIENT_STRENGTH = 0.08; // Low ambient for darker atmosphere
const float LIGHT_INTENSITY = 0.9;
const float AMBIENT_STRENGTH = 0.22; // Boost ambient to preserve surface color
float calculateAttenuation(float distance) {
// Quadratic attenuation: 1 / (constant + linear*d + quadratic*d^2)

Binary file not shown.

46
shaders/wall.frag Normal file
View File

@@ -0,0 +1,46 @@
#version 450
layout(location = 0) in vec3 fragColor;
layout(location = 1) in vec3 fragWorldPos;
layout(location = 0) out vec4 outColor;
const vec3 LIGHT_POSITIONS[8] = vec3[8](
vec3(13.0, 4.5, 13.0),
vec3(-13.0, 4.5, 13.0),
vec3(13.0, 4.5, -13.0),
vec3(-13.0, 4.5, -13.0),
vec3(0.0, 4.5, 13.0),
vec3(0.0, 4.5, -13.0),
vec3(13.0, 4.5, 0.0),
vec3(-13.0, 4.5, 0.0)
);
const vec3 LIGHT_COLOR = vec3(1.0, 0.88, 0.6);
const float LIGHT_INTENSITY = 0.95;
const float AMBIENT_STRENGTH = 0.24;
float calculateAttenuation(float distance) {
const float kConstant = 1.0;
const float kLinear = 0.09;
const float kQuadratic = 0.032;
return 1.0 / (kConstant + kLinear * distance + kQuadratic * distance * distance);
}
void main() {
vec3 baseColor = clamp(fragColor * 1.05, 0.0, 1.0);
vec3 ambient = AMBIENT_STRENGTH * baseColor;
vec3 lighting = vec3(0.0);
for (int i = 0; i < 8; i++) {
vec3 lightDir = LIGHT_POSITIONS[i] - fragWorldPos;
float distance = length(lightDir);
lightDir = normalize(lightDir);
float attenuation = calculateAttenuation(distance);
lighting += LIGHT_COLOR * LIGHT_INTENSITY * attenuation;
}
vec3 finalColor = ambient + baseColor * lighting;
finalColor = clamp(finalColor, 0.0, 1.0);
outColor = vec4(finalColor, 1.0);
}

BIN
shaders/wall.frag.spv Normal file

Binary file not shown.