QodotPlugin / qodot-plugin

(LEGACY) Quake .map support for Godot 3.x
MIT License
960 stars 70 forks source link

Better normal generation for _phong #92

Closed Shfty closed 4 years ago

Shfty commented 4 years ago

Currently vertex normals are calculated based on the 3 planes that make up each vertex, and vertices with duplicate positions are discarded (along with their normal).

The first step is to rewrite this to discard after generation, rather than during it. Normals of duplicate vertices can be averaged in order to get a more correct final results, after which the dupes can be discarded.

If that still doesn't produce satisfactory results, there should be some code in Godot's SurfaceTool class that can serve as reference for proper autogeneration of mesh normals.

Shfty commented 4 years ago

I've implemented the normal averaging technique and it produces fairly good results. They're not perfect, as there are still some lighting discontinuities between faces, but it's a considerable step up from the previous implementation.

There's room for a more advanced implementation in future, but for now I think this is good enough.