Quake3 shaders and fog

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!
Post Reply
achpile
Posts: 5
Joined: Mon Oct 27, 2014 7:21 am

Quake3 shaders and fog

Post by achpile »

Hello, everyone! I'm stuck with applying fog to Quake3 shaders. Well. I have a map with simple textures and shaders (this is the only way I found to use transparent and semi-transparent textures).
At first I set fog to the driver:

Code: Select all

 
driver->setFog(video::SColor(0,0,0,0), video::EFT_FOG_LINEAR, 0, 500, .003f, true, false);
 
After I load mesh like this:

Code: Select all

 
    scene::IQ3LevelMesh* const mesh =
        (scene::IQ3LevelMesh*) smgr->getMesh(mapname);
 
    /*
        add the geometry mesh to the Scene ( polygon & patches )
        The Geometry mesh is optimised for faster drawing
    */
    scene::ISceneNode* node = 0;
    if (mesh)
    {
        scene::IMesh * const geometry = mesh->getMesh(quake3::E_Q3_MESH_GEOMETRY);
        node = smgr->addOctreeSceneNode(geometry, 0, -1, 4096);
        node->setMaterialFlag(video::EMF_FOG_ENABLE, true);
    }
 
Okay, this works great! But next I load the shader objects (semi-transparent glass objects, texts and signs)

Code: Select all

 
    if ( mesh )
    {
        // the additional mesh can be quite huge and is unoptimized
        const scene::IMesh * const additional_mesh = mesh->getMesh(quake3::E_Q3_MESH_ITEMS);
 
        for ( u32 i = 0; i!= additional_mesh->getMeshBufferCount(); ++i )
        {
            const IMeshBuffer* meshBuffer = additional_mesh->getMeshBuffer(i);
            const video::SMaterial& material = meshBuffer->getMaterial();
            const s32 shaderIndex = (s32) material.MaterialTypeParam2;
            const quake3::IShader *shader = mesh->getShader(shaderIndex);
 
            if (0 == shader)
            {
                continue;
            }
 
            node = smgr->addQuake3SceneNode(meshBuffer, shader);
            node->setMaterialFlag(video::EMF_FOG_ENABLE, true);
        }
    }
 
And there's no fog on these objects :(
After I've found out that shader's materials are readOnly

Here's shaders I used:

Code: Select all

 
textures/dsi/dsiglass 
{ 
   qer_editorimage textures/dsi/dsiglass2.tga 
   surfaceparm trans 
   cull disable 
   qer_trans 0.5 
   { 
      map textures/dsi/dsiglass2.tga 
      blendfunc blend 
      rgbGen vertex 
   }    
}
 
(took it from here: http://irrlichtirc.g0dsoft.com/kat104/3 ... rency.html )

So.. Please, help me apply fog to shaders objects. Is there a way to do it? (May be in shader files, or by using transparent textures some different way)
Post Reply