Home Unreal Engine

UDK - Material - Rotate the Pan

polycounter lvl 12
Offline / Send Message
Ace-Angel polycounter lvl 12
Hey to all,

I have been trying to make a material in which I have a texture that Pan's, however, I wasn't too happy with the Pan's direction, so I decided to rotate the direction in which it Pan's.

However, for some reason, it seems like I have forgotten how the blighted function works in me telling the material in which direction to Pan, anyone could tell me how it's done?

I recall it had something to do with adding.

Cheers and ciao.

Replies

  • Dan!
    Offline / Send Message
    Dan! polycounter lvl 6
    the panner nodes properties should have U and V direction available when you click on the node itself.
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    you need a texpanner node. Should be self explanatory once you put it in and look at the properties.
    feed the output into your textures UV's
    Rate is uv units per second. Positive U is right to left, positive V is up to down.

    You can also rotate it in the shader. Use a rotator node, plug that into the uv input for the texpanner. Leave the center at 0.5, and rate to 3.141592, then plug a constant into time. every 0.5 value of the constant = 90 degrees rotation.
  • thiel_joe
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Strange, I could have sworn I tried this exact same method, guess I mixed up the positions of the functions (EI: Put in Panner before Rotate).

    Thanks alot guys, worked like a charm.

    EDIT: Hmm, I was wondering if it can be used for the Normal Map also this function? I just tried it, and for a lack of better terms, my normals information get's flipped when I spin it 180.

    Is there anything I can do to avoid this issue?
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    um.. yes your normals will be flipped when you spin it 180. I didn't think you'd be doing it to a normal map. If your texture is symmetrical about its center then you shouldn't need to rotate the normal map.

    If you need to you can add 1 to your normal map, multiply it by -1 then add 1 again to invert it. (since its from the range of -1 to +1)

    And yes if you put the panner before the rotate it will first move the UV's THEN rotate them. This is evaluated for every frame, so you'll get some really funky behaviour.
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Thanks Valiias for the response, much appreciated.
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Hey guys, quick question, is there a way to control the XY of the Panner and Rotation through a Parameter for a MaterialInstance? For example, I would like to Pan on the X axis, while being able to control it through the MaterialInstance, but so far no dice, I was able to control the UV tiling, but not the other nodes.

    unled1frf.jpg

    Cheers and sorry for double post.
  • sprunghunt
    Offline / Send Message
    sprunghunt polycounter
    Ace-Angel wrote: »
    Hey guys, quick question, is there a way to control the XY of the Panner and Rotation through a Parameter for a MaterialInstance? For example, I would like to Pan on the X axis, while being able to control it through the MaterialInstance, but so far no dice, I was able to control the UV tiling, but not the other nodes.
    .

    To do this I'd set up a manual panner. A panner is just UV's added to time. This way you can insert all kinds of parameters into the shader.
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Interesting, so basically it will be ((Time * Append (Mask_Red# & Mask_Green#) + UV), right?

    Awesome, and I was able to keep it Scalar and not Parametric since prior it's faster.

    However, I'm still unable to get rotate correctly. I created a Radian to Degree workaround with the which is essentially ((# * Pi) / 180), but I think it's causing me some issues. What's the best way to create a manual rotate originally so I can control the XY Centers?
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    :) And here we go into linear algebra.

    Some basic concepts you'll find handy.

    Vectors and scalars play nicely. Any basic aritmetic operation between a vector and scalar applies the operation to each element of the vector.
    Vector vs vector operations require the same number of elements, as their elements are matched up for the operation.

    an off center rotation of a texture is a combination of a movement (translation) of where you want the center to be to the origin, rotating it by how much you want to rotate, then moving it back.

    So for a totally custom rotation setup you'll need to get into some matix multiplication, which, while a fun way to kill time (if you like number crunching), is a bit tedious to set up as unreal nodes.

    From what I can gather that you are trying to do is have a texture you can rotate to some angle, at some arbitrary centerpoint, then pan it in an arbitrary direction.

    (I'd make you a digram but I have no UDK here. :( Work blows. ) So here's a text solution.

    Custom Rotation Block
    {
    UV coords node & 2 vector [centerpoint] -> add node -> rotator (center at 0,0 rate at 1), Scalar[rotation angle] with degree to radian conversion nodes into rotator time
    [centerpoint] * -1 and Rotator_out -> Add }

    Pan section
    {
    TIME, 2vector {Pan Rates) -> Multiply -> Add to, custom Rotation Block output
    }
    -> texture UV's

    Also Ace, you're definitely inspiring me to make a set of video tutorials on shader mathematical concepts, not just you though, but it's a helpful reminder that not everyone who digs into making shaders and effects has dug into linear algebra and vector mathematics.
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Haha, glad to have been of newbie service.

    Also, thank you for all the help, really good stuff, and much appreciated mate.

    You're pretty much spot on the issue, however, I'm essentially trying to make a Switch between two modes of rotating.

    One is a time controlled, essentially it rotating normally, around the axis. Another is, as you said, Rotate by n degree and Pan.

    I was able to tame the Pan parameters, so as Sprung said, I can do anything I want to do with it now, but Rotator is a no go since everytime I try something, it end up with a new issue, even having some kind of sine movement in my rotate on the UV scales.

    Just to post an image of what I mean since I got dizzy from all the spinning, gonna be a while before I go back and try out your solution.

    asdpc.jpg
  • sprunghunt
    Offline / Send Message
    sprunghunt polycounter
    looks great but you don't need to append two constants together all the time. You can just use a 2 constant.
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Haha, true, I will keep that in mind, cheers.
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    :) you're also masking single constants for channels they don't really have.

    OH also of note: The order of operations with rotation and panning matters A LOT.

    Lets say you have tank treads textured on a ball, (or some such) and you want them to rotate to face the direction of movement, then pan along that direction, you will need to have your panning before your rotating.

    If you want to have say.. a chainsaw made of buzz saws, then you'll want your rotate before your pan. and yes you may get some funky effects if the rotation center isn't in the center of the UV layout (usually .5 .5).

    Edit: ... and now I want to go make a spherical tank with chain-buzzsaw arms...
  • rasmus
    Vailias: Tutorials on math as relating to shader shenanigans would be a godsend... Something to help bridge that gap for math-iliterates like myself seems crazy absent. Maybe after you've finished the chainsaw spheretank?
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Got you, that makes alot of sense. Thanks Vailias much appreciated, however, about the masking, the reason I'm masking my single parameters, it because they do not work for some reason if the node is not a specific function.

    An example of what I mean is the TexCoords works fine with the Append in place and are much faster then a 2 Vector, but in my Pan (the manual one Sprung mentioned), without the Masks, only the R works under append.

    So basically, anything I make under 'manual' and not a ready made function, including my custom Fresnel, needs to have the mask components if I need to control specific channels under scalar, or else they don't work for single scalars, and I'm trying to only use scalar since it's much faster, don't know why, but my UDK scene lags whenever I try accessing the 3 scalars.

    Also, I'm not sure, but UDK was compressing my normal maps really badly (EI: I couldn't work with them since they showed really bad artifacts) so I used an Uncompressed settings when I imported them, and so far, it looks like even if I flip my normal maps 180 in my rotation, they still do read out correctly, and I was hoping if anyone could tell me if this is normal (pun intended).

    One last thing, is there a recommended way to hard mask the fresnel in UDK without any kind of map? Here is my current fresnel:
    unled1kyw.jpg


    PS: +1 to Rasmus on said...also, tuts would be nice ;P
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    Ace... the masking thing is.. bizarre. It makes no sence from a data or code standpoint.

    HLSL wise the component mask is equivalent to the swizzle operator (.) so a green mask is just variable.g
    a float value, a scalar, doesn't HAVE a g channel by definition.. so it has to be cast to a float3 or float4 then operated on by the swizzle, then modified into the new vector via the append. I immagine the UDK compiler can compress the overall set of nodes that are irrelevant.

    Float3's SHOULD be faster than a collection of floats, as your GPU has dedicated vector units, and allocates memory better for vectors than scalars (if I recall).

    And I get what is going on in your manual fresnel term there.. but not really the why. The blue constant you have in there will give really wierd results when used as a tangent space normal, and without the inversion from the cam vs normal dot product its not really a fresnel like effect.

    As far as the normal maps go.. you'll want to use normalmap_noAlpha compession usually. it shouldn't artifact badly.

    If you don't do that, then make sure to check out the texture properties and change the unpacking minimum to -1 on all channels, otherwise your normal data will be off. Though it would likely account for its insensativity to rotation.

    A normal map is essentialy a set of offsets for the surface normals at a given pixel. The data range is from -1 to +1, but that has to be specified, either at the engine or shader level. If you don't do either your range is only from 0-1 and your vector length may be more than 1 (hence you normalizing your normal map for good results).

    Also, what do you mean "hard mask the fresnel" ?

    I'll see about tossing some together in the next couple days. I had a couple dry runs put together a while back, but they didn't flow at all, so I'll need to script things a bit better and do some show-prep. :)

    edit: Removed random iphone typo
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    I'm guessing the mask thing is an issue with a certain version of UDK, I didn't update it in a while, so that could be it, will check the latest version and see. Should I report this as a bug if the issue persists? As I said, I only need the mask for when I'm not using specialized node, it works fine on Rotate, UV, etc, but as soon as I have nodes which are adding and subtracting manually, I need to Mask them for some odd reason.

    And again, I'm not sure why, but single channel Scalar's are faster for me for some odd reason. I will try updating UDK and see if anything changes, but even my Instance Material lags for a couple seconds when changing while scalars fly off the bat right away. Pretty sure something funky on my end. Will check and see.

    The Fresnel is indeed funky, I did the entire invert thing to fake the sun shining on my mesh, and the blue number I input was just me being silly and testing out what effect values which aren't rounded have.

    As for the hard mask, well, I don't know how to call it, it's essentially a hardened rim light which is controlled by the Z normals, but I think images will serve better.

    unled1pg.jpg

    Been trying to achieve this effect for a while, but couldn't reach it.
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    simplest way is to take your fresnel term and multiply it by some value, then just constant clamp it between 0 and 1. It has the same effect as moving the white point slider in a photoshop curves adjustment.
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    OOOOOOoooh! Interesting, I didn't know it could be visualized like this, good stuff :)
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    ;) Yeah. I think in curves a lot of the time when working with shaders.. or at least in graphs.

    Its one thing I'm definitely covering in those video tuts.
Sign In or Register to comment.