Page 1 of 3

EMF_TRANSPARENT_ALPHA rendering problem

Posted: Thu Oct 23, 2014 11:20 am
by Harch
Hello everyone! I write a voxel game and decided to add some transparent materials to it. It leads to many bugs and problems, which can't be solved by me. I'll try to show them in video. So, as you can see, i create two chunks(which are two different meshes and meshbuffers and nodes also). When i try to see them from different angles, i get some strange things. No separating quads there. Node's (0, 0, 0) point is the chunk's corner. I'm really tired and i can't find a solution, please, help.
P.S. For lighting i use my own shader, but i'm pretty sure, that it is not the reason. I tried to turn it off, colored the mesh by irrlicht's methods and got exaclty the same bugs, but, just in case, i'll give a code.
P.P.S. And one more very strange thing: blending is working despite i turn it off.
Help me, please, and sorry for my english. The code is below.

Video: http://www.youtube.com/watch?v=Q0dJYQO_Hbc

Code:

Code: Select all

 
int main()
{
    ..............
    SIrrlichtCreationParameters* s_IrrlichtCreationParameters = new SIrrlichtCreationParameters;
    s_IrrlichtCreationParameters->DeviceType = EIDT_BEST;
    s_IrrlichtCreationParameters->DriverType = EDT_OPENGL;
    s_IrrlichtCreationParameters->WindowSize = dimension2d<u32>(1280, 720);
    s_IrrlichtCreationParameters->Bits = 32;
    s_IrrlichtCreationParameters->ZBufferBits = 16;
    s_IrrlichtCreationParameters->Fullscreen = false;
    s_IrrlichtCreationParameters->Stencilbuffer = false;
    s_IrrlichtCreationParameters->Vsync = false;
    s_IrrlichtCreationParameters->AntiAlias = 8;
    s_IrrlichtCreationParameters->WithAlphaChannel = false;
    s_IrrlichtCreationParameters->Doublebuffer = true;
    s_IrrlichtCreationParameters->IgnoreInput = false;
    s_IrrlichtCreationParameters->Stereobuffer = false;
    s_IrrlichtCreationParameters->HighPrecisionFPU = false;
 
    IrrlichtDevice* device = createDeviceEx(*s_IrrlichtCreationParameters);
    delete s_IrrlichtCreationParameters;
 
    ...............
 
    smgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true); //Scene manager
 
    // Creating light shaders
    MyShaderCallBack* mc = new MyShaderCallBack();
    s32 chunkLightMaterialType = driver->getGPUProgrammingServices()->addHighLevelShaderMaterialFromFiles(
                                "Shaders/light.vert", "vertexMain", video::EVST_VS_1_1,
                                "Shaders/light.frag", "pixelMain", video::EPST_PS_1_1,
                                mc, video::EMT_SOLID, 0, EGSL_DEFAULT);
    s32 chunkLightTransparentMaterialType = driver->getGPUProgrammingServices()->addHighLevelShaderMaterialFromFiles(
                                "Shaders/light.vert", "vertexMain", video::EVST_VS_1_1,
                                "Shaders/light.frag", "pixelMain", video::EPST_PS_1_1,
                                mc, video::EMT_TRANSPARENT_ALPHA_CHANNEL, 0, EGSL_DEFAULT);
 
    ..........................
 
    MyFactoryChunkMeshSceneNode* mfcmsn = new MyFactoryChunkMeshSceneNode(device, isve); //Creating factory of nodes
    ..........................
    mfcmsn->setNumberOfMeshesSceneNodeForChunk(3);
    mfcmsn->setHardwareMappingHint(0, EHM_STATIC, EBT_VERTEX_AND_INDEX); //First parameter is number mesh
    mfcmsn->setMaterialType(0, (E_MATERIAL_TYPE)chunkLightMaterialType);
    mfcmsn->setHardwareMappingHint(1, EHM_STATIC, EBT_VERTEX_AND_INDEX); //Glass mesh
    mfcmsn->setMaterialType(1, (E_MATERIAL_TYPE)chunkLightTransparentMaterialType);
    mfcmsn->setHardwareMappingHint(2, EHM_STATIC, EBT_VERTEX_AND_INDEX); //Water mesh
    mfcmsn->setMaterialType(2, (E_MATERIAL_TYPE)chunkLightTransparentMaterialType);
    ...........................
    isve->getFactoryChunkMeshSceneNode()->setMaterialFlag(2, id, EMF_LIGHTING, false); //id - world identificator, 2 - mesh for water, isve - my voxel engine
    isve->getFactoryChunkMeshSceneNode()->setMaterialFlag(2, id, EMF_BLEND_OPERATION, true);
    isve->getFactoryChunkMeshSceneNode()->setMaterialFlag(2, id, EMF_ZWRITE_ENABLE, false);
    isve->getFactoryChunkMeshSceneNode()->setMaterialFlag(2, id, EMF_BACK_FACE_CULLING, false);
    isve->getFactoryChunkMeshSceneNode()->setMaterialFlag(2, id, EMF_COLOR_MATERIAL, false);
    .........................
    isve->stop(); //Stopping engine, waiting all thread
    delete isve;
    device->drop();
    return 0;
}
 
Shaders:

light.vert:

Code: Select all

uniform float s_StarLightIntensity;
 
varying vec3 s_PixelColor;
varying float s_StarLight;
 
void main(void)
{
    gl_Position = ftransform();
    gl_TexCoord[0] = gl_MultiTexCoord0;
    s_PixelColor = gl_Color.xyz;
    s_StarLight = gl_Color[3] * s_StarLightIntensity;
}
 
