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

Re: Shaders - How to setup so that Apha works

Post by robmar »

Okay, I have to upload it somewhere, can´t just paste it here...
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Shaders - How to setup so that Apha works

Post by robmar »

Image
chronologicaldot
Competition winner
Posts: 699
Joined: Mon Sep 10, 2012 8:51 am

Re: Shaders - How to setup so that Apha works

Post by chronologicaldot »

Ah - so we're seeing mesh triangles, whereas the sphere looks like it is perfect (instead of being composed of triangles). Since the curvature of the sphere is softer than the torus, I imagine more faces on the torus would smooth it out like the sphere and make the problem go away / be reduced.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Shaders - How to setup so that Apha works

Post by robmar »

Thanks for that, unfortunately the triangles are quite similar in size, and in debug mode equally visible.
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 »

I assume you mean patches, which are not exactly aligned to the triangles?! I doubt that this has anything to do with the polygons, it's merely in the shader.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Shaders - How to setup so that Apha works

Post by robmar »

So what you mean by "its in the shader" is that the pixel shader math is causing these effects that don´t show unless the alpha is set, and which almost disappear if ZWrite is disabled?

The shader is the classic Gooch produced by 3D Labs, why should it shade the curves of the circle without problems under alpha but the donut not?

Anyway its just setting the alpha to a fixed value... but its clear that the alpha under Irrlicht works on each mesh surface in a additive manner, that must be a known problem in CG modelling right?

We´d all appreciate a little more of an idea of these matters which must be all old ground for CG experts.
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 merely in the shader.
don't think it's in the shader, irrlicht does not handle shaders properly when used with the EMT_TRANSPARENT_ALPHA_CHANNEL and EMT_TRANSPARENT_ADD_COLOR

Image

shader version behind native irrlicht in front
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Shaders - How to setup so that Apha works

Post by robmar »

Who deleted the picture of the issue, and why?
The issue is far from resolved!

Pitcure : Image

http://i.imgur.com/MNV8o.jpg
Last edited by robmar on Tue Jan 08, 2013 10:51 am, edited 1 time in total.
CuteAlien
Admin
Posts: 9971
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Shaders - How to setup so that Apha works

Post by CuteAlien »

The link is still there... but you shouldn't use commons.wikimedia.org/ as image-dumping website :-)
Use imgur for example - that will stay a little longer (although also not infinite).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Shaders - How to setup so that Apha works

Post by robmar »

Thanks, updated!

So does anyone have any views on the alpha blending that is causing these variations in transparency, which seems to be caused when two mesh surfaces of the same object overlap?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Shaders - How to setup so that Apha works

Post by hendu »

Anyway its just setting the alpha to a fixed value... but its clear that the alpha under Irrlicht works on each mesh surface in a additive manner, that must be a known problem in CG modelling right?
It's not a problem, it's how it's supposed to work. Think of the torus as a glass object, with 1mm thick walls, with air inside it.

With that visualization, it should be clear why both surfaces need to be additive - this is what's expected from glass objects, it's how they act in the real world ;)


The problem your arrow highlights, I don't think alpha blending can cause artifacts like that. You should never enable zwrite for transparent objects, that's why it's also a toggle in the driver making extra sure you really want to do that.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Shaders - How to setup so that Apha works

Post by hendu »

Anyway, for your desired effect (one alpha for the whole object, to fade it out), you need to only draw its front face. With alpha blending, without Z writing.

One way to do it: first render the object to the Z-buffer only. You do this by disabling color and alpha writes in all its materials.

Then, when you render it again with the color & alpha writes enabled, only one face will be drawn, giving you the "single-alpha" effect.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Shaders - How to setup so that Apha works

Post by robmar »

okay, that sounds more like it!

but how to do it?

I have many objects, background and foreground, and the shader-fader objects, so its not so simple, especially to keep FPS from collapsing.

What happens if I have "normal" objects overlapping the fading ones? How do I do the passes then?

So Irrlicht renders only front faces of a mesh when Z-write is off?

With Z-write enabled I get this:-
Image
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Shaders - How to setup so that Apha works

Post by robmar »

And with Z-write disabled, I get this, back faces are being rendered, and I can see that the shader is now unable to determine surface Z-position correctly to produce the shading effect.
Image

So my shader won´t render in color correctly, as it uses the Z-position to calculate shading... though the camera object looks better, its still rendering as a glass box.

The donut still looks very messed up... is it something in the mesh file, a .b3d (for some reason its b3d!)

How else can this be done? To get one transparency, as objects in the real-world are not all glass shells!
Post Reply