12-18-2022, 12:38 AM
Hi all! It has been 7 months since my last update, how are you guys doing?
The project is getting more technical now, as all the easy stuff are identified and ripped. Now it is about referring console development documentations for actual formula, reverse-engineering the executable for interpolation algorithm, and debugging those unknown bit-flags.
So today, I'm going to talk about alpha blending for consoles.
Recalling on my Legend of Mana thread when I'm researching how GIMP do alpha blending and found this: https://docs.gimp.org/en/gimp-concepts-layer-modes.html
Console is different in that it uses one standard formula for alpha blending, but disable/zero any register not needed at run time.
For Playstation 2, the formula for alpha blending is:
https://psi-rockin.github.io/ps2tek/#gsalphablending
Using the above formula and look around the main executable ASM code, I manage to discover the 6 blending formula used in PS2 Odin Sphere:
Interestingly, PS2 Odin Sphere sprites uses Blend 0, 1 and 2. Blend 3, 4 and 5 are unused.
The annoying part about the whole formula is it reads BG.rgb twice, it isn't possible to do with WebGL builtin blendFunc(). I'll have to roll my own and ping-pong around.
Since I'll be doing custom blending from now on, WebGL builtin blendFunc() will be disabled.
Similar formula is also discovered on Wii. It is called TEV (Texture Environment Unit) Computation Expression.
The 6 different blending modes on Wii are:
https://rufaswan.github.io/Web2D_Games/i...%20p45.png
https://rufaswan.github.io/Web2D_Games/i...%20p47.png
https://rufaswan.github.io/Web2D_Games/i...%20p49.png
https://rufaswan.github.io/Web2D_Games/i...%20p51.png
https://rufaswan.github.io/Web2D_Games/i...%20p53.png
https://rufaswan.github.io/Web2D_Games/i...%20p57.png
I haven't debug Wii code yet, but I would presume Blend 0 is Decal, Blend 1 is Addition, and Blend 2 is Subtraction.
For completion sake, the alpha blending formula for Playstation One:
The 4 different blending modes on PS1 are:
https://rufaswan.github.io/Web2D_Games/i...6-p345.png
https://rufaswan.github.io/Web2D_Games/i...6-p109.png
Will need help to find the alpha blending formula for these consoles:
- Playstation Portable
- Playstation Vita
- Playstation 3
- Playstation 4
- Nintendo DS (although Kumatanchi never used any)
- Nintendo Switch
- Sega Saturn
Still learning, and keep getting closer and closer to finish line.
Wish you an early Merry Christmas + Happy New Year 2023!
- Rufas
The project is getting more technical now, as all the easy stuff are identified and ripped. Now it is about referring console development documentations for actual formula, reverse-engineering the executable for interpolation algorithm, and debugging those unknown bit-flags.
So today, I'm going to talk about alpha blending for consoles.
Recalling on my Legend of Mana thread when I'm researching how GIMP do alpha blending and found this: https://docs.gimp.org/en/gimp-concepts-layer-modes.html
Console is different in that it uses one standard formula for alpha blending, but disable/zero any register not needed at run time.
For Playstation 2, the formula for alpha blending is:
https://psi-rockin.github.io/ps2tek/#gsalphablending
Code:
Output = ((A - B) * C) + D
Using the above formula and look around the main executable ASM code, I manage to discover the 6 blending formula used in PS2 Odin Sphere:
Code:
Blend 0: Pixel = ((FG.rgb - BG.rgb) * FG.a) + BG.rgb
Blend 1: Pixel = ((FG.rgb - 0) * FG.a) + BG.rgb
Blend 2: Pixel = ((0 - FG.rgb) * FG.a) + BG.rgb
Blend 3: Pixel = ((FG.rgb - BG.rgb) * BG.a) + BG.rgb
Blend 4: Pixel = ((FG.rgb - 0) * BG.a) + BG.rgb
Blend 5: Pixel = ((0 - FG.rgb) * BG.a) + BG.rgb
Interestingly, PS2 Odin Sphere sprites uses Blend 0, 1 and 2. Blend 3, 4 and 5 are unused.
The annoying part about the whole formula is it reads BG.rgb twice, it isn't possible to do with WebGL builtin blendFunc(). I'll have to roll my own and ping-pong around.
Since I'll be doing custom blending from now on, WebGL builtin blendFunc() will be disabled.
Similar formula is also discovered on Wii. It is called TEV (Texture Environment Unit) Computation Expression.
Code:
D + ( ((1-C) * A) + (C*B)
The 6 different blending modes on Wii are:
https://rufaswan.github.io/Web2D_Games/i...%20p45.png
https://rufaswan.github.io/Web2D_Games/i...%20p47.png
https://rufaswan.github.io/Web2D_Games/i...%20p49.png
https://rufaswan.github.io/Web2D_Games/i...%20p51.png
https://rufaswan.github.io/Web2D_Games/i...%20p53.png
https://rufaswan.github.io/Web2D_Games/i...%20p57.png
Code:
D + ( ((1-0) * A) + (0*0) = D + A or Addition
D - ( ((1-0) * A) + (0*0) = D - A or Subtraction
0 + ( ((1-C) * 0) + (C*B) = C * B or Multiplication
D + ( ((1-C) * 0) + (C*B) = D + (C * B) or Addition + Multiplication
0 + ( ((1-C) * A) + (C*B) = (1-C) * A + (C * B) or Decal
D + ( ((1-C) * A) + (C*0) = D + ((1-C) * A) or Proportional
I haven't debug Wii code yet, but I would presume Blend 0 is Decal, Blend 1 is Addition, and Blend 2 is Subtraction.
For completion sake, the alpha blending formula for Playstation One:
Code:
FG.rgb * A + BG.rgb * B
The 4 different blending modes on PS1 are:
https://rufaswan.github.io/Web2D_Games/i...6-p345.png
https://rufaswan.github.io/Web2D_Games/i...6-p109.png
Code:
FG.rgb * 0.5 + BG.rgb * 0.5 or Average
FG.rgb * 1.0 + BG.rgb * 1.0 or Addition
FG.rgb * -1.0 + BG.rgb * 1.0 or Subtraction
FG.rgb * 0.25 + BG.rgb * 1.0 or Quarter Addition
Will need help to find the alpha blending formula for these consoles:
- Playstation Portable
- Playstation Vita
- Playstation 3
- Playstation 4
- Nintendo DS (although Kumatanchi never used any)
- Nintendo Switch
- Sega Saturn
Still learning, and keep getting closer and closer to finish line.
Wish you an early Merry Christmas + Happy New Year 2023!
- Rufas