Skip to content

WIP: renderer: compute normalmap from heightmap when missing normalmap, aka bumpmap #258

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

illwieckz
Copy link
Member

compute normalmap from heightmap when missing normalmap, also known as bumpmapping

two algorithms available:

  • one naive that does the job, uses 3 samples
  • one advanced that does better job, uses 8 samples (sobel operation)

a new cvar is added: r_sobelFiltering, which would be used
to disable or enable various sobel filtering operation including this one

the engine is likely to implement other sobel filters in the future,
for example DarkPlaces has a postprocessing effect that does such kind of compute,
maybe Dæmon based games will want such kind of effect, in this case
a common cvar to enable or disable various sobel compute does not look bad

the r_sobelFiltering cvar is enabled by default

@illwieckz
Copy link
Member Author

It's better to merge #257 (debugging: implement r_showNormalMaps) before even if this one can technically be merged before. By merging #257 first we make Dæmon able to display computed lightmaps from this commit.

@illwieckz illwieckz added T-Feature-Request Proposed new feature A-Renderer labels Dec 29, 2019
@illwieckz
Copy link
Member Author

illwieckz commented Dec 29, 2019

hmmm, currently that code seems to only run with lightMapping glsl shader, I'll enable vertex ones later.

This does not prevent to review the code as it would just require some boilerplate to plug the feature in other glsl shaders, in fact this single line:

gl_lightMappingShader->SetNormalMapFromHeightMap( hasHeightMap && !hasNormalMap );

@illwieckz illwieckz force-pushed the bumpmap branch 2 times, most recently from 48c242b to 7b71475 Compare December 29, 2019 08:10
@illwieckz
Copy link
Member Author

illwieckz commented Dec 29, 2019

Hmm, the normalmap computation itself seems to be OK. but, I was testing it with Xonotic's solarium map which has such kind of "bumpmap" and everything looked good, until I remembered I had disabled normalScaling and then, all the classic normalmaps (not computed ones) were using DirectX format, hence meaning that if the generated normalmap from heightmap looks good, it is produced produced reverted the DirectX way… Which makes sense since I mostly read HLSL examples and found no one GLSL example to read to implement this.

I may edit the test-normal test map or create a new test map to get a proper testbed I'm 100% confident with.

@illwieckz
Copy link
Member Author

I prefer to merge this after #260 (renderer: fix normalmap dark blotches) in order to be able to reuse the normalmap dark-blotch fix instead of duplicating it.

@illwieckz illwieckz force-pushed the bumpmap branch 3 times, most recently from 0d83c91 to 50ed18e Compare January 15, 2020 15:22
@slipher
Copy link
Member

slipher commented Jan 18, 2020

Any screenshots? What should we see if it is working?

@illwieckz
Copy link
Member Author

I'll do screenshot, I also want to make a test map.

@illwieckz
Copy link
Member Author

illwieckz commented Jan 18, 2020

The generated normal map from heightmap is the sand on the beach (using r_showNormalMaps):

bumpmap

bumpmap

bumpmap

bumpmap

So, this is with sobel filtering:

bumpmap

With the other less good but faster algorithm:

bumpmap

bumpmap

bumpmap

Close look, with sobel:

bumpmap

Without:

bumpmap

Fully textured render, with sobel:

bumpmap

bumpmap

Without sobel:

bumpmap

Without normal map computation (flat normal map):

bumpmap

bumpmap

@illwieckz illwieckz force-pushed the bumpmap branch 2 times, most recently from 08e6a21 to 0639b68 Compare January 18, 2020 12:07
@slipher
Copy link
Member

slipher commented Jan 18, 2020

What seems to be is missing is a decision of how steep of an angle a certain height delta represents. So trying to reason this out geometrically... Now so far you've calculated your height differential over 1 pixel in the x direction. So the heightmap should have some physical scale for the difference between a value of 0 and a value of 1 (I don't suppose there's any standard for this?) which you would multiply by to get the physical delta-height. And you have a physical delta-x which is the distance between neighboring pixels on the texture. So (physical delta-x, 0, physical delta-height(x)) would be a tangent vector to your surface. And with reasoning from the y-coordinate calculations, another tangent is (0, physical delta-y, physical delta-height(y)). Then you could cross-product those to get a normal vector.

@illwieckz
Copy link
Member Author

What seems to be is missing is a decision of how steep of an angle a certain height delta represents. So trying to reason this out geometrically... Now so far you've calculated your height differential over 1 pixel in the x direction. So the heightmap should have some physical scale for the difference between a value of 0 and a value of 1 (I don't suppose there's any standard for this?) which you would multiply by to get the physical delta-height. And you have a physical delta-x which is the distance between neighboring pixels on the texture. So (physical delta-x, 0, physical delta-height(x)) would be a tangent vector to your surface. And with reasoning from the y-coordinate calculations, another tangent is (0, physical delta-y, physical delta-height(y)). Then you could cross-product those to get a normal vector.

I'm not sure to have the knowledge to fully understand that (euphemism).

…a bumpmap

compute normalmap from heightmap when missing normalmap, also known as bumpmapping

two algorithms available:

- one naive that does the job, uses 3 samples
- one advanced that does better job, uses 8 samples (sobel operation)

a new cvar is added: r_sobelFiltering, which would be used
to disable or enable various sobel filtering operation including this one

the engine is likely to implement other sobel filters in the future,
for example DarkPlaces has a postprocessing effect that does such kind of compute,
maybe Dæmon based games will want such kind of effect, in this case
a common cvar to enable or disable various sobel compute does not look bad

the r_sobelFiltering cvar is enabled by default
@illwieckz
Copy link
Member Author

I rebased this on master after the great merge.

@illwieckz illwieckz changed the title renderer: compute normalmap from heightmap when missing normalmap, aka bumpmap WIP: renderer: compute normalmap from heightmap when missing normalmap, aka bumpmap May 31, 2021
@illwieckz illwieckz marked this pull request as draft May 31, 2021 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants