Skip to content

Commit 21b3f19

Browse files
committed
getting closer
1 parent a011da7 commit 21b3f19

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

Scenes/CurrentTextures.gd

+27-14
Original file line numberDiff line numberDiff line change
@@ -152,33 +152,42 @@ func save_image_as_png(img, inputPath):
152152

153153
func load_cache_filename(path):
154154
var fileName = path.get_file().get_basename().to_lower()
155-
var cachePath = Settings.unearthdata.plus_file(fileName + ".png")
155+
156+
if(not fileName.to_lower().find("tmapa")):
157+
return
158+
159+
var cachePathtmapa = Settings.unearthdata.plus_file(fileName + ".png")
160+
var cachePathtmapb = Settings.unearthdata.plus_file(fileName.replace("tmapa","tmapb") + ".png")
156161
var tmapaNumber = int(fileName.to_lower().trim_prefix("tmapa")) # Get the specific position to create within the array
157-
158-
if File.new().file_exists(cachePath) == true:
162+
163+
if File.new().file_exists(cachePathtmapa) == true:
159164
# Need to call load() on an Image class if I want the save and load to work correctly (otherwise it saves too fast and doesn't load or something)
160-
var img = Image.new()
161-
img.load(cachePath)
162-
load_image_into_cache(img, tmapaNumber)
165+
var imgA = Image.new()
166+
imgA.load(cachePathtmapa)
167+
var imgB = Image.new()
168+
imgB.load(cachePathtmapb)
169+
load_image_into_cache(imgA,imgB, tmapaNumber)
163170
#print('Loaded cache file: ' + cachePath)
164171
return OK
165172
else:
166-
print('Cache file not found: ' + cachePath)
173+
print('Cache file not found: ' + cachePathtmapa)
167174
cachedTextures.clear()
168175
return FAILED
169176

170-
func load_image_into_cache(img, tmapaNumber):
177+
func load_image_into_cache(imgA, imgB,tmapaNumber):
171178
tmapaNumber = int(tmapaNumber)
172179
while cachedTextures.size() <= tmapaNumber: # Fill all array positions, in case a tmapa00#.dat file inbetween is deleted
173180
cachedTextures.append([null, null])
174-
cachedTextures[tmapaNumber] = convert_img_to_two_texture_arrays(img)
181+
cachedTextures[tmapaNumber] = convert_img_to_two_texture_arrays(imgA,imgB)
175182

176183
# SLICE COUNT being too high is the reason TextureArray doesn't work on old PC. (NOT IMAGE SIZE, NOT MIPMAPS EITHER)
177184
# RES files might actually take longer to generate a TextureArray from than PNG, not sure.
178-
func convert_img_to_two_texture_arrays(img):
179-
if img.get_format() != IMAGE_FORMAT:
180-
img.convert(IMAGE_FORMAT)
181-
185+
func convert_img_to_two_texture_arrays(imgA,imgB):
186+
if imgA.get_format() != IMAGE_FORMAT:
187+
imgA.convert(IMAGE_FORMAT)
188+
if imgB.get_format() != IMAGE_FORMAT:
189+
imgB.convert(IMAGE_FORMAT)
190+
182191
var twoTextureArrays = [
183192
TextureArray.new(),
184193
TextureArray.new(),
@@ -201,7 +210,11 @@ func convert_img_to_two_texture_arrays(img):
201210

202211
for y in ySlices:
203212
for x in xSlices:
204-
var slice = img.get_rect(Rect2(x*sliceWidth, (y+yOffset)*sliceHeight, sliceWidth, sliceHeight))
213+
var slice
214+
if i > 2:
215+
slice = imgA.get_rect(Rect2(x*sliceWidth, (y+yOffset)*sliceHeight, sliceWidth, sliceHeight))
216+
else:
217+
slice = imgB.get_rect(Rect2(x*sliceWidth, (y+yOffset)*sliceHeight, sliceWidth, sliceHeight))
205218
slice.generate_mipmaps() #Important otherwise it's black when zoomed out
206219
twoTextureArrays[i].set_layer_data(slice, (y*xSlices)+x)
207220

Shaders/display_texture_2d.shader

+10-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ const vec2 oneTileSize = vec2(32,32);
1515
const float TEXTURE_ANIMATION_SPEED = 12.0;
1616
uniform int showOnlySpecificStyle = 77777;
1717
uniform sampler2D slxData;
18-
uniform sampler2DArray dkTextureMap_Split_A;
19-
uniform sampler2DArray dkTextureMap_Split_B;
18+
uniform sampler2DArray dkTextureMap_Split_A1;
19+
uniform sampler2DArray dkTextureMap_Split_A2;
20+
uniform sampler2DArray dkTextureMap_Split_B1;
21+
uniform sampler2DArray dkTextureMap_Split_B2;
2022

2123
uniform vec2 fieldSizeInSubtiles = vec2(0.0, 0.0);
2224

@@ -70,9 +72,13 @@ void fragment() {
7072
float mipmapLevel = calc_mip_level(UV * resolutionOfField);
7173

7274
if (index < 272) { // Splitting the TextureArray into 2, so that it will work on older PCs.
73-
COLOR = textureLod(dkTextureMap_Split_A, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index)), mipmapLevel);
75+
COLOR = textureLod(dkTextureMap_Split_A1, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index)), mipmapLevel);
76+
} else if (index < 544){
77+
COLOR = textureLod(dkTextureMap_Split_A2, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index-272)), mipmapLevel);
78+
} else if (index < 1272){
79+
COLOR = textureLod(dkTextureMap_Split_B1, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index)), mipmapLevel);
7480
} else {
75-
COLOR = textureLod(dkTextureMap_Split_B, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index-272)), mipmapLevel);
81+
COLOR = textureLod(dkTextureMap_Split_B2, vec3((UV.x * fieldSizeInSubtiles.x)-float(subtileX), (UV.y * fieldSizeInSubtiles.y)-float(subtileY), float(index-272)), mipmapLevel);
7682
}
7783
}
7884

0 commit comments

Comments
 (0)