Skip to content

Commit a3ca814

Browse files
committed
Implement S3TC (.dds) compressed textures for desktop
1 parent 054a5ba commit a3ca814

6 files changed

Lines changed: 291 additions & 10 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ temp/
77
docs/temp/
88
export/
99
astc-textures/
10+
dds-textures/
1011
RECOVER_*.fla
1112
shitAudio/
1213
.build_time

hmm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
{
200200
"name": "openfl",
201201
"type": "git",
202-
"ref": "a2cc2c58f0f7f20e518ff78673fc29ee8c3c585f",
202+
"ref": "af3dd918ef4b27f4165b9be1b146f2b8dc004514",
203203
"url": "https://github.com/FunkinCrew/openfl"
204204
},
205205
{

project.hxp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ class Project extends HXProject
623623
configureCustomMacros();
624624
configurePolymod();
625625
configureHaxelibs();
626-
configureASTCTextures();
626+
configureCompressedTextures();
627627
configureAssets();
628628

629629
if (!isLinux())
@@ -1708,14 +1708,21 @@ class Project extends HXProject
17081708
}
17091709

17101710
/**
1711-
* Configure the astc textures.
1711+
* Configure the compressed textures.
17121712
*/
1713-
function configureASTCTextures()
1713+
function configureCompressedTextures()
17141714
{
17151715
if (!(isDisplay() && isCleanCommand()) && FEATURE_COMPRESSED_TEXTURES.isEnabled(this))
17161716
{
1717-
readASTCExclusion();
1718-
runASTCCompressor();
1717+
if (isDesktop())
1718+
{
1719+
// Nothing for now
1720+
}
1721+
else
1722+
{
1723+
readASTCExclusion();
1724+
runASTCCompressor();
1725+
}
17191726
}
17201727
}
17211728

@@ -1947,12 +1954,27 @@ class Project extends HXProject
19471954
// path, rename, type, embed, setDefaults
19481955
if (Path.extension(path) == 'png' && FEATURE_COMPRESSED_TEXTURES.isEnabled(this))
19491956
{
1950-
final astcPath:String = "astc-textures/" + path.substr(0, path.length - 3) + "astc";
1951-
if (!isASTCExcluded(path) && FileSystem.exists(astcPath))
1957+
if (isDesktop())
19521958
{
1953-
path = astcPath;
1959+
final ddsPath:String = "dds-textures/" + path.substr(0, path.length - 3) + "dds";
1960+
1961+
if (FileSystem.exists(ddsPath))
1962+
{
1963+
path = ddsPath;
19541964

1955-
if (rename != null) rename = rename.substr(0, rename.length - 3) + "astc";
1965+
if (rename != null) rename = rename.substr(0, rename.length - 3) + "dds";
1966+
}
1967+
}
1968+
else
1969+
{
1970+
final astcPath:String = "astc-textures/" + path.substr(0, path.length - 3) + "astc";
1971+
1972+
if (!isASTCExcluded(path) && FileSystem.exists(astcPath))
1973+
{
1974+
path = astcPath;
1975+
1976+
if (rename != null) rename = rename.substr(0, rename.length - 3) + "astc";
1977+
}
19561978
}
19571979
}
19581980

