func-godot/func_godot_plugin

Fix Phong shading to be per-mesh and not per-brush

RisingThumb opened this issue · 3 comments

Proper Phong Shading
One of the features in FuncGodot is using the _phong and _phong_angle key value pairs to modify generated meshes vertex normals, to allow for smoother shading on brush entities. Currently the implementation only does this on a per brush basis, when it should be done on a per mesh basis. This issue was around in Qodot and has been carried over to FuncGodot. Hopefully we can get this sorted out in the near future

Off the back of the discussion page https://github.com/orgs/func-godot/discussions/2 .

Gonna be looking into this again soon. Any other help on this would be greatly appreciated.

Started work on trying to solve this. Using this branch of the test_project repository:
https://github.com/func-godot/func_godot_test_project/tree/phong-testing

High level overview of the phong process given to me by ericw on the Quake Mapping Discord:

I can give a high level overview, there are a couple steps:

  • it runs on the output of qbsp, so hidden/exterior faces are deleted, everything is welded together
  • first, it's marking edges of the mesh as 'hard' or 'smooth' (same idea as in Blender) based on the _phong_angle (default is 89) and looking at the angle between neighbouring faces compared with the phong angle. So e.g. if you have a cube, the angle between the top face's normal and the sides' normals are all 90 degrees, so those 4 edges around the top face would get marked as "hard"
  • once edges are marked as hard or smooth we calculate vertex-per-face normals. Hard edges just use the face normal, and smoothed edges we're calculating a blended normal by blending together the face normals of the faces sharing the smoothed edge. I forget the exact details here but it's weighted by angle/face area

I believe the answer is going to be in GeoGenerator's run() method. Our main problem is that phong and normal calculations occur on a per brush basis.

My current idea is to remove the phong calculations from the brush generation section and create another threaded loop after the entity's brushes are generated that goes through each brush's vertices and corrects their normals.