The last couple of weeks of dev have been a bit frustrating. I came up against an engine feature that I wanted which – my mistake – I had thought was in Unity 4 but was actually only introduced in Unity 5. Scraps has been halfway converted to Unity 5 for a while so I did a bit more on that conversion, tested the stuff I needed, and realised it still wasn’t going to work anyway. Not a real loss of time because I’ll most likely need to move the game from Unity 4 to 5 eventually anyway, but annoying because I want to get new content out as much as the next person.

I can actually show some work on content rather than code for once though. You may have seen the new pile of crates and barrels on the Test Map in the last update:

In the editor the crates look like the left image, but when the game is run they take on some random colour variation to look a little more interesting. Giving them all different Materials with different tints would blow out the amount of draw calls in the scene, so instead they all share the same Material, and the tint colour is set via the vertex colour on the mesh itself. Pretty simple code:

void SetTint ( Mesh mesh ) { // Tint is set via mesh vertex data rather than in the shader properties, // so that we can still use the same shared single material instance on everything! byte colour255 = ( byte ) ( Random . value * 255 ) ; Color32 [ ] colors = mesh . colors32 ; for ( int j = 0 ; j & lt ; colors . Length ; j ++ ) { colors [ j ] . b = colour255 ; // Setting the blue channel } mesh . colors32 = colors ; } void SetTint(Mesh mesh) { // Tint is set via mesh vertex data rather than in the shader properties, // so that we can still use the same shared single material instance on everything! byte colour255 = (byte)(Random.value * 255); Color32[] colors = mesh.colors32; for (int j = 0; j < colors.Length; j++) { colors[j].b = colour255; // Setting the blue channel } mesh.colors32 = colors; }

The meshes are simple so running through the array is super fast – but it only runs once on level load anyway. Then in the surface shader I use the blue vertex’s blue colour channel value to do whatever – it’s really just a way of getting information from the game to the shader.

// Any extra tint stored in BLUE channel // fmod is % (mod). Using it to map all possible RGB values float4 tint = 0.7 + float4(IN.color.b, fmod(IN.color.b * 2, 1), fmod(IN.color.b * 4, 1), 1) * 0.3; if (IN.color.b > 0) { c.rgb *= tint; } // Any extra tint stored in BLUE channel // fmod is % (mod). Using it to map all possible RGB values float4 tint = 0.7 + float4(IN.color.b, fmod(IN.color.b * 2, 1), fmod(IN.color.b * 4, 1), 1) * 0.3; if (IN.color.b > 0) { c.rgb *= tint; }

You may wonder why I set just the blue channel and then calculate a colour tint based on that rather than setting the whole vertex colour RGB and setting the tint to that value.

The reason is that a lot of things in Scraps are actually done this way – heat effects on vehicle parts, damage texturing on everything, and how shiny vehicle parts are (specularity) are all specified by modifying the different colour channels in the mesh vertex data, so that each vehicle can be shown with one Material and the environment can be drawn with another. So I need the red and green channels for other things. Otherwise every time something got damaged or heated up, it’d have to use its own Material and have its own draw calls, making graphics performance a lot worse.

I also made these barrels. The red one explodes of course. I wrote a generic script that I can attach to any world object to make it explode when destroyed and damage surrounding stuff.

Driving a vehicle by ScrapsEnthusiast there. Yesterday I also added subtle air control to the game, so that’ll be in the next update. It’s tuned more for gameplay than being realistic, but you can at least pretend it’s created from the torque of the wheels spinning in the air.

And I made some light beam/forcefield-style walls that I can use to create more subtle level borders for some levels. Functionally they work the same as the current walls.

For the next game mode I need lots of terrain, so I’ve been improving my terrain creation workflow. I can now take a basic low-detail terrain and put it through my Scraps-specific World Machine setup to get out a terrain fairly quickly with erosion and varied texturing.

OK, the bottom one still doesn’t look amazing yet, but that’s without any grass, fog, sky, etc etc. It’s a lot better than the top one considering the minimal manual effort involved. One thing that’s not obvious in the screenshot is that the “after” terrains also have more fine detail – so I can map out a fairly low-res base terrain and then run erosion on it to make it into a more fully detailed one.