H-uru / Plasma

Cyan Worlds's Plasma game engine
http://h-uru.github.io/Plasma/
GNU General Public License v3.0
202 stars 80 forks source link

Per pixel lighting support in Metal #1551

Open colincornaby opened 6 months ago

colincornaby commented 6 months ago

This PR adds Metal per pixel lighting support to the shaders - controlled by a preprocessor flag. Per pixel lighting defaults to off in since it's an alternative rendering mode that does not match the original engine. While per pixel lighting seems correct - it should be regarded as experimental. Per pixel shading enables a shader variant for the "fixed" pipeline shader. This shader variant is controlled by a shader compile time flag. However - this flag is a function constant which means evaluation of it can be deferred to when the shader is compiled from Metal byte code into vender specific assembly. I.E. - Metal can wait to apply the flag until the final runtime shader compilation.

Metal was originally ported from the OpenGL fork which used per pixel lighting. Metal switched back to per vertex for several reasons:

Please look over this closely - I want to make sure the per vertex path has remained unchanged. Not in a rush to get this in.

colincornaby commented 1 month ago

I brought this branch up to date with master - and now it's acting strangely. For example - it's hitting asserts while trying to load the server.ini. I'll dig a bit and see whats going on. I'm pretty sure this behavior is newly unique to this branch. Last time I was in here it was working.

colincornaby commented 1 month ago

The issue I was befuddled by is addressed in #1591.

dpogue commented 1 month ago

FWIW I'm pretty sure OpenGL is also doing per-vertex lighting to match DirectX.

I might have been doing that in the fragment shader at one point while I was getting it set up, but it's in the vertex shader in the current version of the GL branch.

colincornaby commented 2 weeks ago

Re-stating discussions elsewhere here for the status on this branch.

Relative to this PR:

We'll want to move ahead with this PR to get normal mapping into Metal.