Page 1 of 24

[Patch] Sun Shading

PostPosted: Mon Jul 17, 2017 8:05 am
by HarryTuttle
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 9683 times

(left = arcade, middle = Supermodel (bad), right = Supermodel (good))
lam02.jpeg
lam02.jpeg (231.51 KiB) Viewed 9683 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 9683 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.

Re: [Patch] Sun Shading

PostPosted: Mon Jul 17, 2017 12:54 pm
by Conversus W. Vans
Wow! Great work, Harry! How does this shading fix look with Harley LA Riders? IIRC, the bike drivers look brighter on the real hardware.

Re: [Patch] Sun Shading

PostPosted: Mon Jul 17, 2017 1:19 pm
by HarryTuttle
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...

Re: [Patch] Sun Shading

PostPosted: Mon Jul 17, 2017 1:34 pm
by Ian
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

Re: [Patch] Sun Shading

PostPosted: Mon Jul 17, 2017 1:48 pm
by HarryTuttle
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:

Re: [Patch] Sun Shading

PostPosted: Mon Jul 17, 2017 1:50 pm
by Ian
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.

Re: [Patch] Sun Shading

PostPosted: Mon Jul 17, 2017 1:58 pm
by HarryTuttle
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.

Re: [Patch] Sun Shading

PostPosted: Mon Jul 17, 2017 2:00 pm
by Ian
Post some comparison screenshots and maybe we can figure it out :)

Re: [Patch] Sun Shading

PostPosted: Mon Jul 17, 2017 2:12 pm
by HarryTuttle
That's it:
swt01.png
swt01.png (80.09 KiB) Viewed 9633 times

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

Apparently it doesn't matter if the polygon has specular highlight or not, or how much is the ambient light level.

Re: [Patch] Sun Shading

PostPosted: Mon Jul 17, 2017 2:14 pm
by Ian
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