To get around this most objects draw to two buffers, the back buffer and a second buffer that can then be safely read by the glass objects. This has some downsides and might want to be reworked eventually, but for now its how I handle it. It does mean that my pixel shaders for everything have to explicitly output to two different buffers. The weirdness comes into play in that its perfectly possible for my pixel shader to completely ignore one of the two buffers and just dump to the 0-indexed one. In fact, this has happened a few times when I start reusing an old shader I had written earlier. I had arbitrarily chosen the texture that the glass draws from to be bound to this slot, and the back buffer to be the 1-indexed slot, which means that any objects drawn with this shader don't show up on screen. Uuuuunnnless you look through any glass object. Then bam, they show up all warped.
![]() |
| I drew a giant blue triangle, because why debug with anything more complex that literally necessary. |
This is actually an issue I've run into a few times now, as a week or so passes and I forget that some of the shaders kicking around my git client are outdated. This is the sort of issue I stare at confusedly for a minute and immediately remember past-me's efforts. This time however the issue was much more insidious, and tied into another bug I've been dealing with. The above picture is nicely framed to show off the view of the triangle. What I actually saw when trying to debug the problem was this:
You may notice that it is not a triangle. It's actually a little curve thing wind-sail looking thing. Also if you look closely there's a couple blue strips continuing on around the thing. Also whole chunks of the glass funnel are just missing and see through! What is going on!
Turns out this can be blamed on the depth buffer. What was happening is that the blue triangle was being "drawn" during my first render pass, but just to the glass's reference texture. The fact that it didn't show up in the back buffer didn't stop it from marking its depth in the depth buffer though, so when the second render pass went through and drew all the glass the parts of the funnel that were "occluded" by the invisible triangle weren't drawn at all. Except for the tiiiny bit of funnel that happened to be sticking through it and thus passed the z-test. So the blue shape is actually a plane intersecting a cone, technically making it a section of a parabola. Or maybe a hyperbola, depending on if the funnel is slightly tilted.
Also, the blue stripes. Parts of the funnel not behind the triangle, but close enough to refract from the position it wrote to on the glass reference texture. Yes, this means the glass is refracting something in front of it not behind it. I'll get to it later. Probably. Really should make a bug list somewhere or something for all this technical debt I'm racking up.
In any case, this is what things look like after I've fixed the shader.
Big 'ol blue triangle. Just sitting there. All I wanted to do was draw a simple triangle to test a new model loader, but instead I get to debug shaders and deal with render target issues.
But, the good news, now I know why I can see through the tops of my bottles even though I totally sealed the mesh! Hint: it's exactly what I just talked about!




No comments:
Post a Comment