Skip to content

Commit 063a2bb

Browse files
committed
Fixed light going to occluder edges
1 parent 0722482 commit 063a2bb

File tree

1 file changed

+10
-3
lines changed
  • screwbox-core/src/main/java/dev/screwbox/core/graphics/internal

1 file changed

+10
-3
lines changed

screwbox-core/src/main/java/dev/screwbox/core/graphics/internal/Lightmap.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,25 @@ private void renderDirectionalLight(final DirectionalLight directionalLight) {
130130
}
131131

132132
private void renderPointLight(final PointLight pointLight) {
133-
final var clipArea = new Area(new Rectangle2D.Double(0, 0, lightMapSize.width(), lightMapSize.height()));
133+
Rectangle2D.Double s = new Rectangle2D.Double(pointLight.position.x() / (double) scale - pointLight.radius, pointLight.position.y() / (double) scale - pointLight.radius, pointLight.radius * 2, pointLight.radius * 2);
134+
final var clipArea = new Area(s);
134135
//TODO only when intersects
135136
for (final var occluder : backdropOccluders) {//TODO directly store areas?
136137
//TODO check bounding boxes here!
137138
Polygon translatedPolygon = translateRelativeToLightSource(occluder, pointLight.position);
138139
List<Offset> translatedOffsets = toOffsets(occluder.connect ? combine(occluder.area, translatedPolygon) : translatedPolygon);
139140
var translatedSmoothed = occluder.rounded ? AwtMapper.toSplinePath(translatedOffsets) : AwtMapper.toPath(translatedOffsets);
140-
clipArea.subtract(new Area(translatedSmoothed));
141+
Area rhs = new Area(translatedSmoothed);
142+
if (rhs.intersects(s)) {
143+
clipArea.subtract(rhs);
144+
}
141145
}
142146
for (final var occluder : backdropOccluders) {//TODO directly store areas?
143147
var smoothed = occluder.rounded ? AwtMapper.toSplinePath(toOffsets(occluder.area)) : AwtMapper.toPath(toOffsets(occluder.area));
144-
clipArea.add(new Area(smoothed));
148+
Area rhs = new Area(smoothed);
149+
if (rhs.intersects(s)) {
150+
clipArea.add(rhs);
151+
}
145152
}
146153
graphics.setClip(clipArea);
147154
applyOpacityConfig(pointLight.color());

0 commit comments

Comments
 (0)