[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 Ian » Tue Jun 27, 2017 1:46 am

Not yet, but it's interesting to note that ocean hunter has a very similar shading problem, but in reverse. In supermodel it there is shading, on the real hw it's gone completely, and the model is only lit by ambient. And this only seemed to happen when a scaling matrix was applied to the model.
Ian
 
Posts: 1216
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] Specular Highlight

Postby Ian » Tue Jun 27, 2017 1:17 pm

Well .. i checked out the size of the model normals and they all came out unit length

Code: Select all
   "fsViewNormal   = gl_NormalMatrix  *gl_Normal;\n"
   "float len = length(fsViewNormal);\n"
   "if(len>1.1) {fsColor = vec4(1,0,0,1);}\n"
   "else if(len<0.9) {fsColor = vec4(0,1,0,1);}\n"
   "else  {fsColor = vec4(0,0,1,1);}\n"


Just sets the colour based upon normal length
>1 = red
<1 = green
1~ = blue

Image
Ian
 
Posts: 1216
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] Specular Highlight

Postby Ian » Tue Jun 27, 2017 1:54 pm

Well I tried just simply clamping the ambient to 0.75

Image

This is the Wii version running under Dolphin

Image

The Wii version no doubt renders with triangles, where as the model3 was using quads with quadratic interpolation, so the shading is a bit different in each version. But it could well be the ambient is clamped at something like 0.75. Not sure if that has any negative effects in other games. Don't recall any other games using an ambient of 1.
Ian
 
Posts: 1216
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] Specular Highlight

Postby Bart » Tue Jun 27, 2017 10:14 pm

This is maddening and I'm amazed at the progress you guys have made :)

Why would there be an arbitrary clamp like this? It doesn't seem to make sense... Is there anything about the viewport these models are drawn in that might suggest a different clamp value?
User avatar
Bart
Site Admin
 
Posts: 2058
Joined: Thu Sep 01, 2011 2:13 pm
Location: New York City

Re: [Patch] Specular Highlight

Postby Ian » Wed Jun 28, 2017 2:19 am

I've no idea >_< As always it's possible the logic is wrong .. but i can't see any other reason for this.
Ambient of 1 is a bit of an oddball because it essentially disables regular lighting completely
Will test other games when I have some time to see if anything else set an ambient of 1
Ian
 
Posts: 1216
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] Specular Highlight

Postby Ian » Thu Jun 29, 2017 12:19 pm

HarryTuttle wrote:
Ian wrote:What did you think about the lost world bullets?


Actually it seems there's a little highlight on the right half. I get this shade in Supermodel, in line with the arcade:
lw2.jpeg


Well I finally had a chance to look at this. The lost world bullets shouldn't have specular at all because the light shines directly towards you. We are lighting the back faces! Should be simple enough to do a dot product between the light angle/normal to check we aren't lighting the back faces of objects.

Need to have a closer look at Harry's specular code because he clearly got a lot further with this problem than me.
Ian
 
Posts: 1216
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] Specular Highlight

Postby Bart » Thu Jun 29, 2017 2:42 pm

Regarding the 0.75 clamp -- what if the highest bit of the ambient light value is not used at all, but the rest of the bits form a value that ranges from 0 to 0.5? For example, instead of:

Code: Select all
lightingParams[4] = (float) ((vpnode[0x24]>>8)&0xFF) * (1.0f/255.0f);


What if it's:

Code: Select all
lightingParams[4] = (float) ((vpnode[0x24]>>8)&0x7F) * (1.0f/255.0f);


Does this look really wrong? At any rate, I don't think the Scud Race debug menu corroborates it but who knows if even that is to be trusted.

Another thought is -- is it possible that some part of the lighting calculation is actually unclamped and *wraps*? Seems unlikely if floating point values are used internally but if any of the math is done in fixed point integral format, it could be a remote possibility.
User avatar
Bart
Site Admin
 
Posts: 2058
Joined: Thu Sep 01, 2011 2:13 pm
Location: New York City

Re: [Patch] Specular Highlight

Postby Ian » Thu Jun 29, 2017 3:02 pm

I had actually thought maybe only 7 bits could be used? Quite possible. I'll dig around into the SDK to see if I can find anything
Ian
 
Posts: 1216
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] Specular Highlight

Postby Ian » Thu Jun 29, 2017 3:21 pm

This is the SDK function

void __thiscall PRO_Viewport::SetSunIlluminationData(PRO_Viewport *this, float ambient_contribution, float sun_contribution)
{
PRO_Viewport *v3; // esi@1
unsigned __int8 v5; // c0@1
unsigned __int8 v6; // c3@1
double v7; // st7@2
double v8; // st7@5
float v9; // [sp+8h] [bp-Ch]@1
float v10; // [sp+8h] [bp-Ch]@9
float v11; // [sp+Ch] [bp-8h]@1
float v12; // [sp+10h] [bp-4h]@1

v11 = ambient_contribution;
v3 = this;
v12 = sun_contribution;
v9 = sun_contribution + ambient_contribution;
if ( !(v5 | v6) )
{
v7 = ambient_contribution;
v7 = v7 / v9;
v11 = v7;
v8 = sun_contribution;
v8 = v8 / v9;
v12 = v8;
}
v10 = v11;
if ( v11 >= 1.0 )
v10 = 0.99900001;
*((float *)v3 + 65) = v12;
*((_BYTE *)v3 + 82) = (signed __int64)(v10 * 256.0);
PRO_Pingpong_Data_Block::NotifyUpdate(v3);
}


So it's definitely using just 8 bits. Code is also confusing. It seems to force normalise the sunparamaters, so they always add up to one. Unless I am reading it incorrectly.

The manual says this
The default provides an ambient lighting of 0.5 and a sun intensity of 0.5. These values should not add to more than 1.0 or be negative.
Ian
 
Posts: 1216
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] Specular Highlight

Postby Ian » Thu Jul 27, 2017 2:15 pm

HarryTuttle wrote:
Ian wrote:What did you think about the lost world bullets?


Actually it seems there's a little highlight on the right half. I get this shade in Supermodel, in line with the arcade:
Image


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
Ian
 
Posts: 1216
Joined: Tue Feb 23, 2016 9:23 am

PreviousNext

Return to The Dark Room

Who is online

Users browsing this forum: No registered users and 2 guests