Horde3D

Next-Generation Graphics Engine
It is currently 28.03.2024, 09:46

All times are UTC + 1 hour




Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: 18.02.2009, 16:44 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
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.


Top
 Profile  
Reply with quote  
PostPosted: 18.02.2009, 17:59 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
What is the blend mode set to? I don't see that setting in the section you posted.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 18.02.2009, 18:02 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
Aah yes that's it, i missed on that one, thanks a lot!


Top
 Profile  
Reply with quote  
PostPosted: 11.04.2009, 05:17 
Offline

Joined: 11.04.2009, 05:11
Posts: 1
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!


Top
 Profile  
Reply with quote  
PostPosted: 11.04.2009, 21:21 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
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.


Top
 Profile  
Reply with quote  
PostPosted: 22.04.2009, 09:36 
Offline

Joined: 11.06.2008, 10:34
Posts: 119
anyidea when alphas, and alpha shadow cast will be re-implemented in the new shader system?

_________________

Let's bring 'em out! Any old iron! Any old iron!
A door opens and a homewife brings out a rather sophisticated-looking ground-to-air missile system, and dumps it on the cart.
Thank you.


Top
 Profile  
Reply with quote  
PostPosted: 22.04.2009, 23:03 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
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.


Top
 Profile  
Reply with quote  
PostPosted: 01.06.2009, 11:23 
Offline

Joined: 01.06.2009, 11:15
Posts: 14
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


Top
 Profile  
Reply with quote  
PostPosted: 03.06.2009, 00:11 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
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.


Top
 Profile  
Reply with quote  
PostPosted: 19.02.2010, 05:11 
Offline

Joined: 18.09.2009, 07:44
Posts: 17
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 1067 times
Top
 Profile  
Reply with quote  
PostPosted: 25.02.2010, 12:30 
Offline

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


Top
 Profile  
Reply with quote  
PostPosted: 08.03.2010, 00:14 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
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.


Top
 Profile  
Reply with quote  
PostPosted: 18.03.2011, 14:08 
Offline

Joined: 29.10.2010, 14:28
Posts: 46
Location: Hungary
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


Top
 Profile  
Reply with quote  
PostPosted: 19.03.2011, 21:26 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
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.


Top
 Profile  
Reply with quote  
PostPosted: 20.03.2011, 22:04 
Offline

Joined: 29.10.2010, 14:28
Posts: 46
Location: Hungary
Programming the soft particle is way above my head. I would appreciate if someone post me a solution in horde.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next

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