Materials after Vertex shift for Procedural Generation of a Terrain

Hi,

I’ve been working on a procedural ‘Tile’ based landscape generator. And it’s going rather well.

I do, however, have one problem…

Here’s what my terrain looks like in wire-frame after generation via Perlin Noise

Here’s what it looks like when it is solid with GLSL

As you can see, for some reason the shader doesn’t want to change the object from being rendered as a plane. It just wants to render it the same way as before, only respecting the borders of the mesh.

As for the way I am doing it, I am iterating over every vertex in the mesh and applying the perlin noise function, using a VertexProxy object. After the generation, I am reinstancing the physics mesh.

Here’s the code in question:

#Imports
import random
import landscapeMaterial
#I'll have to somehow include this with the binary
from noise import snoise2

#This script generates a landscape using perlin
terrain_octaves = 8
terrain_scale = 32
terrain_intensity = 16

def generate(planar):
    for mesh in planar.meshes:
        for mat_index in range(len(mesh.materials)):
            for vert_index in range(mesh.getVertexArrayLength(mat_index)):
                vertex = mesh.getVertex(mat_index, vert_index)
                
                vertX = planar.worldPosition.x + vertex.x
                vertY = planar.worldPosition.y + vertex.y
                
                vertex.z = snoise2(vertX / terrain_scale, vertY / terrain_scale, terrain_octaves)*terrain_intensity
    planar.reinstancePhysicsMesh()
    
def main(obj):
    generate(obj)

What am I doing wrong? Is there a recalculate shaders function I am not aware of? Is it simply that the normals are still facing the wrong direction? Any help would be appreciated

Thanks in advance.

Re instance the GFX? (not that I know)

I didn’t find it in the API, but in the meantime I think I have found a better solution.

For everyone reading this thread:
What I did, is simply created my own shader. This allowed the shader to be compiled and assigned to the object after it was generated using the algorithm. Works like a charm, and may be just the ticket for my height based image textures which I will be applying.

What it now looks like:


Better eh?

What did I do?
In my loop, I added a new line

mat.shader.setSource(VertexShader, FragmentShader, 1)

I then wrote a simple fragment and vertex shader to apply the vertex colours to the landscape, like this:


VertexShader = """
//Basic Vertex shader, nothing special required
void main() {
    gl_FrontColor = gl_Color;
    gl_Position = ftransform();
}
"""

FragmentShader = """
void main() {
    gl_FragColor = gl_Color;
}
"""

I can now modify these shaders any way I wish, and they will be applied after. I am thinking I will write an LOD system using this method.

Could you use a topographical map to generate terrain in this fashion?

Yeh, I guess you could. I could post a script here if you’d like, wouldn’t be too difficult.