MENOZ Posted July 25, 2008 Share Posted July 25, 2008 hello, I wanted to know how the smoke shader is done, so i'm diggin into the VOP network of the Billowy_smoke default material. i found that a global varialbe dPdz (change in position with depth) is multiplied by a negative density value. what the dPdz global variable is? thank you! Quote Link to comment Share on other sites More sharing options...

Mario Marengo Posted July 25, 2008 Share Posted July 25, 2008 I wanted to know how the smoke shader is done, so i'm diggin into the VOP network of the Billowy_smoke default material.i found that a global varialbe dPdz (change in position with depth) is multiplied by a negative density value. dPdz is just what you say: the amount by which P changes w.r.t the current (not unit, if it behaves like dPdu) change in depth (z). That negative exponent is modeling exponential decay (in intensity) over distance due to absorption, which in this case is proportional to density. The argument to exp() is made negative (on purpose) so that the curve is unity at zero and decays gradually with distance. If it were positive, it would start at one and increment exponentially with distance (no good in this case). Make sense? Quote Link to comment Share on other sites More sharing options...

MENOZ Posted July 25, 2008 Author Share Posted July 25, 2008 (edited) ok, i think i understood what is the dPdz variable. thank you. but now i don't understand the rest. can you explain me what is the exp function? at first i was thinking it was something like a power of a number, like this: 2^{3} = 8 so the exp VOP use my input as exponent, but why if i use a negative exponent it should return a number between 1 and 0 ? there is somethig that i don't understand.. Edited July 25, 2008 by MENOZ Quote Link to comment Share on other sites More sharing options...

Mario Marengo Posted July 25, 2008 Share Posted July 25, 2008 ok, i think i understood what is the dPdz variable. thank you.but now i don't understand the rest. can you explain me what is the exp function? at first i was thinking it was something like a power of a number, like this: 2^{3} = 8 so the exp VOP use my input as exponent, but why if i use a negative exponent it should return a number between 1 and 0 ? there is somethig that i don't understand.. The mathematical constant "e" is just a number (2.71828...), like "pi" (3.14159...). So raising "e" to some exponent is no different than doing the same to any positive number. It's just that "e" happens to show up a lot all over the place (like "pi"), especially when modeling natural things like growth and decay, so it gets to have a special name all to itself . The function "exp()" does just that: it raises "e" to some power (the argument is that power). So writing "exp(-5)" is identical to writing "pow(2.71828...,-5)" -- and the reason I keep adding dots after the number is that "e" (like "pi") has a possibly infinite number of decimals (it's another "transcendental" number like pi). Raising a number to a negative exponent is the same as the inverse of raising the same number to a positive exponent: e^(-5x) == 1/e^(5x). So when the exponent is negative, the value decays because "1/x" approaches zero as "x" approaches infinity. With a positive exponent the value grows because "x^pow" grows in relation to "x" -- i.e: as "x" grows, so does "x^pow" grow. HTH. Quote Link to comment Share on other sites More sharing options...

MENOZ Posted July 26, 2008 Author Share Posted July 26, 2008 (edited) The mathematical constant "e" is just a number (2.71828...), like "pi" (3.14159...). So raising "e" to some exponent is no different than doing the same to any positive number. It's just that "e" happens to show up a lot all over the place (like "pi"), especially when modeling natural things like growth and decay, so it gets to have a special name all to itself . The function "exp()" does just that: it raises "e" to some power (the argument is that power). So writing "exp(-5)" is identical to writing "pow(2.71828...,-5)" -- and the reason I keep adding dots after the number is that "e" (like "pi") has a possibly infinite number of decimals (it's another "transcendental" number like pi).Raising a number to a negative exponent is the same as the inverse of raising the same number to a positive exponent: e^(-5x) == 1/e^(5x). So when the exponent is negative, the value decays because "1/x" approaches zero as "x" approaches infinity. With a positive exponent the value grows because "x^pow" grows in relation to "x" -- i.e: as "x" grows, so does "x^pow" grow. HTH. thank you very much for the explanation! i't a lot clearer now. flollowinf the VOP network i find a complement VOP. now.. with this function my decaying curve should now grow, approximating to 1 instead of 0. right? so now i have to understand how to visualize my curve in 3d space. i mean, say i have a sphere, as i go inside the sphere the value of my density raises from 0, to 1. it's right? the dPdz is the depth as seen from the camera, or from the normal fo my object? it's related in some way to the UV coordinates? (i think no ) thank you! Edited July 26, 2008 by MENOZ Quote Link to comment Share on other sites More sharing options...

