Horde3D

Next-Generation Graphics Engine
It is currently 28.03.2024, 10:42

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Opacity / Alpha
PostPosted: 01.02.2013, 14:23 
Offline

Joined: 01.02.2013, 14:17
Posts: 2
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Opacity / Alpha
PostPosted: 01.02.2013, 20:47 
Offline

Joined: 17.11.2009, 17:00
Posts: 205
Location: Russia, Moscow
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Opacity / Alpha
PostPosted: 05.02.2013, 11:19 
Offline

Joined: 01.02.2013, 14:17
Posts: 2
Hi,
thank you very much, got it working :)
Best regards
Klaus


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 51 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group