Pixa (was raster / shader project - insane?)

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Raster / shader project - insane?

Post by andythenorth »

FooBar wrote:I'm quite surprised you can draw a tanker out of a single line of pixels!
Here's how it's done ;)

This image shows each individual element used (usually all of these elements are drawn together).

The elements are coded in lists of pixel values, which suits me - but they could also be loaded as graphics from files, which might be less tedious than compiling lists in code.
Attachments
tanker_construction.png
tanker_construction.png (12.57 KiB) Viewed 7138 times
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Raster / shader project - insane?

Post by FooBar »

Ah, I see. So this line basically defines where each element must be placed, right?
User avatar
Emperor Jake
Tycoon
Tycoon
Posts: 3427
Joined: 24 Apr 2007 09:37
Skype: Discord: Emperor Jake #4106
Location: Not Actually Japan
Contact:

Re: Raster / shader project - insane?

Post by Emperor Jake »

andythenorth wrote:Tanker B-Train :)
Looks great, but it's technically not a B-train, it's more of a "true" road train. (see link) Having been somewhat of a truck enthusiast in the past, I am knowledgeable about the wheel arrangements and their proper names. If you want I'd be glad to assist :)

(Or maybe the American definition of B-train is something different to the B-double I have in mind)
User avatar
Emperor Jake
Tycoon
Tycoon
Posts: 3427
Joined: 24 Apr 2007 09:37
Skype: Discord: Emperor Jake #4106
Location: Not Actually Japan
Contact:

Re: Raster / shader project - insane?

Post by Emperor Jake »

Ah, I see. It seems to be the same thing but with less axles. (Australian trucks have the most axles and tyres - a standard Australian semi-trailer has 22 tyres, as opposed to the American 18 and the European 12 or 14)

Will some of those other combinations be in the set as well?

As you may have noticed, I am very interested in this set, as I use a LOT of trucks in my games, and I'm not entirely satisfied with the currently available truck sets. Keep at it! :)
/encouragement
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Raster / shader project - insane?

Post by andythenorth »

Stake trailer with steel coils load. 4 pass render for this one:
1. draw flatbed, far-side stakes
2. draw coil furthest from camera
3. draw coil nearest to camera
4. draw near-side stakes
steel_trailer.png
steel_trailer.png (10.17 KiB) Viewed 7068 times
User avatar
MinchinWeb
Traffic Manager
Traffic Manager
Posts: 225
Joined: 01 Feb 2011 12:41
Contact:

Re: Raster / shader project - insane?

Post by MinchinWeb »

andythenorth wrote:Tanker B-Train :)
andythenorth wrote:
Emperor Jake wrote:(Or maybe the American definition of B-train is something different to the B-double I have in mind)
You're right, it's actually a Turnpike Double :) http://www.fhwa.dot.gov/publications/pu ... /fork3.gif
I looked it up because I was curious. Turns out "B-train" (at least in Alberta, Canada) refers to how the two trailers are hooked together. There's also such things as A-trains and C-trains. (I hope my picture is clear enough...).
ABC Train.png
ABC Train.png (16.38 KiB) Viewed 7055 times
The Alberta Highway Design Guide also has this:
Alberta Infrastructure's [i]Highway Geometric Design Guide[/i] wrote:...a 25m [long] double-trailer combination (WB-23) commonly known as the Super B train. This design vehicle also covers A and C trains with similar dimensions. Details of A, B and C-train connections are shown in Figure D-5e [the picture above]. This is the longest tractor-trailer combination allowed on Alberta highways without special permits.
A Rocky-Mountain Double is sometimes called a WB-36 and can be up to 28 m long.

P.S. Andy, your trucks look amazing. I'm excited to see the whole set!
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Pixa (was raster / shader project - insane?)

Post by andythenorth »

With help from Alberth (and others) I've been packaging the code for this into a python module so other people can use it ;)

It will be released as 'Pixa' when done (name suggested by Rubidium; unlike most of my projects this one is not an acronym).

Meanwhile I've also been documenting how it works. Here's the diagram of the render stage; there will be other diagrams showing how to put the rest of the pipeline together around this.

'Gestalt' is a shape or form, typically a vehicle with all of its load states, colour variations etc. For example, in BANDIT I have a gestalt for each of tank trailer, tipping trailer, flatbed trailer. A gestalt is a python file defining values and rules for rendering.
Attachments
render_stage.png
render_stage.png (58.49 KiB) Viewed 6963 times
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Pixa (was raster / shader project - insane?)

Post by FooBar »

Nice, I've been talking to Voyager One that we may want to give this a go for rendering more or less crude shapes for cargo wagons (for the Dutch set) that then can be manually retouched to make it look more like the real vehicles.
I'm interested to learn if I can deploy this system myself. If not, I'll make sure to query you for assistance :wink:
andythenorth wrote:unlike most of my projects this one is not an acronym
Oh, but that can be solved by making it a backronym. How about...
Pixa Insane piXel Algorithm :twisted:
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Pixa (was raster / shader project - insane?)

Post by Roujin »

You could say that "pixa" stands for "Pixa Is Not an Acronym". I'd like that. :lol:
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
Eddi
Tycoon
Tycoon
Posts: 8271
Joined: 17 Jan 2007 00:14

