Search Unity

Funny switches between transparent and non-transparent

Discussion in 'Shaders' started by jashan, Mar 20, 2008.

  1. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Hi there,

    not perfectly sure this is the right forum (might also be UnitySupport), but I'm trying to get a better understanding of how shaders are handled in Unity (yesterday, I did my first few experiments with shaders, so you can call me a complete noob in this area ;-) ).

    The setup I have is as follows (and the setup might be the problem):

    • - Plane with the MirrorShader from the UnifyWiki to cause "reflective look"

      - Floor-Plane with a Transparent/Specular level right above that (0.01 above, to be exact); this creates the raster (blue with yellow lines). The texture has an alpha channel, so the "mirror" from below shines through, also the main color has opacity 75% to let the mirror shine through a little more than what is defined in the alpha channel (at first, I tried putting that texture on the "mirror plane", but that completely failed to look he way I wanted it)

      - Floor-Smoke with Particles/Alpha Blended, the "center" of the smoke is "solid" but through the alpha channel, the edges "bleed out" to transparent, color animation goes from fully transparent to fully opaque and back. Currently, the renderer is set to Billboard, I might go back to "Sorted Billboard" when the FPS is high enough, which would probably remove some of the artifacts - but these are not what I'm worried about. What is important is that people can't "see through" the smoke as long as it's dense. This is really important because the idea of the smoke is to make the walls hard to spot for other players - if this suddenly becomes transparent, that give players with this "bug" an advantage they should not have.

      - Walls are just specular (no reflections there)

      - These "power-up boxes" with Transparent/Diffuse shader, center with text is fully opaque, edges are fully transparent, main color is fully opaque (Opacity = 100%)

      - up to 3 point lights (depending on FPS) and one directional light (switched off when all 3 point lights are on); render mode is always auto

    The funny behavior I'm getting is illustrated with the screen shots below. I had noticed similar things before, but extremely rare, but now it's kind of severe (since I added the reflective floor): More or less "randomly" (to me), the smoke and the power-ups become very transparent; much more transparent than they are supposed to be (and as they are most of the time). It might be distance related, or dependent on the camera angle: Usually, when I get close to the power-ups, they become "solid". With the smoke, it's harder to reproduce and find any solid pattern.

    What am I doing wrong here? Btw, this is on a Mac Pro with ATI Radeon X1900 (I still need to check how this looks on PCs and other machines ;-) ). I'll post V0.85 of the game when it's ready ;-)

    Any insight (or pointer to documentation on what exactly happens here) would be appreciated... Could that by like a Z-Buffer issue or something like that? If so, how would that be fixed?

    Sunny regards,
    Jashan
     

    Attached Files:

  2. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Ok, cool - got that one settled :)

    The problem was:

    Transparent shaders above one another are asking for trouble, it seems ;-)

    The solution I'm using now is my first own (kind of) shader. I took the MirrorReflection shader and add my texture onto it with its alpha channel. I needed to do some tweaking on the alpha-channel of that texture to get the result I was looking for, but I like the way it looks now...

    The "important trick":

    Code (csharp):
    1. SetTexture[_ReflectionTex] { matrix [_ProjMatrix] combine texture }
    2. SetTexture[_MainTex] { Combine texture lerp(texture) previous DOUBLE }
    It's not exactly what I wanted - actually, I would have liked to use the Specular (aka Glossy ;-) ) shader with it. But that comes with a lot of CGPROGRAM-stuff which I better don't start messing with... for now ;-)

    Sunny regards,
    Jashan