Blender 3D: Noob to Pro/Procedural Eyeball

From Wikibooks, open books for an open world
Jump to: navigation, search

Level: intermediate

Building a better (procedural) eyeball!
Originally created by Jon McKay (Ammusionist) and posted on blenderartists.org/forum
[1] The end result of this tutorial is an eyeball that fulfills the following requirements:

  1. Single mesh
    • I wanted to be able to append a single object into any project.
  2. Procedural Textures
    • I didn't want to have to rely on image maps that could get lost.
  3. Versatile
    • One single model to be used for any type of character, be it human, alien or whatever.
  4. Easy
    • Any effects needed to be quickly accessible. I don't want to be wasting time faffing around with colour-band settings at the texture level
  5. Impressive
    • This sucker needs to look good any way it goes.
  6. One other thing I really wanted was the iris musculature to follow the pupil dilation!

[Total Noob] I found this tutorial both informative and useful. It's best to download the PDF version with the screen shots if you want to get as much info out of it as I did, and in fact, understand all that's going on in the Tute

New Link (08th Nov '11): Here is the full tutorial as a pdf file. 9 pages of screenshots and extremely detailed instructions. (1.2mb)

(Noob note: In my blender 2.49, I had to unclick the 'Traceable' setting on the cornea of my eye when following the PDF tutorial, else I ended up with a giant black 'olive', this does not appear to affect ray mirroring, and corrects my problem.)


Creating the Mesh[edit]

[noob note1] Maybe worth to look at this link instead... http://web.pdx.edu/~wlf/tut.html


Note: You might want to check out this video first: http://www.youtube.com/watch?v=KKmHUZroaBA
The objective here is to make a great looking eyeball. That means it may not be anatomically perfect, but there are some things we need to take into account: The eye should consist of a white (white bit with veins); an iris (coloured bit); a pupil (black but in the centre of the iris) and a cornea (clear bit surrounding the whole eye). These may not be absolutely correct, but these are how I'm referring to the pieces of the eye.

  • Start with a ball: Go to a front view (Keypad-1) and create a UV sphere. 24 Rings and segments should be sufficient. It'll give us plenty of smoothness and enough verts to work with when we create shapes.
 NOOB NOTE: If you want the eye to point toward you, you may have to rotate it 90 degrees. Go to side view [num3], click Rkey and rotate while pressing the control key. Return to front view.
(Noob Note #2: If you, like most people, want the eyeball's iris and pupil to point towards the front, but don't want to change views, press the RKEY, then XKEY to   restrict rotation to the X-AXIS, then, while holding CTRLKEY, rotate the sphere by 90o.)
  • This sphere will become the coloured parts of the eye, but we also need a second sphere for the cornea. Use the Z key to switch to a wireframe view (if you're not already there). Hit the A key a couple of times to ensure all points are selected then Shift-D to duplicate the sphere.
(Mast3rlinkx's addition: I started the other tutorial, Realistic Eyes in Blender, but it's incomplete. I thought I could use the base mesh of that tutorial here for a more realistic look, and a less confusing mesh. I used this shape for the cornea.)
  • Press S-Key to scale and scale the second sphere to slightly larger than the first. (Hint: Hold shift while scaling for fine adjustment) or you could also enter a value, 1.01.
  • Now that we have a nice confusing mesh, we're going to make our life easier. We're going to hide the outer bit for the moment. Hit the "H" key.
  • Don't panic like I did the first time I accidentally hit H, you can bring it all back with Alt-H. (Note: In blender Alt + some key often reverses the effect of pressing the key in the first place!)
  • OK Now to create the basic mesh for the inner part. Basically, we need to make a concave iris/pupil section.
  • Switch to a side view and use the Border Select (B-Key) to select the first four rings and the tip. Now we're going to flatten these. Press "S" for scale "Y" for Y axis only and "number 0" for scale-to zero. (Mast3rlinkx says: If you do this, your poor eyeball will have a pinched appearance where the pupil and iris should be. What you should do is hit S, then Z, then 0. Then drag along the Z-Axis so the flattened area is flush with the curve of the sphere.) (Noob Note: The axis you need to use will change depending on the way you aligned your eye. If you want the front to point along the Y-axis, scale Y to 0; otherwise, scale Z to 0.)
  • Now grab the flattened verts with the "G" key and press Y so that it goes the right way, and drag it a little into the eyeball. [noob note: you can also select two opposite vertices in the fourth ring before scaling along the Z axis, and press CTRL + S to snap the 3D cursor to the center of the fourth ring. Then set the pivot point to 3D cursor.]
  • Now for the cornea. It's not perfectly spherical; it bulges slightly at the front. We're going to use the Proportional Editing tool.
  • First, we need to un-hide the cornea. Hit Alt-H
  • Usually you would use the O-Key, but this little menu item allows you to activate proportional editing for Connected vertices.
  • Once activated, you can select the type of falloff from the 3D header bar. Select “Root Falloff” (Mast3rlinkx's Second Addition: Instead of root falloff, which looked less realistic than it could have, I used Sphere Falloff and got a more realistic look. That's just my opinion, being someone who points out the anatomically incorrect portions of a cartoon character's appearance.)
  • Press A-Key a couple of times again to make sure no points are selected, switch to a side view (Keypad-3) and right click just to the left of the front-most point. We just want to select that one vertex.
  • Now comes some fun. We want to drag that point away from the eye in the y axis, so press “G” for grab and “Y” for Y axis. As you move the vertex, you'll see a circle that defines the influence of the proportional editing. Adjust it so it is about ¼ the height of the whole eye and drag it out until it looks right.
  • To clean the model up, we're going to apply a subsurface and apply some smoothing. Go to the editing buttons and find the modifier panel.
  • Add a subsurface modifier and set both level and render level to 2.
  • Now hit Tab to switch to Object mode and hit the "Set Smooth" button in the Link and Materials panel.
  • Now would be a good time to save your work before we go on to textures.

Adding the Textures[edit]

You're going to need multiple materials on this mesh. It's possible to apply materials to selected faces.

  • First, switch to editing mode and change the select mode to Face select. (Oh, and switch off proportional editing if it's still on from the last section)
  • Press A a couple of times to ensure nothing is selected.
  • Press Z to switch off wireframe; this will be easier without it.
  • Place the mouse pointer in the centre of one of the faces on the outside layer of the eye and press “L” to select linked faces. If you get a message saying “Nothing Indicated” try positioning the pointer on a different face and try again.
  • Once the cornea section is selected, in the “Links and Materials” panel of the editing buttons, click “New”. The counter above it will change to “1 Mat 1” best read as material 1 of 1. Click “Assign” to assign the cornea faces to material 1.
  • Hide the cornea faces (H-Key). We'll assign the rest from the outside in. If a face is already assigned to a material and it is assigned to another, it just switches place. Therefore, it's easiest next to assign all the visible faces.
  • Press A to select all and, as above, click “New” then click “Assign”.
  • Now for the iris and pupil. Hit A to deselect all.
  • Switch to a front view and zoom in. Hit “B” twice to enable paint select and select the central faces plus one ring out. You can control the size of the selector by rotating your mouse wheel.
  • Again, create a “New” material index and “Assign” the pupil faces to it.
  • Finally, click A to deselect all and use paint select again to select the remaining faces on the iris. Assign them to a new material.
  • Now we're ready to make the materials. Switch to object mode (Tab). Change to the object editing buttons and in the Draw panel, locate the “Transp” control. Set this on. This means as we go we'll be able to see through the cornea.

Cornea Material[edit]

We'll start with the simplest texture first. The cornea is basically just colourless and transparent. Note that we're using Z-Transparency instead of Ray Trans. This is because some lighting conditions make the eye under the cornea difficult to see. (NOTE: Until I get the images uploaded, you should refer to the pdf version for the settings. Meanwhile, here is how I see them:

Go to the shading buttons (F5)

Under the Links and Pipeline tab, ZTransp is clicked along with Radio and Tracable.

Under the Material tab, col is white and alpha is 0.1 .

Under the Shaders tab, CookTor Spec is 1.674 and Hardness is 333. (Noob Note: I could be wrong, but in Blender 2.63 it appears you need to set the Shading->Emit to 1.67 and Specular->Hardness to 333.)

Under the Mirror Transp tab, Ray Mirror is clicked, RayMir is 0.4, Depth is 3 --Bonapon (talk) 14:31, 6 October 2009 (UTC))

(Noob note: In my blender 2.49, I had to unclick the 'Traceable' setting on the cornea of my eye when following the PDF tutorial, else I ended up with a giant black 'olive', this does not appear to affect ray mirroring, and corrects my problem.)

White Material[edit]

The white of the eye's a little trickier. The material here includes some red veins that can be seen at the side of the eye, but not from the front. This can be done with two textures, but there's a cheat we can use.

First, the veins:

Switch to Material Index 2 (In the Links and Materials panel, click the right arrow so it reads “4 Mat 2” or Material 2 of 4).

Click the cross or X next to the material name and add a new material.

Go to the texture buttons:

Using a marble texture, copy these settings.

(Here are the settings that I see

Under the Colors tab:

Cur: 0: Pos=0; R=1, G=0.617, B=0.629; A=1;

Cur: 1: Pos=0.340; R=1, G=1, B=1; A=0;

Under the Marble tab:

Sharper, Soft noise and Sin are clicked;

NoiseSize=0.634; NoiseDepth=5; Turbulence=26.04;

--Bonapon (talk) 15:25, 6 October 2009 (UTC))

The two colour band items are shown here separately. This makes a nice marble texture that will evenly cover the eyeball. So how to hide it from the front of the ball? Another colour band trick, but this time in the material itself.

Here they are in all their glory.

(As I see them:

Under the material tab, Col is white and alpha is 1;

Under the Ramps tab:

Cur: 0: Pos=0.690; R=1, G=1, B=1; A=0; Input is Shader; (These settings are not shown in the pdf so I have extrapolated. Please correct if wrong.)

Cur: 1: Pos=0..690; R=1, G=1, B=1; A=1; Input is Normal;

--Bonapon (talk) 15:43, 6 October 2009 (UTC))

The colour band items are both white with one alpha 0.0 and one alpha 1.0. As you can see they are very close together to give a fairly clear line that the veins will stop at. The input setting for the band is set to “Normal” this means the left hand side of the band refers to faces that are parallel to the camera view and the right is faces that are facing directly towards the camera.

I've also added a bit of mirroring so that we get a little scenery reflected!

There's also some colour band fun to be had with the pupil material.

Pupil Material[edit]

I wanted a nice black texture, but I also wanted to get a red-eye effect if a light is shone directly at it from behind the camera. Why? I guess just because I can, and now so can you!

As before move to the next material index and create a new material.

There's no textures in this one. It's basically black and a little reflective with a nice hard specular.

(In the materials button (F5):

Under the Links and Pipeline tab, Ztransp, Radio, Tracable and Shadbuff are clicked;

Under the Material tab, Col is Black, presumably with an alpha of 1, while Spe is white with an alpha of 0.6;

Under the Shaders tab, CookTor spec is 0.594, Hard is 294;

Under the Mirror Transp tab, Ray Mirror is clicked, RayMir is 0.3;

--Bonapon (talk) 18:14, 6 October 2009 (UTC))

Have a good look at the colour band settings though!

Position 1 is black with an alpha of 0 and positioned at 0.97. Trust me on this setting, it took a while to get it right!

(Under the Ramps tab:

Cur=0; Pos=0.970; R=0, G=0, B=0, A=0; --Bonapon (talk) 18:22, 6 October 2009 (UTC))

The second is all the way across at position 1 and is fully red (with no blue or green) and alpha 1. We want the red-eye to respond to light not angle like the white of the eye, so set the colour band input to “Shader”.

(Cur=1; Pos=1; R=1, G=0, B=0, A=1 (The alpha of the second position is not shown in the pdf) ; --Bonapon (talk) 18:22, 6 October 2009 (UTC))

Now the bit you've all been waiting for – the iris!

Iris UV Map[edit]

Save your work and grab a cup of coffee for this part. It's a little involved.

We need the texture to stay glued to the mesh irrespective of the shape of the mesh. This gives the effect of the muscles in the iris expanding and contracting. In a nutshell, we're going to UV map a procedural texture to a single part of the mesh.

OK, here we go. Switch to a material editing window. You'll need to be able to see both a 3D window and an image window. It wouldn't hurt to see a buttons panel as well. My material screen kind of looks like this.

(Noob Note: To clarify: an "Image Editor" window option is in the Select Window Type drop down button situated at the very left of the header next to the View drop down. Select 'UV/Image Editor. To achieve the screen the author describes, first split your view. Then select a front ortho view with NUM1 in the right window. In the left select UV/Image Editor from the Select Window Type button as described.)--WithAlligators (talk) 05:59, 24 February 2010 (UTC) (Blender 2.49b)

Make sure the window is displaying a front view (Keypad-1) this will be important when we unwrap the bit we're going to use.

Change the 3D window to mesh editing / face select and use the brush select (B-Key twice) to select the iris faces.

Now change to UV Face Select mode. The faces should remain selected. (As of Blender 2.46 the UV Face Select mode no longer exists. It's been merged with Edit mode. All you have to do is select all the vertices/faces/edges in Edit mode and press the U-key.)

With the cursor in the 3D window, press “U-Key” for unwrap and select “Project from View”. The image window should now contain a nice even circle of dots. Put the cursor in the image window and press “A” to select all the points. Scale and move them until they fit nicely in the outer square of the image grid. Now select each ring in turn using brush select, starting from the innermost, and scale them until they cover from the centre to the outside of the image grid as shown.

Now we've got a map, lets get a texture. Switch back to a modelling screen and change to object mode for the next part.

Iris Material[edit]

Firstly, a texture to control the colour blend across the iris. Generally it starts on the outer edge dark and gets lighter as it moves to the centre. Sounds like a job for the blend texture.

The texture itself is fairly straight forward, but again, the colour band is where the magic happens.

I've pictured all three stops in the colour band. Note the alpha values. This blend texture is meant to tint the iris texture so it's lighter in the centre and darker in the outside. (Note: I will have to create my own screen prints as I don't know if the original author has uploaded images or if they are copyrighted. For this to happen, I will first have to complete the tutorial myself.--Bonapon (talk) 20:34, 8 October 2009 (UTC))

Now for that iris texture:

I stumbled over this texture almost by accident when I was working on a different project. Copy the settings as they appear here.

Note: the colour band points are black with alpha 0 and white with alpha 1. This allows the material colour to come through the texture, so we can set the main eye colour in the material buttons.

The main colour is blue which sets the colour of the iris. The centre colour comes from the texture settings:

The blend texture is applied to the UV map input. The green colour is used as a lighten mix to tint the iris near the centre. Using the Stencil option allows the other texture to show through.

The iris texture is applied to UV again and some normal as well as colour is applied. This makes some small shadows in the iris when the light is from the side. Add some lights and have a look at your eyeball so far.

Pupil Dialation[edit]

We're going to use shape keys to create the pupil effects.

We're going to create a normal eye and a cat's eye. Fortunately, the fully dilated eye is the same in both cases so that's going to be our shape key basis.

Go to the edit buttons and select the Shape Key panel.

Make sure “Relative” is selected and click “Add Shape Key” to create the base shape.

Switch to edit mode, point selection. Select just the first loop in of the iris. To select an edge loop in point mode, place the cursor on a line between two points that's on the loop and Alt-Right Click. Shift + Alt-RClick will add the selected loop to what's already selected.

Now scale this to just inside the width of the loop that the iris shares with the white..

Now do the same with each of the other two loops. This should produce a nice dilated pupil.

Hint: If you scale the inner loop out, but the edge of the colour doesn't follow it exactly, drop it and hit Shift-E, then move the pointer to the right. This causes the subsurfaced mesh to closer follow the selected edge.

Now to create the normal (human) pupil shape. Switch to object mode (Tab) and add a new shape key. Name it “Normal Pupil Contract”

Now grab the edge loop between the pupil and the iris. Scale is down so it's just a little bigger than the loop in the pupil. Select all the points in the pupil as well now and scale them all very small.

Now select the next loop out and scale it down, followed by the final edge loop. It should look like this.

Now switch back to object mode and try the shape key slider out. Pretty neat huh?

Let's make a cat's eye now. Switch shape keys back to “Basis” and add a new shape key called ”Cat Pupil”.

Use the same method as before to scale the edge loops. As you scale, restrict your scaling to the X axis (That is “S” then “X”). You should end up with a shape key like this:

That's pretty much it. Try some other things like rotating iris edge loops in the shape keys for spiral eyes, or weird shapes for the contracted pupil.

Don't forget to save – and enjoy!

(noob note: when switching between sliders, the previous one must be reset, or their effects will combine in weird and unfathomable ways)