Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix D3D9 Lighting Material #1530

Merged
merged 1 commit into from Feb 3, 2019

Conversation

Projects
None yet
2 participants
@RobertBColton
Copy link
Member

RobertBColton commented Feb 3, 2019

This pull request fixes some Direct3D9 rendering regressions for Project Mario. The specific problem is that vertices that do not have color data are not being rendered when lighting is enabled. Most of the models in Project Mario do not have color or alpha data, but do have texture and normal coordinates.

As is probably obvious, this is not the case with our OpenGL systems or classic GM where the vertices would be simply drawn opaque black. The problem stems from the fact that Direct3D9 uses a default material that's black and transparent where the 0 alpha of the default material cancels out the texel color of the vertex. To help clarify, you can think of the material as D3D's analog to glColor from OpenGL, but for lighting.

https://docs.microsoft.com/en-us/windows/desktop/direct3d9/materials

When you create a Direct3D device, the current material is automatically set to the default shown in the following table. Diffuse | (R:0, G:0, B:0, A:0)

https://docs.microsoft.com/en-us/windows/desktop/direct3d9/ambient-lighting

The value for Cₐ is either:

  • vertex color1, if AMBIENTMATERIALSOURCE = D3DMCS_COLOR1, and the first vertex color is supplied in the vertex declaration.
  • vertex color2, if AMBIENTMATERIALSOURCE = D3DMCS_COLOR2, and the second vertex color is supplied in vertex declaration.
  • material ambient color.

I likely introduced this regression in #1395 when I removed similar code originally added by me in c1b8ef1 that was setting a custom material when defining point lights. That way still had a problem because it is actually more correct and cleaner to only set the material once at startup so it affects all types of lights and because there is no need to change it. The cause of the confusion was that apitrace does not show you what the current material state is anywhere I could see it.

Master Pull
Project Mario D3D9 Master Project Mario D3D9 Pull Request

@RobertBColton RobertBColton force-pushed the fix-d3d9-lighting-material branch from 2801ab5 to 463336d Feb 3, 2019

@RobertBColton RobertBColton requested a review from JoshDreamland Feb 3, 2019

@RobertBColton

This comment has been minimized.

Copy link
Member Author

RobertBColton commented Feb 3, 2019

@JoshDreamland alright, this one is ready to go when you get a chance to look at it!

@RobertBColton RobertBColton merged commit aab95f2 into master Feb 3, 2019

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details

@RobertBColton RobertBColton deleted the fix-d3d9-lighting-material branch Feb 3, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.