The International Simutrans Forum

 

Author Topic: Darker special color for windows  (Read 11765 times)

0 Members and 1 Guest are viewing this topic.

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1997
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Darker special color for windows
« on: January 29, 2012, 05:07:51 PM »
Both of the two available colors for windows look odd in many of pak128's trains because it's a too light grey and a bit more contrast would be required most of the times. I guess that changing a current special color would be crazy, so I hope it's possible to add an additional color for use in vehicle windows. A darker grey such as #262626 would be nice, but before discussing it would be nice to know whether it's possible or not, or which reasons there are in favour or against. Thank you.

PS: An example of what I try to explain can be seen in the two attached vehicles; in the first one the windows are not visible during day, while in the second they are more visible.

Offline The Hood

  • Devotee
  • *
  • Posts: 2889
  • pak128.Britain developer
Re: Darker special color for windows
« Reply #1 on: January 29, 2012, 05:40:42 PM »
I've been thinking about this too. Pak128.Britain uses very dark black for windows and at present we don't use night lights. What I'd like to see is a way of choosing special night colours e.g. in a config file, so that I could chose e.g. 010101 as being a night colour for pak128.Britain.

Offline Fabio

  • Devotee
  • Administrator
  • *
  • Posts: 2898
  • The Pak128 Guy
    • Visit me on Facebook
  • Languages: EN, IT, RO, FR
Re: Darker special color for windows
« Reply #2 on: January 29, 2012, 05:46:36 PM »
I often feel that more special colours would be needed, maybe more than just this one.

In a way, I would like them to be pakset-customizable instead of hardcoded. Paksets could have a tab file or a compiled pak object with three entries per line: png colour, day colour and night colour. Display routines could lookup this table and replace colours accordingly.

Also more player colours would be nice, for better antialiasing.



The Hood preceded me...

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1997
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Darker special color for windows
« Reply #3 on: January 29, 2012, 06:08:19 PM »
Well, I would like just a change on the window color, but I understand that is not practical as it would modify/leave useless all existing material.

About player colors, the more colors you use for AA, the less you'll have as "normal" colors. For player colors, instead of adding more colors I'd prefer a system such as OTTD's one, which is far in front of us at that: each object is composed by two images, the normal image and a mask image (#FF8000 IIRC) that only shows the places where player color should be applied. Then when you select a player color, the selected color is antialiased all over the mask zone, following the original image reference to reproduce the same area with a different color. I don't know exactly about the coding of this, but I can have an idea of the concept. Results are simply awful, like comparing 16M colors to a CGA 4 color display. Of course that will be probably expensive in memory and/or cpu terms.

Online wlindley us

  • Devotee
  • *
  • Posts: 999
    • Hacking for fun and profit since 1977
  • Languages: EN, DE
Re: Darker special color for windows
« Reply #4 on: January 29, 2012, 06:46:32 PM »
How about modifying makeobj's png converter so that:
  • Transparent in the source PNG should mean transparent in the pakfile.  That alone should make translation from 3D models easier.
  • Images can have optional mask image, such that all colors in the regular painted PNG are permissible (no special colors) -- and the existing special palette colors would be used in the mask image.  Again, the PNG reader should understand Transparent in the mask image as really meaning transparent.
  • Non-special colors in the mask image would have no effect.  Thus, when makeobj reads an existing DAT, with no masks, would default to using the existing PNG as both the image and the mask, and everything would Just Work.  New DATs actually wanting no mask, would use the new parameter with a blank value.
  • The executable program would likewise regard a missing mask as being the same as the image, to maintain full compatibility with existing PAK files.

In the case of windows and other night-colors, the executable would leave the read-in image colors alone during day, and set to the existing special colors at night.


Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9789
  • Languages: De,EN,JP
Re: Darker special color for windows
« Reply #5 on: January 29, 2012, 08:27:25 PM »
What two avialable colors? There are 10 colors for windows, see the attached file.

But actually, what kind of vehicle has black windows during day?

About colors on the fly: This is not possible, the special colors are converted during pak file image conversion. OpenTTD can do this easily, since it has only 8 bit palette. As such trnsparency is just a special color. The 32 bit version use alpha blending indeed, but reduce many graphics effect du to processor load (or rather bus load).

Introducing another special color in makeobj is easy: But it would appear in all previous objects, thus you have to use a new version of shades on any of them ...
« Last Edit: January 29, 2012, 08:33:01 PM by prissi »

Offline Zeno

  • ENASSA Designer
  • Devotee
  • *
  • Posts: 1997
    • Zeno's Simutrans Creations
  • Languages: ES, EN, CAT
