Important Announcement
Forum has been made read-only. Please click here for more information or here to return to The Spriters Resource.

Switch BNTX research
#10
(07-26-2017, 12:15 PM)KillzXGaming Wrote: Ah yes true. Does appear to be identical to original if i copy to the other channels.

Also another note, BC5 textures in this case used as normal maps seem to look quite strange.
http://i.imgur.com/j9DzRIV.png

Original
http://i.imgur.com/RVVIw0T.png

Well, normals are unit vectors, so on BC5 the Z component is not stored on the texture, only X and Y. Then Z is calculated based on X and Y (since X² + Y² + Z² are always 1 on unit vectors, Z can be computed as sqrt(1 - (X² + Y²)). Those blocks does seems weird through, its probably because the sign [-1, 1] is not being interpreted correctly. The way fragment shader expects is usually 0 being -1, and 255 being 1, but on a signed byte it's mapped as 128 = -1, 0 = 0 and 127 = 1. Not sure if this is the problem through.

Anyway I didn't looked into this yet, My focus currently is getting the swizzle correct for all textures, and then I'll start working on each pixel format. But thanks for pointing out this issue, I'll try to fix it as soon as I have the swizzle fully working.

(07-26-2017, 11:39 AM)Random Talking Bush Wrote: The way I've got it for my QuickBMS script right now is incredibly hacky and frankly I'm not even sure how it's working, so I can't say for sure. Unsure

This seems to be quite a interesting piece of code. I kind of isolated the problem I have with the swizzle currently, and also managed to understand a little better how it is supposed to work.

The easiest way I found to understand the ordering was this:

We first we have a 2x2 block. I will call it the "small block". Each small block contains 4 (2x2) tiles, and is ordered like this:

Code:
+--+--+
|0 |2 |
+--+--+
|1 |3 |
+--+--+

Then, we have a 2x4 block. Let's call it the "medium block". Each medium block contains 8 (2x4) small blocks, and is ordered like this:

Code:
+----+----+
|0   |4   |
|    |    |
+----+----+
|1   |5   |
|    |    |
+----+----+
|2   |6   |
|    |    |
+----+----+
|3   |7   |
|    |    |
+----+----+

And then we have a 2x16 block, a "large block". Each large block contains 32 (2x16) medium blocks. The ordering follows the same pattern of the previous blocks, and this is the biggest swizzled block that a texture can contain (at least on the files I observed). When the image is smaller than the block size (for example, images with less than 128 pixels of height (or 512 for 4x4 tiles compressed textures), then the block is ignored, and swizzle is performed just on the block sizes that does "fit" inside the texture.

So, basically my current problem is - what happens when the image size is not a multiple of those block sizes? Or when they don't have a power of 2 size?

The following textures can be decoded fine:
- Size is power of 2
- Width and height are greater than 128 (or 512 for compressed textures)

All other cases may or may not work properly.

I also generated mapping for some of the texture sizes for analysis.

[spoiler]
From a 64x66 texture, rounded to 64x96:

Code:
0   2   16  18  64  66  80  82  128 130 144 146 192 194 208 210
1   3   17  19  65  67  81  83  129 131 145 147 193 195 209 211
4   6   20  22  68  70  84  86  132 134 148 150 196 198 212 214
5   7   21  23  69  71  85  87  133 135 149 151 197 199 213 215
8   10  24  26  72  74  88  90  136 138 152 154 200 202 216 218
9   11  25  27  73  75  89  91  137 139 153 155 201 203 217 219
12  14  28  30  76  78  92  94  140 142 156 158 204 206 220 222
13  15  29  31  77  79  93  95  141 143 157 159 205 207 221 223

32  34  48  50  96  98  112 114 160 162 176 178 224 226 240 242
33  35  49  51  97  99  113 115 161 163 177 179 225 227 241 243
36  38  52  54  100 102 116 118 164 166 180 182 228 230 244 246
37  39  53  55  101 103 117 119 165 167 181 183 229 231 245 247
40  42  56  58  104 106 120 122 168 170 184 186 232 234 248 250
41  43  57  59  105 107 121 123 169 171 185 187 233 235 249 251
44  46  60  62  108 110 124 126 172 174 188 190 236 238 252 254
45  47  61  63  109 111 125 127 173 175 189 191 237 239 253 255

256 258 272 274 320 322 336 338 384 386 400 402 448 450 464 466
257 259 273 275 321 323 337 339 385 387 401 403 449 451 465 467
260 262 276 278 324 326 340 342 388 390 404 406 452 454 468 470
261 263 277 279 325 327 341 343 389 391 405 407 453 455 469 471
264 266 280 282 328 330 344 346 392 394 408 410 456 458 472 474
265 267 281 283 329 331 345 347 393 395 409 411 457 459 473 475
268 270 284 286 332 334 348 350 396 398 412 414 460 462 476 478
269 271 285 287 333 335 349 351 397 399 413 415 461 463 477 479

From a 86x174? texture rounded to 96x192:

Code:
0    2    16   18   256  258  272  274  512  514  528  530  768  770  784  786  1024 1026 1040 1042 1280 1282 1296 1298
1    3    17   19   257  259  273  275  513  515  529  531  769  771  785  787  1025 1027 1041 1043 1281 1283 1297 1299
4    6    20   22   260  262  276  278  516  518  532  534  772  774  788  790  1028 1030 1044 1046 1284 1286 1300 1302
5    7    21   23   261  263  277  279  517  519  533  535  773  775  789  791  1029 1031 1045 1047 1285 1287 1301 1303
8    10   24   26   264  266  280  282  520  522  536  538  776  778  792  794  1032 1034 1048 1050 1288 1290 1304 1306
9    11   25   27   265  267  281  283  521  523  537  539  777  779  793  795  1033 1035 1049 1051 1289 1291 1305 1307
12   14   28   30   268  270  284  286  524  526  540  542  780  782  796  798  1036 1038 1052 1054 1292 1294 1308 1310
13   15   29   31   269  271  285  287  525  527  541  543  781  783  797  799  1037 1039 1053 1055 1293 1295 1309 1311

32   34   48   50   288  290  304  306  544  546  560  562  800  802  816  818  1056 1058 1072 1074 1312 1314 1328 1330
33   35   49   51   289  291  305  307  545  547  561  563  801  803  817  819  1057 1059 1073 1075 1313 1315 1329 1331
36   38   52   54   292  294  308  310  548  550  564  566  804  806  820  822  1060 1062 1076 1078 1316 1318 1332 1334
37   39   53   55   293  295  309  311  549  551  565  567  805  807  821  823  1061 1063 1077 1079 1317 1319 1333 1335
40   42   56   58   296  298  312  314  552  554  568  570  808  810  824  826  1064 1066 1080 1082 1320 1322 1336 1338
41   43   57   59   297  299  313  315  553  555  569  571  809  811  825  827  1065 1067 1081 1083 1321 1323 1337 1339
44   46   60   62   300  302  316  318  556  558  572  574  812  814  828  830  1068 1070 1084 1086 1324 1326 1340 1342
45   47   61   63   301  303  317  319  557  559  573  575  813  815  829  831  1069 1071 1085 1087 1325 1327 1341 1343

64   66   80   82   320  322  336  338  576  578  592  594  832  834  848  850  1088 1090 1104 1106 1344 1346 1360 1362
65   67   81   83   321  323  337  339  577  579  593  595  833  835  849  851  1089 1091 1105 1107 1345 1347 1361 1363
68   70   84   86   324  326  340  342  580  582  596  598  836  838  852  854  1092 1094 1108 1110 1348 1350 1364 1366
69   71   85   87   325  327  341  343  581  583  597  599  837  839  853  855  1093 1095 1109 1111 1349 1351 1365 1367
72   74   88   90   328  330  344  346  584  586  600  602  840  842  856  858  1096 1098 1112 1114 1352 1354 1368 1370
73   75   89   91   329  331  345  347  585  587  601  603  841  843  857  859  1097 1099 1113 1115 1353 1355 1369 1371
76   78   92   94   332  334  348  350  588  590  604  606  844  846  860  862  1100 1102 1116 1118 1356 1358 1372 1374
77   79   93   95   333  335  349  351  589  591  605  607  845  847  861  863  1101 1103 1117 1119 1357 1359 1373 1375

96   98   112  114  352  354  368  370  608  610  624  626  864  866  880  882  1120 1122 1136 1138 1376 1378 1392 1394
97   99   113  115  353  355  369  371  609  611  625  627  865  867  881  883  1121 1123 1137 1139 1377 1379 1393 1395
100  102  116  118  356  358  372  374  612  614  628  630  868  870  884  886  1124 1126 1140 1142 1380 1382 1396 1398
101  103  117  119  357  359  373  375  613  615  629  631  869  871  885  887  1125 1127 1141 1143 1381 1383 1397 1399
104  106  120  122  360  362  376  378  616  618  632  634  872  874  888  890  1128 1130 1144 1146 1384 1386 1400 1402
105  107  121  123  361  363  377  379  617  619  633  635  873  875  889  891  1129 1131 1145 1147 1385 1387 1401 1403
108  110  124  126  364  366  380  382  620  622  636  638  876  878  892  894  1132 1134 1148 1150 1388 1390 1404 1406
109  111  125  127  365  367  381  383  621  623  637  639  877  879  893  895  1133 1135 1149 1151 1389 1391 1405 1407

128  130  144  146  384  386  400  402  640  642  656  658  896  898  912  914  1152 1154 1168 1170 1408 1410 1424 1426
129  131  145  147  385  387  401  403  641  643  657  659  897  899  913  915  1153 1155 1169 1171 1409 1411 1425 1427
132  134  148  150  388  390  404  406  644  646  660  662  900  902  916  918  1156 1158 1172 1174 1412 1414 1428 1430
133  135  149  151  389  391  405  407  645  647  661  663  901  903  917  919  1157 1159 1173 1175 1413 1415 1429 1431
136  138  152  154  392  394  408  410  648  650  664  666  904  906  920  922  1160 1162 1176 1178 1416 1418 1432 1434
137  139  153  155  393  395  409  411  649  651  665  667  905  907  921  923  1161 1163 1177 1179 1417 1419 1433 1435
140  142  156  158  396  398  412  414  652  654  668  670  908  910  924  926  1164 1166 1180 1182 1420 1422 1436 1438
141  143  157  159  397  399  413  415  653  655  669  671  909  911  925  927  1165 1167 1181 1183 1421 1423 1437 1439

160  162  176  178  416  418  432  434  672  674  688  690  928  930  944  946  1184 1186 1200 1202 1440 1442 1456 1458
161  163  177  179  417  419  433  435  673  675  689  691  929  931  945  947  1185 1187 1201 1203 1441 1443 1457 1459
164  166  180  182  420  422  436  438  676  678  692  694  932  934  948  950  1188 1190 1204 1206 1444 1446 1460 1462
165  167  181  183  421  423  437  439  677  679  693  695  933  935  949  951  1189 1191 1205 1207 1445 1447 1461 1463
168  170  184  186  424  426  440  442  680  682  696  698  936  938  952  954  1192 1194 1208 1210 1448 1450 1464 1466
169  171  185  187  425  427  441  443  681  683  697  699  937  939  953  955  1193 1195 1209 1211 1449 1451 1465 1467
172  174  188  190  428  430  444  446  684  686  700  702  940  942  956  958  1196 1198 1212 1214 1452 1454 1468 1470
173  175  189  191  429  431  445  447  685  687  701  703  941  943  957  959  1197 1199 1213 1215 1453 1455 1469 1471
[/spoiler]

Both are extracted correctly with those patterns, but they were generated using different code, and they are also different. So I basically, don't know why this difference exists, and I'm currently trying to make some sense out of it. I spent some time yesterday trying different solutions, but none of them worked for all samples.

Also, another thing to take into account:  Unused values = space waste. Basically, for a 64x66 textures, this would mean 64x62 pixels worth of wasted space on the file, however this is not what it does, it never wastes so much space. I would expect it to round the texture down to 64x32 then address the top bits linearly, but that doesn't seems to be the case either - rounding it down fixes some textures but break others.
Reply


Messages In This Thread
Switch BNTX research - by gdkchan - 07-21-2017, 09:59 PM
RE: Switch BNTX research - by Random Talking Bush - 07-22-2017, 09:41 AM
RE: Switch BNTX research - by gdkchan - 07-22-2017, 08:28 PM
RE: Switch BNTX research - by Random Talking Bush - 07-23-2017, 09:06 AM
RE: Switch BNTX research - by gdkchan - 07-23-2017, 11:57 PM
RE: Switch BNTX research - by aboood40091 - 08-18-2017, 12:23 PM
RE: Switch BNTX research - by gdkchan - 08-19-2017, 02:09 PM
RE: Switch BNTX research - by aboood40091 - 09-21-2017, 09:03 PM
RE: Switch BNTX research - by gdkchan - 07-24-2017, 10:22 PM
RE: Switch BNTX research - by KillzXGaming - 07-26-2017, 11:15 AM
RE: Switch BNTX research - by Random Talking Bush - 07-26-2017, 11:39 AM
RE: Switch BNTX research - by KillzXGaming - 07-26-2017, 12:15 PM
RE: Switch BNTX research - by gdkchan - 07-26-2017, 01:10 PM
RE: Switch BNTX research - by gdkchan - 07-27-2017, 10:50 AM
RE: Switch BNTX research - by aboood40091 - 07-26-2017, 03:23 PM
RE: Switch BNTX research - by gdkchan - 07-26-2017, 10:37 PM
RE: Switch BNTX research - by Random Talking Bush - 08-05-2017, 01:48 AM
RE: Switch BNTX research - by gdkchan - 08-05-2017, 08:20 AM
RE: Switch BNTX research - by Rich - 09-19-2017, 09:33 AM

Forum Jump:


Users browsing this thread: 3 Guest(s)