[Patch] Specular Highlight

Technical discussion for those interested in Supermodel development and Model 3 reverse engineering. Prospective contributors welcome.
Forum rules
Keep it classy!

  • No ROM requests or links.
  • Do not ask to be a play tester.
  • Do not ask about release dates.
  • No drama!

Re: [Patch] Specular Highlight

Postby HarryTuttle » Thu Jul 27, 2017 3:02 pm

Ian wrote:Well I finally figured out why there is almost no specular on the model3 whilst in ours we had specular. It's because the model normals are not unit length. They are like 0.2 in length instead of 1. So I guess only receive 20% of the usual brightness.
I think it's safe to say we have probably figured out all the corner cases with regards to specular? Especially now we understand what LA machine guns is doing


This is what I'm currently after in my investigations on model scale behavior, I'll summarize my findings by this weekend then will post whatever I found. That could be hopefully a starting point. :)
User avatar
HarryTuttle
 
Posts: 558
Joined: Thu Mar 09, 2017 8:57 am

Re: [Patch] Specular Highlight

Postby Ian » Thu Jul 27, 2017 3:06 pm

I tried this in the vertex shader. Preserves normal length whilst deals with the scale of the model matrix

Instead of
Code: Select all
fsViewNormal = normalize(gl_NormalMatrix * gl_Normal);


This

Code: Select all
vec3 p1 = vec3(0.0,0.0,0.0) * mat3(gl_ModelViewMatrix);
vec3 p2 = vec3(0.577350269,0.577350269,0.577350269) * mat3(gl_ModelViewMatrix);
float mScale = length(p2-p1);

fsViewNormal = (gl_NormalMatrix * gl_Normal) * mScale;


Should probably add, p2 is just a unit length normal :)
Ian
 
Posts: 1216
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] Specular Highlight

Postby HarryTuttle » Sun Aug 06, 2017 3:39 pm

PATCH UPDATE (for r623):

- reworked specular behavior: modified coefficients, added a different light model for flat shaded polys (actually two, depending on ambient light level). The general look is even more similar to the real hw counterpart;

- for now viewport intensityClamp is set only for model step 1.0, otherwise scenes will be too dimmed on step 1.5+ games;

- polygon shading under dimmed / dark environments is correctly rendered, before the highlights were still too bright and pronounced;

- cosmetics: renamed every instance of specularCoefficient to specularValue to better follow the nomenclature in <PolyHeader.cpp>

Got no time to post screenshots right now, if you want to try and check with real hw footage start with these: SW Trilogy (intro with Darth Vader), Daytona 2, Scud Race, Le Mans 24, Harley (intro, check the surrounding buildings reflecting glasses).

Note for Daytona 2 PE and L.A. Machineguns: Supermodel correctly renders their lighting model (with negative, darkened, shaded parts), however it's unknown how the original hw selectively sets that behavior on or off. So for now the minimum value is always clamped to "0" and those two titles (maybe others ?) won't render fine, i.e. they'll look too bright with "flat" colors.

Patch:
Attachments
diff.zip
(3.57 KiB) Downloaded 28 times
User avatar
HarryTuttle
 
Posts: 558
Joined: Thu Mar 09, 2017 8:57 am

Re: [Patch] Specular Highlight

Postby Ian » Mon Aug 07, 2017 4:50 am

Harry,
few quick questions. How come you needed to do this?

Code: Select all
+            biasIndex = vec4(0.95, 0.95, 1.05, 1.0);
+            exponent = expIndex[int(shininess)] / biasIndex[int(shininess)];


That based on video observation? It wouldn't surprise me if the weighting of colors on videos were off .. so I'd be quite surprised if you needed that.

Also surely this clamp is not needed?
Code: Select all
specularFactor = min(specularFactor, 1.0);


If you are clamping here too
Code: Select all
+   // Final clamp: we need it for proper shading in dimmed light and dark ambients
+   finalData.rgb = min(finalData.rgb, vec3(1.0));
Ian
 
Posts: 1216
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] Specular Highlight

Postby HarryTuttle » Mon Aug 07, 2017 11:55 am

Ian wrote:How come you needed to do this?

Code: Select all
+            biasIndex = vec4(0.95, 0.95, 1.05, 1.0);
+            exponent = expIndex[int(shininess)] / biasIndex[int(shininess)];


That based on video observation? It wouldn't surprise me if the weighting of colors on videos were off .. so I'd be quite surprised if you needed that.


Yes, it's based on observation. However, when comparing with direct video captures I mostly match them with Supermodel using Virtual Dub. Nothing fancy: gamma curves, color temperature, etc. When done properly you're able to notice even the smallest difference.

