Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharpness map innacurate because of transition to stb_image. #92

Open
Gyrth opened this issue Feb 14, 2023 · 6 comments
Open

Sharpness map innacurate because of transition to stb_image. #92

Gyrth opened this issue Feb 14, 2023 · 6 comments

Comments

@Gyrth
Copy link
Collaborator

Gyrth commented Feb 14, 2023

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.

  • Setting stbi_write_png_compression_level to 0
  • Setting stbi_write_png_compression_level to 10
  • Changing the stbi_write_png comp value to 4 in image_export.cpp

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
Copy link
Contributor

feliwir commented Feb 15, 2023

@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:
d4aa66b#diff-ff31ad9a5068f6649cb3d495abaf5447550115e00873c8ada8835f85dcc5fd51R121
and
d4aa66b#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
Copy link
Collaborator Author

Gyrth commented Feb 15, 2023

@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
Copy link
Contributor

feliwir commented Feb 15, 2023

@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
Copy link
Collaborator

autious commented Mar 21, 2023

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

@Gyrth
Copy link
Collaborator Author

Gyrth commented Mar 21, 2023

@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
Copy link
Collaborator

autious commented Mar 22, 2023

Understood!

Gyrth added a commit to Gyrth/overgrowth that referenced this issue Mar 22, 2023
This fixes the banding graphical issue on the terrain. WolfireGames#92
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants