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

Compatibility renderer support #500

Merged

Conversation

Xtarsia
Copy link
Contributor

@Xtarsia Xtarsia commented Sep 25, 2024

Admin edit:
Fixes #217

  • Enables compatibility support
  • Modifies custom shaders w/ special defines
  • Improves GPU mouse and shader; supports compatibility mode
  • Fixes not-normalized normals for all renderers
  • Hides the region border normal fix outside of regions (was noticable at small region sizes)

Detects whether Godot is using the compatibility renderer.

If so,
The generated shader will have a set of #defines added that allow full support for the standard shader.
The shader override will have the #defines visible at the begining on the shader, before shader_type.

The editor will inject code at the begining, and the end either the standard shader, or any provided override shader
in order to draw a "decal" on the terrain.

in the interest of simplicity, the gdscript changes are as small as possible, tho some things are a bit inneficient,
performace is fine and its only during editing anyways.

The slope tool doesnt have propper decal support.

adding terrain3d.get_compatibility() seems a bit dubious to me, but saved repeating a ton of code in gdscript, and ensures that the editor is always on the same page.

Finally, there are no warnings at the moment when the albedo and normal arrays are in compressed mode. for 4.3 this is fixed anyways, but for 4.2 all textures will be black. The workaround is to re-import all textures as "Lossless". Resizing to half resolution results in the same VRAM use for Lossless vs Compressed at the original size.

EDIT: recently updated test version is available: https://github.com/Xtarsia/Terrain3D/actions/runs/11079134556

@TokisanGames TokisanGames added the enhancement New feature or request label Sep 26, 2024
src/terrain_3d.h Outdated Show resolved Hide resolved
src/terrain_3d.h Outdated Show resolved Hide resolved
Copy link
Owner

@TokisanGames TokisanGames left a comment

Choose a reason for hiding this comment

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

Very nice. This is a good one. to be our 500th PR! (edit: oh # 500 means our 500th document including issues and discussions. This is our... 144th PR)

I added a note that it will fix a ticket.

Please also try exporting the demo to webgl. I reviewed code but haven't tested it yet. I'll also test the export.

You can also add some notes to platform.md that it is now supported, and what they need to do for 4.2 and 4.3. And any notes for WebGL as well.

I thought you said 4.2 must use '(vram) uncompressed' before. Here you say 'Lossless'. Do both work? Whichever does, make sure to get the exact name for the documentation and our discord guidance.

@Xtarsia
Copy link
Contributor Author

Xtarsia commented Sep 26, 2024

Im unable to get web export working, i suspect due to needing custom export template build for terrain 3D, or something along those lines.

As for textures import settings for 4.2, both options work.

I'll add some initial things to platform.md in the mean time.

@TokisanGames
Copy link
Owner

TokisanGames commented Sep 27, 2024

  • In compatibility mode, the minimum.gdshader complains about fma, even though it isn't connected to anything. I had to comment it out.

  • My notes on getting webgl working have been moved to HTML WebGL support #502 . It isn't successful yet.

@TokisanGames
Copy link
Owner

  • Nice work. Aside from webgl, it works well. It even stutters just like I remember in Godot 3. :/

  • The lack of visual indication for the slope tool is a problem. Drawable is not intuitive without it. If you don't already know how it works it will be easy to be confused by it. What can we do about this?

  • Figuring out how to build for web won't hold this PR or release up.

  • It renders very differently. Brighter, stronger normals, half the speed.

image

@Xtarsia Xtarsia force-pushed the compatibility-renderer-support branch from 446b80a to 257adb7 Compare September 28, 2024 21:58
@Xtarsia
Copy link
Contributor Author

Xtarsia commented Sep 29, 2024

I think I need to tidy up the regex stuff a bit still.

@TokisanGames
Copy link
Owner

TokisanGames commented Sep 29, 2024

It seems that all the samplers need highp. Including those in uniforms.glsl.
Mistakenly posted an update here

@Xtarsia Xtarsia force-pushed the compatibility-renderer-support branch from 36be33d to d3b9747 Compare October 1, 2024 20:32
@Xtarsia Xtarsia marked this pull request as ready for review October 2, 2024 09:16
@Xtarsia
Copy link
Contributor Author

Xtarsia commented Oct 2, 2024

This PR godotengine/godot#85430 should make correctly determining when to use compatibility modifications much simpler.

Copy link
Owner

@TokisanGames TokisanGames left a comment

Choose a reason for hiding this comment

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

Great, thanks for all the updates. I've made a few changes and am squashing now.

int idx;
// Insert after render_mode ;
insert_names.clear();
regex->compile("render_mode[^;]*;");
Copy link
Owner

Choose a reason for hiding this comment

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

Changed to a non-greedy render_mode.*;?

@@ -745,6 +748,10 @@ Terrain3D::Terrain3D() {
}
break;
}
// check if setting overriden by command line
if (arg.begins_with("--rendering-driver opengl3")) {
Copy link
Owner

Choose a reason for hiding this comment

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

This doesn't work. --rendering-driver is not included in args.
/c/gd/bin/Godot_v4.2.2-stable_win64_console.exe --rendering-driver opengl3 -e project.godot
reports only "--editor" in the args.

I'm adding a new parameter.
--terrain3d-renderer=compatibility

regex->compile("render_mode[^;]*;");
match = regex->search(code);
if (match.is_valid()) {
_shader_override->set_code(code.insert(match->get_end(), "\n\n" + String(_shader_code["EDITOR_COMPATIBILITY_DEFINES"])));
Copy link
Owner

Choose a reason for hiding this comment

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

Because the INSERT system grabs trailing newlines, I applied .strip_edges() which cleaned up the extra spaces this was inserting and not removing when switching renderers.

@TokisanGames TokisanGames merged commit bddd59a into TokisanGames:main Oct 2, 2024
@TokisanGames
Copy link
Owner

Ok, down to 4 clean, topical commits. Thanks for all the work on this. It will help a lot of people.

@Xtarsia Xtarsia deleted the compatibility-renderer-support branch October 2, 2024 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Compatibility Renderer
2 participants