Tuesday, October 16, 2012

Procedural Eye

Download the eye and Mental Ray shaders for Maya 2013 ( Maya Binary ).
Download the Maya Ascii version. 

This is an eye that I use for personal art pieces. Everything is procedural from the size and shape of the cornea to the vein textures. Normally I set the detail lower than what you see above but the detail is there if I need it.

This was inspired by Alex Alvarez's free tutorials:  http://www.thegnomonworkshop.com/store/category/167

The backgrounds / light probes are from Paul Debevec.
Rendered turntable of eye.

The file consists of:  A control node, eye geometry with history, eye shaders, eye textures, reference spheres, ibl node and camera with a lens shader.

Control Node

This is where you access and set the attributes for the eye's shape.
  • char_hi_side_eye_ctrl.iris = The size of the iris. The number corresponds to the isoparm of the main spheres.
  • char_hi_side_eye_ctrl.pupil = The size of the pupil.
  • char_hi_side_eye_ctrl.cornea_bulge = How far the cornea bulges out from the natural curve of the eye.  10 = typical human bulge, 0 = no bulge.  Negative numbers will make the cornea concave.
  • char_hi_side_eye_ctrl.iris_concave = How much does the iris scoop inwards/outwards.  10 = concave, 5 = flat, 0 = convex.
Iris and Pupil Size
Iris Convex/Concave and Cornea Bulge

Eye Geometry

If anyone is interested in the detailed steps involved in building the eye pieces, let me know and I'll do a write-up.  The basic steps are:
  • make a sphere.
  • detach at an isoparm.
  • connect control node value to detach node.
  • create a node that rides at the detach point in Z.
  • parent a deformer to that rider, in our case a lattice.
  • connect control node value to the deformer.
  • scale the deformer based on the detached piece's radius.

Shaders

Notes on shaders and textures
  • All shaders are mia_material_x, exception is the pupil which is a surface shader.
  • All textures are converted to linear color space with a gamma node.
  • All "noise" is fractal noise.  Fractals repeat cleanly at the uv borders so we don't see a seam, the noise node does not.

Sclera Shader

To anyone not familiar with a shader/texture network this probably looks like a mess.  It is, but it's much better than our previous versions.

Nodes in the network:
  • char_hi_side_sclera_vein_noise_threshold = Tells where the veins start and stop.  White = 0% veins, Black = 100% veins.
  • char_hi_side_sclera_vein_noise = The fractal that makes the shape of veins.  Set the color gain to 0 and the color offset to 1 to turn off the veins.
  • char_hi_side_sclera_vein_col_ramp = The color of the veins.
  • char_hi_side_sclera_combo_col_ramp = The red color and the proportion to white of the sclera.
  • char_hi_side_sclera_noise = The fractal for the white of the sclera.  Set the color gain to 0 and the color offset to 1 to turn off the noise.
  • char_hi_side_sclera_bright_col_ramp = The color for the companion part of the bright section of the sclera.  I have it set to bright blue.
  • char_hi_side_sclera_bump = The bumpiness of the sclera.
  • char_hi_side_sclera_vein_noise_bump_md = Multiplier for the vein bump.  Set it to 0 to turn it off.
  • char_hi_side_sclera_bump_ramp = Tells where the bump on the sclera starts and stops.
  • char_hi_side_sclera_shd = The sclera shader.
Veins On and Off

Iris Shader

 Nodes in the network:
  • char_hi_side_iris_base_col_ramp = The deep, background color of the iris.
  • char_hi_side_iris_noise = The fractal for the brighter, radial lines in the iris. Reduce the frequency ratio to simplify. Set the color gain to 0 and the color offset to 1 to turn off the bright lines.
  • char_hi_side_iris_col_ramp = The color of the bright lines.
  •  char_hi_side_iris_shd = The iris shader.
Iris Colors 
 Detailed to Simplified Eyes

Cornea Shader


Nodes in the network:
  • char_hi_side_cornea_noise = A continuation of the sclera fractal into the edge of the cornea.  If you edit the sclera fractal ( char_hi_side_sclera_noise ) do the same edits to this texture.
  • char_hi_side_cornea_col_ramp = A continuation of the sclera bright color into the edge of the cornea.  If you edit the sclera bright color ( char_hi_side_sclera_bright_col_ramp ) do the same edits to this texture.
  • char_hi_side_cornea_trans_ramp = The transition from opaque sclera to clear cornea.
  •  char_hi_side_cornea_shd = Cornea shader.

How to add it to your character

