Hello Guest

Author Topic: Weird transparency question  (Read 3920 times)

Grebenots

  • Newbie
  • *
  • Posts: 9
    • View Profile
Weird transparency question
« on: May 20, 2013, 04:12:55 am »
You might not have heard of this before.

I have 3 sprite layers if you will (not layers, but 3 sprites with different z values).  Anyways, we will call them (tree, cloud, sun).  Now tree is always to be in the background.  The cloud, will travel horizontally across the screen in front of tree, with it's child the sun, completely hidden behind it.

Now the cloud needs to have transparency, because the tree needs to be seen through the cloud.  However, the sun needs to remain hidden behind the cloud, despite this.

Is there any way to do this?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Weird transparency question
« Reply #1 on: May 20, 2013, 09:56:19 am »
Not without any work on your part.
The easiest way to do this is to set up the scene in a way that is most convenient for most cases - the likely solution will mean the sun is on top of everything. What you need to do is perform a RayCast from the camera to the sun, or from the sun towards the camera, whichever is better. The result of the raycast = "Is there something in front of the sun". You can use tags to just hit clouds. Now that you've got this information, the next thing to do is to scale the sun to 0 if its not visible. Do it over time, and you've got yourself something which doesn't look completely horrid ;)

Grebenots

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Weird transparency question
« Reply #2 on: May 20, 2013, 03:20:11 pm »
What I ended up doing, is create a child cloud with alpha 255 and put it behind the other cloud but in front of the sun.  It still allows the top cloud to be transparent to the tree and also hides the sun.  It however messes with the transparent look when it's just over my background, but overall, it looks good.