Shaders - How to setup so that Apha works

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Shaders - How to setup so that Apha works

Post by robmar »

I´ve been trying to use the Alpha byte on the output of shaders in GLSL and HLSL, and noticed that its necessary to set the material type on loading the shader.

I´m not sure which material type to use, as I can´t find a material that allows the alpha byte on the PS shader to simply work.

Does anyone know how the alpha can be activated, so that color.a works?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Shaders - How to setup so that Apha works

Post by hendu »

The EMT_TRANSPARENT_ALPHA_CHANNEL type.
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Shaders - How to setup so that Apha works

Post by Granyte »

If you are using 1.8 you also need to set the blen operation
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Shaders - How to setup so that Apha works

Post by robmar »

I tried with EMT_TRANSPARENT_ALPHA_CHANNEL, but the rendering is showing artifacts, parts correctly transparent and shaded, other parts showing the lines of triangles that make up the object.

I´m using 1.7.3. Can´t upgrade to 1.8 as the shadows are now too slow.

Any idea why triangles should show when alpha is below 1.0 (object debug is not set)?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Shaders - How to setup so that Apha works

Post by hybrid »

Yes, only at alpha == 0.0 the triangle won't show at all, in all other situations the poly will blend with varying transparency.
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Re: Shaders - How to setup so that Apha works

Post by Klunk »

had similar problems
http://irrlicht.sourceforge.net/forum/v ... =1&t=45238
the issue seems to be alpha shader are not sorted correctly as per "native" irrlicht materials, the solution is to set the material ZWriteEnable to false. may work for you.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Shaders - How to setup so that Apha works

Post by robmar »

@Klunk: Thanks for that!

@Hybrid: Come on, spill the beans! How about an understandable explanation as to why the Polys should be blending with "varying" transparency?

Is there a work-around such that the shader alpha will work correctly without nasty unexpected artifacts?
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Shaders - How to setup so that Apha works

Post by robmar »

@Klunk: Disabling ZWrite on the objects fixed it, but of course now the rendering sequence isn´t and won´t be correct, and a cube that is behind the shader rendered objects is rendered "incorrectly" over them.

Anyone know how to fix this issue? ... without destroying z-order rendering!! :) ahhhhh!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Shaders - How to setup so that Apha works

Post by hybrid »

Well, transparency is not arbitrary, but changes based on the alpha value. As it should be. Sorting happens based on the base material setting. If base material is using blending, it will be sorted into the transparent render phase, i.e. back to front and after all solid elements. If this does not work, just adjust example 10 to show this problem and we can see if there's something to fix.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Shaders - How to setup so that Apha works

Post by robmar »

To produce the issue I just set the shader color Alpha to 0.5 and load the torus.b3d mesh from nVidia´s samples, this donout shows the issue, but the standard cube and spherescenenode does not.

Looking closer I´m not sure these are the poly´s as such showing, but some variation in blending between them along the donout´s body.

There seems to be a cumulative (additive) blending of the meshes´ surfaces, resulting in transparency changes where there are overlapping polys... rather than the color.alpha simply affecting the whole of the object shape, it seems to be applied to each mesh surface and added to any overlapping mesh segment, and on more compelx shapes, where there is overlap, the transparency changes, giving a patchy effect.

Does that give enough clue to the problem?
Last edited by robmar on Mon Jan 07, 2013 5:22 pm, edited 1 time in total.
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Re: Shaders - How to setup so that Apha works

Post by Klunk »

it's an Alpha Sort problem, shaders set to EMT_TRANSPARENT_ALPHA_CHANNEL and EMT_TRANSPARENT_ADD_COLOR are not sorted like the built in materials.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Shaders - How to setup so that Apha works

Post by robmar »

Z-order sort you mean? Is there a solution that does not involve rewriting large amounts of code?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Shaders - How to setup so that Apha works

Post by hendu »

Show us a pic of that torus drawing wrong.

If it looks like what I think, you just entered the in-object draw order, which cannot be correct for transparent pixels ever (for an object of any complexity) - it's simply impossible using current technology.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Shaders - How to setup so that Apha works

Post by robmar »

If I disable ZWrite, most of these artefacts disapear, however, on the donut, when it´s rotated so that 4 of its surfaces overlap, the transparency level decreases, showing that there is still a cumulative transparency effect related to the number of surfaces in the line of view, if you follow what I´m mean... seems to indicate that alpha works per surface, not per model, which might seem to be a more useful real-world effect.

I mean here I am wanting to make a nice fade-out effect in Irrlicht of a complex mesh, and all the overlapping sub meshes have varied brightness, it looks horrible.... mmm back-culling....??? Nope, that didn´t do anything!
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Shaders - How to setup so that Apha works

Post by hendu »

Please, show a picture.
Post Reply