View Full Version : UDK - Material - Eye - UV Dilation/Expansion from Center
01-26-2012, 04:23 PM
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?
01-26-2012, 04:42 PM
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.
01-26-2012, 06:29 PM
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.
01-26-2012, 07:59 PM
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.
01-26-2012, 08:02 PM
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.
01-27-2012, 02:47 PM
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.
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
01-28-2012, 02:34 AM
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?
01-28-2012, 06:33 AM
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
01-31-2012, 03:26 AM
OK, some more testing and I think I got it, thanks to a certain Gaussian function ;P
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.
01-31-2012, 09:23 AM
Crap I actually did this the other day and forgot to post!http://imbuefx.com/random/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!
01-31-2012, 11:09 AM
Ohhh...interesting stuff. I'll keep my eye on this. ;)
01-31-2012, 03:12 PM
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
01-31-2012, 07:18 PM
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.
edit: Fwiw the texture based one with that whorl looks freekin amazing in motion. :)
02-02-2012, 02:38 PM
Awesome, kitty eyes!
vBulletin® v3.8.4, Copyright ©2000-2013, Jelsoft Enterprises Ltd.