chunky
chunky copied to clipboard
2.1 Glass reduces intensity of emitters significantly
Similar to https://github.com/llbit/chunky/issues/528 but with glass instead.
1.4.5

2.0beta6

2.1-274

2.1-308

Scene scenes.zip
I went back to see when that was introduced. It was when localIntersect for class was made to be false. Setting it back to true fixes this issue but we don't get refraction anymore and we can see the inside. So i'll have to look further
@aTom3333 We would need to remember that the ray already hit a glass block of that color (previousMaterial of the ray) and then skip intersection in the intersect method of the glass model. This could make glass blocks behind glass blocks (glass air glass, like in your image) invisible, I'll have to try it out.
Refraction shouldn't be affected by this change. :thinking: It works fine for e.g. slime blocks which also use local intersection.
By the way: localIntersect means that instead of using a cube with the block's texture, the intersect method of the block gets called.
If localIntersect is true then the ray goes through the glass instead of generating an intersection that can refract. This is because TexturedBlockModel.intersect(…) makes a decision about intersecting the glass block based on the texture alpha but not the refraction index.
https://github.com/llbit/chunky/blob/ed0d57550d6f836690b4ae5ade465f2b7eac42ed/chunky/src/java/se/llbit/chunky/model/TexturedBlockModel.java#L60-L65
As you can see that only happens when the texture is fully transparent which is probably why refraction still works with other blocks like slime. Maybe TexturedBlockModel should intersect even when the texture alpha is zero and let the path tracer decide what to do based on the texture alpha and refractive index?
EDIT: I've experimented a bit with removing that if condition and I'm correctly getting refraction (and that emitter light reduction bug) no matter the value of localIntersect for glass, though there is an inconsistency with ray bounces inside the glass.
I think this means the problem here is a loss of energy with refracted rays.
localIntersect = false (same as OP)

localIntersect = true
Notice the darker ground under the glass.
From my testing it seems like the effect is most significant when the light source is directly adjacent to the glass.

