Basically I am trying to project a texture onto a mesh based on world space.. which works fine. I'm able to add by a negative constant to control how much of the texture is projected onto the up-facing geometry normals, and multiplying by a constant controls how intense the effect is.
The problem I'm trying to solve is how to control the edge falloff of the effect with a mask while still keeping the interior of the effect in full power... (i.e using a mask to give the edges of the projected texture a better shape without muting or diluting the majority of the texture)
If I simply multiply by a mask it obviously masks out the entire projected texture, whereas I really want to concentrate this mask only along the edges.
Anyone have any suggestions? Thanks in advance!
This is a really simple mock-up in UDK but it illustrates the effect I'm after.
These shader nodes are controlling the alpha of a LERP.
Uploaded with
ImageShack.us
Replies
Forgot to mention, you do this to the Z-Mask nodes before connecting to the Lerp Alpha.
Here's a tutorial which shows you how to do this kind of thing with vertex colour:
http://www.laurenscorijn.com/vertex-blending-snow.html
you can essentially use the dot product instead of vertex colour.
Uploaded with ImageShack.us
I spent some time last night chasing down a solution.. got a few close things, but nothing that worked exactly right. I have a similar desposit example shader made up, but I was using an IF based threshold to control the hard edge of the falloff.
I have another idea for getting the edge area mask but I'll need to get home and get UDK up and running to test it out. Update coming later.
Also FYI the way your math is running right now you could delete the add node and just half your multiplier and get the same result.
Basically it'll take your image and remap 0-1 to Min-1. (The Constant clamp node is 0-1). The smaller the Min value, the softer the transition. You can then take that output and apply your multiplier to alter the overall strength of the mask.
I haven't gotten around to figuring out the math to remap to an arbitrary range (ie. Min to Max, instead of Min to 1), but I'll probably sort that out later today when my brain wakes up from this lunch coma.
(I was using this for vertex color, but for the diagram I stuck in a texture to actually illustrate the output)
So for an edge mask what we're essentially looking for is to modulate a hard edged mask with a more natural looking one at a specific point. Namely the point right close to zero, where our initial mask goes to nearly or totally black.
The dot product of the surface normal of a sphere and the world up vector creates a smooth gradient, identical to the number line, with zero sitting on the sphere's equator and 1 being at the north pole. For the edge of this initial case we know its at 0. So what we need to do to create our textured edge mask, is to mask the texture with the edge area. Basically we need to have our falloff curve be white where our edge is, falloff smoothly from there to black so we can add in the main body falloff mask.
Again with the pure dot product case we need 0 to be 1, but both 1 and -1 to be 0. An inverse parabola. So we take our edge mask value to be -(x)^2 where the value of x is the value of the dot product we just set up.
So we can control where the edge is we can use a simple threshold value. Just a number between -1 and 1. Best between 0 and 1. The main deposit area portion of this is pretty straight forward.
The threshold moves our edge area, so we need to move our input to the edge mask creator by the same value. so we end up with -(x-c)^2) for our edge value, where C is the edge threshold value. This basically just moves the "point" of the parabola to the exact edge threshold value. The slope of the parabola, which is the relative narrowness of the edge mask, can be controlled with an additional exponent. so our full edge mask equation is (-(x-c)^2)^n) where n is our edge falloff power.
So then you multiply your hard edged main deposit mask with the inverse of this edge mask (So the white parts are where the edge ISN'T) to get a smooth edged, but still tightly clamped main mask. Then you multiply the edge mask with your chosen masking texture, and add that result to the recently created smooth edged main deposit mask, to get a more interestingly edged deposit texture.
Pictures now. For my edge mask I chose a 256x256 photoshop clouds filter texture. I dressed it up a bit with multiple layers to get something resembling a multi octave perlin noise function.. Its acceptable for this example. I also used a white greentooth on a black background to better illustrate where the edge area is and how it intersects the main body.
Heres the shader network with commentary.
Showing how important it is to have a good edge mask. (snowy teapot in the foreground)
And an example of what this can look like with a more natural falloff texture.
Pardon the overdone specularity, I wanted to ensure the materials read separately in these shots.
What's also fun is ramping up the final mask exponent. Its like watching snow melt.
Hope that work for you.
What's with the first minus? Won't that simply get nullified once you square it?
[edit]nevermind, I read the parentheses wrong [/edit]
[ame]http://www.youtube.com/watch?v=PWpqwVQYosw&hd=1[/ame]
Edit: I should mention that the fidelity of the edge is totally dependent on the greater of the resolution of the normal map, or the polygon density. Basically you need fine normals to get fine normal based edge creation.
EDIT: OK, i see dem tooths
The multiple layered thing could work well. Just have to calculate a mask per channel anyway. The dot product returns a floating point scalar value for any dimension of vector you put into it.