From 9982cae13b172eff796acd9e8aaf268012892e28 Mon Sep 17 00:00:00 2001 From: kayomn Date: Mon, 16 Jan 2023 18:25:35 +0000 Subject: [PATCH] Add cobbled limestone terrain --- terrain/cobbled_limestone_albedo.png | 3 + terrain/cobbled_limestone_albedo.png.import | 34 ++++ terrain/cobbled_limestone_displacement.png | 3 + .../cobbled_limestone_displacement.png.import | 34 ++++ terrain/cobbled_limestone_normal.png | 3 + terrain/cobbled_limestone_normal.png.import | 34 ++++ terrain/cobbled_limestone_roughness.png | 3 + .../cobbled_limestone_roughness.png.import | 34 ++++ terrain/terrain_instance_3d.gd | 169 ++++++++++++++++++ 9 files changed, 317 insertions(+) create mode 100644 terrain/cobbled_limestone_albedo.png create mode 100644 terrain/cobbled_limestone_albedo.png.import create mode 100644 terrain/cobbled_limestone_displacement.png create mode 100644 terrain/cobbled_limestone_displacement.png.import create mode 100644 terrain/cobbled_limestone_normal.png create mode 100644 terrain/cobbled_limestone_normal.png.import create mode 100644 terrain/cobbled_limestone_roughness.png create mode 100644 terrain/cobbled_limestone_roughness.png.import create mode 100644 terrain/terrain_instance_3d.gd diff --git a/terrain/cobbled_limestone_albedo.png b/terrain/cobbled_limestone_albedo.png new file mode 100644 index 0000000..9f80ce4 --- /dev/null +++ b/terrain/cobbled_limestone_albedo.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:03f34c2cdf4e3f941d62bed684cc05017c8daea13218bcc61433a97917770a96 +size 1615088 diff --git a/terrain/cobbled_limestone_albedo.png.import b/terrain/cobbled_limestone_albedo.png.import new file mode 100644 index 0000000..f5e6ff0 --- /dev/null +++ b/terrain/cobbled_limestone_albedo.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cs06oiwrord6t" +path="res://.godot/imported/cobbled_limestone_albedo.png-cbafb40d3c6fc43ce00d68cb02456536.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://terrain/cobbled_limestone_albedo.png" +dest_files=["res://.godot/imported/cobbled_limestone_albedo.png-cbafb40d3c6fc43ce00d68cb02456536.ctex"] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/bptc_ldr=0 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/terrain/cobbled_limestone_displacement.png b/terrain/cobbled_limestone_displacement.png new file mode 100644 index 0000000..b04dbd2 --- /dev/null +++ b/terrain/cobbled_limestone_displacement.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:79990410d9c9212930e7d3e59e2825c3ba9d3c3354ae4e52ddb988d49ee282e5 +size 189441 diff --git a/terrain/cobbled_limestone_displacement.png.import b/terrain/cobbled_limestone_displacement.png.import new file mode 100644 index 0000000..8b1c968 --- /dev/null +++ b/terrain/cobbled_limestone_displacement.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://mkxbjfwdwkaq" +path="res://.godot/imported/cobbled_limestone_displacement.png-8e8b27438ff815a9d58d4a490e04203c.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://terrain/cobbled_limestone_displacement.png" +dest_files=["res://.godot/imported/cobbled_limestone_displacement.png-8e8b27438ff815a9d58d4a490e04203c.ctex"] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/bptc_ldr=0 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/terrain/cobbled_limestone_normal.png b/terrain/cobbled_limestone_normal.png new file mode 100644 index 0000000..c5396be --- /dev/null +++ b/terrain/cobbled_limestone_normal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6ef381960a013f47fb6c1334f36ef99662df8938bdc2b5004ff4fb76dcf93e77 +size 627601 diff --git a/terrain/cobbled_limestone_normal.png.import b/terrain/cobbled_limestone_normal.png.import new file mode 100644 index 0000000..d72444f --- /dev/null +++ b/terrain/cobbled_limestone_normal.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ukk0161x3eg2" +path="res://.godot/imported/cobbled_limestone_normal.png-4d7b2eb9c070e06256eb42d408ff4a14.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://terrain/cobbled_limestone_normal.png" +dest_files=["res://.godot/imported/cobbled_limestone_normal.png-4d7b2eb9c070e06256eb42d408ff4a14.ctex"] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/bptc_ldr=0 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/terrain/cobbled_limestone_roughness.png b/terrain/cobbled_limestone_roughness.png new file mode 100644 index 0000000..d74e666 --- /dev/null +++ b/terrain/cobbled_limestone_roughness.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:002b4dd1f43e3159e5def14b451942db30d75c49e121fcceb7addd0c83e1530f +size 228583 diff --git a/terrain/cobbled_limestone_roughness.png.import b/terrain/cobbled_limestone_roughness.png.import new file mode 100644 index 0000000..0c2675e --- /dev/null +++ b/terrain/cobbled_limestone_roughness.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bcybapft8tl2x" +path="res://.godot/imported/cobbled_limestone_roughness.png-f78cac7004d15ddc2a00fd10f74b8c10.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://terrain/cobbled_limestone_roughness.png" +dest_files=["res://.godot/imported/cobbled_limestone_roughness.png-f78cac7004d15ddc2a00fd10f74b8c10.ctex"] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/bptc_ldr=0 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/terrain/terrain_instance_3d.gd b/terrain/terrain_instance_3d.gd new file mode 100644 index 0000000..712eed8 --- /dev/null +++ b/terrain/terrain_instance_3d.gd @@ -0,0 +1,169 @@ +@tool +class_name TerrainInstance3D extends GeometryInstance3D + +const _DETAIL := 2 + +var _mesh := PlaneMesh.new() + +var _material := ShaderMaterial.new() + +## +## +## +@export +var size: Vector2i = Vector2i.ZERO: + get: + return size + + set(value): + var width := maxi(value.x, 0) + var height := maxi(value.y, 0) + + if (width != size.x) or (height != size.y): + if (width == 0) and (height == 0): + RenderingServer.instance_set_base(self.get_instance(), RID()) + + else: + self._mesh.subdivide_width = width * _DETAIL + self._mesh.subdivide_depth = height * _DETAIL + self._mesh.size = value + + self._material.set_shader_parameter("SIZE", Vector2(value)) + RenderingServer.instance_set_base(self.get_instance(), self._mesh) + + size = value + +## +## +## +@export +var albedo_map: Texture2D = null: + get: + return albedo_map + + set(value): + self._material.set_shader_parameter("ALBEDO_MAP_0", value) + + albedo_map = value + +## +## +## +@export +var albedo_map_b: Texture2D = null: + get: + return albedo_map_b + + set(value): + self._material.set_shader_parameter("ALBEDO_MAP_B", value) + + albedo_map_b = value + +## +## +## +@export +var albedo_map_g: Texture2D = null: + get: + return albedo_map_g + + set(value): + self._material.set_shader_parameter("ALBEDO_MAP_G", value) + + albedo_map_g = value + +## +## +## +@export +var albedo_map_r: Texture2D = null: + get: + return albedo_map_r + + set(value): + self._material.set_shader_parameter("ALBEDO_MAP_R", value) + + albedo_map_r = value + +## +## +## +@export +var normal_map: Texture2D = null: + get: + return normal_map + + set(value): + self._material.set_shader_parameter("NORMAL_MAP_0", value) + + normal_map = value + +## +## +## +@export +var normal_map_b: Texture2D = null: + get: + return normal_map_b + + set(value): + self._material.set_shader_parameter("NORMAL_MAP_B", value) + + normal_map_b = value + +## +## +## +@export +var normal_map_g: Texture2D = null: + get: + return normal_map_g + + set(value): + self._material.set_shader_parameter("NORMAL_MAP_G", value) + + normal_map_g = value + +## +## +## +@export +var normal_map_r: Texture2D = null: + get: + return normal_map_r + + set(value): + self._material.set_shader_parameter("NORMAL_MAP_R", value) + + normal_map_r = value + +## +## +## +@export +var terrain_map: Texture2D = null: + get: + return terrain_map + + set(value): + self._material.set_shader_parameter("TERRAIN_MAP", value) + + terrain_map = value + +## +## +## +@export +var max_height := 100.0: + get: + return max_height + + set(value): + self._material.set_shader_parameter("MAX_HEIGHT", value) + + max_height = max(value, 0.0) + +func _init() -> void: + self._material.shader = preload("res://terrain_shader.gdshader") + + self._mesh.surface_set_material(0, self._material)