From 2843b60fa27cca0ea5e418525e62596b5594f853 Mon Sep 17 00:00:00 2001 From: rainlizard <15337628+rainlizard@users.noreply.github.com> Date: Mon, 27 Jan 2025 00:05:51 +1100 Subject: [PATCH] midas door and darkened bedrock --- Autoload/Names.gd | 3 + Autoload/Slabs.gd | 2 + Scenes/CustomTooltip.gd | 2 + Scenes/DataSlab.gd | 136 +++++++++++++++++++++++++++++- Scenes/OpenMap.gd | 2 +- Scenes/OverheadGraphics.gd | 1 + Scenes/ReadData.gd | 2 + Scenes/SlabDisplay.gd | 4 + Shaders/Bedrock3x3.png | Bin 0 -> 130 bytes Shaders/Bedrock3x3.png.import | 35 ++++++++ Shaders/display_texture_2d.shader | 22 ++++- 11 files changed, 203 insertions(+), 6 deletions(-) create mode 100644 Shaders/Bedrock3x3.png create mode 100644 Shaders/Bedrock3x3.png.import diff --git a/Autoload/Names.gd b/Autoload/Names.gd index 56932b37..71d1f09d 100644 --- a/Autoload/Names.gd +++ b/Autoload/Names.gd @@ -29,6 +29,7 @@ const things = { "STEEL" : "Iron Door", "MAGIC" : "Magic Door", "SECRET" : "Secret Door", + "MIDAS" : "Midas Door", }, TYPE.TRAP : { "BOULDER" : "Boulder Trap", @@ -327,6 +328,8 @@ const slabs = { "PURPLE_PATH": "Purple Path", "DOOR_SECRET" : "Secret Door", "DOOR_SECRET2" : "Secret Door", +"DOOR_MIDAS" : "Midas Door", +"DOOR_MIDAS2" : "Midas Door", "HARD_FLOOR" : "Bedrock", "AUTOMATIC_WALL" : "Wall Automatic", }; diff --git a/Autoload/Slabs.gd b/Autoload/Slabs.gd index 50735b30..771fe5b3 100644 --- a/Autoload/Slabs.gd +++ b/Autoload/Slabs.gd @@ -285,6 +285,8 @@ var icons = { "HEART_PEDESTAL": preload("res://dk_images/crucials/anim0949/r1frame01.png"), "DOOR_SECRET": preload("res://extra_images/secret_door.png"), "DOOR_SECRET2": preload("res://extra_images/secret_door.png"), +"DOOR_MIDAS": preload("res://extra_images/midas_door.png"), +"DOOR_MIDAS2": preload("res://extra_images/midas_door.png"), } var slabOrder = [ diff --git a/Scenes/CustomTooltip.gd b/Scenes/CustomTooltip.gd index 5e4eb71f..8e94c916 100644 --- a/Scenes/CustomTooltip.gd +++ b/Scenes/CustomTooltip.gd @@ -45,6 +45,8 @@ func set_floortexture(floorTextureValue): oTooltipPic.material.set_shader_param("showOnlySpecificStyle", 0) oTooltipPic.material.set_shader_param("slxData", preload("res://Shaders/Black3x3.png")) + #oTooltipPic.material.set_shader_param("slabIdData", preload("res://Shaders/Bedrock3x3.png")) + oTooltipPic.material.set_shader_param("slabIdData", preload("res://Shaders/Black3x3.png")) oTooltipPic.material.set_shader_param("fieldSizeInSubtiles", Vector2(1, 1)) oTooltipPic.material.set_shader_param("animationDatabase", preload("res://Shaders/textureanimationdatabase.png")) oTooltipPic.material.set_shader_param("viewTextures", dataTexture) diff --git a/Scenes/DataSlab.gd b/Scenes/DataSlab.gd index 5272f27b..0be49f45 100644 --- a/Scenes/DataSlab.gd +++ b/Scenes/DataSlab.gd @@ -1 +1,135 @@ -extends Grid +extends Node + +const U8 = 1 +const U16 = 2 + +var buffer = StreamPeerBuffer.new() +var bytes_per_entry = 1 +var width = 0 +var height = 0 +var buffer_size = 0 + +var idImgData = Image.new() +var idTexData = ImageTexture.new() + +#func _input(event): +# if event is InputEventKey and event.pressed and event.scancode == KEY_F11: +# var filename = "a.png" +# var err = idImgData.save_png(filename) +# if err == OK: +# print("Saved slab ID debug image to: ", filename) +# else: +# print("Failed to save slab ID debug image, error: ", err) + +func initialize(w, h, fillValue, setPerEntryBytes): + # Initialize the grid + width = w + height = h + bytes_per_entry = setPerEntryBytes + buffer_size = width * height * bytes_per_entry + + # Clearing a buffer is troublesome, in order to do so I need to set the buffer to an equal-sized blank PoolByteArray. (this takes 0ms) + var blankByteArray = PoolByteArray([]) + blankByteArray.resize(buffer_size) + blankByteArray.fill(fillValue) + buffer.data_array = blankByteArray + +func initialize_img(): + # Initialize the image + idImgData.create(width, height, false, idImgData.FORMAT_RGB8) + idImgData.lock() + + # Load buffer data into image + for y in range(height): + for x in range(width): + var value = get_cell(x, y) + idImgData.set_pixel(x, y, Color8(value, value, value)) + + idImgData.unlock() + idTexData.create_from_image(idImgData) + +func set_cellv(pos, value): + set_cell(pos.x, pos.y, value) + +func set_cell(x, y, value): + # Update grid + var seek_pos = (y * width + x) * bytes_per_entry + if seek_pos >= 0 and seek_pos < buffer_size: + buffer.seek(seek_pos) + if bytes_per_entry == U8: + buffer.put_u8(value) + elif bytes_per_entry == U16: + buffer.put_u16(value) + + # Update idImgData + if x >= 0 and x < width and y >= 0 and y < height: + idImgData.lock() + idImgData.set_pixel(x, y, Color8(value, value, value)) + idImgData.unlock() + idTexData.create_from_image(idImgData) + +func get_cell(x, y): + var seek_pos = (y * width + x) * bytes_per_entry + if seek_pos >= 0 and seek_pos < buffer_size: + buffer.seek(seek_pos) + if bytes_per_entry == U8: + return buffer.get_u8() + elif bytes_per_entry == U16: + return buffer.get_u16() + return -1 + +func get_cellv(pos): + return get_cell(pos.x, pos.y) + + +func resize(new_width, new_height, fillValue): + # Resize grid + var new_buffer_size = new_width * new_height * bytes_per_entry + var new_buffer = StreamPeerBuffer.new() + var new_data_array = PoolByteArray([]) + new_data_array.resize(new_buffer_size) + new_data_array.fill(fillValue) + new_buffer.data_array = new_data_array + + var copy_width = min(width, new_width) + var copy_height = min(height, new_height) + + # This is necessary for the strangely sized data structures that are like: Vector2((width*3)+1,(height*3)+1) + match name: + "DataOwnership", "DataClmPos", "DataWibble": + copy_width -= 1 + copy_height -= 1 + + for y in range(copy_height): + for x in range(copy_width): + var old_value = get_cell(x, y) + var new_seek_pos = (y * new_width + x) * bytes_per_entry + new_buffer.seek(new_seek_pos) + if bytes_per_entry == U8: + new_buffer.put_u8(old_value) + elif bytes_per_entry == U16: + new_buffer.put_u16(old_value) + + width = new_width + height = new_height + buffer_size = new_buffer_size + buffer = new_buffer + + # Resize image + var new_image = Image.new() + new_image.create(new_width, new_height, false, idImgData.FORMAT_RGB8) + new_image.fill(Color8(fillValue, fillValue, fillValue)) + + # Copy old image data + new_image.lock() + idImgData.lock() + var copy_widthi = min(width, new_width) + var copy_heighti = min(height, new_height) + for y in range(copy_heighti): + for x in range(copy_widthi): + new_image.set_pixel(x, y, idImgData.get_pixel(x, y)) + idImgData.unlock() + new_image.unlock() + + idImgData = new_image + idTexData.create_from_image(idImgData) diff --git a/Scenes/OpenMap.gd b/Scenes/OpenMap.gd index d1b4a182..f4d009aa 100644 --- a/Scenes/OpenMap.gd +++ b/Scenes/OpenMap.gd @@ -70,7 +70,7 @@ func start(): #for i in 200: # yield(get_tree(), "idle_frame") #oCurrentMap.clear_map() - open_map("C:/Games/Dungeon Keeper/levels/personal/map00002.slb") + open_map("C:/Games/Dungeon Keeper/levels/personal/map00001.slb") #open_map("D:/Dungeon Keeper/campgns/dpthshdw/map00014.slb") else: # initialize a cleared map diff --git a/Scenes/OverheadGraphics.gd b/Scenes/OverheadGraphics.gd index ed2b183b..4361e8c2 100644 --- a/Scenes/OverheadGraphics.gd +++ b/Scenes/OverheadGraphics.gd @@ -113,6 +113,7 @@ func createDisplayField(setMap, showStyle): mat.set_shader_param("animationDatabase", preload("res://Shaders/textureanimationdatabase.png")) mat.set_shader_param("viewTextures", overheadTexData) mat.set_shader_param("slxData", oDataSlx.slxTexData) + mat.set_shader_param("slabIdData", oDataSlab.idTexData) arrayOfColorRects.append(displayField) oGame2D.add_child_below_node(self, displayField) diff --git a/Scenes/ReadData.gd b/Scenes/ReadData.gd index 83ad0053..4bb42055 100644 --- a/Scenes/ReadData.gd +++ b/Scenes/ReadData.gd @@ -153,9 +153,11 @@ func new_txt(): func read_slb(buffer): oDataSlab.initialize(M.xSize, M.ySize, 0, Grid.U16) oDataSlab.buffer.set_data_array(buffer.data_array) + oDataSlab.initialize_img() func new_slb(): oDataSlab.initialize(M.xSize, M.ySize, 0, Grid.U16) + oDataSlab.initialize_img() func read_own(buffer): oDataOwnership.initialize((M.xSize*3)+1, (M.ySize*3)+1, 5, Grid.U8) diff --git a/Scenes/SlabDisplay.gd b/Scenes/SlabDisplay.gd index 319cf795..54e456a2 100644 --- a/Scenes/SlabDisplay.gd +++ b/Scenes/SlabDisplay.gd @@ -73,6 +73,10 @@ func set_visual(columnArray): material.set_shader_param("fieldSizeInSubtiles", Vector2(3, 3)) material.set_shader_param("animationDatabase", preload("res://Shaders/textureanimationdatabase.png")) material.set_shader_param("viewTextures", dataTexture) + if slabID == 57: + material.set_shader_param("slabIdData", preload("res://Shaders/Bedrock3x3.png")) + else: + material.set_shader_param("slabIdData", preload("res://Shaders/Black3x3.png")) #func _process(delta): # print(material.get_shader_param("dkTextureMap_Split_A")) diff --git a/Shaders/Bedrock3x3.png b/Shaders/Bedrock3x3.png new file mode 100644 index 0000000000000000000000000000000000000000..0ea90879fed214c1685492873121f7dcf9e91046 GIT binary patch literal 130 zcmeAS@N?(olHy`uVBq!ia0vp^%plCc1|-8Yw(bW~jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85nfDK$x+-s>By4DDLUv7$Om#yk*OlKj#@(eFCI-CRp(BFxVI{ VZkQG8XbV)r;OXk;vd$@?2>`rV9pnH2 literal 0 HcmV?d00001 diff --git a/Shaders/Bedrock3x3.png.import b/Shaders/Bedrock3x3.png.import new file mode 100644 index 00000000..3959cd5e --- /dev/null +++ b/Shaders/Bedrock3x3.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Bedrock3x3.png-83955db44e9a66884d8395bb895d23b6.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Shaders/Bedrock3x3.png" +dest_files=[ "res://.import/Bedrock3x3.png-83955db44e9a66884d8395bb895d23b6.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=true +flags/anisotropic=true +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/Shaders/display_texture_2d.shader b/Shaders/display_texture_2d.shader index fb1427ee..d0f0a469 100644 --- a/Shaders/display_texture_2d.shader +++ b/Shaders/display_texture_2d.shader @@ -15,6 +15,7 @@ const vec2 oneTileSize = vec2(32,32); const float TEXTURE_ANIMATION_SPEED = 12.0; uniform int showOnlySpecificStyle = 77777; uniform sampler2D slxData; +uniform sampler2D slabIdData; uniform sampler2DArray dkTextureMap_Split_A1; uniform sampler2DArray dkTextureMap_Split_A2; uniform sampler2DArray dkTextureMap_Split_B1; @@ -22,6 +23,8 @@ uniform sampler2DArray dkTextureMap_Split_B2; uniform vec2 fieldSizeInSubtiles = vec2(0.0, 0.0); +const float DARKENING_FACTOR = 0.35; + // Exact same function as in Godot Source Code float calc_mip_level(vec2 texture_coord) { vec2 dx = dFdx(texture_coord); @@ -62,6 +65,9 @@ void fragment() { discard; } + // Get the slab ID + int slabId = int(texelGet(slabIdData, ivec2(slabX, slabY), 0).r * 255.0); + int index = getIndex(ivec2(subtileX,subtileY)); if (index >= 544 && index < 1000) { // 544 is the index where the TexAnims start (544 - 999) int frame = int(mod(TIME * TEXTURE_ANIMATION_SPEED, 8)); @@ -71,14 +77,22 @@ void fragment() { vec2 resolutionOfField = fieldSizeInSubtiles * oneTileSize; float mipmapLevel = calc_mip_level(UV * resolutionOfField); + vec4 finalColor; if (index < 272) { // Splitting the TextureArray into 2, so that it will work on older PCs. - COLOR = textureLod(dkTextureMap_Split_A1, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index)), mipmapLevel); + finalColor = textureLod(dkTextureMap_Split_A1, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index)), mipmapLevel); } else if (index < 544){ - COLOR = textureLod(dkTextureMap_Split_A2, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index-272)), mipmapLevel); + finalColor = textureLod(dkTextureMap_Split_A2, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index-272)), mipmapLevel); } else if (index < 1272){ - COLOR = textureLod(dkTextureMap_Split_B1, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index-1000)), mipmapLevel); + finalColor = textureLod(dkTextureMap_Split_B1, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index-1000)), mipmapLevel); + } else { + finalColor = textureLod(dkTextureMap_Split_B2, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index-1272)), mipmapLevel); + } + + // Apply darkening if slabId is 57 + if (slabId == 57) { + COLOR = vec4(finalColor.rgb * (1.0-DARKENING_FACTOR), finalColor.a); } else { - COLOR = textureLod(dkTextureMap_Split_B2, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index-1272)), mipmapLevel); + COLOR = finalColor; } }