Results 1 to 8 of 8

Thread: Effects with mental mill - Lesson one

  1. #1
    Join Date
    Jun 2007

    Lightbulb Effects with mental mill - Lesson one

    In this tutorial we are going to create a shader that gives the impression of a surface that is being flooded with water. This shader works great on a flat surface. It uses a bump map and a corresponding height map that contain the information about height and surface orientation.

    This shader is divided into three branches. We will build one branch after the other:

    • The reflective water surface.
    • The bump mapped (solid) surface
    • A control for how the bump mapped surface gets flooded

    The reflective water surface

    We will do a very basic model for the water: Basically it is a constant water color with some animated reflections on top.

    * Create a Generator_water_normal node.
    * On its right side create a Component_reflection_normal node.

    We want the reflections to react to the bumpiness of the water surface, so we will force the reflection node use the normals of the Generator_water_normals node. To do this, we need to expose the normal of the reflection node:

    * Right click the yellow bar of the reflection node and select "Add state parameter > normal".
    * Now you can connect the result of the Generator_water_normals node to the newly generated input.

    What happens here is, that the shader will read the normal from the input instead of reading it from the geometry itself. Next we want the reflections to be attenuated depending on the viewing angle:

    * Create a Component falloff node and and a Math_color_multiply node.
    * Connect both the result of the Component falloff node and the result of the Component reflection node to the Math_color_multiply node.
    This creates some nice reflections with a falloff that we want to add to a water color:

    * On the right side of your network you created so far, create a Math_color_add node.
    * Select the node and in the parameter editor set the values for 'left' to 0.16, 0.29 and 0.36 for RGB.
    * Connect the result of the Math_color_add node to the input 'right'.

    The blueish color that you set in the Math_color_add node is the sea color, you can vary it within meaningful ranges to tint the water differently. Now you created a very simple water surface model.

    The solid, bump mapped surface

    Next we will build the solid surface. We will use a simple illumination shader with a bump map. Place the following two nodes underneath the shader network you created in the previous steps.

    * Create a normals_bupmap node and set its texture to "".
    * Create an Illumination_phong node and expose its normal like you did with the reflection node above (right-click yellow bar, choose "Add state parameter > normal")
    * Plug the result of the normals_bumpmap node into the normal input of the illumination node.

    You are done with the second shader branch for this tutorial. You got a water surface and a solid surface that you want to mix together to create the impression that the structure inbetween the bumps gets filled with water. The mixing will be done by a node called Math_color_mix. Create this node on the right side, next to the two shader branches that you built above and connect the result of the upper branch (Math_color_add) to the first color input of the mix node. Connect the result of lower branch (Illumination_phong) to the second color input of the mix node. You will notice that the two inputs get mixed equally which is not quite exactly what we want.
    We need to create a branch that allows us to control the mixing in a more sophisticated way. This will be trickier since it involves using some math nodes which you might find confusing in the beginning.

    Create the mixing information from a height map

    Create the next shader branch underneath the previous nodes. First we need a texture that contains the height information so that we know where we can fill in the water. We will add some controls that allow to set the softness of the transition as well as to offset it.

    * Create a Texture_lookup_2d node and set its texture to "". This texture stores height values as a grayscale.
    * Convert the result to a float value: Use a Conversion_to_float node.
    * Create a Math_float_smoothstep node and connect the result of the conversion node to the input 'location'.

    Get to know the smoothstep node:
    If you set 'end' of the smoothstep node to 1 you will see the same image that the texture lookup node is delivering. Play around a bit with the start and end values of the smoothstep node and see the effect on the resulting image: By moving start and end to different values, you can extract different ranges from your input. If you set start to 0.5 and end to 1, the node will discard input values below 0.5 and will interpolate the range from 0.5 to 1 so that the output lies between 0 and 1 again.

    * Create a Math_float_add node above the conversion node and connect it to the 'end' input of the smoothstep node.
    * In the math node set 'left' to 0.5 and 'right' to 0.3.

    Wrap the nodes in a Phenomenon:
    * Select the 4 nodes that you just created (Texture_lookup_2d, Conversion_float_to_color, Math_float_smoothstep, Math_float_add) and right click on an empty space in the workspace
    * From the popup menu choose "Create new Phenomenon from selection".
    * rename the Phenomenon to "compress_offset" (right-click the blue bar)
    * Maximize the Phenomenon.
    * In the Math_float_add node, right click the parameter 'left' and choose "add 'left' to 'compress_offset'"
    * From the same node add the parameter 'right' as well.
    * From the texture lookup node, add the 'Texture' parameter to the interface as well.

    * Rename the interface parameter 'left' to 'offset' and 'right' to 'softness'. (Right click the parameter and choose 'rename '<parametername>''. It's enough to change the display name.
    * Connect the result of the Math_float_add node to the input 'end' of the smoothstep node.
    * Connect the interface parameter 'offset' to 'start' of the smoothstep node.
    * Close the Phenomenon

    If you play with the offset and softness values, you get an idea of what is going on: The parameter 'offset' controls the start position of the smoothstep while the sum of 'offset' and 'softness'. If softness is 0, values below 'offset' will be black, values greater than 'offset' will be white. The bigger 'softness' is, the softer the transition will be.

    * On the right side of the compress_offset Phenomenon create a Conversion_to_color node.
    * Connect the result of the Phenomenon to the conversion node as well as the result of the conversion node to the 'Mix' input of the Math_color_mix node.

    You see that the water and the solid surface are mixed the right way. By varying offset and softness you can adjust the water level and the transition softness. So what can we conclude after finishing this tutorial?

    • A shader graph can be usually broken up into 'branches'.
    • It's a good practive to wrap several nodes that belong logically together in a Phenomenon.
    • Renaming of interface parameters of a Phenomenon increases the readability and usability.
    • The smoothstep node interpolates incoming values from 'start' to 'end' so that they will range from 0 to 1. Values outside will be clamped to 0 or 1.

    Further improvements of the shader network:
    • As an exercise for your own, make a Phenomenon that exposes only relevant interface parameters like water color, water level and the transition softness.
    • The surface of the illumination shader is completely smooth. You can add a texture to it to create more variation.
    • You can put the height information in the alpha channel of a texture. In this example the bumpmap could store the height in its alpha channel. This saves a texture lookup.
    • The water surface does not reflect light sources yet. Think of a way to add support for this. HINT: Use only the specular component of an illumination shader and add it to the result of the water-branch.
    Attached Images Attached Images  
    Last edited by ruediger; September 8th, 2009 at 16:31. Reason: Fixed typo

  2. #2
    Join Date
    Jul 2007


    Hi Ruediger

    Thanks for posting this Tutorial, it is exactly the kind of thing that I have been looking for; particularly to familiarize me with the more obscure nodes.

    If I may make a suggestion, it would be particularly helpful if you could make these posts into stickies - perhaps even create a tutorials section.

    I have not stepped through the full tutorial yet, but as soon as I finish, I will no doubt have a few questions.



  3. #3
    Join Date
    Jun 2007


    Hi woc,

    thanks for your input. We will keep in mind creating a tutorial section. As soon as I've got the time to post a new tutorial I'll probably move those to a dedicated area. It makes sense not to have it mixed up with threads that concern questions about mental mill. Currently I will leave it as it is.

    Talking about tutorials - if you created something interesting, we'd be happy to know about your results as well

    Best Regards,

  4. #4
    Join Date
    Jul 2007


    Hi Ruediger

    I would be happy to post the results of my work with the mill. As soon as I have something at a level of completion I will post it.



  5. #5
    Join Date
    May 2008


    Thanks so much for this tutorial - and I am eagerly awaiting new ones. I picked up mental mill this morning, and fx composer. I am so, so glad I can transfer my MRFM shading knowledge into this node based compiler.

    Thanks again!

  6. #6
    Join Date
    Sep 2007


    Really cool

  7. #7
    Join Date
    Apr 2009

    Default question

    I couldn't find "Math scalar add" and " Math scalar smoothstep" node.
    Please help...

  8. #8
    Join Date
    Sep 2007
    San Francisco Bay Area


    Hi Larcel,

    Sorry for any confusion. Old nodes that were named "scalar" are now called "float". You should now find them under the Math categories as Math_float_add and Math_float_smoothstep.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts