Pixa (was raster / shader project - insane?)
Moderator: Graphics Moderators
- andythenorth
- Tycoon
- Posts: 5656
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Pixa (was raster / shader project - insane?)
I am considering using PIL (python image library) to procedurally generate trailers for trucks. Trailers are highly regular in shape, and drawing them to all lengths etc needed for BANDIT will be dull.
I have no experience in this, if I try to invent raster / shader from ground up, it's probably going to be bad.
Anyone interested in helping with this as an experiment?
I have two routes under consideration:
1. comping predefined blocks of pixels, e.g. trailer rear end, n * trailer middle part, trailer front end. This would build up trailers as though building with lego. This route requires component parts shaded for all 8 angles.
2. shading each face (truck trailers are quite regular), e.g floor, rear side, rear end, front side, front end. Pixels would be simply over-written where necessary. This route might be able to use transforms on the - view to generate other views procedurally.
My experience drawing graphics with code is limited to logo-style 'move cursor(delta_x, delta_y), draw(colour)'. Dunno if that's enough
I have no experience in this, if I try to invent raster / shader from ground up, it's probably going to be bad.
Anyone interested in helping with this as an experiment?
I have two routes under consideration:
1. comping predefined blocks of pixels, e.g. trailer rear end, n * trailer middle part, trailer front end. This would build up trailers as though building with lego. This route requires component parts shaded for all 8 angles.
2. shading each face (truck trailers are quite regular), e.g floor, rear side, rear end, front side, front end. Pixels would be simply over-written where necessary. This route might be able to use transforms on the - view to generate other views procedurally.
My experience drawing graphics with code is limited to logo-style 'move cursor(delta_x, delta_y), draw(colour)'. Dunno if that's enough
Last edited by andythenorth on 02 Mar 2012 08:25, edited 1 time in total.
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
- andythenorth
- Tycoon
- Posts: 5656
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Re: Raster / shader project - insane?
Not insane. Works. More another time.
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
- andythenorth
- Tycoon
- Posts: 5656
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Re: Raster / shader project - insane?
Trailer gets a floorplan drawn in false colour.
Pixel generator then sequences pixels to create trailer body.
Pixel sequence is determined by colours in floor plan + body type required.
Won't work at all for complex vehicles.
Will work well for vehicles with regular shapes (fairly certain this includes oval and cylindrical tankers as well as box shapes). Code is pretty simple (this is non-optimised, non-configurable proof of concept):
Pixel generator then sequences pixels to create trailer body.
Pixel sequence is determined by colours in floor plan + body type required.
Won't work at all for complex vehicles.
Will work well for vehicles with regular shapes (fairly certain this includes oval and cylindrical tankers as well as box shapes). Code is pretty simple (this is non-optimised, non-configurable proof of concept):
Code: Select all
import Image
import ImageDraw
spritesheet = Image.open('test_input.png')
spritesheetpx = spritesheet.load()
draw = ImageDraw.Draw(spritesheet)
colours = {}
for x in range(spritesheet.size[0]):
for y in range(spritesheet.size[1]):
colour = spritesheetpx[x,y]
if colour != 255 and colour != 0 and colour != 15:
colours[colour] = ''
if spritesheetpx[x,y] == 240:
if x%2 == 0:
body_colour = 10
cc_colour = 200
else:
body_colour = 11
cc_colour = 201
draw.point([(x,y)],fill=body_colour)
draw.point([(x,y-1)],fill=cc_colour)
draw.point([(x,y-2)],fill=body_colour)
draw.point([(x,y-3)],fill=body_colour)
draw.point([(x,y-4)],fill=14)
if spritesheetpx[x,y] == 238:
if x%2 == 0:
body_colour = 11
cc_colour = 201
else:
body_colour = 12
cc_colour = 202
draw.point([(x,y)],fill=body_colour)
draw.point([(x,y-1)],fill=cc_colour)
draw.point([(x,y-2)],fill=body_colour)
draw.point([(x,y-3)],fill=body_colour)
draw.point([(x,y-4)],fill=14)
if spritesheetpx[x,y] == 209:
draw.point([(x,y)],fill=16)
draw.point([(x,y-1)],fill=17)
draw.point([(x,y-2)],fill=18)
draw.point([(x,y-3)],fill=19)
draw.point([(x,y-4)],fill=14)
spritesheet.save('a_test_trailer.png')
print colours
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
- andythenorth
- Tycoon
- Posts: 5656
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Re: Raster / shader project - insane?
Improved generator code; also a utility which will print out indexes for the palette used in a spritesheet.
Palette Utility
Code: Select all
import Image
import ImageDraw
spritesheet = Image.open('test_input.png')
spritesheetpx = spritesheet.load()
draw = ImageDraw.Draw(spritesheet)
# global constants
body_colour = 10
cc_colour = 202
#each sequence is a tuple containing lists in format: [(x-offset,y-offset), colour]
pixel_sequences = dict (
body_outer = ([(0, 0), body_colour], [(0, 1), cc_colour], [(0, 2), body_colour], [(0, 3), body_colour], [(0, 4), 14]),
body_end = ([(0, 0), body_colour], [(0, 1), cc_colour], [(0, 2), body_colour], [(0, 3), body_colour], [(0, 4), 14]),
body_inner = ([(0, 0), 16], [(0, 1), 17], [(0, 2), 18], [(0, 3), 19], [(0, 4), 14]),
)
key_colour_mapping = {
209 : dict(seq = 'body_inner', colour_shift= 0),
238 : dict(seq = 'body_outer', colour_shift = 0),
240 : dict(seq = 'body_end', colour_shift = -1),
}
def get_pixel_sequence(x, y, key_colour):
key_map = key_colour_mapping[key_colour]
raw_sequence = pixel_sequences[key_map['seq']]
pixel_sequence = []
for i in raw_sequence:
pixel_sequence.append({
'x' : x + i[0][0],
'y' : y - i[0][1],
'colour' : i[1] + key_map['colour_shift'],
})
return pixel_sequence
colours = {} #used for debug
for x in range(spritesheet.size[0]):
for y in range(spritesheet.size[1]):
colour = spritesheetpx[x,y]
if colour != 255 and colour != 0 and colour != 15:
colours[colour] = ''
if spritesheetpx[x,y] in key_colour_mapping.keys():
seq = get_pixel_sequence(x, y, spritesheetpx[x,y])
for i in seq:
draw.point([(i['x'],i['y'])], fill=i['colour'])
spritesheet.save('a_test_trailer.png')
print colours # debug: what colours did we find in this spritesheet?
Palette Utility
Code: Select all
import Image
import ImageDraw
import ImagePalette
spritesheet = Image.open('test_input.png')
block_size = 30
palette_key = Image.new('P',(16*block_size,16*block_size))
draw = ImageDraw.Draw(palette_key)
print spritesheet.mode
palette_key.putpalette(spritesheet.palette)
x = 0
y = 0
for i in range (256):
draw.rectangle([(x,y),(x+block_size,y+block_size)],fill=i)
bg_size = draw.textsize(str(i))
text_pos = (x+(block_size/4),y+(block_size/3))
draw.rectangle([(text_pos[0]-1,text_pos[1]+1),(text_pos[0]+bg_size[0],text_pos[1]+bg_size[1]-2)],fill=255)
draw.text((x+(block_size/4),y+(block_size/3)),str(i),fill=1)
x = x+block_size
if x == 16*block_size:
x = 0
y = y + block_size
palette_key.save('palette_key.png')
- Attachments
-
- DOS palette example - this palette is generated directly from the palette used by a specific sprite.
- palette_key.png (9.83 KiB) Viewed 6156 times
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Re: Raster / shader project - insane?
Your ideas are intriguing to me and I wish to subscribe to your newsletter.
- andythenorth
- Tycoon
- Posts: 5656
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Re: Raster / shader project - insane?
I thought I'd better prove all angles work before going onto tanker bodies etc.
Here's a comp of the input (top row) and result (second row).
The magic colours in the trailer floor plan map to sequences of pixels. Each sequence contains colours and x / y offsets from starting pixel. Straight shapes offset in y direction only. I can do regular curved shapes by offsetting in x direction as well.
I'll also do loading/load sprites (for coal etc) by drawing the pattern on the floor pattern, then varying the length of the sequence.
For things like steel loads, I'm going to comp them on from pre-drawn images, using more magic pixels to set location.
Zoomed (for luck):
Here's a comp of the input (top row) and result (second row).
The magic colours in the trailer floor plan map to sequences of pixels. Each sequence contains colours and x / y offsets from starting pixel. Straight shapes offset in y direction only. I can do regular curved shapes by offsetting in x direction as well.
I'll also do loading/load sprites (for coal etc) by drawing the pattern on the floor pattern, then varying the length of the sequence.
For things like steel loads, I'm going to comp them on from pre-drawn images, using more magic pixels to set location.
Zoomed (for luck):
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Re: Raster / shader project - insane?
Interesting concept.
The only drawing-by-code I once did is a graph, via PHP using GD. But that appears to be more or less the same as how PIL works, so I can more or less follow what you're doing (apart from tuples and dicts, I'm only familiar with arrays, these appear overly complicated).
Now do one with cargo
The only drawing-by-code I once did is a graph, via PHP using GD. But that appears to be more or less the same as how PIL works, so I can more or less follow what you're doing (apart from tuples and dicts, I'm only familiar with arrays, these appear overly complicated).
Now do one with cargo
- andythenorth
- Tycoon
- Posts: 5656
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Re: Raster / shader project - insane?
A little python-php translation then for youFooBar wrote:I can more or less follow what you're doing (apart from tuples and dicts, I'm only familiar with arrays
List ~= array with ints as keys (0-based)
Tuple ~= array with ints as keys (0-based), but immutable (can't append, slice etc)
Dict ~= array
Later I will.Now do one with cargo
I've no idea what this technique I'm using is called. I'm sure it exists in computer graphics lore.
It reminds of extruding a spline in CGI, but it differs quite a bit.
Also reminds me slightly of of building Doom levels in the wad editor, about 16 years ago
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Re: Raster / shader project - insane?
Ah, thanks. I guess the fact that dict !== array makes that the other two actually have a useandythenorth wrote:A little python-php translation then for you
List ~= array with ints as keys (0-based)
Tuple ~= array with ints as keys (0-based), but immutable (can't append, slice etc)
Dict ~= array
As for what it's called? I guess it's some form of computer generated imagery.
- andythenorth
- Tycoon
- Posts: 5656
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Re: Raster / shader project - insane?
FooBar wrote:Now do one with cargo
- Attachments
-
- test_input.png (5.88 KiB) Viewed 6074 times
-
- zoom.png (18.47 KiB) Viewed 6072 times
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Re: Raster / shader project - insane?
very cool
if you keep the purple for the cargo, you can then use that as base for recolouring.
if you keep the purple for the cargo, you can then use that as base for recolouring.
- andythenorth
- Tycoon
- Posts: 5656
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Re: Raster / shader project - insane?
I'll just generate pngs at compile time with the cargo colours neededFooBar wrote:if you keep the purple for the cargo, you can then use that as base for recolouring.
Resulting grf will be a little larger than if recolour sprites were used, openttd (may) be fractionally faster due to not recolouring. Swings / roundabouts
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
- andythenorth
- Tycoon
- Posts: 5656
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Re: Raster / shader project - insane?
Procedural buildings (quick test)
- Attachments
-
- a_test_building.png (4.95 KiB) Viewed 5998 times
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Re: Raster / shader project - insane?
Didn't Zephyris do something like that at some point?
AroAI - A really feeble attempt at an AI
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
- andythenorth
- Tycoon
- Posts: 5656
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Re: Raster / shader project - insane?
Yes, same idea, different approach to implementation.Lord Aro wrote:Didn't Zephyris do something like that at some point?
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
- andythenorth
- Tycoon
- Posts: 5656
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Re: Raster / shader project - insane?
- Attachments
-
- a_test_building.png (5.63 KiB) Viewed 5985 times
-
- floor_plan.png (8.65 KiB) Viewed 5985 times
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
- andythenorth
- Tycoon
- Posts: 5656
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Re: Raster / shader project - insane?
Generation of load colours and load states is done.
A range of body colours can be generated.
The trailer length, number of wheels etc are controlled by the input png file that defines the floorplan.
Below are a few examples of output - the generator creates more than this, but it's not necessary to prove that by posting them all here
This can (obviously) be extended to other styles of body, e.g. flatbed, open etc
A range of body colours can be generated.
The trailer length, number of wheels etc are controlled by the input png file that defines the floorplan.
Below are a few examples of output - the generator creates more than this, but it's not necessary to prove that by posting them all here
This can (obviously) be extended to other styles of body, e.g. flatbed, open etc
- Attachments
-
- 7_8_tipping_trailer_fifth_wheel_cc_1_COAL.png (2.48 KiB) Viewed 5926 times
-
- 7_8_tipping_trailer_fifth_wheel_cc_2_COAL.png (2.49 KiB) Viewed 5926 times
-
- 7_8_tipping_trailer_fifth_wheel_cc_1_GRAI.png (2.49 KiB) Viewed 5926 times
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
- andythenorth
- Tycoon
- Posts: 5656
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Re: Raster / shader project - insane?
Tank trailer input file + result.
The extra set of wheels in the input file is used to generate separate pngs for A trailers and B trailers - the brown pixels are painted as tyres, or masked out with blue.
The extra set of wheels in the input file is used to generate separate pngs for A trailers and B trailers - the brown pixels are painted as tyres, or masked out with blue.
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
- andythenorth
- Tycoon
- Posts: 5656
- Joined: 31 Mar 2007 14:23
- Location: Lost in Music
Re: Raster / shader project - insane?
Tanker B-Train
- Attachments
-
- b-train.png (61.07 KiB) Viewed 5815 times
FIRS Industry Replacement Set (released) | HEQS Heavy Equipment Set (trucks, industrial trams and more) (finished)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Unsinkable Sam (ships) (preview released) | CHIPS Has Improved Players' Stations (finished)
Iron Horse ((trains) (released) | Termite (tracks for Iron Horse) (released) | Busy Bee (game script) (released)
Road Hog (road vehicles and trams) (released)
Re: Raster / shader project - insane?
I'm quite surprised you can draw a tanker out of a single line of pixels!
Who is online
Users browsing this forum: No registered users and 4 guests