I set up a simple example to demonstrate my issue:
I have tried a bunch of things and nothing seemed to work perfectly.
I noticed alphaIndex + needDepthPrePass works until I move the camera to certain angles.
I made a RTT with a simple shader and it worked, but felt like this was a hack and not the right way to do things. I am concerned about performance and flexibility (if I had multiple characters each with their own RTT so that I could animate the invisibility effect).
I looked at Multi Render Targets too, but I’m not yet familiar with how they work.
Here are some pictures to help demonstrate what I mean:
If I could hide the red from this angle that would be great, it’s visible through the green here.
You would probably need to render the scene without the group then grab stencil pass or a mask, then capture the group full color in an RTT then draw it back onto the main scene with your transparency amount masked by the stencil or mask RTT you made.
I spent the last couple hours going through it. I simplified the code just so I can what was really happening.
Others may view that here:
I am not sure what the overall performance gains are with this versus what I had. I know this renders the groups separately, but I’m concerned about now having two render target textures now, and also constantly updating a ghost camera.
Using alpha/visibility still seems to be the most performant way, but this approach is interesting.
I decided to go with RTTs instead of transparency. I am doing it a slightly different way though. I realized I could implement other effects other than just transparency, such as glow, warp, etc.
Yuup! Once you understand the basics of what we did then it unlocks a ton of possibilities. Remember you can capture any kind of 3d buffer and convert the coordinates in your shader to do magic. Its all just passing data around so you can use it. You would be amazed how many effects actually happen in screenspace.
So there’s an issue with layer masks and animations.
BUT I managed to get it working with a depth renderer + an RTT. Essentially the code I posted earlier + a depth renderer + using the samplers you get from them in the GLSL.