Enhance constrast of edges on procedure texture

Hi !

I’m trying to display a ground profile and I’m not happy at all with the rendering :confused:
This ground profile only comprises random linear slopes and plateau. I would like to enhance the contrast of the edges where the slope is changing.

I’m recreating this ground profile using the following snippet of mine:

def make_height_map(height_map: np.ndarray) -> Geom:
    """Create height map.
    """
    # Compute the number of vertices
    num_vertices = int(np.prod(height_map.shape[:2]))

    # Define vertex format
    vformat = GeomVertexFormat.get_v3()
    vdata = GeomVertexData('vdata', vformat, Geom.UH_static)
    vdata.uncleanSetNumRows(num_vertices)
    vertex = GeomVertexWriter(vdata, 'vertex')

    # # Add grid points
    for i in range(height_map.shape[0]):
        for j in range(height_map.shape[1]):
            vertex.addData3(*height_map[i, j])

    # Make triangles
    prim = GeomTriangles(Geom.UH_static)
    for j in range(height_map.shape[1]):
        for i in range(height_map.shape[0] - 1):
            k = j * height_map.shape[0] + i
            if j < height_map.shape[1] - 1:
                prim.add_vertices(k + 1, k, k + height_map.shape[0])
            if j > 0:
                prim.add_vertices(k, k + 1, k + 1 - height_map.shape[0])

    # Create geometry object
    geom = Geom(vdata)
    geom.add_primitive(prim)

    return geom

model = GeomNode('floor')
node = self.render.attach_new_node(model)
model.add_geom(make_height_map(height_map))
material = Material()
material.set_ambient(Vec4(0.95, 0.95, 1.0, 1.0))
material.set_diffuse(Vec4(0.95, 0.95, 1.0, 1.0))
material.set_specular(Vec3(1.0, 1.0, 1.0))
material.set_roughness(0.4)
node.set_material(material, 1)
node.set_two_sided(True)

Reading the documentation, it seems to be related to not providing the normal information when I create the geometry. Is it possible to automatically deduce the normal without specifying it manually ?

Here is what I get by specifying the normal:

I’m not really satisfied either x) The linear slopes appear curvy and there is strange shadow at several places out of nowhere :confused:

Apparently increasing the resolution of the mesh is helping:

Yet there is still the strange shadow. I think it is coming from a directed light I added.

Try disabling the two-way model. This can affect the shadow.

You need to use pixel-by-pixel lighting that does not require a large resolution of the model to display the shadow. You can just call the auto shader.

Ok I see, thank you! I will have a look.

What about the strange shadow ? I don’t understand how to fix this :confused:

Well, have you tried serega’s suggestions? Those were, I believe, directed at solving the shadow issue.

If so, however, how are you generating your normals? I think that I recall that Panda’s shadow-mapping code uses the normals of geometry to which it’s applied in order to produce a surface-offset. Thus, if there’s a problem with those normals, I could see it causing a problem with the shadow-mapping.