Home Technical Talk

"EyeShaderSimple", a CGFX viewport shader

polycounter lvl 19
Offline / Send Message
kodde polycounter lvl 19
Hey gang,

Here's my EyeShaderSimple. It includes what I find to be the necessary components for making real time eyes.

This shader is created for Maya, but I don't see any reason for it not to work with 3DSMax. I created it using Mental Mill and exported with Custom CGFX preset. There's an example Maya scene bundled.

You can download the shader here, at bottom of page.

EyeShaderSimple0.2.jpg

*Updated this first post to match latest version*

Replies

  • Eric Chadwick
    Options
    Offline / Send Message
    Cool!

    Why not indent the cornea/pupil mesh?
  • JordanW
    Options
    Offline / Send Message
    JordanW polycounter lvl 19
    You should take a look at MassEffect 2's eyes, they're really nice. I think your content/approach has some issues. You should be able to make an eye in 1 material that represents all the separate layers. You could do a smooth clear-coat highlight/reflection that uses no normal to represent the cornea. Your normal map looks like it represents the iris bumping off of the surface of the sphere but it's actually flatish and recessed compared to the cornea so maybe you could generate a normal map of a iris+sclera against a sphere. You could then use a bump offset/parallax to push that texture back so it looks correct when viewed at an angle.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    The part where the iris transitions to the pupil is indented in my high poly source, and the iris is more flat than the cornea is. Maybe I should push it further. Either way, my intention wasn't to impress you with a perfect eye but rather to share the shader. You go make something nice with it :P

    eye-anatomy.jpg

    JordanW> I actually played a bit of ME2 yesterday and tried to figure out their eyes, they do look good. Sounds like a cool idea using the parallax, would love to try it, but the parallax implementation from Mental Mill that exports to Maya is borked. I don't know how to fix it either :(
    Do you know how modern games actually handle eyes? Do they use your suggested method?

    ME2 Eyes
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    I like the idea of making it as one piece. Even if I don't get parallax working I could make the Normal Map only affect the reflections and specular and model the cornea area kind of flat. That way I would get the illusions of a spherical cornea when viewed in front angles but still have the Diffuse appear flat... I think... hmm
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Well I tried making a version without cornea separated. Worked out quite well.
    Shader for this didn't need any alpha. The diffuse part isn't normal map, so unfortunately the larger part of the eye couldn't benefit from a normal map to get a more smooth result. Don't think you notice that well either way. The specular and reflections use a normal map which simulates a spherical cornea.

    eyez2.jpg
  • Eric Chadwick
    Options
    Offline / Send Message
    The eyes in Mass Effect show the counter-lighting on the iris very well... the left sides of the irises are seemingly lit by refracted light when the lighting is coming in from the right. Looks like your setup isn't replicating this. Pushing the pupil vertex inwards is one way, using a normalmap or bent normals is another.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Alright, think I got your point.
    So now the mesh is indented for counter lighting on the diffuse part. Normal map takes care of faking spherical cornea for specular and reflection.
    Keep those suggestions coming, appreciate it.

    [ame]http://www.youtube.com/watch?v=YK7spXJXecc[/ame]
  • Eric Chadwick
    Options
    Offline / Send Message
    Looking good! You could use a bit softer transition between the sclera (white) and the iris, the sclera fades out at the edges of the cornea, and it overlaps the iris a little casting a soft shadow onto it. That's what makes the darker edge around the outside of the iris. A pic.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    transition.jpg

    Solved this with tweaking the diffuse and reflectivity textures.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    I went ahead and cleaned up my latest iteration and made it available. The URL is at the first post. Enjoy.
  • Hazardous
    Options
    Offline / Send Message
    Hazardous polycounter lvl 12
    Hey nice dude!! :D
  • AreDub3D
    Options
    Offline / Send Message
    Wow - nice improvements!
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Thanks guys, glad you like it.
  • chronic
    Options
    Offline / Send Message
    chronic polycounter lvl 10
    can we see what the geometry and maps look like for the last image you posted?
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Chronic> I'm not sure if I saved that exact same scene that is represented in the last image, but the bundled one is pretty much the same. Texture compression is the main difference.

    Btw I was lazy and re used old UV layout from when I used a transparent cornea, so I'm not using the UV space efficiently here.

    There's also the possibility to use a specular (colored) with gloss stored in it's alpha, I'm not using it in this example.

    Here's the bundled example:
    bundledeye.jpg

    Once again, normal map is only affecting the specular and reflections not the diffuse texture.
  • Brice Vandemoortele
    Options
    Offline / Send Message
    Brice Vandemoortele polycounter lvl 19
    Usually one would model the cornea and use a parallax shader to produce the refraction. I've never thought about doing it the other way around ^^ clever
    But the specular is very tigh, does it behave well in motion even tough the geometry is not what the normal map is storing? I mean the normals are correct, but doesn't it appear to swing because it is still related to the mesh surface?

    Btw the highlights of the cube are clamped, maybe you should look into putting those extra bright bits in a multiplier in the alpha or something, so that they don't have that 'gray ldr' look. Since you have a fresnel factor that problem will show up a lot
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Brice> Thanks for the feedback. Someone above already suggested parallax mapping and I'd very much like to try it, but the mental mill implementation -> maya is borked :(

    The specular seems to behave quite well imo, but I haven't studied eyes in detail to know for sure. There's a gloss factor and possibility to use a gloss texture if one would like to tweak this. There's a youtube clip above with a moving light which shows how the specular bends with the normal map.

    The reflections have a gain value you can tweak that will multiply the reflections with itself to make the light areas pop. The gain on the example images above has already been tweaked compared to no gain at all, could push it further. Is this what you meant with tweaking them?
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    The reflection gain feature I spoke of:

    reflectiongain.jpg
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    I played around some more with the shader using some nice artwork I've borrowed. Think I got it quite well. Shadows would probably add a bit but it's a damn hassle to manually do a second shadow pass and composite it.

    FelixHeadEyesWeb.jpg
  • wailingmonkey
    Options
    Offline / Send Message
    think you may be underestimating the power of the eyelid shadow to
    add realism. (or did I misunderstand you?)

    eye-shadows.jpg
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Hey thanks for the paintover.

    Now that you show me I am tempted to add that. However I'm not sure how to get them that smooth in a good feasible way. Depth map shadows could work, but probably not that smooth and probably jagged, risk or artifacts as well. Painting them on the diffuse wouldn't work if these are to be animated eyes. Maybe some form of plane with a transparent solution?

    Any ideas on this? Would be nice to get this kind of result right in your viewport/hardware render.
  • ivars
    Options
    Offline / Send Message
    ivars polycounter lvl 15
    Actually, most of the time, the upper eyelid will move with the eye, always resting slightly above the pupil.

    Here's just a random youtube clip to illusrate:
    [ame]http://www.youtube.com/watch?v=ur7uvLwNb0U[/ame]
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Awesome! Thanks for sticking it in my face.

    FelixHeadEyesWeb2.jpg

    Here's a gif as well showing you a comparisson. Didn't show up with regular IMG tags.
    eyeShadowComparisson.gif

    Solved it with polygon planes with transparency. Please give me some opinions on this solution. Would this be a possible solution for a game? Why not? How else?
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Well I incorporated the eyelid shadow through a polygon plane as a feature in v0.3 and created a new bundled example scene. Hope you like it.

    You can download the shader here, at bottom of page.

    **Changes in v0.3 since v0.2**

    Added drop shadow fake to simulate the shadow under the eyelid. This is done by creating a polygon plane, shaping
    it along and placing it at the eyeball. Switch to the "Drop_Shadow_Transp_use_Diff_Alpha" technique and add an
    alpha channel to your diffuse texture. Any surface area which isn't completely opaque will not recieve lighting,
    specular highlights or reflections, this is so the shadow fake stays black. Look at the bundled project to see how
    this works. There's also a Transparency Gain and Transparecy Subtract to fine tune the effect.


    Here's a video of my shader showcase example, got all excited and did a bit of rigging as well :)

    [ame]http://www.youtube.com/watch?v=EzH4q0lq8K8[/ame]
  • wailingmonkey
    Options
    Offline / Send Message
    nice job, kodde! that looks pretty swank. :)
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Thanks wailingmonkey. Was pleased with that shadow you pointed out.
    Contemplating on maybe trying to add eyelashes as well.
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 19
    Uncanny valley here I come ;)

    eyelashtest01.jpg

    Not really happy with them, could be better. Ideas? Suggestions?
  • Mark Dygert
    Options
    Offline / Send Message
    Sorry for the necomancy but I just found this while searching for something else and I have to say, Killer work! Really well done =)

    Eye.gif
    You might want to add geometry for the pupil so you can dilate the eyes growing/shrinking the iris by scaling the pupil geometry. I've done this with morph/blend shapes, animated UV's and even carefully placed bones set to scale.

    Stuff like this is mostly used in cinematic work but a realtime solution would indeed rock.

    Quick note about upper eye lashes, they are often thicker and longer than the lower lashes. Also lashes are at their longest in the enter of the eye and get shorter toward the corners of the eyes.
Sign In or Register to comment.