RobertBeckebans / RBDOOM-3-BFG

Doom 3 BFG Edition source port with updated DX12 / Vulkan renderer and modern game engine features
https://www.moddb.com/mods/rbdoom-3-bfg
GNU General Public License v3.0
1.38k stars 247 forks source link

(Enhancement) Better/more realistic specular effects? #282

Closed aFoxNamedMorris closed 3 years ago

aFoxNamedMorris commented 8 years ago

I was wondering if it was possible or planned to have some improved specular highlighting. Metal looking like metal, etc.

For example:

Hope I put this in the right place...

~SteamFox

BielBdeLuna commented 8 years ago

this is excellent looking, what have you changed? you changed more than the specular power isn't it?

aFoxNamedMorris commented 8 years ago

I didn't change anything. It's a screenshot of an enhancement mod for the 2004 version of Doom 3. I was using it as a reference.

BielBdeLuna commented 8 years ago

ok, so it's one of those mods that changed the interaction, they solved the way specular some times in some surfaces gets all wonky, I think they "renormalized" the surface which I don't know what this means, I think Carmak spoke several times on that problem.

it was the base of those mods that did "perfect metallic surfaces", before sikkpin implemented his HDR in the ARB progs

aFoxNamedMorris commented 8 years ago

Basically, if I'm remembering this correctly, renormalizing literally means that the shader changes the way that the geometry normals and the specularity interact. Change how much the normal affects the specularity, and it's done... I probably could fork the code and set this up, then do a pull request.

BielBdeLuna commented 8 years ago

great, I'd like to see the renormalizing where is done and the effect itself

aFoxNamedMorris commented 8 years ago

I'll be working on it soon. It's likely part of the interaction shaders, though I'll have to dig a bit to find it. Stay tuned.

EDIT: Having trouble finding where this is handled... I created a fork, and my own SpecularHighlights branch. This could take a while. Feel free to hop in. :)

EDIT2: Looks like it may be in the renderprogs. I'm fiddling around now.

RobertBeckebans commented 8 years ago

Probably everything in the interaction shaders even provided by the community is wrong. Metallic specular reflections require indirect light information sampled from screen space colors or cubemap probes placed in the map. The interaction shaders itself are only about direct light interaction and "not" indirect light.

Stochastic Screen-Space Reflections from http://advances.realtimerendering.com/s2015/index.html explains it quite well. That's a technique that I will implement anyway.

BielBdeLuna commented 8 years ago

but this doesn't have to do in the quality of the specular, but on the quality of the normals, isn't it? (maybe not on the quality of the normals but this thing about re-nomalitzation)

it's got nothing to do with indirect light but the specular reflection of direct light (which itself is an un-physic idea, there is no diffuse and specular there is only specular with smoothness of the surface affecting the way reflected photons look like )

the wonkiness of the reflection can be seen specially with a higher specularPower value like 100 or 1000, in a flat surface the reflection won't be displayed correctly with the correct perspective, it's like if the triangle of the surface somewhat distorted the reflections

BielBdeLuna commented 8 years ago

I've found Carmack's plan where he talks about renormalizing the normalmap and the probles he encountered: http://www.bluesnews.com/cgi-bin/finger.pl?id=1&time=20030129210315

Renormalization of surface normal map samples makes significant quality
improvements in magnified textures, turning tight, blurred corners into shiny,
smooth pockets, but it introduces a huge amount of aliasing on minimized
textures. Blending between the cases is possible with fragment programs, but
the performance overhead does start piling up, and it may require stashing
some information in the normal map alpha channel that varies with mip level.
Doing good filtering of a specularly lit normal map texture is a fairly
interesting problem, with lots of subtle issues.

And I've found this article with a piece of code: http://www.ozone3d.net/tutorials/bump_map_compression_p2.php but I haven't tried it yet, In the article one can see that the renormlaitzation helps achieve a more correct specular reflection

--EDIT-- tried it by adding this after bumpMap in interaction.pixel:

bumpMap = half4( normalize( bumpMap.xyz * 2.0 - 1.0 ), bumpMap.w);

but all the bump map effects became even wonkier! :) so this piece of code don't solve the problem of wonky specular in the current implementation.

aFoxNamedMorris commented 8 years ago

Ooh! Nice work! Looking forward to seeing where this goes. Should I keep tinkering? On Jan 11, 2016 12:42 PM, "Biel Bestué de Luna" notifications@github.com wrote:

I've found Carmack's plan where he talks about renormalizing the normalmap and the probles he encountered: http://www.bluesnews.com/cgi-bin/finger.pl?id=1&time=20030129210315

Renormalization of surface normal map samples makes significant quality improvements in magnified textures, turning tight, blurred corners into shiny, smooth pockets, but it introduces a huge amount of aliasing on minimized textures. Blending between the cases is possible with fragment programs, but the performance overhead does start piling up, and it may require stashing some information in the normal map alpha channel that varies with mip level. Doing good filtering of a specularly lit normal map texture is a fairly interesting problem, with lots of subtle issues.

