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?