aliens

Author Topic: Paletted 8bit -> 24bit shading.  (Read 58822 times)

Volutar

  • Guest
Paletted 8bit -> 24bit shading.
« on: January 22, 2013, 02:49:42 pm »
I've been thinking recently on where OXC could go after 1.0, when custom graphics loaders will be added, and 24bit screen mode will be main mode.
We obviously will face THE problem at least of battlescape shading/lighting. UFO:EU have paletted graphics with very "deep" and saturated shades. When it will become 24bit, this shading will become flat.

And I don't know how to overcome this. 24bit oxc will lose this special "night" style.

On screenshot: top line - palette of battlescape; bottom line - flat shaded 24bit lighting.

Offline michal

  • Commander
  • *****
  • Posts: 629
    • View Profile
Re: Paletted 8bit -> 24bit shading.
« Reply #1 on: January 22, 2013, 02:52:01 pm »
I don't understand it. Can't we show that colors in 24 bpp? Can't 24 bpp basically represent nearly all possible colors?

Volutar

  • Guest
Re: Paletted 8bit -> 24bit shading.
« Reply #2 on: January 22, 2013, 03:08:01 pm »
The matter is in SHADING, in lighting falloff gradients, not still representation. There won't be any palette, and color (248,248,248) can be shaded only as gray... but in xcom1 this "hightlight" color corresponding to 4th stripe (warm plastic gradient) and 14th stripe (cold metalic gradient). Engine would have no information on how exactly this color should be "shaded"

Offline LCSand

  • Captain
  • ***
  • Posts: 73
    • View Profile
Re: Paletted 8bit -> 24bit shading.
« Reply #3 on: January 22, 2013, 03:09:51 pm »
Yes, that is what I think too. Just convert the indexed palette images to 24 bit images when loading.
Of couse I have no idea how much the current code relies on the indexed stuff for things like lighting.

Offline kkmic

  • Commander
  • *****
  • Posts: 582
  • Undefined
    • View Profile
Re: Paletted 8bit -> 24bit shading.
« Reply #4 on: January 22, 2013, 03:12:20 pm »
Hmm.. how about calculating the new gradient form the maximum and minimum values? That was my plan all along....

So basically we keep using only the "max and min" for each color group, and we calculate everything in between.

Volutar

  • Guest
Re: Paletted 8bit -> 24bit shading.
« Reply #5 on: January 22, 2013, 03:18:27 pm »
The thing is - there's no color groups in 24bit. How will you find what color group is (248,248,248)???
« Last Edit: January 22, 2013, 03:24:39 pm by Volutar »

Offline kkmic

  • Commander
  • *****
  • Posts: 582
  • Undefined
    • View Profile
Re: Paletted 8bit -> 24bit shading.
« Reply #6 on: January 22, 2013, 03:33:30 pm »
By calculating the color range when the palette is loaded?

We should end up with something like in the attachement

Volutar

  • Guest
Re: Paletted 8bit -> 24bit shading.
« Reply #7 on: January 22, 2013, 03:39:16 pm »
kkmic, I'm repeating once more: there is no palette in 24mode. Every game sprite will be 24bit even as files. What is the formula of shading, which will "endup" with those gradients you've shown? Considering there's no palette at all. There will be bunch of 24bit sprites. That's all.

Offline LCSand

  • Captain
  • ***
  • Posts: 73
    • View Profile
Re: Paletted 8bit -> 24bit shading.
« Reply #8 on: January 22, 2013, 04:13:53 pm »
Every game sprite will be 24bit even as files.
Will it realy? That would mean including converted artwork from the original, wich I think will not be done. Or creating new artwork.
Also the palette currently used is known and could be used for compatible artwork.

Offline pmprog

  • Commander
  • *****
  • Posts: 647
  • Contributor
    • View Profile
    • Polymath Programming
Re: Paletted 8bit -> 24bit shading.
« Reply #9 on: January 22, 2013, 04:26:36 pm »
Whilst the SDL "surface" won't have a palette in 24bpp mode, there's nothing stopping OXC implementing a custom palette and use the lock() and unlock() methods to access a surface and manually replace colours.

This will allow you to retain the palette shifting for lighting, whilst expanding the other possibilities (mixing battlescape, geoscape and basescape items)

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: Paletted 8bit -> 24bit shading.
« Reply #10 on: January 22, 2013, 04:57:17 pm »
how about bigger color index? not 255 but 64k colors (it is possible in SDL?)? we could load every palette at once, and have two graphic from xcom1 and xcom2 on one screen.

Volutar

  • Guest
Re: Paletted 8bit -> 24bit shading.
« Reply #11 on: January 22, 2013, 05:15:35 pm »
Quote
That would mean including converted artwork from the original, wich I think will not be done.
why not? this convertion can be done "on the fly". and then - HD sprites and graphics without palette limitation.

Quote
there's nothing stopping OXC implementing a custom palette and use the lock() and unlock() methods to access a surface and manually replace colours.
Of course. No other way to apply lighting in software mode. But how will you shade pixel with 24bit value (248,248,248) which have index 80 and index 224 (yes, two EXACT colors have different shading gradients in terms of palette)??? If you even manage to convert 24bit into 8bit palette (which will greatly cutoff colors), you will get ambiguous values, and that won't let you shade those sprites properly.

Quote
This will allow you to retain the palette shifting for lighting
so you're suggesting to keep limited palette graphics? geez...

Quote
how about bigger color index? not 255 but 64k colors
1. it's bad idea. 2. it's impossible.

Offline Daiky

  • Battlescape Programmer
  • Administrator
  • Commander
  • *****
  • Posts: 904
    • View Profile
Re: Paletted 8bit -> 24bit shading.
« Reply #12 on: January 22, 2013, 05:19:37 pm »
It's more a discussion of taste. Ufo tts uses 24bit graphics and "flat" shading. I don't remember anyone complain, I didn't even really notice it.
Example:
https://media.indiedb.com/images/downloads/1/29/28380/tts.JPG

edit: well there are probably better screenshots out there, but I can't access anything here at work. But you get the point. I like to see real examples, not theory. So show the difference between good and bad, and then we make a poll to see how bad bad actually is. And if it is really bad, then we can look for a solution. Now it's like looking for a solution to a problem that is not even proven it's a problem at all.
« Last Edit: January 22, 2013, 05:26:14 pm by Daiky »

Volutar

  • Guest
Re: Paletted 8bit -> 24bit shading.
« Reply #13 on: January 22, 2013, 05:25:10 pm »
Daiky, yes this is matter of shading "style". And I Believe it would look much better and stylish if it were somehow closer to palette.

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: Paletted 8bit -> 24bit shading.
« Reply #14 on: January 22, 2013, 06:15:31 pm »
btw Volutar who will be shading in 24bit? there is SDL function that do it? or it will be do by our side?
If we do it, why dont try made special function that change hue and saturation of pixels?
I think that will be possible to made result similar to original gradient.
Maybe we should use exp function to do it? they can be written to table to speed up.
something like this:
Code: [Select]
shade(R, G, B, shade)
{
    R *= exp(-0.1337*shade);
    G *= exp(-0.42*shade);
    B *= exp(-0.7*shade)
}