Fixed lighting

This commit is contained in:
2025-12-16 09:13:22 -07:00
parent de5f47f47b
commit 32df388c77
6 changed files with 85 additions and 66 deletions

View File

@@ -3,6 +3,7 @@ package screens
import (
"fmt"
"image/color"
"math"
"time"
"github.com/hajimehoshi/ebiten/v2"
@@ -168,28 +169,14 @@ func (g *GameplayScreen) updateRaycastLights() {
return
}
screenWidth := g.bounds.Width
lightX := float64(screenWidth - 80)
lightY := 80.0
if currentMap.TimeOfDay == maps.Daytime {
g.raycastSystem.SetShadowIntensity(0.25)
for _, lightSrc := range currentMap.Lighting.Sources {
g.raycastSystem.SetShadowIntensity(lightSrc.ShadowDarkness)
g.raycastSystem.AddLight(&raycast.LightSource{
X: lightX,
Y: lightY,
Radius: 800.0,
Color: color.RGBA{R: 255, G: 250, B: 220, A: 255},
Intensity: 1.0,
})
} else {
g.raycastSystem.SetShadowIntensity(0.7)
g.raycastSystem.AddLight(&raycast.LightSource{
X: lightX,
Y: lightY,
Radius: 500.0,
Color: color.RGBA{R: 200, G: 220, B: 255, A: 255},
Intensity: 0.7,
X: lightSrc.X,
Y: lightSrc.Y,
Radius: lightSrc.Radius,
Color: lightSrc.Color,
Intensity: lightSrc.Intensity,
})
}
}
@@ -276,10 +263,7 @@ func (g *GameplayScreen) Draw(screen *ebiten.Image) {
currentMap.Draw(screen)
g.hud.ScreenName = currentMap.DisplayName
// Apply nighttime darkening overlay BEFORE raycasting
if currentMap.TimeOfDay == maps.Nighttime {
g.drawNightOverlay(screen)
}
g.drawAmbientOverlay(screen, currentMap)
// Draw raycasting shadows/lighting
if g.raycastEnabled != nil && *g.raycastEnabled {
@@ -375,32 +359,37 @@ func (g *GameplayScreen) drawSaveNotification(screen *ebiten.Image) {
func (g *GameplayScreen) updateHeroLighting(currentMap *maps.Map) {
if g.raycastEnabled == nil || !*g.raycastEnabled {
g.hero.InShadow = false
g.hero.ShadowIntensity = 0
g.hero.Brightness = 1.0
return
}
// Check if hero is in shadow
inShadow := g.raycastSystem.IsPointInShadow(g.hero.X, g.hero.Y, g.world)
g.hero.InShadow = inShadow
ambient := currentMap.Lighting.AmbientBrightness
maxDirectLight := 0.0
if inShadow {
if currentMap.TimeOfDay == maps.Daytime {
g.hero.ShadowIntensity = 0.3
for _, light := range currentMap.Lighting.Sources {
inShadow := g.raycastSystem.IsPointInShadow(g.hero.X, g.hero.Y, g.world)
if !inShadow {
maxDirectLight = math.Max(maxDirectLight, light.Intensity)
} else {
g.hero.ShadowIntensity = 0.6
indirect := light.Intensity * (1.0 - light.ShadowDarkness)
maxDirectLight = math.Max(maxDirectLight, indirect)
}
} else {
g.hero.ShadowIntensity = 0
}
g.hero.Brightness = math.Min(1.0, ambient+maxDirectLight)
}
func (g *GameplayScreen) drawNightOverlay(screen *ebiten.Image) {
opts := &ebiten.DrawImageOptions{}
opts.ColorScale.Scale(0.4, 0.4, 0.6, 1.0)
func (g *GameplayScreen) drawAmbientOverlay(screen *ebiten.Image, currentMap *maps.Map) {
if currentMap.Lighting.AmbientBrightness >= 1.0 {
return
}
darkness := 1.0 - currentMap.Lighting.AmbientBrightness
alpha := uint8(darkness * 200)
overlay := ebiten.NewImage(int(g.bounds.Width), int(g.bounds.Height))
overlay.Fill(color.RGBA{R: 0, G: 0, B: 30, A: 120})
overlay.Fill(color.RGBA{R: 0, G: 0, B: 0, A: alpha})
screen.DrawImage(overlay, &ebiten.DrawImageOptions{})
}
@@ -409,16 +398,15 @@ func (g *GameplayScreen) drawCelestialBody(screen *ebiten.Image, currentMap *map
return
}
cx := float32(g.bounds.Width - 80)
cy := float32(80)
radius := float32(25)
for _, lightSrc := range currentMap.Lighting.Sources {
cx := float32(lightSrc.X)
cy := float32(lightSrc.Y)
radius := float32(25)
if currentMap.TimeOfDay == maps.Daytime {
vector.DrawFilledCircle(screen, cx, cy, radius, color.RGBA{R: 255, G: 230, B: 100, A: 255}, true)
vector.DrawFilledCircle(screen, cx, cy, radius+3, color.RGBA{R: 255, G: 240, B: 150, A: 100}, true)
} else {
vector.DrawFilledCircle(screen, cx, cy, radius, color.RGBA{R: 240, G: 240, B: 255, A: 255}, true)
vector.DrawFilledCircle(screen, cx, cy, radius+3, color.RGBA{R: 200, G: 200, B: 255, A: 80}, true)
vector.DrawFilledCircle(screen, cx, cy, radius, lightSrc.Color, true)
glowColor := lightSrc.Color
glowColor.A = 80
vector.DrawFilledCircle(screen, cx, cy, radius+3, glowColor, true)
}
}