Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terrain normals #709

Open
fjansson opened this issue Aug 17, 2024 · 0 comments
Open

Terrain normals #709

fjansson opened this issue Aug 17, 2024 · 0 comments

Comments

@fjansson
Copy link

I've found that normals of the terrain entity vary too little, i.e. they point mostly upwards even if the terrain is sloping.

The current code:
models/procedural/terrain.py

  rl =  _height_values[x+1][z] - _height_values[x-1][z]
  fb =  _height_values[x][z+1] - _height_values[x][z-1]
  self.normals.append(Vec3(rl, 1, fb).normalized())

It seems the two derivatives rl and fb should be scaled with the mesh size, as for example here:
https://stackoverflow.com/questions/6656358/calculating-normals-in-a-triangle-mesh/21660173#21660173

I tried the following and it works much better (still not sure if there's a factor 2 missing):

  rl =  (_height_values[x+1][z] - _height_values[x-1][z]) * (w-1)
  fb =  (_height_values[x][z+1] - _height_values[x][z-1]) * (h-1)
  self.normals.append(Vec3(rl, 1, fb).normalized())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant