playMaker

Author Topic: How to Occlude With an Invisible Object?  (Read 2260 times)

Stinkhorse

  • Playmaker Newbie
  • *
  • Posts: 20
How to Occlude With an Invisible Object?
« on: January 30, 2016, 02:46:40 PM »
I have a hunch this is going to be a "Layers!" answer, but here's the breakdown of what I'm trying to do:

I have a static background image that is constant in the scene, and all the images that make up the stage are all white and semi transparent. Against the dark background, the level of transparency versus opacity becomes a shorthand for shadows and light.


Eventually that flicker will be powered by torch light.

So the trick I'm trying to solve for is how to obscure objects as they step back in space, while still displaying my unified background? My initial thought is a separate object drawn to the shape of the object in front, and then specifically tied to the object's that it will be obscuring behind it telling each of them not to draw. That is a huge amount of by-hand-work considering the entire game has this style, and the environments are intended to be parallaxing, zooming in and out, and having characters moving across it all. I need something a little more automated.

My next thought is a more abstracted solution, where I have a prefabbed "environment object" with a childed "obscuring object" and I have one of them for every layer I intend to make use of, specifically targeting each of the layers they are to obscure. Then I swap in and out the various images I need attached to them, and that solution doesn't seem quite as bad.

The ultimate solution would be a one time shader applied to the obscuring object, so that it doesn't matter where or how I place it; anything behind it gets obscured. That would allow me to have a single prefab environment object that I can place anywhere in the environment in 3D space and just have to let the game handle the occlusion and parallaxing rather than managing it by hand.

Any suggestions?

Stinkhorse

  • Playmaker Newbie
  • *
  • Posts: 20
Re: How to Occlude With an Invisible Object?
« Reply #1 on: January 31, 2016, 03:43:57 AM »
Still working through this problem. I don't know if I have a solution but I have an idea. If anyone knows if this will work or not let me know.

First some further visual examples of my goal:





Potential Solution:
Right now I have my Main Camera looking at my scene, and a separate camera looking at my stationary background color. The effect is awesome, and setting that up gave me the idea to make a 3rd camera containing all the scene objects and player. Instead of trying to get all the parts to talk to each other, and tell who needs to obscure who while still maintaining the transparency, I can have each object in the be two paired items: a transparent visual object and a duplicate shape with a solid color behind it. All the objects would share this same color, including a full background screen. Let's say magenta for proper developer eye strain. As the third camera sends all the combined objects, with all their transparencies to the main cam, it has a script telling the resulting picture that everything magenta is 100% opaque. This would leave a final third image placed over the green BG Color that's fully formed, properly transparent, and manipulable as I need it to be.

This seems like a plausible implementation. If there are holes in this idea let me know and I'll try another tack.

Stinkhorse

  • Playmaker Newbie
  • *
  • Posts: 20
Re: How to Occlude With an Invisible Object?
« Reply #2 on: February 01, 2016, 09:19:02 PM »
I thought I had a lead with Chroma Keying a scene, and I suspect it still might work, but right now I'm kind of stumped on how to move forward with this.

Is there a postprocess way to get a color on screen, and then before rendering the frame, swap out everything that's using that color with transparency or a view from another camera?

Stinkhorse

  • Playmaker Newbie
  • *
  • Posts: 20
Re: How to Occlude With an Invisible Object?
« Reply #3 on: February 02, 2016, 10:38:58 PM »
Ok, at this point I have a pretty clear idea of what needs to be done, and it's pretty much the complete opposite direction from where I was looking. I also lack the knowledge of HOW to do it.

The suggestion I was given was to create an art asset with 100% opaque white for the main channel to create the visual of the object. Then I would create the object's occluding shape and pencil outline with the alpha channel. The background color image would then be projected onto the object's channels at varying opacity levels. For the alpha channel it would be 100% because it needs to be opaque to occlude the layers behind it. For the white object it would depend on where it is in the scene (closer would be a lower % to make it whiter, further away would be a higher percentage to make it darker).

It's a pretty simple solution technically to describe, but it's completely outside my understanding to even begin guessing how I would implement it. Is there a way to do this in an FSM or are we in shader territory here?