Horde3D
http://horde3d.org/forums/

using alpha channel in shader
http://horde3d.org/forums/viewtopic.php?f=2&t=652
Page 1 of 2

Author:  jimbo [ 18.02.2009, 16:44 ]
Post subject:  using alpha channel in shader

Im using the new shader system, and trying to make a simple shader that uses the alpha channel of the TGA texture for
transparency and has no lighting or shadowmap. All parts of the texture which should be transparent show up black opaque.
Here's the shader:

Code:
[[FX]]
<Sampler id="albedoMap" />
<Uniform id="specParams" a="0.1" b="16.0">
   <!-- Description
      a - Specular mask
      b - Specular exponent
   -->
</Uniform>

<Context id="AMBIENT">
   <Shaders vertex="VS_GENERAL" fragment="FS_AMBIENT" />
</Context>

[[VS_GENERAL]]

#include "shaders/utilityLib/vertCommon.glsl"

uniform vec3 viewer;
attribute vec2 texCoords0;
attribute vec3 normal;

varying vec4 pos, vsPos;
varying vec2 texCoords;
varying vec3 tsbNormal;


void main( void )
{
   // Calculate normal
   vec3 _normal = calcWorldVec( normal );

   // Calculate tangent and bitangent
   tsbNormal = _normal;
   // Calculate world space position
   pos = calcWorldPos( gl_Vertex );

   vsPos = calcViewPos( pos );
   
   // Calculate texture coordinates and clip space position
   texCoords = texCoords0;
   gl_Position = gl_ModelViewProjectionMatrix * pos;
}

[[FS_AMBIENT]]   

uniform sampler2D albedoMap;
varying vec2 texCoords;

void main( void )
{
   gl_FragColor = texture2D( albedoMap, texCoords );
}


This simple shader worked with the old shader system. I'm not sure what's wrong here.

Author:  swiftcoder [ 18.02.2009, 17:59 ]
Post subject:  Re: using alpha channel in shader

What is the blend mode set to? I don't see that setting in the section you posted.

Author:  jimbo [ 18.02.2009, 18:02 ]
Post subject:  Re: using alpha channel in shader

Aah yes that's it, i missed on that one, thanks a lot!

Author:  Bakuhatsu [ 11.04.2009, 05:17 ]
Post subject:  Re: using alpha channel in shader

Sorry to bump an old topic on my first post but my question is related to this.

I am totally new to Horde3D (I am a 3D artist rather than a coder) and I cannot figure out how to get alpha-channel textures to display properly.

Could anyone possibly explain how I would go about adding alpha support to the standard model shader?
I have tried using the code above, with the required blend mode, however the model's texture UVs are destroyed when using it.

Also is it possible to add alpha pass early on so that it affects the shadowmaps?

Many thanks!

Author:  marciano [ 11.04.2009, 21:21 ]
Post subject:  Re: using alpha channel in shader

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.

Author:  PuG [ 22.04.2009, 09:36 ]
Post subject:  Re: using alpha channel in shader

anyidea when alphas, and alpha shadow cast will be re-implemented in the new shader system?

Author:  marciano [ 22.04.2009, 23:03 ]
Post subject:  Re: using alpha channel in shader

We also did not have full transparency support in the sample shaders of Beta2. But we will add a basic solution using the new shader system soon.

Transparent shadow maps (to make transparent objects cast attenuated shadows) are a different story. They are a very special technique, so I think we will not add them to the default samples.

Author:  torsk [ 01.06.2009, 11:23 ]
Post subject:  Re: using alpha channel in shader

hi

I've replicated steps marciano told, but depth sorting is still a problem. DrawGeometrys "order=" parameter doesn't seem to have any effect.

Here's the model + texture i am trying to render: http://www.drugphish.ch/~thok/snowtree.zip

Author:  marciano [ 03.06.2009, 00:11 ]
Post subject:  Re: using alpha channel in shader

I tried out the steps myself before I have written them down and I think I recall that sorting worked. What version of Horde are you using? Also please note that only meshes are sorted, not individual polygons.

Author:  craigomatic [ 19.02.2010, 05:11 ]
Post subject:  Re: using alpha channel in shader

marciano wrote:
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...

This post was very useful!

See attached for a modified version of model.shader that works with Beta4 as described in marciano's post

Attachments:
model.zip [1.93 KiB]
Downloaded 1325 times

Author:  Irdis [ 25.02.2010, 12:30 ]
Post subject:  Re: using alpha channel in shader

My bad, it was my fault that there was an error with the h3dSetAnimParams. As for the deferred pipeline, now I understand that is is complicated to get transparency in deferred shading. If I find a way to use transparency in deferred shading (translate from rough GL to horde's pipeline), I will share it.

Author:  marciano [ 08.03.2010, 00:14 ]
Post subject:  Re: using alpha channel in shader

Translucent geometry can be rendered with a deferred pipeline as well, if you do an additional forward pass after the lighting stage which draws the translucent objects.

Author:  anchor [ 18.03.2011, 14:08 ]
Post subject:  Re: using alpha channel in shader

hello!

can you show an example deferred.pipeline.xml with TRANSLUCENT pass?
i would like to see particles with deferred shading. (i tried in many ways,
but i can not figure out what is the right way to do this.) i need deferred
shading because of soft particles. or can i read the depth buffer in forward
pipeline too? if yes, how?

anchor

Author:  marciano [ 19.03.2011, 21:26 ]
Post subject:  Re: using alpha channel in shader

Hi anchor, if you really just need the depth for soft particles and maybe a few simple post processing effects (DOF, basic SSAO) and you will not benefit from more light sources or the other data in the g-buffer, I would not recommend to switch to the deferred pipeline because it has a constant performance overhead and complicates things like MSAA.

It is pretty easy to access the depth in the forward pipeline. In the pipeline definition you need to set up a render target that serves as a temporary backbuffer. The HDR pipeline does something like that and should be a good reference. You can bind the depth buffer as texture using the BindBuffer command with bufIndex=32. Just make sure that you blit the temporary render target somehow to the main backbuffer at the end of the pipeline, for example during a post processing effect.

Author:  anchor [ 20.03.2011, 22:04 ]
Post subject:  Re: using alpha channel in shader

Programming the soft particle is way above my head. I would appreciate if someone post me a solution in horde.

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