And I've found this article with a piece of code: http://www.ozone3d.net/tutorials/bump_map_compression_p2.php but I haven't tried it yet

— Reply to this email directly or view it on GitHub https://github.com/RobertBeckebans/RBDOOM-3-BFG/issues/282#issuecomment-170629694 .

BielBdeLuna commented 8 years ago

I've been tinkering with it, but I can't get it to work @RobertBeckebans I see you normalize the "localNormal" I've tried to add this: " *2.0 -1.0" to the localNormal but the effect was the same as renormalizing the bumpMap sample that I did before. do you see any improvement in any of this code?

I think the improvement we should see should be more akin like: from this (which I think resembles how doom3 handles the specular highlights): http://www.ozone3d.net/tutorials/images/bump_map_compression/bump_map_uncompressed_non_normalized.jpg

to this: http://www.ozone3d.net/tutorials/images/bump_map_compression/bump_map_uncompressed_normalized.jpg

but the code is too different to port it from the glsl in the article to the cg in renderprogs, or at least I don't know how to interpret it, to make a correct port (if necessary at all). Sorry! :(

nbohr1more commented 8 years ago

OK this seems like you are conflating ideas.

If you want improved Normal Map processing with renormalization. You will need to covert this ARB shader:

http://forums.thedarkmod.com/topic/15178-tdm-engine-development-page/page-4#entry352322

to GLSL (etc).

Source:

https://web.archive.org/web/20111203210912/http://mhquake.blogspot.com/2011/11/doom-3-shaders.html

Relevant code block:

- perform the diffuse bump mapping

- instead of using the normalization cube map, normalize with math

DP3 light, tex0,tex0; RSQ light, light.x; MUL light, light.x, tex0;

-----------------

TEX localNormal, tex1, texture[1], 2D;

- MOV localNormal.x, localNormal.a #- normal map compression hack - is this the only shader they're used in????;

MAD localNormal, localNormal, scaleTwo, subOne; DP3 light, light, localNormal;

If you want the specular look, check out Maha-X's "Brilliant Highlights" mod which is the source of nearly every metallic shader mod for Vanilla Doom 3 including Sikkpin's mod. The problem being, of course, that it's not a PBR method so the true resolution is to author PBR materials to replace the metals in Doom 3 and use those for an accurate metal look.

aFoxNamedMorris commented 8 years ago

So wait for Robert to finish what he's working on. Got it. On Jan 11, 2016 6:25 PM, "nbohr1more" notifications@github.com wrote:

OK this seems like you are conflating ideas.

If you want improved Normal Map processing with renormalization. You will need to covert this ARB shader:

http://forums.thedarkmod.com/topic/15178-tdm-engine-development-page/page-4#entry352322

to GLSL (etc).

Source:

https://web.archive.org/web/20111203210912/http://mhquake.blogspot.com/2011/11/doom-3-shaders.html

Relevant code block: perform the diffuse bump mapping instead of using the normalization cube map, normalize with math

DP3 light, tex0,tex0; RSQ light, light.x; MUL light, light.x, tex0;

-----------------

TEX localNormal, tex1, texture[1], 2D; MOV localNormal.x, localNormal.a # normal map compression hack - is this the only shader they're used in????;

MAD localNormal, localNormal, scaleTwo, subOne; DP3 light, light, localNormal;

If you want the specular look, check out Maha-X's "Brilliant Highlights" mod which is the source of nearly every metallic shader mod for Vanilla Doom 3 including Sikkpin's mod. The problem being, of course, that it's not a PBR method so the true resolution is to author PBR materials to replace the metals in Doom 3 and use those for an accurate metal look.

— Reply to this email directly or view it on GitHub https://github.com/RobertBeckebans/RBDOOM-3-BFG/issues/282#issuecomment-170730631 .

nbohr1more commented 8 years ago

Well, that depends on whether Robert is a texture artist with PBR authoring tools too. The other option is to create a cvar to force a new interaction shader with the brilliant highlights feature similar to the half lambert cvar.

aFoxNamedMorris commented 8 years ago

Sounds like a good option for the average end user. On Jan 11, 2016 7:33 PM, "nbohr1more" notifications@github.com wrote:

Well, that depends on whether Robert is a texture artist with PBR authoring tools too. The other option is to create a cvar to force a new interaction shader with the brilliant highlights feature similar to the half lambert cvar.

— Reply to this email directly or view it on GitHub https://github.com/RobertBeckebans/RBDOOM-3-BFG/issues/282#issuecomment-170742851 .

ghost commented 8 years ago

@RobertBeckebans That Stochastic Screen-Space Reflections looks very impressive. Would it be possible to add some sort of cheap caustics with it?