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

PBR Terrain Shader + Lighting Rewrite + Triplanar terrain #184

Merged
merged 42 commits into from
Jun 17, 2023

Conversation

JamesTKhan
Copy link
Owner

@JamesTKhan JamesTKhan commented Jun 2, 2023

Large PR full of breaking changes and probably impractical to review it in full. It was not possible to break most of these down into smaller PRs while still being able to build the app.

I have thought about moving the Terrain Shader to use PBR shader for a while. This modifies the custom PBR shader to support terrain splatmaps and to support triplanar texturing. This also improves terrain normal calculations. Makes triplanar PR obsolete. I noticed latest gdx-gltf code has heavily refactored how the glsl code is organized so.. I already know down the road that is going to be a painful migration to update gdx-gltf but will probably be for the best but, one thing at a time.

Now that both Terrain and Models are using PBR, it was time to remove a bunch of Mundus lighting code and refactor things so that we use gdx-gltf and libGDX lighting conventions whereas before it was a mix up of PBR for models and custom lighting for terrains. This was a large and painful refactor but cleans up the code in some ways due to removing a bunch of lighting classes and code.

Terrain and Lighting changes

  • Overhaul Terrain Normals. Improves terrain normal calculations and accuracy at the cost of additional memory by averaging the normals. Shading will be visibly different.
  • Breaking Change: Lighting all around will be different.
    • No more ambient intensity (libGDX convention).
    • Intensity level for existing lights will need adjustment due to new light calcs
    • Attenuation selection is gone (to match libGDX convention)
  • Breaking Change: ShadowMapper class removed. Replaced with MundusDirectionalShadowLight
  • Terain UV Scale is no longer changed under Settings, it is changed on the terrain material
  • Update water shader lighting code (non-PBR) to more closely match light code from PBR shaders
    • Updated Point/Spot light code
    • Added Gamma correction to water shader
    • Added sRGB to Linear (thanks to gdx-gltf) calculations to water shader
  • New CLI argument to disable shader preprocessor caching for development purposes

New Terrain Normals with PBR shading
image

Old Terrain Shader and Normals
image

Material Changes
Materials are now represented in the UI in the same way the actually behave. To edit a material, you select the material in the asset dock. You can no longer directly edit a material from a Model Component Widget. Editing a Material from within the Model Widget gives the false impression that you are only editing the material for that single GameObject. Instead, I added a new Edit button that takes you to the current Material to edit it. This makes for a cleaner UI (at the expense of an additional click) and easier to add material to the Terrain Widget as well.

mats2

Triplanar specific stuff

  • Adds Triplanar option under terrain settings

Triplanar should work on terrains up to 252 Vertex resolution

Note: Triplanar is not always better, it is situation depending on your terrain. Triplanar is more expensive (more texture sampling) and can look bad with lots of sharp edges close together, etc..

triplanar2

Rendering refactor
I removed rendering logic from GameObject, SceneGraph and Components. Rendering logic was tightly coupled with the data. The goal here is to decouple rendering logic from the data which will allow us to have more flexibility in the future like abstracting rendering out of the scene class and enhanced post processing. Now rendering is all in one place (the scene class) whereas before it was a mess, scattered down from SceneGraph -> GameObject -> Component. Ideally would like to abstract it somewhere else later but I'm trying to keep the PR small.

RenderableComponents only have to provide a RenderableProvider now (aka ModelInstance) and they don't need to know anything else about the rendering logic.

Previously we were using the render methods inside components like an update method, now those actions are moved to the update method which already existed. Another bonus to this move is that components that don't render anything don't need an empty render method anymore (Lights, Properties).

@JamesTKhan JamesTKhan marked this pull request as ready for review June 5, 2023 20:43
@JamesTKhan JamesTKhan linked an issue Jun 6, 2023 that may be closed by this pull request
@JamesTKhan JamesTKhan marked this pull request as draft June 9, 2023 16:26
# Conflicts:
#	commons/src/main/com/mbrlabs/mundus/commons/Scene.java
#	commons/src/main/com/mbrlabs/mundus/commons/scene3d/components/TerrainComponent.java
# Conflicts:
#	commons/src/main/com/mbrlabs/mundus/commons/Scene.java
@JamesTKhan JamesTKhan marked this pull request as ready for review June 11, 2023 23:01
@antzGames
Copy link
Collaborator

I retested the runtime with RoBB 3D on both desktop and web and it looks good.

@Dgzt
Copy link
Collaborator

Dgzt commented Jun 17, 2023

I've tested on my PoC desktop projects and it looks very good.

# Conflicts:
#	commons/src/main/com/mbrlabs/mundus/commons/Scene.java
#	gdx-runtime/CHANGES
@JamesTKhan
Copy link
Owner Author

Thanks for testing. I will go ahead and merge. This was the last major change before 0.5.0. If any small bugs pop up they can be fixed down the road.

@JamesTKhan JamesTKhan merged commit a36ad44 into master Jun 17, 2023
@JamesTKhan JamesTKhan deleted the terrain_lighting branch June 17, 2023 17:44
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.

Triplanar Texture mapping for Terrain
3 participants