Re: Darker special color for windows
« Reply #6 on: January 29, 2012, 09:20:07 PM »
What two avialable colors? There are 10 colors for windows, see the attached file.
There are two grey window colors candidate for a "dark" window.

But actually, what kind of vehicle has black windows during day?
Dunno in Germany, but in spain most passenger trains have darkened glass windows that look like plain black when seen from 50 or 100 m.

Anyway, I tried all other reasonable colors (green, red, magenta, blue and yellow are not appropiate for a window) and the vehicles keep looking odd for same reason. None of them make contrast enough with the vehicle's body paint. I will try providing a frame for those windows or other workaround :(

Offline Fabio

  • Devotee
  • Administrator
  • *
  • Posts: 2898
  • The Pak128 Guy
    • Visit me on Facebook
  • Languages: EN, IT, RO, FR
Light & Shadow
« Reply #7 on: February 02, 2012, 02:50:40 PM »
Could you please consider this requests:


Shadow
Presently shadows (e.g. trees) are painted with a cris-cross pattern of black pixels.
New special color #3A4040 would be painted as a 50% transparent black pixel.


Light
Special color #B9CCCC could be totally transparent in daylight, but turn 50% transparent light at night.
This could be used e.g. for street lamps and other light sources.


The first one is much more important, IMHO.





If special colors are to be compiled by Makeobj, why not include them (well, the non standard ones) in DAT files?
E.g.
Code: [Select]
NightColor[0]=#FF8000


Offline Spike

  • *
  • Posts: 1361
  • First Simutrans Developer and Graphics Artist
Re: Darker special color for windows
« Reply #8 on: February 02, 2012, 03:27:05 PM »
My arts book says, that in shadows the scattered blue light of the sky is present while the yellow direct light from sun is blocked, and therefore suggests to give shadows a slight blue tint (if blue sky is assumed).

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2269
Re: Darker special color for windows
« Reply #9 on: February 02, 2012, 04:13:09 PM »
Could just make it so that the current grey indicates window, then it is up to the pak to define what colour this will appear in game in the day and at night. That way we don't end up using any more special colours, and backwards compatibility is retained?

Although I guess fabio and TheHoods suggestions would allow this anyway after rereading!

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9789
  • Languages: De,EN,JP
Re: Darker special color for windows
« Reply #10 on: February 02, 2012, 04:45:58 PM »
Using a pak to overide day and night special colors is easy.

Using transparency to render will take more time and may not get the intended results. But the main problem is than any new special color will require a recoding of all pngs to remove/include it for all paks to be compiled by makeobj. I can here the crys of joy from the pak set authors (including mine).

Offline Fabio

  • Devotee
  • Administrator
  • *
  • Posts: 2898
  • The Pak128 Guy
    • Visit me on Facebook
  • Languages: EN, IT, RO, FR
Re: Darker special color for windows
« Reply #11 on: February 02, 2012, 09:01:26 PM »
A simple script could change those special colours, and if it becomes pakset-dependent, it will only affect paksets willing to undergo a similar process.

Transparency would enhance shadows dramatically, which are the main drawbacks in your opinion?

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5601
  • Languages: EN, NO
Re: Darker special color for windows
« Reply #12 on: February 03, 2012, 07:35:07 AM »
I fear that alpha blending/transparency, without hardware acceleration like in Simutrans3D, will easily cut frame rate in half. It will of course vary with how many shadows or other transparent objects there are on the screen.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2269
Re: Darker special color for windows
« Reply #13 on: February 03, 2012, 08:06:18 AM »
Alpha blending is very slow (relatively) compared to just normal plotting. In game I'm running at the moment it's getting to point where I have to turn off station coverage unless I really need to check it or game is unplayable (note - I wrote a lot of the early code for blending!)

Offline Fabio

  • Devotee
  • Administrator
  • *
  • Posts: 2898
  • The Pak128 Guy
    • Visit me on Facebook
  • Languages: EN, IT, RO, FR
Re: Darker special color for windows
« Reply #14 on: February 03, 2012, 09:21:07 AM »
Well, having shadows in a special colour, couldn't set in display options dialog whether we want it drawn as solid 50% transparency or dark colour - full transparency pattern.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9789
  • Languages: De,EN,JP
Re: Darker special color for windows
« Reply #15 on: February 03, 2012, 02:05:33 PM »
There is still the issue that a new color require all paksets to treat their images with a new version of shades. Apart from the speed issue.

As kierongreen supports my no on special transparent colors, ill move this to denied, even though pak-set configurable special colors may come.

Offline sdog

  • Devotee
  • *
  • Posts: 2039
Re: Darker special color for windows
« Reply #16 on: February 04, 2012, 01:21:42 AM »
kierongreen's suggestion from above would not require pak-sets to re-draw their images:
Could just make it so that the current grey indicates window, then it is up to the pak to define what colour this will appear in game in the day and at night. That way we don't end up using any more special colours, and backwards compatibility is retained?

