Skip to content

Commit

Permalink
GND: Enable posterization of the lightmap alpha channel
Browse files Browse the repository at this point in the history
It seems that the "posterization effect" is a due to the use of 16-bit colors. Ergo, the lightmap alpha channel also needs to be posterized since there's no way to store more than 4 bits for each channel.
  • Loading branch information
rdw-software committed Mar 18, 2024
1 parent 0bc2856 commit 33adeb3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Core/FileFormats/RagnarokGND.lua
Original file line number Diff line number Diff line change
Expand Up @@ -821,14 +821,16 @@ function RagnarokGND:GenerateLightmapTextureImage(posterizationLevel)
local posterizedRed = bit.rshift(red, posterizationLevel)
local posterizedGreen = bit.rshift(green, posterizationLevel)
local posterizedBlue = bit.rshift(blue, posterizationLevel)
local posterizedAlpha = bit.rshift(alpha, posterizationLevel)
posterizedRed = bit.lshift(posterizedRed, posterizationLevel)
posterizedGreen = bit.lshift(posterizedGreen, posterizationLevel)
posterizedBlue = bit.lshift(posterizedBlue, posterizationLevel)
posterizedAlpha = bit.lshift(posterizedAlpha, posterizationLevel)

bufferStartPointer[writableAreaStartIndex + 0] = posterizedRed
bufferStartPointer[writableAreaStartIndex + 1] = posterizedGreen
bufferStartPointer[writableAreaStartIndex + 2] = posterizedBlue
bufferStartPointer[writableAreaStartIndex + 3] = alpha
bufferStartPointer[writableAreaStartIndex + 3] = posterizedAlpha
else -- Slightly wasteful, but the determinism enables testing (and it's barely noticeable anyway)
bufferStartPointer[writableAreaStartIndex + 0] = 255
bufferStartPointer[writableAreaStartIndex + 1] = 0
Expand Down
2 changes: 1 addition & 1 deletion Tests/FileFormats/RagnarokGND.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ describe("RagnarokGND", function()
assertEquals(lightmapTextureImage.height, 8)

local rawImageBytes = tostring(lightmapTextureImage.rgbaImageBytes)
local expectedTextureChecksum = 546589407
local expectedTextureChecksum = 288753058
local generatedTextureChecksum = miniz.crc32(rawImageBytes)
assertEquals(generatedTextureChecksum, expectedTextureChecksum)
end)
Expand Down
2 changes: 1 addition & 1 deletion Tests/Tools/RagnarokTools.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("RagnarokTools", function()
it("should export the GND lightmap data in a human-readable format if a valid GND buffer is passed", function()
local expectedLightmapChecksum = "be735bab85771a54892d4129d7aba3126e0f7f41f2c9891a28aa8dcfc897d2fa"
local expectedShadowmapChecksum = "4a7a36bedbb8e73797b91b2f568b59b8d4600dc3975e2265114339a5142e9175"
local expectedTextureChecksum = "a740daf79dda0245b71824d441f42baa9cb9c9449458090b983ec7b80a05b3bc"
local expectedTextureChecksum = "dfbff3a58a516c0990147567388431dee2d05dae12a01bd5fb4d30230bb79573"

local gndFileContents = C_FileSystem.ReadFile(path.join("Tests", "Fixtures", "no-water-plane.gnd"))
RagnarokTools:ExportLightmapsFromGND(gndFileContents)
Expand Down

0 comments on commit 33adeb3

Please sign in to comment.