Daemon
Daemon copied to clipboard
WIP: renderer: compute normalmap from heightmap when missing normalmap, aka 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
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.
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 );
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.
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.
Any screenshots? What should we see if it is working?
I'll do screenshot, I also want to make a test map.
The generated normal map from heightmap is the sand on the beach (using r_showNormalMaps):
So, this is with sobel filtering:
With the other less good but faster algorithm:
Close look, with sobel:
Without:
Fully textured render, with sobel:
Without sobel:
Without normal map computation (flat normal map):
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.
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).
I rebased this on master after the great merge.














