diff --git a/scripts/cube_logic.lua b/scripts/cube_logic.lua index 4aff96a..0873815 100644 --- a/scripts/cube_logic.lua +++ b/scripts/cube_logic.lua @@ -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) diff --git a/shaders/ceiling.frag b/shaders/ceiling.frag new file mode 100644 index 0000000..d4a62b9 --- /dev/null +++ b/shaders/ceiling.frag @@ -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); +} diff --git a/shaders/ceiling.frag.spv b/shaders/ceiling.frag.spv new file mode 100644 index 0000000..650caec Binary files /dev/null and b/shaders/ceiling.frag.spv differ diff --git a/shaders/floor.frag b/shaders/floor.frag new file mode 100644 index 0000000..ad568f1 --- /dev/null +++ b/shaders/floor.frag @@ -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); +} diff --git a/shaders/floor.frag.spv b/shaders/floor.frag.spv new file mode 100644 index 0000000..464d0b0 Binary files /dev/null and b/shaders/floor.frag.spv differ diff --git a/shaders/solid.frag b/shaders/solid.frag index cec1102..5e503b7 100644 --- a/shaders/solid.frag +++ b/shaders/solid.frag @@ -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) diff --git a/shaders/solid.frag.spv b/shaders/solid.frag.spv index b11bf63..914c613 100644 Binary files a/shaders/solid.frag.spv and b/shaders/solid.frag.spv differ diff --git a/shaders/wall.frag b/shaders/wall.frag new file mode 100644 index 0000000..71c2b9f --- /dev/null +++ b/shaders/wall.frag @@ -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); +} diff --git a/shaders/wall.frag.spv b/shaders/wall.frag.spv new file mode 100644 index 0000000..1ecb352 Binary files /dev/null and b/shaders/wall.frag.spv differ