Skip to content

Commit

Permalink
Add support for 4.2 (#131)
Browse files Browse the repository at this point in the history
* Add support for 4.2
  • Loading branch information
spimort authored Sep 14, 2024
1 parent bc62022 commit 8bbb956
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ I'm gonna be happy to accept PR for new features if it fits.

## Godot 4.2 and lower (4.x)

Starting with Godot 4.3, a breaking change has been introduced in the engine (see [this post from the Godot Team](https://godotengine.org/article/introducing-reverse-z/)). This forces TerraBrush to adapt to the new requirements.

This breaking change impacts the water shader used in the plugin. If you are still using a version before Godot 4.3, you should stick to a version of TerraBrush before 0.8.0-alpha.
The demo scene has been updated to Godot 4.3 which makes it break with older version of Godot.

## Key Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ uniform float EdgeScale = 0.1;
uniform float Near = 0.5;
uniform float Far = 100.0;
uniform vec3 EdgeColor: source_color;
uniform bool InvertedZ = true;

float fresnel(float amount, vec3 normal, vec3 view) {
return pow((1.0 - clamp(dot(normalize(normal), normalize(view)), 0.0, 1.0)), amount);
}

float edge(float depth) {
// Invert the depth value
depth = 1.0 - depth;
depth = 2.0 * depth - 1.0;
return Near * Far / (Far + depth * (Near - Far));
// Invert the depth value
if (InvertedZ) {
depth = 1.0 - depth;
}
depth = 2.0 * depth - 1.0;
return Near * Far / (Far + depth * (Near - Far));
}

void calculateWaterVertex(
Expand Down
1 change: 1 addition & 0 deletions addons/terrabrush/Scripts/StringNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ internal static class StringNames {
public static readonly StringName UseBrushScale = "UseBrushScale";
public static readonly StringName ScaleNoiseTexture = "ScaleNoiseTexture";
public static readonly StringName RandomPlacementRange = "RandomPlacementRange";
public static readonly StringName InvertedZ = "InvertedZ";
}
8 changes: 8 additions & 0 deletions addons/terrabrush/Scripts/Water.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ public void UpdateWater() {
_clipmap.Shader.SetShaderParameter(StringNames.Near, Near);
_clipmap.Shader.SetShaderParameter(StringNames.Far, Far);
_clipmap.Shader.SetShaderParameter(StringNames.EdgeColor, EdgeColor);

// This is for compatibility with Godot 4.2
var engineVersion = Engine.GetVersionInfo();
var major = (int) engineVersion["major"];
var minor = (int) engineVersion["minor"];
if (major == 4 && minor < 3) {
_clipmap.Shader.SetShaderParameter(StringNames.InvertedZ, false);
}
}

public void AddRippleEffect(float x, float y) {
Expand Down
2 changes: 1 addition & 1 deletion addons/terrabrush/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="TerraBrush"
description=""
author="spimort"
version="0.8.1-alpha"
version="0.8.2-alpha"
script="Plugin.cs"

0 comments on commit 8bbb956

Please sign in to comment.