Shaders - How to setup so that Apha works
-
- 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
The torus renders perfectly for me, even in transparent mode. Without shaders, of course, but I doubt that that's the cause. The torus has no texture coords, though, so maybe that's your problem? Not sure if you use them inside the shader.
Re: Shaders - How to setup so that Apha works
The torus is okay. I'm going to assume from here on that your shader is not working correctly because it is verified not an Irrlicht problem.
Re: Shaders - How to setup so that Apha works
I posted the shader code earlier in this thread, its just a simple and standard pass-through shader with external alpha input.
if ( fAlpha != 0.0 )
{
float4 col = tex2D(Texture, In.TexCoord);
Out.color = float4(col.xyz, fAlpha);
}
else
Out.color = float4(0.0, 0.0, 0.0, 0.0);
Are there any problems with this? Copied a part above where the texture coords are used...
Also, I left in the old Gooch technique pass definitions, though I don´t think they were used...
if ( fAlpha != 0.0 )
{
float4 col = tex2D(Texture, In.TexCoord);
Out.color = float4(col.xyz, fAlpha);
}
else
Out.color = float4(0.0, 0.0, 0.0, 0.0);
Are there any problems with this? Copied a part above where the texture coords are used...
Also, I left in the old Gooch technique pass definitions, though I don´t think they were used...
Re: Shaders - How to setup so that Apha works
hendu, I read that irrlicht didn´t do occlusion rendering, I think thats what its called, and just rendered objects in z order one over the other, back-placed objects to front, so that the front objects just overwrite the back ones, but if alpha is used in the shader, then the rendering of front and back surfaces of the same mesh will be additive.
Is that what you mean by "messed up"?
Is that what you mean by "messed up"?
-
- 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
For proper transparent blending, objects have to be rendered back to front, such that the front objects can blend with the background. For solid objects, the render order does not matter, but you can save some time due to z-fail if you render front to back.
The problem with transparency arises always when objects intersect. If two transparent planes are intersecting, you cannot tell which one to draw first, as either choice would be wrong. At least on the mesh level. Of course you could do this on the poly level, where intersections are less often, but this would kill the frame rate. However, you also get the problem with just one transparent object, if polys or parts of the mesh itself intersect. In all these cases you can get wrong rendering. For most objects, this is not much of a problem, though, as you simply skip backfaces and get only very few intersects or wrong render orders. But it still can happen anywhere in these cases.
Enabling Z-Write makes this problem worse, as this would skip even more faces, and while a wrong order may still result in largely correct blending, a z-buffer discard will always remove the second blend color.
The problem with transparency arises always when objects intersect. If two transparent planes are intersecting, you cannot tell which one to draw first, as either choice would be wrong. At least on the mesh level. Of course you could do this on the poly level, where intersections are less often, but this would kill the frame rate. However, you also get the problem with just one transparent object, if polys or parts of the mesh itself intersect. In all these cases you can get wrong rendering. For most objects, this is not much of a problem, though, as you simply skip backfaces and get only very few intersects or wrong render orders. But it still can happen anywhere in these cases.
Enabling Z-Write makes this problem worse, as this would skip even more faces, and while a wrong order may still result in largely correct blending, a z-buffer discard will always remove the second blend color.
Re: Shaders - How to setup so that Apha works
That's not the entire shader code is it?
Have you used the transparency material on the torus without the shader?
Using a texture you can use EMT_TRANSPARENT_ALPHA_CHANNEL as long as the texture itself has alpha'd pixels in it. Without a texture (or with) you would want to use EMT_TRANSPARENT_ADD_COLOR to see a basic transparency effect. EMT_TRANSPARENT_ALPHA_CHANNEL_REF is used for masks like a sniper scope image drawn over a 3d scene to give the perception you're looking through a sniper scope.
I use the transparency material add color currently for things like glass and it works just like it should.
Have you used the transparency material on the torus without the shader?
Using a texture you can use EMT_TRANSPARENT_ALPHA_CHANNEL as long as the texture itself has alpha'd pixels in it. Without a texture (or with) you would want to use EMT_TRANSPARENT_ADD_COLOR to see a basic transparency effect. EMT_TRANSPARENT_ALPHA_CHANNEL_REF is used for masks like a sniper scope image drawn over a 3d scene to give the perception you're looking through a sniper scope.
I use the transparency material add color currently for things like glass and it works just like it should.
Re: Shaders - How to setup so that Apha works
Not its just a snippet. The complete shader is posted on page 3 here I think.
It uses tex2d so if the torus has bad mapping, maybe that is causing the rings when I use the shader alpha value. Could anyone try to fix the torus and I can try it again?
I still can´t manage to do that with blender, as the interface makes me feel like a blind person in a 747 coclpit!
Thanks for the explanation hybrid, seems that using alpha for a "simple" 3D fade effect is more complex that seems.
Are there any examples of fade effects that solve the surface overlap issue, maybe say in Ogre?
It uses tex2d so if the torus has bad mapping, maybe that is causing the rings when I use the shader alpha value. Could anyone try to fix the torus and I can try it again?
I still can´t manage to do that with blender, as the interface makes me feel like a blind person in a 747 coclpit!
Thanks for the explanation hybrid, seems that using alpha for a "simple" 3D fade effect is more complex that seems.
Are there any examples of fade effects that solve the surface overlap issue, maybe say in Ogre?
Re: Shaders - How to setup so that Apha works
Made a new torus in wavefront obj, the texture shows, but has a bad repeat pattern when tiled.
The artifacts still show though.
Any ideas?
The artifacts still show though.
Any ideas?
Re: Shaders - How to setup so that Apha works
Same mesh not tiled:-
Re: Shaders - How to setup so that Apha works
Is this with Z writing on or off?
Re: Shaders - How to setup so that Apha works
The Torus model is not bad. Disable the shader but keep the built in transparency material and screenshot that.
Re: Shaders - How to setup so that Apha works
With built in transparency, which uses pixel blending not alpha, there are no "artifacts". However that isn´t very useful to know.
Z writing is enabled, as it is for other models that don´t show this patterning.
As I also at times used stereo glasses, I need the Zwrite enabled... I would imagine...
Z writing is enabled, as it is for other models that don´t show this patterning.
As I also at times used stereo glasses, I need the Zwrite enabled... I would imagine...
Re: Shaders - How to setup so that Apha works
Then that is causing your artifacts..
Re: Shaders - How to setup so that Apha works
As far as I've learned, all blending techniques are, at the base level, the same. Alpha is simply a component of a 32bit color that can be used by the blending techniques to achieve a custom transparency look.robmar wrote: With built in transparency, which uses pixel blending not alpha, there are no "artifacts". However that isn´t very useful to know.
What you're talking about, I have no idea.
Irrlicht's built-in materials use the fixed-function pipeline to achieve their effects. When you introduce a shader to your program, you're simply adding a custom function into the pipeline. With the way Irrlicht allows you to base a custom shader on a built-in material, I assume your shader would be running after the materials effects have been calculated. I would believe then if you wrote a proper shader that changed the alpha depending on some number you fed in through your program to the shader, probably the objects alpha value, you'd achieve the effect you want and the control of the alpha blending effect you want. But that's just what I've read in the massive shader manuals you can freely find on the internet anywhere and from plucking along in Irrlicht for the past 5 or so years.
From here I would tell you that your result of the test I asked you to perform is simple proof that your shader is jacked up, yo'.
Your next step is this: Write a shader that takes the value of the texture, then outputs that exact same value. No tricks, no bells, no whistles. It should take maybe less than 10 lines to do it. To me, that is a 'pass-through' shader.
Set the shader in Irrlicht to be based off the transparency material you used in the previous test I asked you to perform, and then run it and tell me what you see.
P.S. Irrlicht doesn't, on it's own, handle alpha values. It simply implements them so that you can use them to achieve your own effects if you so choose.
Re: Shaders - How to setup so that Apha works
I did the "next step" shaded already, and posted it here earlier on.
Maybe its just an issue with the torus, as with other meshes its okay.
I would like to find a fix for the surface overlap issue, but disabling z write meses up drawing order.
Oh well, guess it will have to wait til a solution is found.
Maybe its just an issue with the torus, as with other meshes its okay.
I would like to find a fix for the surface overlap issue, but disabling z write meses up drawing order.
Oh well, guess it will have to wait til a solution is found.