Author Topic: Support for PNG Alphachannel for tree graphics  (Read 34512 times)

0 Members and 1 Guest are viewing this topic.

Offline kierongreen

Re: Support for PNG Alphachannel for tree graphics
« Reply #140 on: December 10, 2016, 07:16:00 PM »
The code treats fully alpha pixels as though they are special transparent colour no matter what their RGB value is.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 16164
  • Total likes: 450
  • Helpful: 178
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Support for PNG Alphachannel for tree graphics
« Reply #141 on: December 10, 2016, 09:55:08 PM »
The code treats fully alpha pixels as though they are special transparent colour no matter what their RGB value is.

Yes, I had gathered that. What I am interested in is to what extent that a halo of 1-2px wide around an object of partially transparent pixels will really have on performance. As noted, I have not seen any noticeable difference with pedestrians.

May I ask what matters - the total number of semi-transparent pixels on screen at any time, or the number of objects that have at least some semi-transparent pixels in them?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline kierongreen

Re: Support for PNG Alphachannel for tree graphics
« Reply #142 on: December 10, 2016, 10:08:40 PM »
Both count - routines for plotting semi transparent pixels are slightly slower than standard ones in general and additionally every semi transparent pixel within each image will cause a further slowdown. If you've found that slowdown to be acceptably small then great - and as you say, multithreading may be reducing the impact somewhat (but memory bandwidth may still be a limiting factor)

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 16164
  • Total likes: 450
  • Helpful: 178
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Support for PNG Alphachannel for tree graphics
« Reply #143 on: December 10, 2016, 10:37:10 PM »
From what I understand, at least on fairly modern architectures, multi-threading is closely linked to memory bandwidth.

Another advantage of the alpha process is that it will make it much easier to explain to new content creators how to produce graphics for the pakset as it cuts out two whole steps.

Edit: Incidentally, I am having a look at the Pak128.Britain trees to see whether I can export them using this new method, as I suspect that it would greatly improve their appearance. However, I cannot find the smaller trees to simulate their various levels of growth. May I ask how this was done, if you remember - was it just a case of scaling the base tree or were there actually different models for younger and older trees? Also, how exactly were the trees made? The models seem so fantastically complex that it seems most improbable that each leaf was modelled individually by hand.
« Last Edit: December 11, 2016, 12:41:33 AM by jamespetts »
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8830
  • Total likes: 324
  • Helpful: 229
  • Languages: De,EN,JP
