Home Unreal Engine

Texture splatting - Grass

Vetril
null
Offline / Send Message
Vetril null
Hello. I'm working in UE4 a personal project: a top-down game.

I'm working on terrain materials. I created a tileable grass texture and a displacement map to go with it.



I want to splat this texture with a few others. If I use the displacement map as a mask to modulate the linear blending works better than expected (the map wasn't really created for this purpose), but of course the grass blades get progressively "cut".




This doesn't look bad, per se, and I guess it would be less noticeable if I used a dirt texture rather than a flat color. Still, the original idea was to mask entire clumps as the blend goes from grass to dirt.

I'd like to avoid handpainting another texture just for the grass, but it if comes to that I can do it and stick the heightmap into the A channel of the albedo. An idea I had was to create the map by going through the photoshop layers stack of the clumps (about 100) and fill them with about 5 or 6 shades of grey, effectively making a heightmap with discrete values. Then, by blending at intermediate values, I'd be able to isolate specific parts. However, this might be tricky as I have some clump lines which go in a cycle (clump A above clump B above clump C above clump A).

Do you think this is the best approach? Would you suggest something different? I'm wondering if I should actually make a heightmap at all - do you think it would improve the visuals, considering how the terrain will be viewed?

Replies

  • Vetril
    Options
    Offline / Send Message
    Vetril null
    Ok, round 2.

    I made a new texture and built a heightmap. I quickly realized that to avoid linear blending at all (giving me the sharp transitions that I want), the shader needs to be able to filter whole patches of grass.

    The idea to solve this is to collapse the whole grass patch into a single point coordinate, and for each point that belongs to the patch, test against that single point (thus always getting the same blend as long as we are inside the patch).
    To do this, I pick the UV coordinates of the pixel at the center of the map and I store them into the RGB channels of another texture, together with the heightmap itself in the A channel.
    So far, I use RG to identify a pixel within the [0, 255] range in both dimensions. B identifies the offset from the top left corner, by counting in base 256 from left to right, top to bottom.
    So, for example, the pixel coordinates (442, 250) would map to RGB coordinates (186, 194, 9).
    In the shader, I can retrieve the pixel coordinates, convert them to UV values and sample the heightmaps at that point. 
    The problem is that I need to be very precise: a small rounding error, expecially in the B value, will lead to UV coordinates that are completely off target.

    I'd like to ask you guys how you would convert the UV coordinates into RGB channels in order to be as accurate as possible.
Sign In or Register to comment.