-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implement an Sample-Distribution Shadow Mapping filter #2578
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
base: master
Are you sure you want to change the base?
Conversation
codex128
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry this took me so long.
jme3-core/src/main/java/com/jme3/renderer/opengl/ComputeShader.java
Outdated
Show resolved
Hide resolved
| * The shader should not be used after calling this method. | ||
| */ | ||
| public void delete() { | ||
| gl.glDeleteProgram(programId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest making use of the NativeObjectManager to ensure the shader is properly deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a minor problem with using NativeObjectManager; the renderer doesn't expose its instance. It could be made to expose that (or a way to add NativeObjects to its own?).
I could also create a NativeObjectManager for the filter itself, but it would also need to be polled for dead objects every frame. Not sure what the best way to do it would be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or a way to add NativeObjects to its own?
This sounds good to me. Keep the manual destroy method around, too, in case there is a situation where GLRenderer is not available.
| * Deletes this buffer and releases GPU resources. | ||
| * The buffer should not be used after calling this method. | ||
| */ | ||
| public void delete() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, consider using NativeObjectManager for this.
jme3-core/src/main/resources/Common/MatDefs/Shadow/Sdsm/SdsmPostShadow.frag
Outdated
Show resolved
Hide resolved
|
Pulled this branch and ran the test. Worked flawlessly and looks absolutely amazing! |
Full engine compute shader support would require a setup similar to Material with proper uniforms, defines, versioning, etc. That is a lot of work and Material itself is pretty well baked into the vertex pipeline. Probably best to work with the limited support this PR offers until jme4 rolls around. |
codex128
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks good to me.
The only thing that should be done now is to have ComputeShader, GLFence, and ShaderStorageBufferObject extend NativeObject.
Sample-Distribution Shadow Mapping (SDSM) is a technique for dynamically fitting the shadow maps of a shadow filter to the depth samples that will be needed, resulting in improved shadow quality.
This commit adds the option to use a SdsmDirectionalLightShadowFilter in place of a regular DirectionalLightShadowFilter. Usage requires GL 4.3+ support.
I don't think this is 100% ready for merging immediately, but it does work. I've been told there might be code for compute shaders coming, in which case this can be adapted to use that instead of somewhat kludgily inventing its own wheel. There's a lot around handling specific GL 4.3+ APIs (for example this needs compute shaders) that I'm not sure how engine wants to do it.
Mentioned on the forums here:
https://hub.jmonkeyengine.org/t/reducing-shadow-motion-issues/49289/3
Included is a TestSdsmDirectionalLightShadow sample app. I was using a stripped down version of the Sponza model to test lighting, but it's still pretty big and it didn't seem like large test data gets included in PRs. It's available here, and goes in the jme3-examples directory alongside "town.zip": https://drive.google.com/file/d/18mmwRPe--gskuWjfBfv9nB-dCSzfa1eB/view?usp=sharing
Example with SDSM:

Example without SDSM:

(Note that some parts of the translation from Kotlin to Java I delegated to Claude Code, so if there are still some uselessly verbose parts I didn't catch those can be fixed.)