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

Implement rendering pipeline and post-processing #12465

Merged
merged 132 commits into from
Sep 6, 2022

Conversation

x2048
Copy link
Contributor

@x2048 x2048 commented Jun 20, 2022

This PR implements rendering pipeline as described in #12411 Alternative B and a minimal post-processing shader on top of the pipeline.

Fixes #12411 and fixes #5446

To do

This PR is Ready for review

  • Define base classes
  • Implement simple rendering steps (3D and HUD)
  • Implement RenderingCorePlain as a pipeline
  • - Rendering to a TextureBuffer
  • - Scaling as a pipeline step
  • Implement Stereo modes
  • - Anaglyph
  • - Interlaced
  • - Page flip removed because not supported by current Irrlicht version
  • - Side by Side / Top Bottom / Cross eyed
  • Handle window resizing in a generic way
  • Implement shadow mapping as a pipeline step
  • Implement post-processing as a pipeline step
  • Implement common pipeline factory for 3D stage
    Merge undersampling with all 3d modes - postponed to a future PR
  • Merge post-processing with all 3d modes
  • Move tonemapping to postprocessing
  • Optimize use of textures
  • Fix spaces vs tabs
  • Make it work on GLES2

How to test

  • Choose your favorite stereo mode with or without shaders
  • Start the game
  • Everything must work correctly

@x2048 x2048 added WIP The PR is still being worked on by its author and not ready yet. @ Client rendering labels Jun 20, 2022
@x2048 x2048 changed the title Implement deferred shading Implement rendering pipeline and post-processing Jun 20, 2022
@rubenwardy rubenwardy added Roadmap The change matches an item on the current roadmap Feature ✨ PRs that add or enhance a feature labels Jun 20, 2022
@rubenwardy rubenwardy added this to the 5.7.0 milestone Jul 10, 2022
@x2048 x2048 force-pushed the deferred_rendering branch 3 times, most recently from bedc367 to 23c51aa Compare July 13, 2022 01:03
@x2048 x2048 removed the WIP The PR is still being worked on by its author and not ready yet. label Jul 15, 2022
@lhofhansl
Copy link
Contributor

Tried. Everything seems to work as before.
@x2048 That's a lot of code to review. Anything you'd like to focus on?

@x2048
Copy link
Contributor Author

x2048 commented Jul 15, 2022

@lhofhansl I'd love you feedback on the way pipelines are built, side-by-side would be a good example.
And the framework itself pipeline.h / pipeline.cpp may need a pair of eyes.

Thank you!

@x2048 x2048 requested a review from lhofhansl July 15, 2022 17:02
minetest.conf.example Outdated Show resolved Hide resolved
@x2048
Copy link
Contributor Author

x2048 commented Jul 16, 2022

@lhofhansl I've made slight changes to the pipeline framework, removing duplicated code here and there.

@lhofhansl
Copy link
Contributor

With the latest update I find different behavior:

  1. the sun is no longer rendered
  2. shadows are suddenly view angle dependent
  3. entities are do not have shadows on them anymore