Without knowing how you rig and deform your characters, it's a little tough to give a definitive answer.  This is how we integrate the eye for our characters.
  • Import the eye template.
  • Rename all of the nodes to match the current character.
  • Cluster: char_hi_side_sclera, char_hi_side_cornea, char_hi_side_iris an char_hi_side_pupil.
  • Move and scale the cluster to the character's eye location.  Note that the eye is 1cm in diameter, so if you need your eyes to be 2.4cm ( human size ) you scale the cluster to 2.4.
  • Bind the eye to an eye joint.
  • Lattice the same nodes as above if you need non-spherical eyes. We make non-spherical eyes all the time.
  • Deform the lattice to the desired shape.

27 comments:

  1. Really awesome!
    Is there any chance to get an .obj version (or something that can be imported in blender)?

    If not, thank you anyway for sharing your knowledge.

    ReplyDelete
    Replies
    1. I can make an .obj version. I guess I could bake the procedural textures as static images well.

      I've never used Blender so I can't replicate the deformations, procedural textures or shaders though.

      Delete
    2. Hi Todd, and sorry for my delay.
      If You make an .obj version with baked textures it will be great! (if you have enough time, of course).

      bajma

      Delete
  2. Yisus, awesome work. I'm trying to do something (more or less) like that with Zbrush, but I think I'd better use Maya for that, I really hope you can do a tutorial, if it's not done yet!

    ReplyDelete
  3. Hi, Great tutorial but cant open the file you have provided :(
    Any other way to get this file and the textures?

    ReplyDelete
    Replies
    1. What version of Maya are you using? This file was made with Maya2013.

      You can open the file in earlier versions of Maya by going to "File -> Open Scene... -> []", set the file type to "mayaBinary" and check "ignore version". The file should open in Maya2012, at least it does for me.

      Delete
  4. I feel ecstatic I found you website and blogs.
    jhocena

    ReplyDelete
  5. // Warning: (Mayatomr.Nodes) : iblShape: IBL ignored. File texture not found, or constant black input color. //
    // Warning: (Mayatomr.Nodes) : iblShape: IBL ignored. File texture not found, or constant black input color. //
    // Warning: (Mayatomr.Nodes) : iblShape: IBL ignored. File texture not found, or constant black input color. //
    // Warning: (Mayatomr.Scene) : output data type "rgba" not directly supported by image format jpg, conversion performed by mental ray //

    ReplyDelete
    Replies
    1. I have Maya2013.
      file type to "mayaBinary" and check "ignore version" doesn't work :(

      Delete
  6. Those are warnings not errors.

    The first three state that the IBL node has no texture. I did not supply a texture for the IBL with the eye file.

    The last warning is normal if your image output type is jpg.

    To get rid of the top three warnings:
    - Go to "Window -> Rendering Editors -> Render Settings".
    - Click on the "IndirectLighting" tab.
    - Click on the black arrow next to "Image Based Lighting".
    - The "Attribute Editor" should open with "iblShape" as the active tab.

    - You can do a number of things:
    - Click the folder icon next to "Image Name" and find a panoramic image to use as a lighting source.

    - OR -
    - Switch "Type" to "Texture".
    - Add a texture by clicking on the checkerboard at the right of the "Texture" slider, or click on the color swatch and make it a solid color.

    - OR -
    - Go back to the "render Settings" window and click "Delete" next to "Image Based Lighting", that will remove the IBL.
    - Make some lights and render.

    If you choose to use the IBL, make sure "Final Gathering" is checked on, otherwise the image will be black.

    ReplyDelete
  7. wow... Yes now it works ! I've downloaded the campus light probe from Paul Debevec site. Thanks Todd for the detailed answer !
    I've also added your blog to my favourites. My eye model has a realistic geometry. And a problem is that the iris of human eye has only flat shape.
    So in the side view it looks absolutely flat. But in real world there is an anterior chamber between cornea and iris with liquid. It makes some refractions I mean looks like magnifying glass and makes iris side view in cornea area more volumetric. Your cornea shader is looks like very complicated for me now. Would be nice if you have a tutorial or link about magnifying glass, lenses, liquid medium or something similar to this. Also I make the nimbus iris as a separate mesh to look more realistic and I suppose to use ramp shader on it. Still learning how to use it and how it works.

    Best regards! Michael Matskevich

    ReplyDelete
  8. With the release of maya 2013 autodesk changed the ASCII format so backwards compatibility is no longer possible. What you've provided is fantastic but it would be much appreciated if you could save out an obj baked version, or at least a .ma version as I believe there is a script floating around to convert a 2013 .ma to a 2012 and earlier .ma

    Thanks again for your great contribution,
    -Matt

    ReplyDelete
    Replies
    1. As far as I know, Autodesk made no changes in terms of backwards compatibility for Maya2013's ASCII format or binary format. You can open a 2013 in 2012, the file above opens just fine in Maya2012. I open 2013 files in 2012 all the time.

      You may be confusing Autodesk's change in binary format for Maya2014, making 2014 files non-compatible in previous versions. But they did say you can save in ASCII format and open the file in previous versions.

      Maya 2014 "What's New" page:
      http://download.autodesk.com/global/docs/maya2014/en_us/index.html?url=files/New_in_General.htm,topicNumber=d30e6351
      Scroll down to "Larger Maya scene files and geometry caches"

      I can save out an obj and some baked textures I guess, but it won't come with any of the eye controls, shaders or procedural textures.

      Delete
    2. Todd you are correct, I had a brain fart and was thinking 2013 was the latest version of maya not 2014. Sorry about that, as it stands is it possible you can post the .ma file? I only see the .mb file in the link you posted and that wont seem to open no matter if ignore version is checked or not. Thanks again and sorry for the confusion :)

      Delete
    3. I've added an ASCII version. Check the top of the post.

      Delete
  9. Thanks so much Todd! This is great, thanks for sharing!

    ReplyDelete
  10. I have done my own eyeball but my refractions are so bad (
    http://img706.imageshack.us/img706/6724/irisrefractiondistortio.jpg
    what I'm doing wrong?

    ReplyDelete
    Replies
    1. It looks like you have a bump or displacement on the cornea causing the distorted refraction. It could be something else, but that's my guess.

      If you want to PM me the file I can take a look.

      Delete
  11. Awesome stuff Todd! The only question is how did you figured out all that math you have in the "char_hi_side_eye_exp" expression? Is it described somewhere or how? Thank you for sharing this with us!

    ReplyDelete
    Replies
    1. Remember when you were a kid in math class and you asked yourself, "When will I ever use this?" Well, this is when.

      When I first started in VFX I had long forgotten most of the math I learned in school. Now I use algebra, trigonometry and calculus almost every day, I just have to re-learn everything. It's easier the second time.

      I keep the basic structure of the eye as a 1cm sphere ( also known as a unit circle/sphere ) because the math is straight forward. Some of the math is trigonometry, the rest is trial and error. In some parts I convert degrees to radians ( Maya uses radians internally ) again because the math is straight forward.

      I may do a full explanation for the expression some day, but for now I'll take the easy way out and point you to wikipedia.

      https://en.wikipedia.org/wiki/Trigonometry
      http://en.wikipedia.org/wiki/Radian

      Delete
  12. I am a new Maya Student. Thanks for sharing your eyeball. I have a dumb question. What are the three reference spheres on the right for? I will check out the attribute nodes later to see if I can make a brown eye. Thanks again.

    ReplyDelete
    Replies
    1. The reference spheres are used to judge lighting. One is pure white, another 50% grey and another a mirror.

      When you make a shader, especially when you string lots of nodes together, if you are not careful you can set values too high or too low. If you render and something doesn't look as you expected the culprit could be the lights, the shader, the textures...

      So as a base of reference you can look at the white and grey spheres to verify the light intensities. The mirror sphere lets you see light placement.

      Delete
  13. In the second comment you wrote: "I guess I could bake the procedural textures as static images well."
    I really need a big detailed texture. Could you please make one with size 5000x5000 or bigger?
    P.S. Too bad I can't import a Maya project into Blender :(

    ReplyDelete
    Replies
    1. If I have time I'll bake the textures, but it won't be for a while, plus I would make 2k textures max.

      If you're in the need of a 5k texture, I'm guessing that you'll need to see the eye very close. The shader and procedural textures I've made are OK for general use, but not made to hold up under that scrutiny.

      If were to make a detailed 5k texture, the shader and and procedural textures would have to be rebuilt. Most likely what I would do is hand paint something.

      Delete
  14. Thanks for sharing your eye model, this will be super useful!

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. How does the connection between geometry?
    I'm not sure I've been to the basic step.
    Please let me know step by step how to do it.

    I'm a Maya learning student.
    I tried studying alone.
    That should not be.
    I tried to open the node editor.
    I'm not sure though.

    my email adress is hanna8861@gmail.com
    And thank you so mush this tutorial!!

    ReplyDelete