Re: Pixa (was raster / shader project - insane?)

Post by Eddi »

that would be "PINA"... did you read a book "backronyms for dyslexics" or something? :p
User avatar
Bob_Mackenzie
Chairman
Chairman
Posts: 823
Joined: 25 Mar 2010 13:36

Re: Pixa (was raster / shader project - insane?)

Post by Bob_Mackenzie »

but he said it WASN'T and acronym.. :mrgreen:
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Pixa (was raster / shader project - insane?)

Post by andythenorth »

More Pixa docs: using a Gestalt to assemble spritesheets.

Pixa doesn't enforce a particular spritesheet structure, this inherent flexibility means authors have to put together a small pipeline to assemble spritesheets to suit their project.

For BANDIT, each vehicle type has Variations; each Variation being a specific combination of colours, cargo type, vehicle length, and other details. For each Variation, Pixa outputs a png spritesheet, with 1 row per load state for that Variation (BANDIT typically uses 4 load states per vehicle, so 4 rows).
Attachments
gestalt_assemble_spritesheets.png
gestalt_assemble_spritesheets.png (62.4 KiB) Viewed 6808 times
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Pixa (was raster / shader project - insane?)

Post by andythenorth »

Doing some work with some tarpaulin loads from Mr. Bird...
Attachments
8_8_cargo_tarps_default.png
8_8_cargo_tarps_default.png (1.95 KiB) Viewed 6705 times
8_8_cargo_tarps_cc2.png
8_8_cargo_tarps_cc2.png (1.96 KiB) Viewed 6705 times
8_8_cargo_tarps_cc1.png
8_8_cargo_tarps_cc1.png (1.96 KiB) Viewed 6705 times
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Pixa (was raster / shader project - insane?)

Post by andythenorth »

Alberth and I have found some optimisations to Pixa that decreased total render time in the test project by more than 50%. :D

I've also switched it to use python multiprocessing, as rendering pngs is an embarrassingly parallel problem. The speed effect of this varies by number of cores / thread units available, and the size of the project.

The net effect of this can be seen in the render times (per BANDIT image) below.

Unoptimised: 0.15s / image
Optimised, MP (4 thread units): 0.03s / image

This will vary significantly depending on the size and type of image, how many render passes are used etc. However if it scales linearly, rendering 1,000 BANDIT-style images would take ~1min. This is very slow, but acceptable as rendering images won't need to be done very often.
Coxx
Transport Coordinator
Transport Coordinator
Posts: 328
Joined: 19 Mar 2007 19:12

Re: Pixa (was raster / shader project - insane?)

Post by Coxx »

Sounds like a interessting concept for ships to.
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5658
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Pixa (was raster / shader project - insane?)

Post by andythenorth »

Pixa is now released as 0.1 here http://dev.openttdcoop.org/projects/pixa/repository

To get pixa, checkout (or download) that project, then from the project root run 'python setup.py install' (this will install pixa to your system python).

There's no further documentation and no tutorial yet. Pixa is in use for BANDIT and there are examples there.
If anyone would like to try using pixa, we can work through it here, which will provide an example / tutorial for others.

Pixa is good for three cases so far:
1. quickly generating sprites for vehicles or buildings that have regular shapes or patterns
2. compositing vehicle sprites with cargo sprites for different load states (empty, part-loaded, fully loaded etc).
3. recolouring; although recolour sprites can be used in game, an alternative approach is to recolour before compiling. This works for different cargos, liveries etc.

PIL is a required dependency; this is also required for nml, so many authors will already have it.
Pixa works well with python's built-in multi-processing module, which can significantly decrease render time when multiple thread units, cores or CPUs are available.
Pixa can be used with a makefile.
Pixa has also been tested as working on the openttdcoop compile farm.
Eddi
Tycoon
Tycoon
Posts: 8271
Joined: 17 Jan 2007 00:14

Re: Pixa (was raster / shader project - insane?)

Post by Eddi »

Quickly getting started.

I've recently discussed with andythenorth about a "how-to" for pixa, so here's the quick-and-dirty conclusion for the first steps.

1) install python and PIL with the usual installers for your OS

2) install pixa. from your downloaded source, run:

Code: Select all

python setup.py install
3) make a floorplan image with your favourit image processor, preferrably already in TTD (DOS) Palette.

4) make a script (or use the python interactive console)

Code: Select all

import pixa
import Image
4a) open your image file

Code: Select all

floorplan = Image.open("test-input.png")
4b) make a spritesheet out of your image

Code: Select all

spritesheet = pixa.Spritesheet(floorplan.size[0], floorplan.size[1], floorplan.palette)
spriterow = {'height' : floorplan.size[1], 'floorplan' : floorplan}
4c) define the transformations you want to do on the image (here: replace all pixels with colour 86 (green) to pixels with colour 240 (flashing red))

Code: Select all

seq = pixa.PixaSequence(points = [(0,0,240)])
sc = pixa.PixaSequenceCollection(sequences = { 86 : seq })
spriterow['render_passes'] = [{'seq':sc, 'colourset':None}]
4d) process the image

Code: Select all

spritesheet.render(spriterows=[spriterow])
4e) save the image

Code: Select all

spritesheet.save('test-output.png')
for more advanced stuff, you may refer to the BANDIT source for examples.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 11 guests