News:

Use the "Forum Search"
It may help you to find anything in the forum ;).

Support for PNG Alphachannel for tree graphics

Started by NNW, March 07, 2016, 08:53:06 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kierongreen

The code treats fully alpha pixels as though they are special transparent colour no matter what their RGB value is.

jamespetts

Quote from: kierongreen 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.

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.

kierongreen

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)

jamespetts

#143
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.
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.

prissi

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.

Vladki

Quote from: jamespetts on December 10, 2016, 09:55:08 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:

jamespetts

#146
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?
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.

Sarlock

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

Vladki

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...

jamespetts

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.

wlindley

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.

jamespetts

Quote from: wlindley 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.

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.

kierongreen

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.

jamespetts

#153
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.
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.

Sarlock

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

jamespetts

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.

Sarlock

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

jamespetts

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.

An_dz

I've compiled my own libpng so it's probably 1.6, do you need it for Windows Sarlock?

Leartin

Quote from: Sarlock on December 23, 2016, 06:16:33 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.

An_dz

I don't have an 'always on computer' so it would not be reliable.

prissi

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.

jamespetts

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.

jamespetts

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.

Leartin

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.

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


jamespetts

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.

Leartin

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.

Ters

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.

jamespetts

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.

An_dz


Sarlock

Thank you, thank you, An_dz!


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

Leartin

Quote from: kierongreen 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.

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?

An_dz

/* 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.