Mario Marengo Posted July 26, 2008 Share Posted July 26, 2008 flollowinf the VOP network i find a complement VOP. now.. with this function my decaying curve should now grow, approximating to 1 instead of 0. right?so now i have to understand how to visualize my curve in 3d space. i mean, say i have a sphere, as i go inside the sphere the value of my density raises from 0, to 1. it's right? Yes, it takes the complement because it needs to convert decay due to absorption (or out-scattering in this case) to opacity, which is a complementary concept. Up to just before the Complement VOP, the code is saying "Less and less energy remains the farther we move away from the sample point, because the medium is scattering it away from the path". And after the Complement VOP, the code says "The farther we move away from the point, the more occluded that point gets -- it becomes harder and harder to see because more stuff gets in the way". Two sides of the same coin, or two interpretations of the same process (you can think of the first one as "visibility" and the second one as "opacity"). OK. now I need to convince you that modeling opacity as the complement of e-to-some-negative-power is not the same as using e-to-some-positive-power. I'll start by asking you to look at the second graph I posted earlier (the one for the positive exponent e^{5x}). Look at the values on the Y-axis, and note how it's already reached ~150 after only a singe unit distance away from zero. And also there, but harder to see, is the fact that when x=0, y=1 (not 0). So... if someone were to interpret that second graph as "opacity", they would be saying "When I'm directly on top of the sample point (x=0), I can't see it at all because y=1 (opacity=1), and as I move farther away from it, I can see it progressively less than not-at-all -- in fact, at one unit away from it, I can see it 150 times less than not-at-all! (opacity=150)"... and someone listening would naturally conclude that the speaker was blind On the other hand, if you try to visualize the graph for the complement of 1/e^{-5x} ( that is to say: 1 - (1/e^{-5x}) ), you'll see that when you're at the sample point (x=0), you see it perfectly clearly (opacity=0), and as you move away from it, you see it less and less clearly because opacity is progressively increasing towards 1 (not 150 and beyond). Make sense? the dPdz is the depth as seen from the camera, or from the normal fo my object? it's related in some way to the UV coordinates? (i think no ) dPdz is the size of the step that the volume renderer (yes, Mantra has a separate engine for volumes) is taking along some path through the volume. This path is usually along the camera ray (I), but it could be any other direction as well. For example, if the shader traces a shadow ray at some point, then the next instance of that same shader will be taking steps (with likely differently-sized dPdz) along the shadow path (and evaluating your shader for Of, not Cf, because shadow rays only care about opacity), not the camera path... and so on for every ray spawned by your shader or elsewhere. UV coordinates don't play any role in any of this. Quote Link to comment Share on other sites More sharing options...

MENOZ Posted July 26, 2008 Author Share Posted July 26, 2008 thank you so much for your explanation! OK. now I need to convince you that modeling opacity as the complement of e-to-some-negative-power is not the same as using e-to-some-positive-power. well no, you didn't have to convince me about this your explanation is much appreciated! thank you! i used the new ramp parameter to model the opacity of my volume, just to try, even if it's not phisically correct it's cool, and you have a great control over the opacity. it's similar to what you can find on maya fluid Quote Link to comment Share on other sites More sharing options...

## Recommended Posts

## Join the conversation

Note:Your post will require moderator approval before it will be visible.