Skip to content

Commit 0d030a6

Browse files
committed
Fix reflection on transparent areas of glass panes.
1 parent 88e491b commit 0d030a6

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

chunky/src/java/se/llbit/chunky/model/minecraft/GlassPaneModel.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,53 @@ public Quad[] getQuads() {
173173
public Texture[] getTextures() {
174174
return textures;
175175
}
176+
177+
/**
178+
* Intersects this glass pane model with the given ray.
179+
* <p>
180+
* Unlike {@link QuadModel#intersect(Ray, Scene)}, this method also registers
181+
* hits in the transparent regions of the quads. In addition, biome tinting is
182+
* disabled as a minor optimization, since it does not affect glass panes.
183+
*
184+
* @param ray the ray to test for intersection
185+
* @param scene the scene providing context for the intersection
186+
* @return true if the glass pane was hit, false otherwise
187+
*/
188+
@Override
189+
public boolean intersect(Ray ray, Scene scene) {
190+
boolean hit = false;
191+
ray.t = Double.POSITIVE_INFINITY;
192+
193+
Quad[] quads = getQuads();
194+
Texture[] textures = getTextures();
195+
196+
float[] color = null;
197+
for (int i = 0; i < quads.length; ++i) {
198+
Quad quad = quads[i];
199+
if (quad.intersect(ray)) {
200+
color = textures[i].getColor(ray.u, ray.v);
201+
ray.t = ray.tNext;
202+
if (quad.doubleSided)
203+
ray.orientNormal(quad.n);
204+
else
205+
ray.setNormal(quad.n);
206+
hit = true;
207+
}
208+
}
209+
210+
if (hit) {
211+
double px = ray.o.x - Math.floor(ray.o.x + ray.d.x * Ray.OFFSET) + ray.d.x * ray.tNext;
212+
double py = ray.o.y - Math.floor(ray.o.y + ray.d.y * Ray.OFFSET) + ray.d.y * ray.tNext;
213+
double pz = ray.o.z - Math.floor(ray.o.z + ray.d.z * Ray.OFFSET) + ray.d.z * ray.tNext;
214+
if (px < E0 || px > E1 || py < E0 || py > E1 || pz < E0 || pz > E1) {
215+
// TODO this check is only really needed for wall torches
216+
return false;
217+
}
218+
219+
ray.color.set(color);
220+
ray.distance += ray.t;
221+
ray.o.scaleAdd(ray.t, ray.d);
222+
}
223+
return hit;
224+
}
176225
}

0 commit comments

Comments
 (0)