Re: Support for PNG Alphachannel for tree graphics
« Reply #144 on: December 11, 2016, 04:15:32 PM »
The alpha blending does not change anything concerning multithreading. So as longs as the rendering is does not cause the framerate to drop, just the CPU load and memorey bandwidth will be higher. (But the latter not much, since I guess most of the stuff on one tile might anyway happen in some of the caches.

Offline Vladki

Re: Support for PNG Alphachannel for tree graphics
« Reply #145 on: December 13, 2016, 09:50:15 PM »
Yes, I had gathered that. What I am interested in is to what extent that a halo of 1-2px wide around an object of partially transparent pixels will really have on performance. As noted, I have not seen any noticeable difference with pedestrians.

But the difference in appearance IS noticeable. It really looks good.  :thumbsup:

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 16164
  • Total likes: 450
  • Helpful: 178
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Support for PNG Alphachannel for tree graphics
« Reply #146 on: December 19, 2016, 12:18:05 AM »
I am not sure that using an alpha blend for all objects works very well. Take the below example of a 'bus: the band of alpha around the body is such that the wheels are actually a little transparent. This would not, I imagine, look very good compared to more solid wheels, and, moreover, would look inconsistent with other graphics in the pakset.

I suspect that alpha is best left for trees and smoke after all - even the pedestrians I suspect would probably have been fine had they been exported using version 2.65a or earlier of Blender as I have now discovered is necessary to avoid black bands around objects.

Edit: Actually, when I looked at that graphic on the forum, the transparency on the wheels seemed hardly noticeable, so I ran some tests in game. Can anyone spot the difference between the standard and the transparent version?
« Last Edit: December 19, 2016, 01:11:22 AM by jamespetts »
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Sarlock

Re: Support for PNG Alphachannel for tree graphics
« Reply #147 on: December 19, 2016, 08:35:04 AM »
Giving this a full test is still on my "to do" list, but I came to the same conclusion, that for most vehicles it didn't seem to make much difference.  For other objects, such as trees, it makes a huge difference in terms of the types of graphics you can make available.

I'm hoping to be able to devote some time to testing this in the coming few weeks, I want to see how it works for catenaries, power lines, stations with glass and certain buildings (particularly to soften the edges of peaks, etc).
Current projects: Pak128 Trees, blender graphics

Offline Vladki

Re: Support for PNG Alphachannel for tree graphics
« Reply #148 on: December 19, 2016, 11:12:01 AM »
pak128-sweden-ex has semi-transparent catenary: see the last screenshot here http://forum.simutrans.com/index.php?topic=15743.0

I can see some difference between bus wheels in the above post, but even the "better" ones are quite blurry. Transparency makes the wheels almost unnoticeable. I have not seen them in game though...

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 16164
  • Total likes: 450
  • Helpful: 178
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Support for PNG Alphachannel for tree graphics
« Reply #149 on: December 19, 2016, 12:38:10 PM »
My thought at present is that, if the difference between graphics that require a fair bit of post-processing work and graphics that require no post-processing work at all is trivial, then it is better to go with the graphics that require no post-processing work because more graphics can be made in the same amount of time.

The complexity is that, whilst transparency will greatly improve tree and smoke graphics (and also the shadows in some depot graphics), using it for, e.g., signals where all the existing graphics have well-defined edges for the posts and rear ladders (with hand-amended transparent cut-outs for the ladders) may end up looking inconsistent with other objects and indistinct.

I am interested in how it looks for power lines and sailing ships, however.

Edit:

There is a further complexity: I have recently discovered that Blender versions of greater than 2.65 simply do not work properly with the traditional method of producing graphics for Pak128.Britain (using a black background and filling with the special colour in the GIMP) because they changed how alpha works: graphics produced with version 2.66 onwards have a black border at the edge of graphics where the black background has been blended with the objects.

Using the transparency method will allow more recent versions of Blender to be used, as well as making graphics production easier; but it has the disadvantage that the graphics will in some respects be inconsistent with those produced using the older method. It is not an easy decision for a pakset maintainer to take.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline wlindley

Re: Support for PNG Alphachannel for tree graphics
« Reply #150 on: December 19, 2016, 02:01:15 PM »
Could the fuzzy-edge problem be mitigated by having Blender export 2x or 4x size bitmaps, and then simply scaling them down?  Any one-pixel-wide translucent border of an object then would become only 1/2 or 1/4 or less in strength.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 16164
  • Total likes: 450
  • Helpful: 178
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Support for PNG Alphachannel for tree graphics
« Reply #151 on: December 19, 2016, 02:02:37 PM »
Could the fuzzy-edge problem be mitigated by having Blender export 2x or 4x size bitmaps, and then simply scaling them down?  Any one-pixel-wide translucent border of an object then would become only 1/2 or 1/4 or less in strength.

That would then eliminate the advantage of not having to do any post-processing.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline kierongreen

Re: Support for PNG Alphachannel for tree graphics
« Reply #152 on: December 22, 2016, 10:40:29 AM »
Try seeing what this looks like in winter - black tyres against black tarmac and a green bus against grass won't highlight edges as much as on snow.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 16164
  • Total likes: 450
  • Helpful: 178
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Support for PNG Alphachannel for tree graphics
« Reply #153 on: December 22, 2016, 12:01:55 PM »
Here it is with snow: the green 'bus has the alpha and the red 'bus has no alpha.

Edit: Darkening the material for the tyres helps - see the second image.

Edit 2: Increasing the wheels to their correct size seems to make a substantial difference: see the third image of the AEC Regent STL in the snow.
« Last Edit: December 22, 2016, 03:54:24 PM by jamespetts »
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Sarlock

Re: Support for PNG Alphachannel for tree graphics
« Reply #154 on: December 23, 2016, 05:33:45 PM »
What I've been using to date from Blender is a RGBA export using F3.  It outputs the alpha along with the image, then I've been taking it in to GIMP and stripping the alpha channel from the image and adding the transparent background.  With the alpha channel option in Makeobj now, I can directly import in to Makeobj from Blender.  Export from Blender with F3 (which could be automated with your scripts) and then presto - it should work.  Removing the transparency fixing step will be a huge time saver for me (as well as improve the graphics quality significantly).
Current projects: Pak128 Trees, blender graphics

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 16164
  • Total likes: 450
  • Helpful: 178
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Support for PNG Alphachannel for tree graphics
« Reply #155 on: December 23, 2016, 05:55:52 PM »
Yes, indeed - this is the intention. This is what I am doing with the 'bus graphics at present.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Sarlock

Re: Support for PNG Alphachannel for tree graphics
« Reply #156 on: December 23, 2016, 06:16:33 PM »
I just jumped in to do some testing and I realize that I don't have an up-to-date version of Makeobj.  I had downloaded what I thought was a nightly version some time ago but I see it's still 55.4 and doesn't seem to support the alpha channel in the graphics I provided to it (it just strips them out).

I tried in the past to compile it but ran in to so many difficulties that I abandoned the attempt.

I did a fairly extensive search for it but can only come across the older version that doesn't support alpha.

If someone could kindly point me to where I could find a recent compile for Windows, I would greatly appreciate it and return the favour with a flood of new alpha-enabled graphics.
Current projects: Pak128 Trees, blender graphics

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 16164
  • Total likes: 450
  • Helpful: 178
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Support for PNG Alphachannel for tree graphics
« Reply #157 on: December 23, 2016, 06:51:38 PM »
I did find when compiling makeobj for Experimental that a newer version of libpng than is provided with Ubuntu is needed to make alpha work, or else the alpha will just be replaced with black. Version 1.5 works, whereas 1.2 does not.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2594
  • Total likes: 290
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: Support for PNG Alphachannel for tree graphics
« Reply #158 on: December 24, 2016, 01:07:22 PM »
I've compiled my own libpng so it's probably 1.6, do you need it for Windows Sarlock?

Offline Leartin

Re: Support for PNG Alphachannel for tree graphics
« Reply #159 on: December 24, 2016, 01:19:28 PM »
If someone could kindly point me to where I could find a recent compile for Windows, I would greatly appreciate it and return the favour with a flood of new alpha-enabled graphics.

I always wonder why makeobj is not released with nightlies, at least if something changed. It's essential to create content, after all. (An_dz, is it possible to automate makeobj releases?)
I'm interested as well, though at this time I can't return the favour in the same way, as I'm occupied with life.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2594
  • Total likes: 290
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: Support for PNG Alphachannel for tree graphics
« Reply #160 on: December 24, 2016, 03:00:38 PM »
I don't have an 'always on computer' so it would not be reliable.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8830
  • Total likes: 324
  • Helpful: 229
  • Languages: De,EN,JP
Re: Support for PNG Alphachannel for tree graphics
« Reply #161 on: December 24, 2016, 09:53:42 PM »
It was not released with the nightlies since the format of things in makeobj (like transparencies, climates, half-height tiles) sometimes changes until it stabilised. Also the version of things released is not know. Generally it was considered bad to have stuff released for a nightly version, as normal people may end up downloading that stuff too.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 16164
  • Total likes: 450
  • Helpful: 178
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Support for PNG Alphachannel for tree graphics
« Reply #162 on: December 26, 2016, 01:50:09 AM »
For some more examples of how using alpha rendering from Blender with no post-processing works in practice, have a look at this thread in the Pak128.Britain forum.

For paksets that use 3d rendering to produce graphics, this feature has the potential to transform productivity in the creation of new graphics. In practice, its flaws (incorrect alpha blending and increased computational intensity) seem so far to be minimal in comparison with the improved appearance overall and, more importantly, the much quicker and easier workflow.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 16164
  • Total likes: 450
  • Helpful: 178
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Support for PNG Alphachannel for tree graphics
« Reply #163 on: January 04, 2017, 07:00:23 PM »
Given the greatly improved quality of the alpha graphics compared to the non-alpha graphics, I wonder whether there is anything to be said for using alpha in the transition between different types of climates? I am sure that alpha would make the following transition look much better, for instance:

Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Leartin

Re: Support for PNG Alphachannel for tree graphics
« Reply #164 on: January 04, 2017, 07:26:26 PM »
That's already there, you use a png where each color channel (R, G, B) is used for a climate. I attached an example file you could use for testing purposes.

Code: [Select]
Obj=ground
Name=SlopeTrans
Image[0][0]=climatexture.0.0
Image[1][0]=climatexture.0.1
Image[2][0]=climatexture.0.2
Image[3][0]=climatexture.0.3
Image[4][0]=climatexture.1.0
Image[5][0]=climatexture.1.1
Image[6][0]=climatexture.1.2
Image[7][0]=climatexture.1.3
Image[8][0]=climatexture.2.0
Image[9][0]=climatexture.2.1
Image[10][0]=climatexture.2.2
Image[11][0]=climatexture.2.3
Image[12][0]=climatexture.3.0
Image[13][0]=climatexture.3.1
Image[14][0]=climatexture.3.3

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 16164
  • Total likes: 450
  • Helpful: 178
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Support for PNG Alphachannel for tree graphics
« Reply #165 on: January 04, 2017, 07:37:11 PM »
Interesting - thank you for that. That seems to be smaller than the one used in Pak128.Britain-Ex; is that for 64 sized paksets? May I also ask whether a shore version exists?

Thank you again.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline Leartin

Re: Support for PNG Alphachannel for tree graphics
« Reply #166 on: January 04, 2017, 07:46:48 PM »
Code: [Select]
Obj=ground
Name=ShoreTrans
Image[0][0]=shore.0.0
Image[1][0]=shore.0.1
Image[2][0]=shore.0.2
Image[3][0]=shore.0.3
Image[4][0]=-
Image[5][0]=-
Image[6][0]=-
Image[7][0]=-
Image[8][0]=-
Image[9][0]=-
Image[10][0]=-
Image[11][0]=shore.1.0

These are the ones used in pak192c, based on pak64 when half heights came out. I'm not sure if you can resize them to another pak size, but it should not be hard to scale the images times two and just try.

EDIT: IIRC, Experimental does not support half heights, thus these probably won't work for you. I think before half heights it was be done quite differently.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 4900
  • Total likes: 217
  • Helpful: 108
  • Languages: EN, NO
Re: Support for PNG Alphachannel for tree graphics
« Reply #167 on: January 04, 2017, 08:53:23 PM »
Earlier, it seems only red and blue were used for slopes. Shores has been red, green and blue since 2008. Only the upper row as shown in Leartin's examples existed. Interestingly, pak64 only uses blending between colors for shores (ever since 2008), but not for slopes.

Offline jamespetts

  • Simitrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 16164
  • Total likes: 450
  • Helpful: 178
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Support for PNG Alphachannel for tree graphics
« Reply #168 on: January 04, 2017, 09:59:04 PM »
The easiest way of bringing this to Pak128.Britain, I think, was using The Gimp to blend the two colours together on the transitions. Here is a screenshot of what the same snow/green transition looks like after blending:

Edit: I notice that the Pak128.Britain shore texture seems already to be blended, albeit not as much as this.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2594
  • Total likes: 290
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: Support for PNG Alphachannel for tree graphics
« Reply #169 on: January 07, 2017, 02:53:40 PM »
Here's makeobj r7988 as Leartin and Sarlock asked.

Offline Sarlock

Re: Support for PNG Alphachannel for tree graphics
« Reply #170 on: January 07, 2017, 06:01:38 PM »
Thank you, thank you, An_dz!


That transition looks great, James!
Current projects: Pak128 Trees, blender graphics

Offline Leartin

Re: Support for PNG Alphachannel for tree graphics
« Reply #171 on: January 11, 2017, 04:16:50 PM »
The code treats fully alpha pixels as though they are special transparent colour no matter what their RGB value is.

I noticed a little inconsitency: This does not work for indexed graphics. It's not a big deal, but if it would work, one could completely abolish background-blue in the workflow and any future tutorials. Maybe there is a simple way to fix it?

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2594
  • Total likes: 290
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: Support for PNG Alphachannel for tree graphics
« Reply #172 on: January 12, 2017, 01:19:50 PM »
Code: [Select]
/* Don't output alpha channel on indexed images (There is a bug in libpng that the first pixel of such a bitmap ihas alpha 0xFFxxxxx */
Seems to be easy, but there's a bug, we should try with the latest version.