RGBA Masking 4 seperate [8 with NRM] Textures

Let me first just say I’m still very new to Unity. I am mostly a modeler and texture guy. Shaders aren’t something I have much experience with outside of 3ds Max and even then, I consider myself very noobish.

To the point - I’m using imported geometry for terrains. [I’m in the ‘if I can do it outside of Unity, I will’ camp] Vertex Painting is an option but I’m trying to keep my geometry density down so Vertex painting doesn’t work out so hot and to be honest, I’d much rather do it in the way I need help with - if at all possible.

I’d like to be able to blend, via RGBA, four separate diffuse channels - each channel with it’s own normal and spec [even spec from alpha is fine]. Coupled with a main color blend channel to give the 4 diffuse channels some color variances. With me so far?

This is a 3ds Max gif grab of a similar principle made by someone else

So two main maps for the terrain - the mask and the blend - then up to 4 diffuse textures [and their normals maps [so up to 8 total] which are masked via the masks RGBA. The more Red, blue, green or Alpha the pixel is in the mask [up to 255] the more it shows that masked texture [up to 100%].

The blend map is basically a color blend [with an alpha channel to blend the blend map over the diffuse textures]. It would take the color values from that blend map and apply them over the diffuse of the [up to four] diffuse textures with the alpha of the blend map being the range from 0% blend [100% alpha] to 100% color blend [0% alpha]. To add some overall broad strokes of color for terrains as opposed to those values being strictly clamped to each of the individual diffuse textures. So as an example - a blend map from light brown to rich dark brown and a single diffuse affected it by it should look like that one diffuse is gradating from a light brown to a rich brown - not just be the color of itself. The alpha channel of that blend map would be the value of the color blend. In the previous example, if the alpha was 100% then we wouldn’t see any change color change in the diffuse texture. If the alpha was 0% then the color of the blend map would completely cover the diffuse texture color. What is key here is that the tonal range remains the same. So highlights and shadows in the original diffuse texture remain - it’s just a color blend.

Of course I would love to be ale to use this shader for anything - not just terrains. Any object I’d want to blend two or more textures for, all I should need is the mask with at least 2 channels to use for masking, at least two diffuse textures [with their associated normal maps] and the color blend should be optional. It uses it if it’s there, otherwise it ignores it.

Could some kind soul chime in on this?

Here is a set of working files for anyone willing to give this a shot. It contains:

  • terrainObject.fbx
  • terrainMask.tga [with alpha]
  • terrainBase.tga [used to blend]
  • 4 ground diffuse textures and 4 asscociated normal maps [please do not use these maps for anything other than this]

I really hope someone can tackle this. I think it would be a nice shader for everyone, not just me.

To sweeten the deal - I’m happy to trade modeling or texture work for your time building this shader. As long as the workload is fair and I’m honest about my time and experience. Do not hesitate to PM me if you have a deal and are unwilling to publicly show off your needs here.

hi there,

you can simply use sixtimesnothing bumpmap for terrain shader – even on regular geometry. all you will have to do is just to tweak the script a little bit.

lars

Thanks for the response Lars. I’ll need you to elaborate a little I’m afraid. What is a sixtimesnothing bumpmap? What makes it simple? Does it provide what I outlined in my original post and if not, would you be willing to change it to suit? Nothing is simple for me regarding shaders. Thanks.

hi,

you can find the shader here:
http://forum.unity3d.com/threads/63282-Bump-maps-for-built-in-terrain

you will have to rename the shader (in the source code) to get access to it in the inspector: just remove the “hidden/terrain engine…/”) pat from the name.
then assign it to a material: there you should find 5 slots for the rgba splatmap and the 4 detail textures.
as it was designed for the built in terrain engine the normal maps are send via script as global textures. so you will have to assign the script that comes with the shader to your terrain.fbx and set it up correctly. you might have to change one or two lines of code as well (as somewhere it tries to access the current terrain as far as i remember).

but anyway: way don’t you use the built in terrain engine? it’s not the best as has been discussed many times already but will render much faster (not on mobile of course –*but the shader mentioned above needs shader model 3 anyway) and give you easily planted grass and trees and billboarding of those.
so in case you do not do any really strange things like overhangs and things like this it is still a pretty capable system.

lars.

Thanks for elaborating on that. I’ll try and digest it as best I can. I’m still hopeful someone would take a stab at my original post, of course.

Any chance you could post the results of what you’ve outlined using the files I provided? I’d to see that what you’re saying is actually going to accomplish what I want and it sounds like you’d get through the initial set-up/hack far faster than I.

I’d prefer doing anything that can be done outside of Unity, outside of Unity. Not to suggest the built-in terrain tools/generator isn’t any good. It’s great [from what I could tell when I tried it out] but comparatively speaking, it limits me so I fall back on what I’m used to.

EDIT***

Added a link to a 3ds max gif grab someone made using the same basic principle [without the alpha, though]

hi prejew,

this is the way your data looks like using a “blend 4 detail textures plus detail normal maps plus color map shader”:

as you can notice:

  • your uv’s are not mapped very accuratley (leading to distorted texturing)

  • your bump maps are not balanced well

  • your terrain mask is incorrect: make sure that the overall sum of all color channels including alpha will always be 1 for any pixel!
    → r + g + b + a = 1.0

  • your terrain has 4 or even 5 uv channels but unity only supports 2 (where the second one mainly is used for lightmaps…)

  • the geometry of your terrain is not that special: no steep cliffs, no overhangs

so after all: just go with the built in terrain and use the color map terrain shader from the asset store (free).
that will give you terrain like this one:

you can model and texture your terrain in your 3d app. export heightmap and splatmap and assign both to the terrain.

using a mesh modeled terrain like yours doesn’t make any sense in unity at all as far as performance and flexibility are concernd – unless you are working for mobile.
but in this case you would not be able to use such hugh amount of textures. look for the terrain for mobile solution (t4m) on the asset store if you want to create terrains for mobile devices.

lars

Thanks for the taking the time to show me the results of what you were explaining to me. That terrain wasn’t generated for anything other than to post here. Sorry it didn’t meet your expectations. Nevertheless, the “blend 4 detail textures plus detail normal maps plus color map shader” is what, exactly? That is the sixtimesnothing bumpmap you mentioned earlier or something different?

the “blend 4 detail textures plus detail normal maps plus color map shader” is what you can make from the original shader developed by sixtimesnothing within a view minutes.
but i highly recommend to download the color map terrain shader as also supports correct color blending of the color map and the detail splats.

lars

Thanks Lars. I’ll give the sixtimenothing bumpmap a look and report back.

I’m not having any luck with this. The result are odd and nothing I do changes it. I knew I shouldn’t have bother starting this thread.

Thanks for your time Lars.