Horde3D
http://horde3d.org/forums/

Opacity / Alpha
http://horde3d.org/forums/viewtopic.php?f=2&t=1859
Page 1 of 1

Author:  Klaus [ 01.02.2013, 14:23 ]
Post subject:  Opacity / Alpha

Hi,
is it possible to set the alpha channel of a material or texture or mesh? Target is to crossfade two planes with different textures.
Or has it to bee done over shaders?
Thx and best regards
Klaus

Author:  Irdis [ 01.02.2013, 20:47 ]
Post subject:  Re: Opacity / Alpha

Transparency has to be done in shaders. You should add something like this to your model.shader (or create a custom .shader file):
Code:
[FX]
... // some code here
// Uniforms
...
float opacity = 1.0; // variable that controls opacity of the object

// contexts
context TRANSLUCENT
{
   VertexShader = compile GLSL VS_GENERAL;
   PixelShader = compile GLSL FS_TRANSLUCENT;
   
   ZWriteEnable = false;
   BlendMode = Blend;
}

... // some code here
[[FS_TRANSLUCENT]]
// =================================================================================================

uniform sampler2D albedoMap;
varying vec2 texCoords;
uniform float opacity;

void main( void )
{
   // gl_FragColor = texture2D( albedoMap, texCoords * vec2( 1, -1 ) ); // use this line to use transparency from the texture (png, tga with alpha channel)
   
   vec3 newCoords = vec3( texCoords, 0 );
   newCoords.t *= -1.0; // Flip texture vertically to match the GL coordinate system
   vec4 albedo = texture2D( albedoMap, newCoords.st );
   
   gl_FragColor = vec4( albedo.rgb, opacity ); // use this line to control transparency from material
}


Then, in your material, you should write something like this:
Code:
 <Uniform name="opacity" a="0.5" />  // for 50% transparency


Note: you should use this with forward pipeline. Deferred pipeline has some issues with rendering transparent surfaces.

Author:  Klaus [ 05.02.2013, 11:19 ]
Post subject:  Re: Opacity / Alpha

Hi,
thank you very much, got it working :)
Best regards
Klaus

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/