WolfireGames / overgrowth

Open Source codebase of the game Overgrowth by Wolfire Games LLC
Apache License 2.0
2.46k stars 249 forks source link

Sharpness map innacurate because of transition to stb_image. #92

Open Gyrth opened 1 year ago

Gyrth commented 1 year ago

I've noticed while running the internal_testing branch on Steam that thrown weapons no longer stick to characters. I compared building after and before commit d4aa66b. And here it seems the issue was introduced. However I can not seem to solve it. I know it has something to do with caching the images to the disk. I thought that compression was causing the sharpness maps to get blurry and that made the sharpness values to be lower than absolute white. This is what I tried so far.

Now the last attempt at a fix did not solve the sharpness issue, but it did fix the terrain normal map generation. Here is what it looks like before and after. By using the comp value 3 (RGB) it generated a lot of vertical lines, but adding 4 (RGBA) this no longer happens. Maybe you can shed some light on this @feliwir? bug_report

feliwir commented 1 year ago

@Gyrth setting/changing the compression level should make no difference, since PNG is a lossless format. It just sets the internal deflate compression level. You're right that the amount of components seems to be wrong here: https://github.com/WolfireGames/overgrowth/commit/d4aa66bfffad9b0dee5dc6d48acb52f6cd80c1ff#diff-ff31ad9a5068f6649cb3d495abaf5447550115e00873c8ada8835f85dcc5fd51R121 and https://github.com/WolfireGames/overgrowth/commit/d4aa66bfffad9b0dee5dc6d48acb52f6cd80c1ff#diff-ff31ad9a5068f6649cb3d495abaf5447550115e00873c8ada8835f85dcc5fd51R125 This should be 4 (RGBA = 4 components).

Regarding the issue with the sharpness map: If i had to guess i'd say the problem is in image_sampler.cpp, but i'd need to validate this.

Gyrth commented 1 year ago

@feliwir I don't understand why adding an Alpha fixes the colors. As far as I know, this channel isn't even used for normal maps. It just needs RGB values for an Object Space Normal Map.

feliwir commented 1 year ago

@Gyrth this is about memory layout. We don't add an alpha but it's already there. the incoming data is layouted as follows for each pixel: RGBA-RGBA-RGBA-RGBA when we now tell stb_image that we only have 3 components, it will interpret the data as RGB-RGB-RGB-RGB So it will start being wrong starting from the second pixel, where it will use the A as the R and so on.

autious commented 1 year ago

@Gyrth did you have a local fix for this problem?

Gyrth commented 1 year ago

@Gyrth did you have a local fix for this problem?

For the terrain normal map issue, yes. But for the sharpness map issue with weapons I couldn't find a solution.

autious commented 1 year ago

Understood!