Part 2: Texturing and misc stuff

We haven't assigned textures to the material in the previous part to have a better understanding of how different output nodes work, however we can do that now.
As an example, let's (re)create a basic material for a rock, Rock_Common_Big_B.

Instead of simple colors, we'll now use textures and attach their outputs to the material inputs.
  • Add a texture node (called Texures -> Texture2D in the Nodes pane) to the graph.
    The sampler has multiple outputs: RGB is a 3-component color vector, just like the one we've used when specifying colors; the R,G,B and A values are floating point values for Red, Green, Blue and Alpha.
  • The new texture node is initally highlighted in red, with a "Texture2D : No valid texture resource set" error message, as we haven't assigned a texture to it yet.
    To fix this,
    • Select the Rock_Common_Big_B_DM texture in the Resource Browser (make sure that it stays selected!)
    • Select the Texture2D node in the Material Editor
    • Slect the TextureGUID property in the Properties pane of the node
    • Click "..." and click the green "right arrow" button to assign the selected texture resource to the Texture2D node.
    • Connect the RGB output of the texture node to the Diffuse input of the Material node.


Note: You can select the rock as the preview model in the Preview pane of the material editor by selecting the Rock_Common_Big_B model (has a teapot icon) in the Resource Manager window and clicking the Custom button in the Material Preview pane while the resource is selected, but I've only realized this after I've finished the tutorial, so all screenshots will be of spheres instead of a rock smile

If everything is OK, a textured rock should appear (... or a sphere for me :):
[Linked Image]
[Linked Image]

You can determine the type of a texture by looking at its postfix: (eg. _DM for Rock_Common_Big_B_DM):
  • DM: Diffuse Map
  • SM: Specular Map
  • NM: Normal Map
  • GM: Glow Map
  • MSK: Tint Mask

Let's do something a bit more complex than connecting one node to one material output.
A simple thing that we can do with the diffuse rock texture is previewing color channels separately.
To do this, simply connect the R, G, B or A output to the Diffuse material input.

An example of connecting the Red channel to Diffuse:
[Linked Image]
[Linked Image]

... however the preview color - somewhat unexpectedly - is gray, instead of red; why is that?
The reason is that the engine doesn't differentiate between colors when connecting nodes; what it sees is that we gave a single float value (the Red color) to an input that expects a Vector3 value; in this case, the engine "extends" the float value into a Vector3 by copying the same float value to each component of the vector - e.g. 0.3 becomes (0.3,0.3,0.3).

To get a true red color, we need to pass a vector to the Diffuse input with one of the channels (Red) set to the Red color of the texture, and the other channels set to zero (so they don't reflect light).
To do this, we need two additional nodes:
  • The "Combine" node has one output and 4 inputs, although connecting all of them is not necessary.
    The node works by receiving two or more input floats or vectors, and combining them into a single vector.
    Eg. connecting the R, G and B color to the first 3 inputs will combine them into a Vector3 (R,G,B) output.
    Connecting them in a different order, eg. G, B, R, A will result in a (G,B,R,A) Vector4.
    The node can also append vectors; a Vector3 and a float input will result in a Vector4 output.
    The inputs are always appended to each other from the first (top) input to the last (bottom) one in order.
  • After placing a Combine node, let's connect the Red (R) output of the Texture to the first input of the Combine node.
  • We also need to tell the node that the G and B channels are zero (0), otherwise it won't output a Vector3, this is where the "Float (1)" node from the previous tutorial comes in.
    Place a new Float node and connect its output to the second and third (Green and Blue) input of the Combine node (don't connect the fourth one!).
    The float value is 0 by default, no need to change that.
  • Finally, connect the output of the Combine node to the material Diffuse input.
    (This will disconnect the texture and the material from each other.)

The new - this time really red - material:
[Linked Image]
[Linked Image]



We can also increase/reduce the intensity of one or more of the color components (... and do many other wonderful things):
The basic idea is to use a simple combination of the Multiply (or Divide) and the Combine nodes by multiplying one of the color components before passing it on to the Combine node:
  • Add a new Multiply node to the graph.
    Its operation is very simple, it multiplies the input (X, Y) values, so the output becomes X * Y.
    When multiplying colors, a value less than 1 will reduce and larger than one will increase color intensity.
  • Connect a color component of your choice from the Texture node to the Multiply node (doesn't matter if its connected to the X or Y input, the result is the same.)
  • Connect a Float value to the other input of the Multiply node.
  • Connect the output of the Multiply node to the corresponding Combine input (eg. if you're multiplying the Red component then connect it to the firt input, second input for Green, etc.)
  • Connect the other two Texture color outputs to the empty Combine inputs.

Example of multiplying the green component with 0.5 and 1.5:
[Linked Image]
[Linked Image]
[Linked Image]
NOTE: The Diffuse property specifies the % of light reflected in all directions (0.0 = 0%, 1.0 = 100%).
Multiplying the color with a value larger than one, may yield colors that are larger than 1, which means that the surface emits *more* light than it receives.
While the renderer can handle this, this behavior does not occur in real life materials due to the law of conservation of energy, and should be utilized with care!

... Part 3 will have Diffuse/Specular/Normal maps and a blinking Emissive texture!