[Patch] Sun Shading

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!

[Patch] Sun Shading

Postby HarryTuttle » Mon Jul 17, 2017 8:05 am

Ian, I've made some progress on regular sun lighting, i.e. excluding fixed-shading and self-illumination.

(left = arcade, right = Supermodel)
lam01.jpeg
lam01.jpeg (233.75 KiB) Viewed 1213 times

(left = arcade, middle = Supermodel (bad), right = Supermodel (good))
lam02.jpeg
lam02.jpeg (231.51 KiB) Viewed 1213 times

This one has always been under my nose and I never noticed (the mechanics' red suits) :oops:

(left = arcade, right = Supermodel)
d2pe01.jpg
d2pe01.jpg (228.26 KiB) Viewed 1213 times

In fragment shader we've always wrongly clamped the dot product between sun vector and vertex direction normal like this:
Code: Select all
// Compute diffuse factor for sunlight
sunFactor = max(dot(sunVector, fsViewNormal), 0.0);

instead it should be (so to have a negative shade):
Code: Select all
// Compute diffuse factor for sunlight
sunFactor = dot(sunVector, fsViewNormal);

In this regard I believe that ambient light could well be above 0.5, even 1.0, because that value will eventually be subtracted by the "sunFactor" value multiplied by sun intensity. Similarly to what happens in fixed-shading with signed values. In the end it seems there's no second sun light merged in.

The results are more consistent with the original Model3 screenshots. Obviously there're still the usual bits of corner cases / weirdness we're accustomed to when dealing with the Real3D.

Also I think there's a missing piece from the puzzle: the (in)famous model scale value that should be multiplied by the vertex direction normal ("fsViewNormal" component), so when it's 0.0 there's no shading; 1.0, vice versa, it's full scale shade. Without that value, as of now, we have some wrongly darkened object.

We should clamp *only* the specular highlight itself, like it's currently done, because you cannot have an absolute black spot on shining surfaces. If you are going to test it, please remove the 0.75 clamping of ambient light.
User avatar
HarryTuttle
 
Posts: 558
Joined: Thu Mar 09, 2017 8:57 am

Re: [Patch] Sun Shading

Postby ConversusVans » Mon Jul 17, 2017 12:54 pm

Wow! Great work, Harry! How does this shading fix look with Harley LA Riders? IIRC, the bike drivers look brighter on the real hardware.
- Conversus W. Vans (Paul)
User avatar
ConversusVans
 
Posts: 194
Joined: Sun Apr 27, 2014 3:27 pm
Location: The Abandoned Land

Re: [Patch] Sun Shading

Postby HarryTuttle » Mon Jul 17, 2017 1:19 pm

ConversusVans wrote:Wow! Great work, Harry! How does this shading fix look with Harley LA Riders? IIRC, the bike drivers look brighter on the real hardware.


Well, currently it has many dark shadow areas where instead it should be bright. I believe that while the general formula is right there're two problems:

- the aforementioned model scale value that is presumably used heavily in Ocean Hunter and maybe other games;

- a bit (?) that tells if a model should have negative shade or clamp that to zero. But where is this information stored? Probably is a model attribute;

Btw I'm still investigating...
User avatar
HarryTuttle
 
Posts: 558
Joined: Thu Mar 09, 2017 8:57 am

Re: [Patch] Sun Shading

Postby Ian » Mon Jul 17, 2017 1:34 pm

Harry, you genius!
I've no idea why the clamp isn't needed? Seems a really strange way of doing the maths, but either way it seems to look good for La machine guns

Image

That means the lighting in the Wii port is wrong :) Or partly wrong

And I think you maybe right, not sure the ambient lighting clamp is really needed at all anymore. Will do some testing and probably remove it
Ian
 
Posts: 1218
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] Sun Shading

Postby HarryTuttle » Mon Jul 17, 2017 1:48 pm

Ian wrote:That means the lighting in the Wii port is wrong :) Or partly wrong


That's why we should be proud of Supermodel! :)

We're slowly understanding all the "gotchas" of Real3D while others prefer following the standard formulae... :twisted:
User avatar
HarryTuttle
 
Posts: 558
Joined: Thu Mar 09, 2017 8:57 am

Re: [Patch] Sun Shading

Postby Ian » Mon Jul 17, 2017 1:50 pm

Congratulations, that's a really great discovery!
Gonna do a bit more testing and push it :)
The old formula in the shaders is pretty much the defacto standard for lighting I think.
Ian
 
Posts: 1218
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] Sun Shading

Postby HarryTuttle » Mon Jul 17, 2017 1:58 pm

I'm sure there's a bit somewhere that tells to clamp to zero or not the dot product, the most evident "offender" is the stage selection screen of SWTrilogy.

But there are also shadowed areas in all games where instead there should be a brighter surface.
User avatar
HarryTuttle
 
Posts: 558
Joined: Thu Mar 09, 2017 8:57 am

Re: [Patch] Sun Shading

Postby Ian » Mon Jul 17, 2017 2:00 pm

Post some comparison screenshots and maybe we can figure it out :)
Ian
 
Posts: 1218
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] Sun Shading

Postby HarryTuttle » Mon Jul 17, 2017 2:12 pm

That's it:
swt01.png
swt01.png (80.09 KiB) Viewed 1163 times

Another example (the car's shading and the rocks on the right):
scud01a.png
scud01a.png (241.8 KiB) Viewed 1163 times

Apparently it doesn't matter if the polygon has specular highlight or not, or how much is the ambient light level.
User avatar
HarryTuttle
 
Posts: 558
Joined: Thu Mar 09, 2017 8:57 am

Re: [Patch] Sun Shading

Postby Ian » Mon Jul 17, 2017 2:14 pm

Yeah I see :)
Virtua fighter 3 also looks a bit broken without clamping
Need to work out what games this fixed, and do a spot the difference on the viewport values
Ian
 
Posts: 1218
Joined: Tue Feb 23, 2016 9:23 am

Next

Return to The Dark Room

Who is online

Users browsing this forum: No registered users and 1 guest