Unfortunately alpha-transparency for models is not yet fully inplemented in the sample shaders. But here is a simple approach that works with the forward pipeline.
Add a new context to the FX section of model.shader. This is required since we need to enable blending.
Code:
<Context id="TRANSLUCENT">
<RenderConfig writeDepth="false" blendMode="BLEND" />
<Shaders vertex="VS_GENERAL" fragment="FS_TRANSLUCENT" />
</Context>
Add the required shader section which is referenced by the new context at the end of model.shader
Code:
[[FS_TRANSLUCENT]]
// =================================================================================================
uniform sampler2D albedoMap;
varying vec2 texCoords;
void main( void )
{
gl_FragColor = texture2D( albedoMap, texCoords * vec2( 1, -1 ) );
}
Make sure that the albedo texture of your model has an alpha channel. To apply the transparency to an object, you need to set its material class to "Translucent". Here is how it is done for the Chicago character (civilian1.material.xml):
Code:
<Material class="Translucent">
<Shader source="shaders/model.shader" />
<ShaderFlag name="_F01_Skinning" />
<Sampler name="albedoMap" map="models/man/civil01.jpg" />
</Material>
The characters should be transparent now. The problem is that they are not yet sorted by depth which looks very strange. To do that, modify line 10 of forward.pipeline.xml:
Code:
<DrawGeometry context="TRANSLUCENT" class="Translucent" order="BACK_TO_FRONT" />
Another problem is that the objects still cast shadows. The reason for that is that the model shader always has the shadow map context defined. There are two quick solutions: either you create a new shader flag _F??_NoShadow which writes 1.0 to the shadow map or you create a completely new shader which just defines the TRANSLUCENT context (and no SHADOWMAP context).
Please note that the transparent objects are currently not influenced by light sources. This should also be possible by modifying the pipeline file and adding another DoForwardLightLoop pass for transparent objects.