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

Gloss control #131

Closed ghost closed 8 years ago

ghost commented 9 years ago

Hey guys,

I'm really digging the new RB-BFG engine and I was wondering if Gloss control is out of the question?

It'd be neat if it was something similar to how Prey supports it in their Materials.

Right now I am trying to make a map for this engine and Gloss support would be very very cool.

If possible, store the Gloss map in the alpha channel of the Specular, or a separate image, I don't think that is super important.

motorsep commented 9 years ago

Same thing as in Doom 3 - alpha channel of specular works as gloss. Supported out of the box.

ghost commented 9 years ago

That's interesting, I'll have to try that when I get home then, Thanks!

BielBdeLuna commented 9 years ago

Motorsep, I didn't know about that. Do you need to do anything special in the material in order for it to recognize the alpha channel in the specular map?

motorsep commented 9 years ago

nope, material system doesn't support it. I don't know for sure BFG engine supports it, but idTech 4 does.

RobertBeckebans commented 9 years ago

The BFG renderer does not support alpha values in the specularmaps. It would require changes to the .bimage format with DXT5 instead of DXT1 RGB compression and changes to the interaction shaders.

2014-06-04 22:54 GMT+02:00 motorsep notifications@github.com:

nope, material system doesn't support it. I don't know for sure BFG engine supports it, but idTech 4 does.

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

BielBdeLuna commented 9 years ago

and having the material shader having a "gloss" value for a more generalist approach to the issue? so instead of having a new map to take care of, maybe it could be easier to treat the whole surface of that material as a whole when it comes to glossiness level. would it be?

ghost commented 9 years ago

Biel, yeah that'd be a pretty good trade off. Controlling the "sharpness" of the specular like Prey does in the material. I've gotten some decent results doing, Not UE4 results, but good enough.

ghost commented 9 years ago

I added an alpha channel to my specular and it didn't change the gloss at all. In Vanilla D3

motorsep commented 9 years ago

@garthhendy Your alpha channel has to be <250 RGB, otherwise it will be treated as 255, which is what engine uses by default for gloss.

Material shader? What is that? GLSL shader? Why do that and give up a bit of performance?

ghost commented 9 years ago

I'm painting with grey 175 RGB value with a black back ground and it doesn't affect the gloss at all.

BielBdeLuna commented 9 years ago

no, Motorsep I meant a new argument in the material shader definition, so it's the whole surface that is treated equal, you don't get the same control, as having a an image to express different gloss values for every texel, but you get some on the glossiness on the whole of the material. it might prove an improvement on the gloss from standard D3 where everything has the same amount of gloss.

ghost commented 9 years ago

http://i.imgur.com/NKPRthk.jpg screenshot of material

http://i.imgur.com/0TmQpUn.jpg shot of the alpha channel. As you can see I get nothing affecting the gloss. The metal part in the middle should be affected.

ghost commented 9 years ago

So I did a bit of googling and people reference Carmack saying Doom 3 doesn't support gloss maps. Engine coders who are dabbling with the engine say it doesn't support gloss maps. So something is a miss here.

BielBdeLuna commented 9 years ago

in fact in d3w.org there was a funny user who kept posting on this issue but soon it turned to postwar. it was funny back then. but one thing is doom3 as a product, another the open source engine. gloss maps are possible (in fact it's one of the new things on the new rendering techniques in the render engines today)

ghost commented 9 years ago

Oh yeah gloss is possible. I found it strange that all of a sudden I didn't know vanilla D3 supported Gloss maps. I've been using the engine since 2004 and shipped a retail game on idtech4 so I'm pretty well versed in knowing what it can and cannot do.

I'd still be totally down with how Prey controls the gloss though. No alpha channel, just values in the material.

{
blend   specularmap
map     textures/scifi_clean/scifi_clean_s
specularexp 240, 1
}   

A value of 1 gives it a soft skin look, a value of 240 is like metal, and 750 is like a wet slime look.

I played around with this in Prey a bunch and it's pretty damn good.

motorsep commented 9 years ago

@garthhendy What idTech 4 game did you ship and what was your role?

I'll check our old engine and see if gloss was ever added in the code. I am almost positive it was supported from day 1.

RobertBeckebans commented 9 years ago

From base/renderprogs/interaction.pixel

That is the part that controls the light equation and specular contribution

const half specularPower = 10.0f; half hDotN = dot3( normalize( fragment.texcoord6.xyz ), localNormal ); half3 specularContribution = _half3( pow( abs( hDotN ), specularPower ) );

half3 diffuseColor = diffuseMap * rpDiffuseModifier.xyz; half3 specularColor = specMap.xyz * specularContribution rpSpecularModifier.xyz; half3 lightColor = lightProj.xyz \ lightFalloff.xyz;

result.color.xyz = ( diffuseColor + specularColor ) * lambert * lightColor

Vanilla D3 used texture lookup to calc the specular contribution so it had a fixed specular power too.

A simple gloss map implementation would be to scale the alpha channel of the specMap which is in range from 0 to 1 to something like 0 and 100.

Then it would be something like

const half specularPower = specMap.a * 100; half3 specularContribution = _half3( pow( abs( hDotN ), specularPower ) )

However this would break compatibility with the original assets because if there is no alpha value then specMap.a will be 1 and 1 * 100 = 100 instead of 10. The result would be similar to UE4 roughness 0. I'm not sure if a scalar multiplier like 10 is enough for good artistic control.

2014-06-05 1:13 GMT+02:00 motorsep notifications@github.com:

@garthhendy https://github.com/garthhendy What idTech 4 game did you ship and what was your role?

I'll check our old engine and see if gloss was ever added in the code. I am almost positive it was supported from day 1.

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

motorsep commented 9 years ago

@RobertBeckebans Where in idTEch 4 would that look up code for specular be? I could diff my fork with vanilla and see if gloss code was added at some point.

RobertBeckebans commented 9 years ago

In the interaction.vfp ARB assembly shader.

2014-06-05 1:25 GMT+02:00 motorsep notifications@github.com:

@RobertBeckebans https://github.com/RobertBeckebans Where in idTEch 4 would that look up code for specular be? I could diff my fork with vanilla and see if gloss code was added at some point.

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

motorsep commented 9 years ago

Ahh, too good to be true - indeed that was added to the shader :( I thought Doom 3 always supported gloss.

BielBdeLuna commented 9 years ago

now I've found again the Sikkpin mod that added gloss maps in the alpha channel of the specular map https://web.archive.org/web/20130909073250/http://www.doom3world.org/phpbb2/viewtopic.php?t=24193 in here there is the ARB implementation on having lights with cubemaps