Wang Tiling for Racer

The shader was developed for Racer 0.8.31 so may not be immediately compatible with the present version. Bear with me, I don't have a huge amount of free time. All the code modification is in Tex2D; if you compare it with standard_f.cg you should be able to bring it in line with whichever version is current.

The example texture is borrowed from this SIGGRAPH presentation, since it's quite striking and easy to see when it goes wrong.

The components involved are:

You can grab all four files in wangtile.7z if you can open 7zip files.

It'll most likely be easiest to implement this using the same material shader combo I had, then replacing components with what you want.

Put the .cg shader in data/renderer/shaders, the two textures in data/track/track_name/, and copy the .shd shaders into track.shd.

Replace the name of the shd's material shader with what you want to use.

At present, the shader's written using global coordinates - it would be relatively easy to switch over to UV coordinates but I haven't bothered because Carlswood's are fairly messed up. The 'scale' factor in the .shd will let you control the size - I'm not sure if it's standard, but in this case you write the number of meters wide you want 1 repetition of the base texture to be - noting that this is actually 1/4 of the image's width. So with scale=2 as in the file, the entire texture will cover an 8x8m square, with each of the 16 tiles being 2x2m squares.

The flowers texture basically has two edge types - call them A and B. Each tile has horizontal and vertical edges - so four edge labels per tile. On the map, these are arranged as [A A] [A B] [B B] [B A], both horizontally and vertically. So the bottom right has edge type 'A' on all four sides. The index texture is designed such that A-A and B-B edges between adjacent tiles always match. Note also that due to the way the tiles are laid out, the image itself tiles fine without this code. It's possible to ignore this, and make all edges tile correctly, ie [A A] [A A] [A A] [A A], if you want less work in creating the base texture. Also, despite me calling them all A, there are 4 different types of 'A' - a left-side A matches a right-side A, and a top A matches a bottom A, but other combinations don't occur.

There's a fairly thorough tutorial on creating the tiling texture at The art of RailWorks. Unlike RailWorks, though, this is packing all the textures into a single sheet - for comparison see schematic, which shows where each RailWorks letter label is. Each distinct shaded triangle has a specific edge, and hue pairs need to match so that the edges work correctly. The interiors of the tiles could be anything, though.

The index texture was generated with some code in R and at the moment is not ready to be put online. I'll fix up some of the glitches, hopefully get it generating into the correct channels etc. and then consider posting it. As it is, the one control map I've provided should be good to go unless there's a specific reason not to use it.

Wikipedia's page on Wang Tiling provides a clearer view of what's happening, albeit not with this particular set of tiles. To build a set of tiles, you could take a look at matlabPyrTools and texture synthesis. I haven't tried these myself. The discussion on Racedepartment is currently here.

Pictures

Since I'm guessing that explains things better than the text:

Demonstration picture 1 of Wang tiling.

Demonstration picture 2 of Wang tiling.

Numbered demonstration picture of tiling.
In this picture, a numbered version of the texture is used to demonstrate how the specific tile in use varies.