light.frag:

Code: Select all

uniform sampler2D s_TextureLayerID;
 
uniform vec4 s_StarLightColor;
 
varying vec3 s_PixelColor;
varying float s_StarLight;
 
vec4 colorDown(in vec4 color)
{
    float dist = 0.0;
    for(int i = 0; i < 3; i++)
        if(color[i] > 1.0 && color[i] - 1.0 > dist) dist = color[i] - 1.0;
    for(int i = 0; i < 3; i++) color[i] = color[i] - dist;
    return color;
}
 
vec4 getLight(in vec4 color, in float starlight)
{
    return colorDown(color + vec4(s_StarLightColor.xyz, 0.0) * starlight);
}
 
void main()
{
    float starlight = s_StarLight;
    vec4 color = texture2D(s_TextureLayerID, vec2(gl_TexCoord[0]));
    gl_FragColor = vec4((color * getLight(vec4(s_PixelColor, 1.0), starlight)).xyz, color.a);
}
 

Re: EMF_TRANSPARENT_ALPHA rendering problem

Posted: Fri Oct 24, 2014 2:10 am
by mongoose7
Maybe try setting gl_FragColor = vec4(0.7) just to eliminate lighting calculations. Also, do you use a texture like that caustic effect anywhere in your program? Maybe try the latest version in the "trunk" branch.

Re: EMF_TRANSPARENT_ALPHA rendering problem

Posted: Fri Oct 24, 2014 7:42 pm
by Harch
I tried to remove the shader and just paint the mesh - the result was the same. So I think that the lighting does not spoil anything :(
I do not use until the other layers of textures. Only the first. I look forward to lighting manually. Values ​​lighting pass to the vertex shader for each vertex by vertex SColor. Alpha is sunlight. RGB is the artificial lighting. But I think that the shader does not do anything wrong. I have checked and no shader.

That is, I'm doing everything right? But is the result of a wrong? And I have to download the latest build irrlicht (or what is trunk?)?

P.S. Sorry for google translate.

Re: EMF_TRANSPARENT_ALPHA rendering problem

Posted: Sat Oct 25, 2014 1:38 am
by mongoose7

Re: EMF_TRANSPARENT_ALPHA rendering problem

Posted: Sat Oct 25, 2014 11:34 am
by Harch
Thank you. I'll check and report the results.

Re: EMF_TRANSPARENT_ALPHA rendering problem

Posted: Sun Oct 26, 2014 9:49 am
by Harch
I checked. The same rendering errors :( What else advise? :)

Re: EMF_TRANSPARENT_ALPHA rendering problem

Posted: Mon Oct 27, 2014 12:56 am
by mongoose7
mongoose7 wrote:Maybe try setting gl_FragColor = vec4(0.7) just to eliminate lighting calculations. Also, do you use a texture like that caustic effect anywhere in your program? Maybe try the latest version in the "trunk" branch.
It would be good to see a picture without effects.

Re: EMF_TRANSPARENT_ALPHA rendering problem

Posted: Mon Oct 27, 2014 12:13 pm
by Harch
I have already done so like. Had the same error. Check once more?

Re: EMF_TRANSPARENT_ALPHA rendering problem

Posted: Mon Oct 27, 2014 2:28 pm
by Harch
Only i did:

Code: Select all

 
gl_FragColor = vec4((color * getLight(vec4(s_PixelColor, 1.0), starlight)).xyz, 0.7);
 

Re: EMF_TRANSPARENT_ALPHA rendering problem

Posted: Mon Oct 27, 2014 8:13 pm
by Harch
http://www.sjbaker.org/steve/omniv/alpha_sorting.html

May be necessary to arrange the polygons in meshbuffer, as written in the link above? If yes, then how to do the functions of the engine?

Re: EMF_TRANSPARENT_ALPHA rendering problem

Posted: Tue Oct 28, 2014 12:29 am
by mongoose7
a) Irrlicht renders transparent meshbuffers after solid ones. You don't have to do anything.
b) TRANSPARENT_ALPHA_CHANNEL_REF is rendered as solid, which is what you would want.
In summary, you do not have to do your own sorting.

While it is true that Irrlicht doesn't sort the transparent mesh buffers, and that this can matter, if all the transparent materials are the same then it doesn't matter. So this should not be an issue for you.

Re: EMF_TRANSPARENT_ALPHA rendering problem

Posted: Tue Oct 28, 2014 7:27 am
by Harch
So, the problem is not it? And then what is it? :(

Re: EMF_TRANSPARENT_ALPHA rendering problem

Posted: Tue Oct 28, 2014 8:54 am
by mongoose7
I don't even know what your problem is.

Re: EMF_TRANSPARENT_ALPHA rendering problem

Posted: Tue Oct 28, 2014 11:36 am
by CuteAlien
Irrlicht sorts transparent meshes only per node. I fear you have no choice for now but to split it into several nodes. And yeah - sorting per meshbuffer at least would be nice I guess. Per polygon would be too slow I suppose for most cases. Making sorting completely flexible would be optimal, but not trivial for this case. I suppose best solution would be if Irrlicht offers just some more sorting options, but not really anyone working on that currently.

Re: EMF_TRANSPARENT_ALPHA rendering problem

Posted: Tue Oct 28, 2014 5:57 pm
by Harch
But how then were taken to clone minecraft on irrlicht? In these projects transparency is normally, despite the fact that the transparent block are combined into one meshbuffer ...