scripts/dds/compress-textures.ps1

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
param (
2+
[Parameter(Mandatory = $true)]
3+
[string]$Bc7enc
4+
)
5+
6+
Remove-Item -Recurse -Force "dds-textures" -ErrorAction SilentlyContinue
7+
8+
New-Item -ItemType Directory -Force -Path "dds-textures" | Out-Null
9+
10+
$Excludes = @(
11+
"assets/ui/options/",
12+
"assets/ui/cursor/",
13+
"assets/ui/fonts/",
14+
"assets/ui/freeplay/",
15+
"assets/ui/soundtray/",
16+
"assets/ui/story-mode/levels/",
17+
"assets/ui/editors/",
18+
"assets/gameplay/dialogue/",
19+
"assets/gameplay/notestyles/pixel/",
20+
"assets/gameplay/characters/bf-pixel/",
21+
"assets/gameplay/characters/gf/",
22+
"assets/gameplay/characters/gf-car/",
23+
"assets/gameplay/characters/gf-christmas/",
24+
"assets/gameplay/characters/gf-dark/",
25+
"assets/gameplay/characters/gf-pixel/",
26+
"assets/gameplay/characters/nene-pixel/",
27+
"assets/gameplay/characters/pico-pixel/",
28+
"assets/gameplay/characters/senpai/",
29+
"assets/gameplay/characters/spirit/",
30+
"assets/gameplay/stages/mainStage/",
31+
"assets/gameplay/stages/school/",
32+
"assets/gameplay/stages/schoolErect/",
33+
"assets/gameplay/stages/schoolEvil/",
34+
"assets/gameplay/stages/schoolEvilErect/",
35+
"assets/ui/results/clear-percent/",
36+
"assets/ui/results/difficulty/",
37+
"assets/ui/results/rank-text/"
38+
)
39+
40+
$ExcludeFiles = @(
41+
"assets/gameplay/characters/bf/icon-bf.png",
42+
"assets/gameplay/characters/bf-old/icon-bf-old.png",
43+
"assets/gameplay/characters/bf-pixel/icon-bf-pixel.png",
44+
"assets/gameplay/characters/dad/icon-dad.png",
45+
"assets/gameplay/characters/darnell/icon-darnell.png",
46+
"assets/gameplay/characters/face/icon-face.png",
47+
"assets/gameplay/characters/gf/icon-gf.png",
48+
"assets/gameplay/characters/mom/icon-mom.png",
49+
"assets/gameplay/characters/monster/icon-monster.png",
50+
"assets/gameplay/characters/parents-christmas/icon-parents.png",
51+
"assets/gameplay/characters/parents-christmas/icon-parents-christmas.png",
52+
"assets/gameplay/characters/pico/icon-pico.png",
53+
"assets/gameplay/characters/senpai/icon-senpai.png",
54+
"assets/gameplay/characters/spirit/icon-spirit.png",
55+
"assets/gameplay/characters/spooky/icon-spooky.png",
56+
"assets/gameplay/characters/tankman/icon-tankman.png",
57+
"assets/gameplay/characters/tankman/icon-tankman-bloody.png",
58+
"assets/gameplay/characters/sserafim-chaewon/icon-sserafim-chaewon.png",
59+
"assets/gameplay/characters/sserafim-eunchae/icon-sserafim-eunchae.png",
60+
"assets/gameplay/characters/sserafim-kazuha/icon-sserafim-kazuha.png",
61+
"assets/gameplay/characters/sserafim-sakura/icon-sserafim-sakura.png",
62+
"assets/gameplay/characters/sserafim-yunjin/icon-sserafim-yunjin.png",
63+
"assets/ui/title/title-screen-text/spritemap1.png",
64+
"assets/ui/title/title-screen-text-mobile/spritemap1.png",
65+
"assets/gameplay/characters/nene/nene/spritemap1.png",
66+
"assets/gameplay/characters/pico-holding-nene/pico-holding-nene/spritemap1.png",
67+
"assets/gameplay/characters/sserafim-eunchae/sserafim-eunchae/spritemap1.png",
68+
"assets/gameplay/characters/sserafim-kazuha/sserafim-kazuha/spritemap1.png",
69+
"assets/gameplay/characters/sserafim-akura/sserafim-sakura/spritemap1.png",
70+
"assets/gameplay/characters/sserafim-gf/sserafim-gf/spritemap1.png",
71+
"assets/gameplay/characters/sserafim-yunjin/sserafim-yunjin/spritemap1.png",
72+
"assets/gameplay/general/health-bar.png",
73+
"assets/gameplay/playable-characters/bf/results/graphics/results-excellent/spritemap1.png",
74+
"assets/gameplay/playable-characters/bf/results/graphics/results-good/gf.png",
75+
"assets/gameplay/playable-characters/bf/results/graphics/results-great/gf/spritemap1.png",
76+
"assets/gameplay/playable-characters/bf/results/graphics/results-shit/spritemap1.png",
77+
"assets/gameplay/stages/mainStageErect/bright-light.png",
78+
"assets/gameplay/stages/mainStageErect/light-above.png",
79+
"assets/gameplay/stages/mainStageErect/light-green.png",
80+
"assets/gameplay/stages/mainStageErect/light-red.png",
81+
"assets/gameplay/stages/mainStageErect/light-orange.png",
82+
"assets/gameplay/stages/spookyMansionErect/stairs-dark.png",
83+
"assets/gameplay/stages/spookyMansionErect/stairs-light.png",
84+
"assets/gameplay/stages/tankmanBattlefield/bricks-ground.png",
85+
"assets/gameplay/stages/tankmanBattlefieldErect/bricks-ground.png",
86+
"assets/gameplay/stages/sserafim/cutscene/cutscene-main/spritemap1.png"
87+
)
88+
89+
Get-ChildItem -Path "assets" -Filter "*.png" -Recurse -File | ForEach-Object
90+
{
91+
$relative = $_.FullName.Substring((Get-Location).Path.Length + 1).Replace("", "/")
92+
93+
if ($ExcludeFiles -contains $relative)
94+
{
95+
return
96+
}
97+
98+
foreach ($exclude in $Excludes)
99+
{
100+
if ($relative.StartsWith($exclude))
101+
{
102+
return
103+
}
104+
}
105+
106+
$directory = Split-Path $relative -Parent
107+
108+
$out = Join-Path "dds-textures" $directory
109+
110+
New-Item -ItemType Directory -Force -Path $out | Out-Null
111+
112+
$dds = Join-Path $out ([System.IO.Path]::GetFileNameWithoutExtension($_.Name) + ".dds")
113+
114+
Write-Host "Compressing: $relative"
115+
116+
& $Bc7enc `
117+
-3 `
118+
-g `
119+
-q `
120+
$_.FullName `
121+
$dds
122+
123+
if ($LASTEXITCODE -ne 0)
124+
{
125+
throw "bc7enc failed for $($_.FullName)"
126+
}
127+
}

scripts/dds/compress-textures.sh

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [ -z "$1" ]; then
6+
echo "Usage: $0 <bc7enc>"
7+
exit 1
8+
fi
9+
10+
BC7ENC="$1"
11+
12+
chmod +x "$BC7ENC"
13+
14+
rm -rf "dds-textures"
15+
16+
mkdir -p "dds-textures"
17+
18+
EXCLUDES=(
19+
"assets/ui/options/"
20+
"assets/ui/cursor/"
21+
"assets/ui/fonts/"
22+
"assets/ui/freeplay/"
23+
"assets/ui/soundtray/"
24+
"assets/ui/story-mode/levels/"
25+
"assets/ui/editors/"
26+
"assets/gameplay/dialogue/"
27+
"assets/gameplay/notestyles/pixel/"
28+
"assets/gameplay/characters/bf-pixel/"
29+
"assets/gameplay/characters/gf/"
30+
"assets/gameplay/characters/gf-car/"
31+
"assets/gameplay/characters/gf-christmas/"
32+
"assets/gameplay/characters/gf-dark/"
33+
"assets/gameplay/characters/gf-pixel/"
34+
"assets/gameplay/characters/nene-pixel/"
35+
"assets/gameplay/characters/pico-pixel/"
36+
"assets/gameplay/characters/senpai/"
37+
"assets/gameplay/characters/spirit/"
38+
"assets/gameplay/stages/mainStage/"
39+
"assets/gameplay/stages/school/"
40+
"assets/gameplay/stages/schoolErect/"
41+
"assets/gameplay/stages/schoolEvil/"
42+
"assets/gameplay/stages/schoolEvilErect/"
43+
"assets/ui/results/clear-percent/"
44+
"assets/ui/results/difficulty/"
45+
"assets/ui/results/rank-text/"
46+
)
47+
48+
EXCLUDE_FILES=(
49+
"assets/gameplay/characters/bf/icon-bf.png"
50+
"assets/gameplay/characters/bf-old/icon-bf-old.png"
51+
"assets/gameplay/characters/bf-pixel/icon-bf-pixel.png"
52+
"assets/gameplay/characters/dad/icon-dad.png"
53+
"assets/gameplay/characters/darnell/icon-darnell.png"
54+
"assets/gameplay/characters/face/icon-face.png"
55+
"assets/gameplay/characters/gf/icon-gf.png"
56+
"assets/gameplay/characters/mom/icon-mom.png"
57+
"assets/gameplay/characters/monster/icon-monster.png"
58+
"assets/gameplay/characters/parents-christmas/icon-parents.png"
59+
"assets/gameplay/characters/parents-christmas/icon-parents-christmas.png"
60+
"assets/gameplay/characters/pico/icon-pico.png"
61+
"assets/gameplay/characters/senpai/icon-senpai.png"
62+
"assets/gameplay/characters/spirit/icon-spirit.png"
63+
"assets/gameplay/characters/spooky/icon-spooky.png"
64+
"assets/gameplay/characters/tankman/icon-tankman.png"
65+
"assets/gameplay/characters/tankman/icon-tankman-bloody.png"
66+
"assets/gameplay/characters/sserafim-chaewon/icon-sserafim-chaewon.png"
67+
"assets/gameplay/characters/sserafim-eunchae/icon-sserafim-eunchae.png"
68+
"assets/gameplay/characters/sserafim-kazuha/icon-sserafim-kazuha.png"
69+
"assets/gameplay/characters/sserafim-sakura/icon-sserafim-sakura.png"
70+
"assets/gameplay/characters/sserafim-yunjin/icon-sserafim-yunjin.png"
71+
"assets/ui/title/title-screen-text/spritemap1.png"
72+
"assets/ui/title/title-screen-text-mobile/spritemap1.png"
73+
"assets/gameplay/characters/nene/nene/spritemap1.png"
74+
"assets/gameplay/characters/pico-holding-nene/pico-holding-nene/spritemap1.png"
75+
"assets/gameplay/characters/sserafim-eunchae/sserafim-eunchae/spritemap1.png"
76+
"assets/gameplay/characters/sserafim-kazuha/sserafim-kazuha/spritemap1.png"
77+
"assets/gameplay/characters/sserafim-akura/sserafim-sakura/spritemap1.png"
78+
"assets/gameplay/characters/sserafim-gf/sserafim-gf/spritemap1.png"
79+
"assets/gameplay/characters/sserafim-yunjin/sserafim-yunjin/spritemap1.png"
80+
"assets/gameplay/general/health-bar.png"
81+
"assets/gameplay/playable-characters/bf/results/graphics/results-excellent/spritemap1.png"
82+
"assets/gameplay/playable-characters/bf/results/graphics/results-good/gf.png"
83+
"assets/gameplay/playable-characters/bf/results/graphics/results-great/gf/spritemap1.png"
84+
"assets/gameplay/playable-characters/bf/results/graphics/results-shit/spritemap1.png"
85+
"assets/gameplay/stages/mainStageErect/bright-light.png"
86+
"assets/gameplay/stages/mainStageErect/light-above.png"
87+
"assets/gameplay/stages/mainStageErect/light-green.png"
88+
"assets/gameplay/stages/mainStageErect/light-red.png"
89+
"assets/gameplay/stages/mainStageErect/light-orange.png"
90+
"assets/gameplay/stages/spookyMansionErect/stairs-dark.png"
91+
"assets/gameplay/stages/spookyMansionErect/stairs-light.png"
92+
"assets/gameplay/stages/tankmanBattlefield/bricks-ground.png"
93+
"assets/gameplay/stages/tankmanBattlefieldErect/bricks-ground.png"
94+
"assets/gameplay/stages/sserafim/cutscene/cutscene-main/spritemap1.png"
95+
)
96+
97+
is_excluded()
98+
{
99+
local file="$1"
100+
101+
for exclude in "${EXCLUDE_FILES[@]}"; do
102+
[ "$file" = "$exclude" ] && return 0
103+
done
104+
105+
for exclude in "${EXCLUDES[@]}"; do
106+
[[ "$file" == "$exclude"* ]] && return 0
107+
done
108+
109+
return 1
110+
}
111+
112+
find "assets" -type f -name "*.png" | while read -r f; do
113+
if is_excluded "$f"; then
114+
continue
115+
fi
116+
117+
out="dds-textures/$(dirname "$f")"
118+
mkdir -p "$out"
119+
120+
dds="$out/$(basename "${f%.png}.dds")"
121+
122+
echo "Compressing: $f"
123+
124+
"$BC7ENC" \
125+
-3 \
126+
-g \
127+
-q \
128+
"$f" \
129+
"$dds"
130+
done

source/funkin/util/assets/AssetsUtil.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class AssetsUtil
1414
{
1515
static final EXTENSIONS:Map<String, FunkinAssetType> = [
1616
'astc' => FunkinAssetType.IMAGE, // Texture image utilizing Adaptive scalable texture compression
17+
'dds' => FunkinAssetType.IMAGE, // Texture image utilizing Adaptive scalable texture compression
1718
'bmp' => FunkinAssetType.IMAGE, // Bitmap image
1819
'css' => FunkinAssetType.TEXT, // Cascading stylesheet
1920
'csv' => FunkinAssetType.TEXT, // Comma-separated values file

0 commit comments

Comments
 (0)