Home Unreal Engine

Controlling edge falloff on a worldspace projected texture

polycounter lvl 11
Offline / Send Message
Progg polycounter lvl 11
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.

upvectorsnow.jpg

Uploaded with ImageShack.us

Replies

  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Did you try connecting to a Power node as to control the sharpness of the falloff? Either that, or try a Clamp node and see which one suits your needs better.

    Forgot to mention, you do this to the Z-Mask nodes before connecting to the Lerp Alpha.
  • Progg
    Options
    Offline / Send Message
    Progg polycounter lvl 11
    Well that math is already plugged into a constant clamp, otherwise it doesnt work at all. The power does help to control the falloff and I did try that, but I'm trying to figure out how to add a black and white texture (mask) to the edges of the projected texture only
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Hmm, in that case, I would most likely either try a Position/Eye Vector node or Fresnel node, I'm not exactly sure how you would be able to limit to the lower edges of the projection.
  • sprunghunt
    Options
    Offline / Send Message
    sprunghunt polycounter
    I think what is being suggested is that you clamp the texture to create a mask that isolates the mid ranges of the dot product. Then you can use this to apply your edge texture. That's one way to do it.

    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.
  • Progg
    Options
    Offline / Send Message
    Progg polycounter lvl 11
    Thanks for that link I'll give it a read through.
  • Vailias
    Options
    Offline / Send Message
    Vailias polycounter lvl 18
    Progg: is that little set plugged directly into the lerp? It will be easier to see where your edge is, mathematically speaking, if you post more of the shader network.
  • Progg
    Options
    Offline / Send Message
    Progg polycounter lvl 11
    @vailias It isn't much more than whats shown. Just a multiply which the higher the number the sharper and worse the falloff is, and the addition with a -constant between -1 and -0.1 which controls the quantity of the texture projected on each upfacing poly.

    snowshader.jpg

    Uploaded with ImageShack.us
  • Vailias
    Options
    Offline / Send Message
    Vailias polycounter lvl 18
    funky.. you're not actually using the model's normal map to control the deposits. easy to plug that in later anyway.
    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. :)
  • Progg
    Options
    Offline / Send Message
    Progg polycounter lvl 11
    Yeah that's what I ended up doing. That's why I only posted those top 3 nodes in the first screenshot. :P
  • LoTekK
    Options
    Offline / Send Message
    LoTekK polycounter lvl 17
    What I did (for a different purpose) was to basically remap the entire range to a smaller value range (works a bit like levels, I guess). It's a couple more nodes than you have, but it's also [arguably] more predictable to control.

    relevel.jpg

    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)
  • Vailias
    Options
    Offline / Send Message
    Vailias polycounter lvl 18
    Alright, Got it. Minor hiccup here or there along the mathematical road but I have a solution. Had to remember how to play with quadratic equations.


    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.
    UDK_EdgedDepositShaderNetwork.jpg


    Showing how important it is to have a good edge mask. :) (snowy teapot in the foreground)
    UDK_DepositShader_GreentoothMask.jpg

    And an example of what this can look like with a more natural falloff texture.
    UDK_EdgedDepositShader_GoodExample.jpg


    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.
  • LoTekK
    Options
    Offline / Send Message
    LoTekK polycounter lvl 17
    Sexy, thanks for sharing that.
    (-(x-c)^2)^n

    What's with the first minus? Won't that simply get nullified once you square it?
    [edit]nevermind, I read the parentheses wrong :p[/edit]
  • Vailias
    Options
    Offline / Send Message
    Vailias polycounter lvl 18
    video. :) Just moving one parameter off screen, the edge threshold, till about the middle of the video, when I pull down the final snow mask exponent to deep freeze the rocks.

    [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. :)
  • rasmus
    Options
    Offline / Send Message
    I'm probably totally putting my foot in my mouth here, but couldn't you also create two dot products, multiplied to have different "reach", and subtract one with the other to get the edge mask? Another slightly different idea you could do is map an RGB gradient to the dot product and use that as a mask for different layers... Valias, my brain is tired, but aren't the greentooths supposed to show up on your cliffs as well? :)

    EDIT: OK, i see dem tooths :)
  • Progg
    Options
    Offline / Send Message
    Progg polycounter lvl 11
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Thanks for sharing that Valias.
  • Vailias
    Options
    Offline / Send Message
    Vailias polycounter lvl 18
    @rasmus: not sticking your foot in your mouth. I started with something similar in one attempt. Using a dot product and it's inverse slightly offset by exponent, and multiplied together. It does create an edge area but the edge is very dim and doesn't blend well with a sharp edged core area.

    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.
Sign In or Register to comment.