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

Screen Space Reflections (SSR) #181

Merged

Conversation

Kagamma
Copy link
Member

@Kagamma Kagamma commented Aug 15, 2020

This PR adds SSR screen effect to the engine.

The shader is based on Riccardo Balbo's implementation of SSR: https://github.com/riccardobl/SimpleSSRShader

TCastleViewport have 2 new properties:

  • ScreenSpaceReflections: Enable(true)/Disable(false) SSR. Default is false.
  • ScreenSpaceReflectionsSurfaceGlossiness: Adjust default surface glossiness (0..1). Default is 0.5.

Limitations:

  • Since we lack various information about the scene (mainly because the engine doesn't have Deferred Rendering pipeline), the whole scene is reflectable - no bump mapping, roughness or metallic check.
  • No filters (I can't figure out how best to implement it without resorting to low-level APIs).

Some screenshots:
image1
image
image4
image2

@michaliskambi
Copy link
Member

This looks great. Thank you!

My main concern is that I would not like to implement it by another Boolean variable inside TCastleViewport and I would not like it to add this inside (already large) CastleViewport unit. Which is all my fault -- ScreenSpaceAmbientOcclusion is implemented as a Boolean variable like that, and I didn't propose a better design for it yet.

My idea is to remake ScreenSpaceAmbientOcclusion, and also ScreenSpaceReflections now, as components, that could reside in a different unit (like CastleViewportScreenEffects? ).

The TCasleScreenEffects already offers a flexible API to add/remove effects.

We should not need to modify a single TCastleViewport.ScreenEffectsCount or TCastleViewport.ScreenEffectsNeedDepth to add new effects. Likewise, TCastleViewport.SSRShaderInitialize should not be necessary.

We should have a component like TScreenSpaceReflections with a property like SurfaceGlossiness: Single.

This would also enable natural way to control specific screen effects parameters by properties, and expose them as published for CGE editor. IOW, allow adding screen effects from editor.

So, all those comments kind of wait on me, to propose a better way to design "standard" screen effects inside CGE, like screen-space ambient occlusion and now screen-space reflections. Give me a bit of time to try to do it (if I will fail, I'll merge the current implementation, and will redesign it later :) ).

@michaliskambi michaliskambi merged commit afd80ab into castle-engine:master Nov 5, 2020
@michaliskambi
Copy link
Member

First of all, sorry (again) for taking so long to review this. I think this is the 3rd time where your PR took me a looong time to apply, simply because of my lack of time. Sorry about this, and (this is important!) I hope that my long review times did not discourage you from doing more work on CGE. Over the years, you provided a number of big CGE features, so I hope that you will keep them coming :)

And I hope that my review times will get better.

I'm applying it now, as everything is cool -- the remaining work is on my side to

  1. propose a new API to add screen effects inside CGE. See Trello ticket: https://trello.com/c/2hWdcmEO/97-make-screen-effects-like-ssao-ssr-and-more-as-components . When this happens, I'll remake SSR to be a nice component.

  2. new GLSL functions to query screen point without any divisions. See Trello ticket: https://trello.com/c/wmKO7kn3/96-make-glsl-api-for-screen-effects-that-avoids-dividing-multiplying-by-screen-sizes

michaliskambi added a commit that referenced this pull request Nov 5, 2020
use them

Also fixes incorrect
  float depth = texture2D(screen_depth, pos)
It should be
  float depth = texture2D(screen_depth, pos).r
but now it can be even better:
  float depth = screenf_01_get_depth(pos)

See #181
@michaliskambi
Copy link
Member

  1. I solved https://trello.com/c/wmKO7kn3/96-make-glsl-api-for-screen-effects-that-avoids-dividing-multiplying-by-screen-sizes faster than I thought :)

    We now have screenf_01_position (previous tex_coord_frag, only renamed) and screenf_01_get_color(...) and screenf_01_get_depth(...).

    Documented on https://castle-engine.io/x3d_extensions_screen_effects.php , and will be added to news soon.

    I updated GLSL code of SSR to use them. I needed to update this code a bit anyway, as

    float depth = texture2D(screen_depth, pos)
    

    was reported as invalid by my current OpenGL (renderer: Mesa DRI Intel(R) UHD Graphics 630 (Coffeelake 3x8 GT2), OpenGL version: 3.0 Mesa 18.3.6).

    It makes sense, as texture2D returns vec4, so it should be accessed like texture2D(...).r to get float. screenf_01_get_depth is doing that now.

  2. I added option to play with it in view3dscene, "View -> Screen Effects -> Screen Space Reflections". It works cool!

scene_0
scene_0_ssr

michaliskambi added a commit to castle-engine/castle-model-viewer that referenced this pull request Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants