Skip to content

Commit

Permalink
Fix the Custom shaders perf (#117)
Browse files Browse the repository at this point in the history
There was a problem with custom shaders since it was applying the textures directly to the shader, it was making the scene file big (by copying the textures as local resource)
  • Loading branch information
spimort authored Jul 13, 2024
1 parent e9321da commit ebd8598
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion addons/terrabrush/Scripts/Snow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void UpdateSnow() {
Shader = ResourceLoader.Load<Shader>("res://addons/terrabrush/Resources/Shaders/snow_clipmap_shader.gdshader")
};
} else {
_clipmap.Shader = SnowDefinition.CustomShader;
_clipmap.Shader = Utils.CreateCustomShaderCopy(SnowDefinition.CustomShader);
}

_clipmap.CreateMesh();
Expand Down
2 changes: 1 addition & 1 deletion addons/terrabrush/Scripts/Terrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void BuildTerrain() {
Shader = ResourceLoader.Load<Shader>("res://addons/terrabrush/Resources/Shaders/heightmap_clipmap_shader.gdshader")
};
} else {
_clipmap.Shader = CustomShader;
_clipmap.Shader = Utils.CreateCustomShaderCopy(CustomShader);
}

_clipmap.ClipmapMesh.Layers = (uint) VisualInstanceLayers;
Expand Down
13 changes: 13 additions & 0 deletions addons/terrabrush/Scripts/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,17 @@ public static Texture2DArray TexturesToTextureArray(IEnumerable<Texture2D> 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;
}
}
2 changes: 1 addition & 1 deletion addons/terrabrush/Scripts/Water.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void UpdateWater() {
Shader = ResourceLoader.Load<Shader>("res://addons/terrabrush/Resources/Shaders/water_clipmap_shader.gdshader")
};
} else {
_clipmap.Shader = CustomShader;
_clipmap.Shader = Utils.CreateCustomShaderCopy(CustomShader);
}

_clipmap.CreateMesh();
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.7.1-alpha"
version="0.7.2-alpha"
script="Plugin.cs"

0 comments on commit ebd8598

Please sign in to comment.