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;
}
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;
}
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);
}