edit:
just realized i'm beating a dead horse here, sorry haven't seen it was already moved to denied patches.

Offline VS

  • Senior Plumber (Devotee)
  • Devotee
  • *
  • Posts: 4856
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: Darker special color for windows
« Reply #17 on: February 04, 2012, 10:01:37 AM »
The irony is that the original request (in thread title) is not entirely denied, only what was discussed in the whole thread is denied :P

Offline Spike

  • *
  • Posts: 1361
  • First Simutrans Developer and Graphics Artist
Re: Darker special color for windows
« Reply #18 on: February 04, 2012, 11:16:51 PM »
I haven't checked the alpha blending code yet, but a 50% blend can be cheated very fast

assuming 8 bit per channel RGB:

Code: [Select]
   int rgb1, rgb2;
   ...
   int blended = ((rgb1 & 0x00FEFEFE) + (rgb2 & 0x00FEFEFE)) >> 1;

That should be quite fast. I used that with good success in other projects.

Edit: If it's already done this way, I'm sorry, didn't want to play Mr. "I know it better", but it's late and I should get some sleep, and don't want to check the code now ... hopefully the snippet will help. Same trick can be done in rgb 555, but I don't have the mask values right available from memory.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2269
Re: Darker special color for windows
« Reply #19 on: February 05, 2012, 12:16:17 AM »
I'm pretty sure I did it this way - actually I think 1/4 and 3/4 blends were also hardcoded maybe.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5601
  • Languages: EN, NO
Re: Darker special color for windows
« Reply #20 on: February 05, 2012, 08:34:10 AM »
I wan't so much worried about the math, but the fact that you need an extra read operation. Of course, if Simutrans renders a complete tile at a time (I haven't checked), caching might help somewhat.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2269
Re: Darker special color for windows
« Reply #21 on: February 05, 2012, 09:42:16 AM »
Once you get down to machine code there's no such thing as rendering a complete tile at a time. Well, at least unless you are using hardware accelerated graphics. It's not just the extra read operation alone that will slow things down, it'll be the knock on affect on register usage and memory caching. Plotting a tile, with clipping and a simple 1 bit transparency maybe uses 5 registers for each line loop - read address, write address, image pixel, transparent colour and end of line address. If you want to just add one colour for half transparency you need to add two registers to that, the semi transparent colour and background pixel.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4631
  • Languages: EN, DE, AT
Re: Darker special color for windows
« Reply #22 on: February 05, 2012, 09:56:26 AM »
even though pak-set configurable special colors may come.
... which is reality since r5187 thanks to prissi.

have fun :)

Offline Fabio

  • Devotee
  • Administrator
  • *
  • Posts: 2898
  • The Pak128 Guy
    • Visit me on Facebook
  • Languages: EN, IT, RO, FR
Re: Darker special color for windows
« Reply #23 on: February 05, 2012, 10:30:57 AM »
... which is reality since r5187 thanks to prissi.

have fun :)

Awesome! Could you please document how should it be coded in dat? Thanks in advance!

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4631
  • Languages: EN, DE, AT

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5601
  • Languages: EN, NO
Re: Darker special color for windows
« Reply #25 on: February 05, 2012, 12:34:53 PM »
Once you get down to machine code there's no such thing as rendering a complete tile at a time. Well, at least unless you are using hardware accelerated graphics. It's not just the extra read operation alone that will slow things down, it'll be the knock on affect on register usage and memory caching.

I wasn't thinking of some single instruction that draws a tile, but that rendering finishes drawing in a very confined area before moving on to draw somewhere else. That way, (almost) the entire tile could fit in the cache.

Plotting a tile, with clipping and a simple 1 bit transparency maybe uses 5 registers for each line loop - read address, write address, image pixel, transparent colour and end of line address. If you want to just add one colour for half transparency you need to add two registers to that, the semi transparent colour and background pixel.

You can't keep the background colour in a register without a to me very exotic way of drawing things, but then you would need multiple read adresses, one for each sprite covering the pixel.
Normal rendering with only 100 % transparency would go as follows:
Code: [Select]
read pixel from sprite
if pixel is not transparent
    write pixel to render buffer
With blending, it becomes:
Code: [Select]
read pixel from sprite
read pixel from render buffer
blend the colours
write pixel to render buffer
The second read is what worries me. One could of course move the second read and the blending into an if block, but that would only help where there is no partial transparency. Or is there something I have overlooked?

Offline The Hood

  • Devotee
  • *
  • Posts: 2889
  • pak128.Britain developer
