diff --git a/addons/terrabrush/Scripts/Snow.cs b/addons/terrabrush/Scripts/Snow.cs index cd35d60..80a2200 100644 --- a/addons/terrabrush/Scripts/Snow.cs +++ b/addons/terrabrush/Scripts/Snow.cs @@ -47,7 +47,7 @@ public void UpdateSnow() { Shader = ResourceLoader.Load("res://addons/terrabrush/Resources/Shaders/snow_clipmap_shader.gdshader") }; } else { - _clipmap.Shader = SnowDefinition.CustomShader; + _clipmap.Shader = Utils.CreateCustomShaderCopy(SnowDefinition.CustomShader); } _clipmap.CreateMesh(); diff --git a/addons/terrabrush/Scripts/Terrain.cs b/addons/terrabrush/Scripts/Terrain.cs index 3be2b2b..7be5d62 100644 --- a/addons/terrabrush/Scripts/Terrain.cs +++ b/addons/terrabrush/Scripts/Terrain.cs @@ -57,7 +57,7 @@ public void BuildTerrain() { Shader = ResourceLoader.Load("res://addons/terrabrush/Resources/Shaders/heightmap_clipmap_shader.gdshader") }; } else { - _clipmap.Shader = CustomShader; + _clipmap.Shader = Utils.CreateCustomShaderCopy(CustomShader); } _clipmap.ClipmapMesh.Layers = (uint) VisualInstanceLayers; diff --git a/addons/terrabrush/Scripts/Utils.cs b/addons/terrabrush/Scripts/Utils.cs index cc4c664..a3e9a31 100644 --- a/addons/terrabrush/Scripts/Utils.cs +++ b/addons/terrabrush/Scripts/Utils.cs @@ -61,4 +61,17 @@ public static Texture2DArray TexturesToTextureArray(IEnumerable textu return textureArray; } + + public static ShaderMaterial CreateCustomShaderCopy(ShaderMaterial customShader) { + var newShader = new ShaderMaterial { + Shader = customShader.Shader + }; + + foreach (Godot.Collections.Dictionary uniform in customShader.Shader.GetShaderUniformList()) { + var uniformName = (string) uniform.GetValueOrDefault("name"); + newShader.SetShaderParameter(uniformName, customShader.GetShaderParameter(uniformName)); + } + + return newShader; + } } diff --git a/addons/terrabrush/Scripts/Water.cs b/addons/terrabrush/Scripts/Water.cs index 5882a2d..560660d 100644 --- a/addons/terrabrush/Scripts/Water.cs +++ b/addons/terrabrush/Scripts/Water.cs @@ -108,7 +108,7 @@ public void UpdateWater() { Shader = ResourceLoader.Load("res://addons/terrabrush/Resources/Shaders/water_clipmap_shader.gdshader") }; } else { - _clipmap.Shader = CustomShader; + _clipmap.Shader = Utils.CreateCustomShaderCopy(CustomShader); } _clipmap.CreateMesh(); diff --git a/addons/terrabrush/plugin.cfg b/addons/terrabrush/plugin.cfg index e9241a6..57b124e 100644 --- a/addons/terrabrush/plugin.cfg +++ b/addons/terrabrush/plugin.cfg @@ -3,5 +3,5 @@ name="TerraBrush" description="" author="spimort" -version="0.7.1-alpha" +version="0.7.2-alpha" script="Plugin.cs"