(I'm pretty sure this did not happen when I tested yesterday)

@x2048
Copy link
Contributor Author

x2048 commented Jul 16, 2022

Hmm... I can't confirm. Sun and entity self-shadowing can be seen here:
image

Area where shadows are rendered is dependent on view angle and it may be noticed if you rotate head fast, when shadow_update_frames is 8 or 16.

@lhofhansl
Copy link
Contributor

Hmm... Lemme test that again...

@lhofhansl
Copy link
Contributor

Re-compiled everything. The sun is visible. My mistake.

But the other issues remain. What thew me off is that shadows seem to dependent on the aliasing setting. When aliasing is none, then entities self-shadow, but blocks no longer have shadows. At other aliasing settings blocks have shadows again, but entities don't. So some problems with the pipeline setup I assume.

@lhofhansl
Copy link
Contributor

Shadow issue remain with latest push (antialiasing affecting whether shadows work or not)

@Andrey2470T
Copy link
Contributor

@x2048 I don't understand how to test sun rays effect which judging by your words in 'Postprocessing' Minetest Forums topic you added in this PR. I just don't see those rays neither in MTG nor in Devtest games.

@x2048
Copy link
Contributor Author

x2048 commented Jul 19, 2022

@Andrey2470T , the godrays are on a separate branch, to keep this PR scoped.

@x2048
Copy link
Contributor Author

x2048 commented Jul 19, 2022

@lhofhansl Can it be a driver problem? I can see all shadows with any AA setting (might be AA does not work for me at all?)

@lhofhansl
Copy link
Contributor

@x2048 possible, but not likely. This is with the current Nvidia driver and only with this change.
Lemme try with Intel as well.

@lhofhansl
Copy link
Contributor

Nope tested with NVidia and Intel. Definitely something weird. Shadows are off when starting Minetest, then when switching antialiasing (without existing Minetest) shadows show up again.
Again. With both NVidia and Intel.

It is as if shadows are missing from the pipeline and then added when antialiasing is changed.

screenshot_20220719_161014
screenshot_20220719_161053

@Andrey2470T
Copy link
Contributor

Yes, they render now. I noted the rays will disappear at once as soon as the sun gets outside the player camera view. I don't know exactly whether this behaviour is correct or needs a fix.

@x2048
Copy link
Contributor Author

x2048 commented Jul 19, 2022

@Andrey2470T This is a known limitation, and I've made the transition subtle in the latest commit.

@lhofhansl
Copy link
Contributor

So I'm happy to merge this without the caching. @x2048 do you think that would be OK (is the caching helping much)? Or do do you think we should try to track that down first?

BTW. I tried to check the results of the setters and only cache when the return value indicates success, but that does not solve the problem.

@x2048
Copy link
Contributor Author

x2048 commented Aug 28, 2022

It was a long shot, glad that it worked.

I'd like to try and fix this. Caching uniforms was not without a reason.

@x2048
Copy link
Contributor Author

x2048 commented Aug 28, 2022

Draft documentation on how to play with the pipeline until a better API is created: https://gist.github.com/x2048/7b398f6e10a0f302971d034931dadfa5

@lhofhansl
Copy link
Contributor

FYI. I changed the *ShaderSetting template such that I can control for each instance whether it's cached or not.
If all settings in game.cpp, clientenvironment.cpp, shadowScreenQuad.h are cached everything still works fine, so it must be one or more of the *ShaderSettings in shader.cpp itself.

@lhofhansl
Copy link
Contributor

It's one or more of these in shader.cpp:

	CachedPixelShaderSetting<f32, 16, false> m_shadow_view_proj;
	CachedPixelShaderSetting<f32, 3, false> m_light_direction;
	CachedPixelShaderSetting<f32, 1, false> m_texture_res;
	CachedPixelShaderSetting<f32, 1, false> m_shadow_strength;
	CachedPixelShaderSetting<f32, 1, false> m_time_of_day;
	CachedPixelShaderSetting<f32, 1, false> m_shadowfar;
	CachedPixelShaderSetting<f32, 4, false> m_camera_pos;
	CachedPixelShaderSetting<s32, 1, false> m_shadow_texture;

(Note I added a "cache" parameter to the template).

@x2048
Copy link
Contributor Author

x2048 commented Aug 29, 2022

This is good finding. Did you manage to narrow it down further to a specific setting?

@lhofhansl
Copy link
Contributor

Not, yet. It seems if I cache any of these I see the effect again. I had limited time yesterday, I'll try some more today.

@lhofhansl
Copy link
Contributor

Ok. It's these two:

	CachedPixelShaderSetting<f32, 16, false> m_shadow_view_proj;
	CachedPixelShaderSetting<f32, 4, false> m_camera_pos;

If either of these are cached, shadows sometimes do not display.

@x2048
Copy link
Contributor Author

x2048 commented Aug 29, 2022

Is there a branch somewhere that I could pull in? I guess, we can go with two uncached uniforms and solve it later.

@lhofhansl
Copy link
Contributor

Is there a branch somewhere that I could pull in? I guess, we can go with two uncached uniforms and solve it later.

Not easily right now, sorry.

@lhofhansl
Copy link
Contributor

But here's the simple change to shader.h. And then you can mark the two constants with false.

shader.diff.txt

Use shader info ID instead of material renderer ID as step state
Use tile material and draw type values that avoid collisions with main nodes
@x2048
Copy link
Contributor Author

x2048 commented Aug 31, 2022

@lhofhansl Can you try now? I changed what makes the state of PostProcessingStep and which material type is passed when generating the shader.

Edit: It affects how MT shader system caches the material for the post-processing shader, and as a result how that shader works, including when the cached uniform values may be used.

@lhofhansl
Copy link
Contributor

It's still happening :(

Copy link
Member

@sfan5 sfan5 left a comment

Choose a reason for hiding this comment

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

Works on GL and GLES

there's a minor review comment remaining, please address it!

@lhofhansl
Copy link
Contributor

If we merge as is, we should at least avoid caching the two shader constants I have identified as causing the shadow issues.

x2048 and others added 2 commits September 4, 2022 23:15
Fixes instability of shadows on certain hardware

Co-authored-by: lhofhansl <[email protected]>
@x2048
Copy link
Contributor Author

x2048 commented Sep 4, 2022

@lhofhansl I've pushed the changes that disable caching of light space matrix and light vector. Can you verify?

src/client/shader.cpp Outdated Show resolved Hide resolved
@lhofhansl
Copy link
Contributor

lhofhansl commented Sep 5, 2022

Works.

(BTW. The new volumetric light with bloom is pretty awesome. I hope we can get that one shortly after this.)

@x2048 x2048 merged commit ff6dcfe into minetest:master Sep 6, 2022
@x2048 x2048 deleted the deferred_rendering branch September 6, 2022 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@ Client rendering Feature ✨ PRs that add or enhance a feature Roadmap The change matches an item on the current roadmap >= Two approvals ✅ ✅
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: Refactoring RenderingCore stack Add shader-based post-processing