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.
This commit is contained in:
emil28092005
2026-06-17 16:13:46 +03:00
parent f905fe3040
commit c82ff48119
12 changed files with 474 additions and 106 deletions
+2 -1
View File
@@ -15,7 +15,8 @@ public static class MeshMath
{
var ab = b - a;
var ac = c - a;
var normal = Vector3.Cross(ab, ac);
// 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
+22 -5
View File
@@ -74,9 +74,12 @@ public static class SceneSerializer
var l = e.Get<Light>();
entry.Light = new SceneLight
{
Type = l.Type,
Direction = l.Direction,
Position = l.Position,
Color = l.Color,
Intensity = l.Intensity
Intensity = l.Intensity,
Range = l.Range
};
}
@@ -144,10 +147,21 @@ public static class SceneSerializer
if (entry.Light != null)
{
entity.Set(new Light(
entry.Light.Direction,
entry.Light.Color,
entry.Light.Intensity));
if (entry.Light.Type == LightType.Point)
{
entity.Set(Light.Point(
entry.Light.Position,
entry.Light.Color,
entry.Light.Intensity,
entry.Light.Range));
}
else
{
entity.Set(Light.Directional(
entry.Light.Direction,
entry.Light.Color,
entry.Light.Intensity));
}
}
if (entry.Camera != null)
@@ -208,9 +222,12 @@ internal sealed class SceneMaterial
internal sealed class SceneLight
{
public LightType Type { get; set; }
public Vector3 Direction { get; set; }
public Vector3 Position { get; set; }
public Vector3 Color { get; set; }
public float Intensity { get; set; }
public float Range { get; set; }
}
internal sealed class SceneCamera