Files
Cortex_Engine/src/Engine.Graphics/MeshMath.cs
T
emil28092005 c82ff48119 fix: rlgl depth FBO shadows, correct normals, linear gamma, per-channel Fresnel
- Shadow mapping via rlgl: custom depth FBO (2048x2048, 24-bit depth texture)
  instead of color-attachment approach. Proper depth-only render pass.
- Shadow map bound via MaterialMapIndex.Emission (texture unit 1), sampled
  in shadow receiver shader with PCF 3x3 soft shadows.
- Fixed inverted normals: Cross(ac, ab) for CW winding in OBJ files.
- Linear workflow: pow(albedo, 2.2) before lighting, pow(result, 1/2.2) after.
- Per-channel Fresnel: vec3 F0 + (1-F0)*pow(1-HdotV,5) instead of F0.x.
- Single CollectLights call after BeginMode3D.
- Shadow pass after BeginDrawing (inside frame).
- Backface culling disabled globally for mixed-winding meshes.
- Point light support: Light.Point/Directional factory methods, attenuation,
  ImGui inspector with type combo, position/range for point lights.
- Floor rendered for both light types (shadow receiver or main shader).
- 66/66 tests passing.
2026-06-17 16:13:46 +03:00

27 lines
802 B
C#

using System.Numerics;
namespace Engine.Graphics;
/// <summary>
/// Shared mesh math utilities used by loaders and procedural generators.
/// </summary>
public static class MeshMath
{
/// <summary>
/// Compute a flat face normal from three vertex positions.
/// Falls back to Vector3.UnitY for degenerate (zero-area) triangles.
/// </summary>
public static Vector3 ComputeFaceNormal(Vector3 a, Vector3 b, Vector3 c)
{
var ab = b - a;
var ac = c - a;
// Cross(ac, ab) instead of Cross(ab, ac) to match CW winding in typical OBJ files
var normal = Vector3.Cross(ac, ab);
if (normal.LengthSquared() > 0.00001f)
normal = Vector3.Normalize(normal);
else
normal = Vector3.UnitY;
return normal;
}
}