sprites, transparency and deep rasters

   4875   7   0
User Avatar
Member
121 posts
Joined: July 2005
Offline
Hi all

I'm having having a hard time working with sprites, transparency and deep rasters. The sprites are shaded with some noise, and composite fine with the background. Now I want to render out a Pz plane for adding depth of field in halo. But in the Pz channel I see the complete sprites, and not just the noise, and this of course results in unusable depth of field.

What do I have to do to get this working correct?

Thanks in advance
Achim
User Avatar
Member
941 posts
Joined: July 2005
Offline
Hi Achim,

Pz is a global variable. This means it doesn't know anything about any transparency tricks you may be doing with the surface – it is calculated before your shader is even called (all globals are).

Two solutions come to mind:

1. Go back to the shader and export “the right thing”. That is to say: add an export float parameter (let's call it myPz) with a default value of, say, 1e+6.
Then inside the shader, you will assign it the correct (alpha-modulated) depth value (something like if(myAlpha>0)myPz=Pz; else myPz=1e+6;, or maybe a continuous range across the AA region, like myPz=fit(myAlpha,0,1,1e+6,Pz);), then use *that* variable (instead of plain Pz) for your deep raster layer.

2. If what you're after is nothing more complicated than the global Pz, modulated by “coverage” or “existence”, then there may be a comp solution. Multiply the Pz layer by the alpha channel (which you should convert to a float) of your RGBA image, and then comp the result over a 1-channel float image with a constant high number (sey 1e+6).

I haven't actually tried any of this, but I think there should be a solution lurking in there

Cheers!
Mario Marengo
Senior Developer at Folks VFX [folksvfx.com] in Toronto, Canada.
User Avatar
Member
121 posts
Joined: July 2005
Offline
Mario Marengo
1. Go back to the shader and export “the right thing”. That is to say: add an export float parameter (let's call it myPz) with a default value of, say, 1e+6.
Then inside the shader, you will assign it the correct (alpha-modulated) depth value (something like if(myAlpha>0)myPz=Pz; else myPz=1e+6;, or maybe a continuous range across the AA region, like myPz=fit(myAlpha,0,1,1e+6,Pz);), then use *that* variable (instead of plain Pz) for your deep raster layer.

Hey Mario, thanks very much, that sounds good. I'll give that a try, but there is one thing I am not sure about,
will the fit() approach result in identical depth values for points (at the same distance) when I comp
this pass and another (background) pass which uses standart depth map calculation?


Mario Marengo
2. If what you're after is nothing more complicated than the global Pz, modulated by “coverage” or “existence”, then there may be a comp solution. Multiply the Pz layer by the alpha channel (which you should convert to a float) of your RGBA image, and then comp the result over a 1-channel float image with a constant high number (sey 1e+6)

Thought about that soluation as well, but it unless I did something wrong, it won't work, because

Lets say there are 2 sprites which overlap, the one in the back is seen through the transparent areas of the one before it,
and when I multiply the Pz plane by the alpha, it has the depth info from the one in front of it, because the depth channel has
the complete sprites in it.


Gonna try option 1 now
Achim
User Avatar
Member
941 posts
Joined: July 2005
Offline
puma.snyder
Hey Mario, thanks very much, that sounds good. I'll give that a try, but there is one thing I am not sure about,
will the fit() approach result in identical depth values for points (at the same distance) when I comp
this pass and another (background) pass which uses standart depth map calculation?

It was just a thought for smoothing the edges of the noise (internal to the sprite, not the primitive edges that Mantra will AA for you), so that you don't end up with ratty-looking noise swirls. But we're talking about *depth* here, so, on second thought, that suggestion doesn't make very much sense… ignore :roll:

puma.snyder
Lets say there are 2 sprites which overlap, the one in the back is seen through the transparent areas of the one before it,
and when I multiply the Pz plane by the alpha, it has the depth info from the one in front of it, because the depth channel has
the complete sprites in it.

Right. Makes sense. It's option #1 for you then.


Cheers!
Mario Marengo
Senior Developer at Folks VFX [folksvfx.com] in Toronto, Canada.
User Avatar
Member
121 posts
Joined: July 2005
Offline
Too bad, this doesn't work either, because

if(myAlpha>0)myPz=Pz; >> this works fine

but

else myPz=1e+6 >> heres the problem

In this case myPz should have the value of Pz of the sprite behind it, and not 1e+6.


So there must be another way, but maybe I'm just heading in the wrong direction for what I am actually after.

In fact I want to create some kind of atmosphere which reacts to an Object passing by (I'll answer in the other thread over at odforce after some sleep). So for now I use a bunch of particles, and thought I could use sprites with a perlin noise pattern for rendering. When trying to add depth of field I ran into this problem. I assume for nearly every way of rendering this, I have to use some kind of heavily transparent objects, so there must be a way to do this :?: , or would you take a completely different approach :?:


Thanks again
Achim
User Avatar
Member
941 posts
Joined: July 2005
Offline
Hi Achim,

OK. Let's see if we can straighten out this Pz business….

After thinking about it a bit more, I realized you don't really need to create a separate parameter at all. Using Pz straight should work fine. It makes sense; really!

Pz is calc'd as you come into the shader. It's value is the depth of the current sample point. And the depth of the sample point, in the case of multiple transparent layers, is determined by the opacity of the preceeding layers. Opacity, in turn, is given by Of. Sooo… plain-vanilla Pz ought to work, provided that Of is set correctly.

But I believe you that you tried it and it didn't work, so I went ahead and tested it. Here's what I get:

The Geometry



The Noise


The Depth


That last one is just the straight global Pz (with blending on, natch), and Of is simply the raw noise value itself… nothing fancy.
Mario Marengo
Senior Developer at Folks VFX [folksvfx.com] in Toronto, Canada.
User Avatar
Member
121 posts
Joined: July 2005
Offline
Hey Mario, thanks again for taking the time to test it. I rebuild the scene and the shader, and you were right, the standart Pz contains now the correct values, before its was totally messed. ops:

Though this is still a little “rough”, but I guess thats unavoidable when having Z-depth with transparency. But for this case, where the sprites are quite small (and lots of them), it seems I can get away with it
User Avatar
Member
941 posts
Joined: July 2005
Offline
puma.snyder
Though this is still a little “rough”, but I guess thats unavoidable when having Z-depth with transparency. But for this case, where the sprites are quite small (and lots of them), it seems I can get away with it

Yes; those are the “ratty edges” I was going on about before.
One simple way to deal with them would be to first threshold Of so it doesn't compare to absolute-zero, but to some small (but non-zero) number (i.e: raise the floor of the noise). This would be equivalent to “eroding” those internal edges. Then in comp, you simply blur the grayscale “weight” image (the version after adjusting for the floating-point depth range), so as to blend between the layers. (I hope that description makes sense )

Hmmm… I *think* that should work… worth a try anyway.

Cheers!
Mario Marengo
Senior Developer at Folks VFX [folksvfx.com] in Toronto, Canada.
  • Quick Links