Get ambient lighting block working

This commit is contained in:
James Lambert 2023-06-06 19:54:18 -06:00
parent a16c7f9732
commit e088c3959b
5 changed files with 20 additions and 2 deletions

View file

@ -16,6 +16,16 @@ materials:
twoTone: true
gSPGeometryMode:
clear: [G_LIGHTING]
gDPSetCycleType: G_CYC_2CYCLE
gDPSetCombineMode:
- color: [PRIMITIVE, "ENVIRONMENT", TEXEL0, "ENVIRONMENT"]
alpha: ["0", "0", "0", "1"]
- color: ["COMBINED", "0", "SHADE", "0"]
alpha: ["0", "0", "0", "1"]
gDPSetRenderMode:
- G_RM_PASS
- G_RM_ZB_OPA_SURF
properties:
tileSizeS: 1

View file

@ -531,6 +531,10 @@ function Color4.__mul(a, b)
return color4(a.r * b.r, a.g * b.g, a.b * b.b, a.a * b.a)
end
function Color4.__tostring(v)
return 'color4(' .. v.r .. ', ' .. v.g .. ', ' .. v.b .. ', ' .. v.a .. ')'
end
--- Linearly interpolates between two points
--- @function lerp
--- @tparam Color4 b

View file

@ -33,7 +33,7 @@ local function proccessStaticNodes(nodes)
if chunkV.material.properties.staticLit == "true" then
for index, pos in pairs(chunkV.mesh.vertices) do
-- chunkV.mesh.colors[index] = static_lighting.light_vertex(pos, chunkV.mesh.normals[index])
chunkV.mesh.colors[1][index] = static_lighting.light_vertex(pos, chunkV.mesh.normals[index])
end
end

View file

@ -46,7 +46,7 @@ local function build_ambient_block(ambient_mesh)
end
local function evaluate_ambient_block(block, pos, normal)
local lerp_values = block.bb:unlerp(pos)
local lerp_values = block.bb:unlerp(pos):min(sk_math.vector3(1, 1, 1)):max(sk_math.vector3(0, 0, 0))
local x0 = block.colors[1]:lerp(block.colors[2], lerp_values.x)
local x1 = block.colors[3]:lerp(block.colors[4], lerp_values.x)
@ -98,6 +98,10 @@ local function find_nearest_ambient_boxes(pos, max_count)
end
end
if #distances == 1 then
return boxes, {1}
end
local weights = {}
local total_weight = 0