Home Unreal Engine

Align planar texture coordinates to 3d vector location

polycounter lvl 13
Offline / Send Message
16bit polycounter lvl 13
I'm trying to create a material where a textures uv coordinates are aligned towards a 3d vector represented by a constant 3.

This is similar to a aligning by screen position, except instead of pointing towards the screen, I need it to point to the constant.

Replies

  • Vailias
    Options
    Offline / Send Message
    Vailias polycounter lvl 18
    Sounds like you're asking for texture projection. You can do that with a light in UDK, but if you want to do it in shader it.. may or may not be doable. I think it is but I haven't developed a node structure for it yet.


    For something similar, but not quite, specify the vector3 in worlspace. hook up a world to tangent transform for it.
    Use the dot product of the surface normal(blue channel or Vector3(0,0,1) and your transformed vector as the V coordinate, and the dot product of the tangent(green channel of the surface normal or Vector3(0,1,0)) and your transformed vector for the U channel.
    You'll get a result similar to a spherical environment map projection oriented toward your 3vector constant. You can also use the light vector without the transform to have the texture follow the light.
    Its not actual projection of course, but depending on what you need to do it might be of use.
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    3dproj.jpg

    Is this how you mean?

    I'm not sure I created it right since it doesn't appear to be working.

    It's supposed to be projecting from the red arrow, but it's projecting from the green one instead.
  • Xendance
    Options
    Offline / Send Message
    Xendance polycounter lvl 7
    16bit wrote: »
    3dproj.jpg

    Is this how you mean?

    I'm not sure I created it right since it doesn't appear to be working.

    It's supposed to be projecting from the red arrow, but it's projecting from the green one instead.

    Could it be because the dot products aren't clamped to 0...1 range?
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    Clamping it just gets rid of the mirroring.
  • 16bit
    Options
    Offline / Send Message
    16bit polycounter lvl 13
    projectionmapcorrect.jpg

    What I had done is this. Which works perfectly, but however I don't know how to plug in the world vector to control it.
  • Vailias
    Options
    Offline / Send Message
    Vailias polycounter lvl 18
    Yeah the first way you had was wha I was thinking of.
    Also be aware this will only work on curved surfaces. Any flat bit will be a single color
    Also I made a mistake.
    You'll actually want the green channel and the red channel for u and v respectively, and yes tangent space u and dotted to your world projection point.

    And again this isn't actually projection. It's closer to environment mapping.
    Also, For what it's worth the first pic you posted was projecting along the red axis. That dot in the center is the bottom center of your texture map which Is likely a black line.
    The falloff of the dot product values aren't linear so you'll get some distortion of your texture.
    Anyhow try your first setup again with a tangent space green and red vector dotted to your projection vector transformed from world space to tangent.
Sign In or Register to comment.