Monday, January 26, 2015

Outdoor assets update



I've been noodling with outdoor environment assets and scenes yet again. There's some new snazzy cliffs and rocks, terrain textures and tiles and a whole lot more is coming as we speak.


Thematically we have two outdoor types so far:

1) dry desert with red cliffs, desert palm trees and cacti (is it "cacti" or "cactuses"?)
2) jungle swamp with more dense vegetation, grass and mud.

Because our system is tile-based without terrain painting features or anything fancy like that, I had to find a way to create varying and organic terrain transitions to different ground types in some other way. I tried to create textures that had all the transition tiles done in Photoshop, but that was a major pain in the ass. Instead I'm now experimenting with vertex color controlled texture blending:

Left: Painting vertex colors in MODO and viewing the result in Unity

Positive things about this technique is that it's a lot more easy to control and edit and also there's no need for separate transition textures. This technique is quite versatile and can be used for most assets, e.g. adding sand and grass to rocky walls, darkening crevices, adding rust to metal surfaces and so on.

The downside is that it takes a lot more vertices per terrain tile (or any other asset) to get any sensible results. I've decided to solve this issue by preparing low-poly tiles (2 tris) to be used in areas that don't need any transitions, and a set of denser meshes for areas that do.

A set of new assets for the desert areas

Currently I'm exporting different terrain tiles with vertex colors from MODO because Unity lacks vertex painting tools by default as far as I know. There are some cool looking vertex painting tools available for it, but I'll stick with this workflow for now.

The shader that we use at the moment - which blends two textures by vertex color information - is a combination of Unity's default Mobile Diffuse shader mixed with a very cool shader from Zhan Studio:

http://www.zhanstudio.com/blog/unity-mobile-terrain-shader-with-multi-uv-mixing

What I basically did was I replaced the control texture part of the shader with a vertex color control and simplified it to a minimum. I've not done any performance testing with the shader yet but for a quick'n'dirty test shader it works just fine:

Shader "Mobile/Diffuse-VertexBlend-2" {
Properties {
 _Diffuse1 ("Layer 1 (G)", 2D) = "white" {}
 _Diffuse0 ("Layer 0 (R)", 2D) = "white" {}
}
                
SubShader {
 Tags {
     "RenderType" = "Opaque"
 }
CGPROGRAM
#pragma surface surf Lambert noforwardadd
#pragma target 2.0

struct Input {
 float2 uv_Diffuse0 : TEXCOORD1;
 float2 uv_Diffuse1 : TEXCOORD2;
 half4 color : COLOR0;
};
 
sampler2D _Diffuse0, _Diffuse1;
 
void surf (Input IN, inout SurfaceOutput o) {
    fixed4 col;
 col  = IN.color.r * tex2D (_Diffuse0, IN.uv_Diffuse0);
 col  += IN.color.g * tex2D (_Diffuse1, IN.uv_Diffuse1); 
 o.Albedo = col.rgb;
 o.Alpha = col.a; 
}
ENDCG 
}
// Fallback to Diffuse
Fallback "Diffuse"
}

Download the .shader file: Mobile-Diffuse-VertexBlend-2.shader
If you find errors or think of ways to optimize it (I'm a shader-n00b), please feel free to share the results!

Anyways, that's it for this post. More coming soon. Thanks for reading!


-Sami

2 comments :

  1. nice work things are looking really good. I like the textures and colors you are using for the desert.

    ReplyDelete
    Replies
    1. Thanks! I'm aiming for a good eye pleasing color balance and am also trying keeping it simple.

      Delete