UV Edge Blending?

Edited*

I was trying to get boring old poop corners to be less poop cornery. Like this image below.


Some background on this, I’m attempting to write a script that generates random land masses given plane mesh of any size with any level of subdivision. The script moves verts around to create flowing slopes and such. That part’s still in production. What I was able to do is figure out how to texture land masses based on various criteria such as face slope and height. So steeper faces would be given a more rough texture such as stoney dirt or rock while flatter faces would be given a texture such as grass. The problem I had was blending the edges together. What I achieved was this.


It’s not much to look at now but at the suggestion of below contributors I was able to weight textures based on vertex color. I dynamically assign vertex color based on face data (slope and such as mentioned above). My script currently looks like this:

import bge

Grade Data

slope_to_stone = 3
elevation_to_snow = 100

Get Object Data

cont = bge.logic.getCurrentController()
own = cont.owner
mesh = own.meshes[0]

Get Poly Data

poly_count = mesh.numPolygons
current_poly = 0
last_poly = poly_count - 1

while current_poly <= last_poly:
# Update Poly Focus
poly = mesh.getPolygon(current_poly)
current_poly = current_poly + 1

# Get Vert Data
verts = [poly.v1, poly.v2, poly.v3, poly.v4]
for index, vert in enumerate(verts):
    key = int(index)
    verts[key] = mesh.getVertex(0, vert)
    
# Get Vert Slope
grade_weight = 4
vert_positions = [verts[0].z, verts[1].z, verts[2].z, verts[3].z]
high_point = max(vert_positions)
low_point = min(vert_positions)
slope = 1 - ( (high_point - low_point) / (high_point + grade_weight) )


# Apply Texture
for vert in verts:
    # Set Color Based On Slope
    r = vert.color[0] * slope
    g = vert.color[1] * slope
    b = vert.color[2] * slope
    
    vert.color = [r, g, b, 1.0]

It’s not really UV edge blending or whatever I thought I was trying to achieve initially. Ended up using Nodes with a Geometry Node determining the fraction between a dirt and grass texture. The greater the slope the more “dirt” is present in a face. Giving me the output of that - a nice transition between edges.

Next issue I have - using Vert Color I can blend two textures together at their edges, but I can’t figure out how to blend more than 1. Using multiple Mix Nodes makes sense, but Vert Color is already being used for Dirt and Grass. If I wanted to add Stone and Snow to the mix, how would I do this?

I don’t know that that’s possible. Try this, instead: http://gametutorials.tutorialsforblender3d.com/Stencils/Page1

For blending, yeah, stencils are probably easier to deal with. If you wanted to automate the process, it might be possible to draw onto a texture, but it’d be easier to deal with the vertex colors of each vertex in your landmass mesh. As for blending the edges so you don’t have that white outline around each tile, you’d do well to leave some padding around each tile where the tile’s colors “bleed out”.

Check this Unity doc page for some info about the concept of texture padding (that should apply to the BGE as well).

I’m not sure if stenciling can be done in the BGE. I’m pretty familiar with painting on textures by hand, but this has to be done dynamically, and stenciling looks like it’s all just done by hand. Correct me if I’m wrong?

And I did finally realize what I was doing wrong with those white lines and yeah, corrected it. Thanks!

How does this vertex color thing work? As far as I can tell, you just make a vert red or green or blue or whatever, and it makes it that color. How does that change the texture shown?

*I was just thinking that perhaps you use a greyscale image with alpha and apply a color to the material. So a greyscale grass texture with an alpha channel and you make the underlying color green. Is that how you’d do it?

Eh? KingDweeb just posted a tutorial that shows how to do stenciling in the BGE.

If I were to approach your problem, then I’d go with stenciling if the landscape was pre-determined, or vertex colors with a node material if I required more control (like you do). Sorry for not explaining this fully previously; basically, you use a node material for the ground. Use the geometry input with the vertex color input split into separate channels; use those channels to select which material to output.

Ok. Took me a while to make sure I understood stenciling (enough to consider it, anyway). You still have to paint alpha onto the stencil by hand. At least as much as I gleaned from that. You were spot on with needing control. Specifically, I need to do the “painting” in Python, so that I can procedurally or dynamically or whatever word you’re supposed to use here, “paint” faces based on criteria. I’m looking at Nodes, now.

Looks like I might still be wrong about stenciling. Kinda feel like I jumped into some stuff I didn’t fully understand to begin with. :stuck_out_tongue:

Updated the OP.