Official Terrarian
The way the game normally works:
Whenever a tile is drawn, the game does a lookup in the lighting data and writes that color value into the vertices of whatever is being drawn. The shader that draws tiles will multiply that vertex value by the texture color and draw it to the screen.
Sometimes the game wants to draw things while ignoring lighting (emissive), and in those cases it will write the glow color into the vertices and draw a texture in the shape of the part that glows. Dyes and some paints that use custom shaders can also ignore what light color is written in the vertices when drawing the part that glows.
The mod's current approach:
Once tiles are drawn, there is no distinction between pixels that are glowing and pixels that are lit by the lighting texture, so the mod cannot tell the difference between pixels from a regular tile, and pixels from the glow effect of a spelunker potion.
Suggested future mod version:
Whenever a tile is drawn, the game does a lookup in the lighting data and writes that color value into the vertices of whatever is being drawn. The shader that draws tiles will multiply that vertex value by the texture color and draw it to the screen.
Sometimes the game wants to draw things while ignoring lighting (emissive), and in those cases it will write the glow color into the vertices and draw a texture in the shape of the part that glows. Dyes and some paints that use custom shaders can also ignore what light color is written in the vertices when drawing the part that glows.
The mod's current approach:
- Before drawing starts, generate a texture containing lighting data for the part of the world that overlaps with the screen referred to by RandomComputerUser as a "light texture".
- Any code that wrote a light value into vertices, instead write white. Everything is drawn as if it were fully lit.
- After all drawing is finished, multiply the light texture by the entire screen to darken the world back from fully lit to the correct brightness.
Once tiles are drawn, there is no distinction between pixels that are glowing and pixels that are lit by the lighting texture, so the mod cannot tell the difference between pixels from a regular tile, and pixels from the glow effect of a spelunker potion.
Suggested future mod version:
The difference between this fixed mod version and the current version is that lighting will no longer be done in a single step after all drawing is finished. The mod will be able to treat glowing objects differently from lit ones.My plan is to try to rewrite the mod and implement a shader that multiplies the tile texture color by the light texture color and apply the shader while drawing tiles, but I'm not currently sure how long that will take.