0 votes

I generate a terrain based on a youtube tutorial. In short, I create a plane, change the y position of its vertices using tools, then generate a mesh out of it.
here is the code:

var planeMesh = PlaneMesh.new()
planeMesh.size = Vector2(chunkSize, chunkSize)
planeMesh.subdivide_depth = chunkSize * resolution
planeMesh.subdivide_width = chunkSize * resolution

var surfaceTool = SurfaceTool.new()
surfaceTool.create_from(planeMesh, 0)
var arrayPlane = surfaceTool.commit()
var dataTool = MeshDataTool.new()
var error = dataTool.create_from_surface(arrayPlane, 0)

for i in range(dataTool.get_vertex_count()):
    var vertex = dataTool.get_vertex(i)
    vertex.y = noise.get_noise_3d(vertex.x + x, vertex.y, vertex.z + z) * 60
    dataTool.set_vertex(i, vertex)

for s in range(arrayPlane.get_surface_count()):

surfaceTool.create_from(arrayPlane, 0)

meshInstance = MeshInstance.new()
meshInstance.mesh = surfaceTool.commit()
meshInstance.set_surface_material(0, load("res://GFX/TerrainMat.tres"))

I want to make the shading be smooth. If I know well, the normals have to be calculated per vertex and not per side, but I am not sure.
how can I make the shading smooth?

asked Jan 2 in Engine by KijeviGombooc (137 points)

1 Answer

0 votes

Replace the following line:

surfaceTool.create_from(arrayPlane, 0)

with these lines:

surfaceTool.append_from(arrayPlane, 0, Transform.IDENTITY)

This should make your mesh smooth (tested in Godot 3.2.1).

answered Apr 25 by ArdaE (92 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.