Re: Darker special color for windows
« Reply #26 on: February 05, 2012, 02:47:17 PM »
Question (maybe I'm being dumb) - what does 0x01 mean as a colour? I thought they would be specified as six digit hex codes...

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 19346
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Darker special color for windows
« Reply #27 on: February 05, 2012, 02:57:12 PM »
Is 0x not just the initialisation string to tell the compiler (or Makeobj in this case) that the following number is hexidecimal? So 0x01 in hex is the same as 1 in decimal (and octal, and binary and just about every other number base that one cares to imagine...).

Offline Fabio

  • Devotee
  • Administrator
  • *
  • Posts: 2898
  • The Pak128 Guy
    • Visit me on Facebook
  • Languages: EN, IT, RO, FR
Re: Darker special color for windows
« Reply #28 on: February 05, 2012, 04:22:42 PM »
Normal rendering with only 100 % transparency would go as follows:
Code: [Select]
read pixel from sprite
if pixel is not transparent
    write pixel to render buffer
With blending, it becomes:
Code: [Select]
read pixel from sprite
read pixel from render buffer
blend the colours
write pixel to render buffer
The second read is what worries me. One could of course move the second read and the blending into an if block, but that would only help where there is no partial transparency. Or is there something I have overlooked?

Putting the second reading in an if block would help, as this half transparency would be used in a very limited number of pixels. Empirically, for a tree it would be less than 1 quarter of pixels in a tile, but probably quite less.
E.g.
Code: [Select]
Read from image
If not transparent then
If half_transparent then
Read from buffer
Blend colors
Write to buffer
Else
Write to buffer

Only a heavy use of transparency would impact performance, a limited use (e.g. For shadows) would have minimal impact.

Even a true alpha channel would have a limited impact as it would be mostly used for antialiasing, so limited to edges.

Reading routine could then use a threshold:
0-40% full transparency
41-90% half transparency
91-100% fully opaque

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 19346
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Darker special color for windows
« Reply #29 on: February 05, 2012, 04:32:53 PM »
I think that the code for reading hexadecimal values is causing errors here - get_int() seems to be clipping the first digit from a number in a .dat file when it reads non-hexadecimal numbers, so that, for example, 117 becomes 17. I should note that this problem appears in the "111.1 merge" branch of Experimental, so it is not impossible that there is some issue with merging the two, but I think this unlikely, as the get_int() code has always been the same in Standard as Experimental.

Offline Markohs

  • DevTeam, Coder/patcher
  • Devotees (Inactive)
  • *
  • Posts: 1559
  • Languages: EN,ES,CAT
Re: Darker special color for windows
« Reply #30 on: February 05, 2012, 04:36:53 PM »
Maybe a petter aproach is using RGBA 32-bit per pixel objects to give complete flexibility to the PAK creators. Even making the PAK distribution in a a new format, just a .ZIP file with PNG's and .dat .

EDIT: I should have read the entire thread before posting, you already talked about an alpha channel.
« Last Edit: February 05, 2012, 06:08:23 PM by Markohs »

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4631
  • Languages: EN, DE, AT
Re: Darker special color for windows
« Reply #31 on: February 05, 2012, 04:49:08 PM »
I think that the code for reading hexadecimal values is causing errors here - get_int() seems to be clipping the first digit from a number in a .dat file when it reads non-hexadecimal numbers, so that, for example, 117 becomes 17. I should note that this problem appears in the "111.1 merge" branch of Experimental, so it is not impossible that there is some issue with merging the two, but I think this unlikely, as the get_int() code has always been the same in Standard as Experimental.
This should be fixed already.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 19346
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Darker special color for windows
« Reply #32 on: February 05, 2012, 04:54:39 PM »
Aha, excellent! I know that the Github version of Standard is sometimes a little behind the SVN version.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5601
  • Languages: EN, NO
Re: Darker special color for windows
« Reply #33 on: February 05, 2012, 06:45:59 PM »
Only a heavy use of transparency would impact performance, a limited use (e.g. For shadows) would have minimal impact.

I wouldn't call shadows a limited use of transparency. As far as I can see, most trees cast one. It is less than the transparency used for hidden trees and buildings, though, but that made my former computer lag when panning around.

Offline The Hood

  • Devotee
  • *
  • Posts: 2889
  • pak128.Britain developer
Re: Darker special color for windows
« Reply #34 on: February 05, 2012, 06:51:03 PM »
Is 0x not just the initialisation string to tell the compiler (or Makeobj in this case) that the following number is hexidecimal? So 0x01 in hex is the same as 1 in decimal (and octal, and binary and just about every other number base that one cares to imagine...).

I still don't get how 0x01 is supposed to be hex. Surely that leaves just "01"? How would I code #000000 (for example) to be a special colour?