Home Unreal Engine

UDK - Material - Eye - UV Dilation/Expansion from Center

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

I'm trying to create an dilation like shader for UDK.

Basically, the same effect of Iris/Pupil dilation of the eye, kinda like this shader: http://carlosmontero.com/shader_eyeball.php

Problem is, my dilation of the texture doesn't work correctly. It 'expands' my texture (EI: making them larger) without a proper center position (EI: stretching from the middle to out with a stretch tolerance) .

So basically, anyone know of a cheap way to this?

Cheers!

Replies

  • imbueFX
    Offline / Send Message
    imbueFX polycounter lvl 5
    I had to do something similar when I was new with UDK. The trick I came up with is to lerp between to texture coordinates. One being the open state, the other being the closed state.

    That may not be the best approach, but it worked for me. Hope this helps!

    Edit: Now that I actually thought about it for a minute, you could also warp the UVs coming in to your texture sample and distort it against a radial ramp from photoshop. Not sure how clean it would render, but just another thought.
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    That's what I was thinking, but I'm having a hard time in getting UDK to behave properly with my UV's, no matter what I try, it doesn't help since it enlarges my images instead of warping them.

    I also tried using a Tan function to get the correct single expansion, but that didn't work either.
  • imbueFX
    Offline / Send Message
    imbueFX polycounter lvl 5
    If I get a chance I can whip something up really quick. We've done this before at our studio with blackhole effects and it works decently.
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    Simplest way I can think of in 45 seconds:
    use a simple greyscale texture to paint where the pupil is white. have it falloff/feather so its like a bright phong highlight covering the iris.
    Make sure the parts you don't want to scale are black. not dark. Black.

    Multiply a scalar parameter, called say, "iris" by this texture, then append the output so that its a 2vector. Add that 2 vector to a texcoord node, then plug the result into yoru uv's.

    A value of 1 will be no distortion, values less will constrict, and higher than 1 will dilate.
    You CAN do this entirely programatically with a product of sines or gaussians and some manipulation to get it into the right place, but the texture is easier to explain.
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Ah, I see, directly dilating the UV-Coords is done through texture work, interesting and genius!

    Thanks Vailias, however, I'm still having a weird issue. It seems like my texture is being dilated AND twisted around the corner. I both tried a soft radial texture and your Gaussian function, but still no dice.

    95602128.png


    Also, for fun, I tried putting up my Iris parameter, a Light Vector instead, and I'm getting an overlay like effect at certain angles, is this normal?

    The test package if you want to take a look: http://www.mediafire.com/?ipdmm89dwm4s376
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    heya ace, I realized I made a mistake on my mental math the other day which is why you're getting what you're getting. No time at the moment to fix it..

    also your package is only 81k when I download it. Is that right?
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    No problem, take your time.

    Also, yeah, I just uploaded the shader since my UDK keeps on breaking my links for the functions and textures. I have a separate file just for this issue with the textures in it: http://www.mediafire.com/?2ca3qoh0ehpi58i

    This file doesn't have the shader in it BTW.

    Credit goes to Carlos Montero for the textures and you for the Gaussian :P
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    OK, some more testing and I think I got it, thanks to a certain Gaussian function ;P

    87487530.png

    Now I'm trying to figure out how to clamp and get actual values of light distance from -1 to +2 so that the dilation is light dependent, but am unable to get it right, the eye just...wobbles in place when I put up the light. As it shows in the image, the light wobbles the iris on the RG axis, and doesn't actually spread linearly.

    If anyone has tips about this, I would like to hear it.

    EDIT: OK, a cosine/sine function with a linear clamp works wonder for the dilation amount, but I'm still getting the wobble and weird overlay issue previously mentioned.
  • imbueFX
    Offline / Send Message
    imbueFX polycounter lvl 5
    Crap I actually did this the other day and forgot to post!mat_eyeDistortion.jpg
    This is a little simpler instruction wise, but same concept. The distortion texture isn't perfect either, thus stretching it really wide open would give an uneven circle. But for smaller values as demonstrated in the image, it works good enough.

    Hope this helps!
  • cman2k
    Offline / Send Message
    cman2k polycounter lvl 17
    Ohhh...interesting stuff. I'll keep my eye on this. ;)
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    ^
    Haha, if anything, it was your shader which enticed to me to look into this ;P

    Also, hope it's OK I'm using your textures are placeholder for now, I can take down the package if you like, just wanted to use them as an example.

    @imbuefx: Where were you, when I need it mate ;P
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    hehe good you figured out the core of it.
    For light direction control It gets a bit harder as you need to control the scale of the entire shader based on the light vs the object, NOT the light vs the normal of the vertex or pixel in question.

    I gotta jet but see if more experiments help.. In the mean time, here's another network and examples.
    Eye_Shader_Examples.jpg
    Eye_Shader_Network.jpg

    edit: Fwiw the texture based one with that whorl looks freekin amazing in motion. :)
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Awesome, kitty eyes!
Sign In or Register to comment.