Some explanation is needed: expIndex coefficient affects the sharpness and the diameter of the highlight spot (as the usual standard highlight formulae), multIndex the overall brightness / scale of the highlight. The latter is an addition on mine because the exponent alone is not sufficiently bright, even if its shape is correct. That's why I'm speculating that the Real3D uses look-up tables because, unless I missed something obvious, I can't find a simple formula.

Still I needed a last little adjustment. With biasIndex I can lower the brightness while incrementing the sharpness of the highlight, and vice versa. This was necessary to preserve the semplicity of the first two terms:
Code: Select all
expIndex = vec4(8.0, 16.0, 32.0, 64.0);
multIndex = vec4(2.0, 2.0, 3.0, 4.0);

Compared with my previous solution, without said bias and with not so obvious multIndex values :
Code: Select all
expIndex = vec4(8.0, 16.0, 32.0, 64.0);
multIndex = vec4(2.25, 1.85, 3.5, 5.6);

The good thing is that those values seem to produce in all games consistent results with the observed footage. There're still some very little quirks, but I wait for the proper quad poly emulation. Even changing, for example, the "Y" term of the biasIndex from 0.95 to 1.0, will overbright the cars in Scud and the car shading (especially the transparent glasses) in Daytona 2.

Ian wrote:Also surely this clamp is not needed?
Code: Select all
specularFactor = min(specularFactor, 1.0);


If you are clamping here too
Code: Select all
+   // Final clamp: we need it for proper shading in dimmed light and dark ambients
+   finalData.rgb = min(finalData.rgb, vec3(1.0));

At first specularFactor was clamped only for transparent polys, that was a safety measure to avoid alpha > "1", not sure what it could have break, but I left there because doesn't seem to hurt. On a second thought I choose to use it for all cases anyway. finalData.rgb instead clamps only the color components not alpha.

So in the end I think we can remove it and change finalData.rgb to cover all 4 channels (rgb + alpha). I'll try that on Scud and Daytona 2 and let you know. :)
User avatar
HarryTuttle
 
Posts: 558
Joined: Thu Mar 09, 2017 8:57 am

Re: [Patch] Specular Highlight

Postby Ian » Mon Aug 07, 2017 12:04 pm

Anyhow, version 1 of Harry's code :)

Specular highlights!!
Image

Aracde :)
Image

Looks almost perfect
Ian
 
Posts: 1216
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] Specular Highlight

Postby HarryTuttle » Mon Aug 07, 2017 12:12 pm

Ian, about video color match, what do you think about this? ;)

Model 3:
scud03a.jpeg
scud03a.jpeg (203.31 KiB) Viewed 490 times

Supermodel:
scud03b.jpeg
scud03b.jpeg (230.94 KiB) Viewed 490 times

It's clear that I have a problem with fixed shading (the wall in the background and the road)... :)
User avatar
HarryTuttle
 
Posts: 558
Joined: Thu Mar 09, 2017 8:57 am

Re: [Patch] Specular Highlight

Postby Ian » Mon Aug 07, 2017 12:19 pm

Haven't looked at fixed shading in a while .. however.

I think on step 1.5 it might works something like this
(vpambient + fixed shade value) / 2

The vpambient value changes, and so does the fixed shade brightness. You can see this brightness change on many videos.
Ian
 
Posts: 1216
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] Specular Highlight

Postby HarryTuttle » Mon Aug 07, 2017 12:27 pm

HarryTuttle wrote:So in the end I think we can remove it and change finalData.rgb to cover all 4 channels (rgb + alpha). I'll try that on Scud and Daytona 2 and let you know. :)


Just done and seems to produce the same good results, so I'll post and update soon. Then I'll try your suggested change for flat polys.

Done that I'd like have a final look at self-illuminated polys shade (which seems to be hardcoded to be multiplied by "1.5" on all steps 1.5 games) and, in the end, fixed shading now that we have finalized the light model.
User avatar
HarryTuttle
 
Posts: 558
Joined: Thu Mar 09, 2017 8:57 am

Re: [Patch] Specular Highlight

Postby Ian » Mon Aug 07, 2017 12:41 pm

You got some screenshots of the flat polys?
The normal normalisation code wouldn't effect flat polys, since they would all share the same normal at each vertex anyway
But it would effect regular polys
Ian
 
Posts: 1216
Joined: Tue Feb 23, 2016 9:23 am

PreviousNext

Return to The Dark Room

Who is online

Users browsing this forum: YoYo09 and 2 guests