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

Partial fix for Issue #2087 (NegativeScaleTest) #2091

Merged
merged 5 commits into from
Oct 17, 2023

Conversation

codex128
Copy link
Contributor

@codex128 codex128 commented Oct 10, 2023

This PR partially fixes #2087 by "flipping" the face cull mode as the render state is applied to the renderer if the geometry world scale is found to be negative. This does not alter the normal vectors, so shaders still receive backwards normals and models still may not appear quite right (especially with normal maps), but this fixes the face culling issue, at least.

@codex128 codex128 changed the title Partial Fix Issue #2087 (uncertain) Partial Fix for Issue #2087 (uncertain) Oct 10, 2023
@codex128 codex128 changed the title Partial Fix for Issue #2087 (uncertain) Partial Fix for Issue #2087 Oct 10, 2023
@stephengold
Copy link
Member

Did you test these changes on the "NegativeScaleTest" model?

@stephengold stephengold added the defect Something that is supposed to work, but doesn't. Less severe than a "bug" label Oct 11, 2023
@codex128
Copy link
Contributor Author

Oops, no, I didn't. Tested it out just now, and yes, the changes fixed the test model so there are no Xs anymore. I think it may have also fixed the shading on the spheres, but I couldn't tell for certain.

@stephengold stephengold changed the title Partial Fix for Issue #2087 Partial fix for Issue #2087 (NegativeScaleTest) Oct 15, 2023
@stephengold stephengold added this to the Future Release milestone Oct 15, 2023
Copy link
Member

@stephengold stephengold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@riccardobl riccardobl added the hacktoberfest-accepted PRs that are Hacktoberfest valid (Optional if PR is merged or approved during the month of october) label Oct 16, 2023
@stephengold stephengold merged commit 5975b3f into jMonkeyEngine:master Oct 17, 2023
14 checks passed
@stephengold
Copy link
Member

Hey @codex128 ! Thanks for your contribution to JMonkeyEngine.

@Trass3r
Copy link
Contributor

Trass3r commented Oct 24, 2023

According to git bisect this broke our rendering as soon as shadows are enabled.
There's an incorrect glDepthMask(false) for some of the rendered opaque geometry, I guess from the PreShadow material.
Can anyone confirm?

@codex128
Copy link
Contributor Author

codex128 commented Oct 24, 2023

My first guess would be that RenderState#set is problematic, since my change uses set, while the previous code did not. Are you using a shadow filter or a shadow renderer?

@Trass3r
Copy link
Contributor

Trass3r commented Oct 24, 2023

Yeah from my debugging might be ForcedRenderState related.
Happens with both renderer and filter.

@codex128
Copy link
Contributor Author

I've opened #2130 which should fix this issue.

@stephengold
Copy link
Member

Thank you @codex128 for following up on issue #2129.

@JohnLKkk
Copy link
Contributor

JohnLKkk commented Nov 4, 2023

I just found a problem locally. This modification seems to have caused an exception with ShadowFilter (running TestDirectionalLightShadow.java results in a black screen). I found this issue at commitID=5975b3f791d18fae311a10e209b3ed40b5e5c60f.

@JohnLKkk
Copy link
Contributor

JohnLKkk commented Nov 4, 2023

private void updateRenderState(Geometry geometry, RenderManager renderManager, Renderer renderer, TechniqueDef techniqueDef) { if (renderManager.getForcedRenderState() != null) { mergedRenderState.set(renderManager.getForcedRenderState()); } else if (techniqueDef.getRenderState() != null) { // copyMergedTo writes to mergedRenderState techniqueDef.getRenderState().copyMergedTo(additionalState, mergedRenderState); } else { RenderState.DEFAULT.copyMergedTo(additionalState, mergedRenderState); } // test if the face cull mode should be flipped before render if (mergedRenderState.isFaceCullFlippable() && isNormalsBackward(geometry.getWorldScale())) { mergedRenderState.flipFaceCull(); } renderer.applyRenderState(mergedRenderState); }
It should be changed to:
private void updateRenderState(Geometry geometry, RenderManager renderManager, Renderer renderer, TechniqueDef techniqueDef) { if (renderManager.getForcedRenderState() != null) { mergedRenderState.set(renderManager.getForcedRenderState()); } else if (techniqueDef.getRenderState() != null) { // copyMergedTo writes to mergedRenderState mergedRenderState.set(techniqueDef.getRenderState().copyMergedTo(additionalState, mergedRenderState)); } else { mergedRenderState.set(RenderState.DEFAULT.copyMergedTo(additionalState, mergedRenderState)); } // test if the face cull mode should be flipped before render if (mergedRenderState.isFaceCullFlippable() && isNormalsBackward(geometry.getWorldScale())) { mergedRenderState.flipFaceCull(); } renderer.applyRenderState(mergedRenderState); }

@stephengold
Copy link
Member

stephengold commented Nov 4, 2023

@JohnLKkk Thank you for reporting the issue! Two things:

  1. When quoting multiple lines of code at GitHub, please use triple backticks so line breaks and indentation will be preserved, like so:
public static int main(String... args) {
    return 0;
}
  1. Please open a new PR with your fix so it can be reviewed and integrated ASAP.

@codex128
Copy link
Contributor Author

codex128 commented Nov 4, 2023

I believe this problem was fixed in #2130.
TestDirectionalLightShadow.java is working fine for me on that branch.

@JohnLKkk
Copy link
Contributor

JohnLKkk commented Nov 5, 2023

@JohnLKkk Thank you for reporting the issue! Two things:

  1. When quoting multiple lines of code at GitHub, please use triple backticks so line breaks and indentation will be preserved, like so:
public static int main(String... args) {
    return 0;
}
  1. Please open a new PR with your fix so it can be reviewed and integrated ASAP.

Thank you for your guidance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Something that is supposed to work, but doesn't. Less severe than a "bug" hacktoberfest-accepted PRs that are Hacktoberfest valid (Optional if PR is merged or approved during the month of october)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

jme3-plugins imports NegativeScaleTest incorrectly
5 participants