Blender 3D: Noob to Pro/Using a texture to make a material partially transparent
|Applicable Blender version: 2.49.|
To understand the collaboration of textures and material we will use the opacity of a material - the alpha value - as an example. We will show how to set the opacity/transparency of a material with different types of textures.
The Alpha value of the material is set with the A(lpha) slider in the Material panel. This is the basic Alpha value. If Alpha is 1, the material is fully opaque, if Alpha is 0, the material is fully transparent.
Now you change that basic Alpha value with a texture.
- If the basic Alpha value is 1 you can only lower it with a texture, because 1 is the maximum value anyway.
- If the basic Alpha value is 0 you can only increase it with a texture.
The target value of Alpha that can be achieved with the texture is set with the DVar button in the Map To panel. If Alpha is 0 and DVar is 0 than nothing will happen. You can set either:
- Alpha to 1 and DVar to 0, then the texture will lower the Alpha value, or you can set
- Alpha to 0 and DVar to 1, then the texture will increase the Alpha value.
Both methods are possible and equal in the result, but for clarity we will always use method number 1. There are more combinations possible, so it may be that you find tutorials with different settings.
Using a greyscale texture - white for opaqueEdit
In Img. 1a the black areas shall become transparent, the white areas shall become opaque.
- Load the image as Image texture, turn off Use Alpha.
- Set the Alpha value in the material buttons to 1. This is the default value anyway.
- Activate ZTransp (or RayTransp if you need refraction)
- The Map To panel:
- Turn off Col (or else the texture would also affect the color of the material)
- Turn on Alpha inverse, you have to click it twice. We need inverse here, because the texture shall affect the material from its black parts. (Noob Note: On blender 2.63 you need to set a specific 'Alpha' value (the one located under 'influence->diffuse) to -1, as the alpha button referenced in this step no longer exists in 2.63.)
- Turn on Spec inverse (you don't want your transparent sections to show specular highlights) (Noob Note: As far as I could tell, the equivalent to doing this on blender 2.63 is to set a specific 'Intensity' value (located under Influence->Specular) to -1.)
- Set the DVar value to 0. The default value is 1.
Now let's take a look at the texture.
- Where the texture has a value of 0 (e.g. black) it will affect the Map To values fully (because we have used inverse).
- Where the texture has a value of 1 (e.g. white) it will do nothing.
- Where the texture has a value in between 0 and 1 it will affect the Map To values partially.
The result is shown in Img. 1c, the texture applied to a plane rendered against a white world background.
If your texture is inverted, i.e. black shall become opaque and white transparent, simply use the normal Alpha and Spec setting in the Map To panel. (Noob Note If you don't see the white 'shine' on the maple leaf, move the default point lamp (lighting source) closer to the plane mesh to which the texture and material are assigned.)
That's it. It's basically the same for all settings, the only problem that remains is sometimes to know which value a texture will give if you use transparent textures or colored textures.
For 2.7 blenderers out there: To obtain the results I had a hard time and finally came across (almost accidentally) to uncheck the 'use alpha' button in the image sub panel of the texture menu. Then, you can get the results as above.
Using a partially transparent texture to make the material transparentEdit
Often we have a partially transparent texture, and want to directly use that transparency of the texture to make the material transparent too. We have now to think a bit about the values that are generated by the texture itself:
If we load the image texture with Use Alpha, the Alpha value of the image is used as input value for Alpha and Spec in the Map To panel. So a fully transparent pixel in the image has an Alpha value of 0, a fully opaque pixel has an Alpha value of 1. This is exactly the same situation as above, simply turning on Use Alpha and Premul(tiply Alpha in Advance) will give use the same result as with the greyscale image.
- Turn on Use Alpha in the Map Image panel of the texture buttons.
- Turn on Premul in the Image panel. This is necessary to get real partial transparent borders.
- Turn on Col in the Map To panel additionally.
The rendering result is pretty similar to Img. 2a, only that it is affected by lighting (and casts shadows).
Don't forget to turn on TraShadow in the Shaders panel for the object that is receiving the shadow. (Noob Note: In Blender 2.6x you also need to check the "Receive Transparent" box in the shadow section of the material for the object receiving shadows or you will get a black square shadow.)
(Noob Note: In this case add a plane colored white just below the "leaf." This is the object the you should turn on TraShadow with as this is the object that will receive the shadow. This is also providing that you have a light source properly positioned.)