(C++)Irrlicht 1.1 : Fake Glow,Dream and Night Vision

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
lug
Posts: 79
Joined: Tue May 02, 2006 5:15 am
Contact:

Post by lug »

:shock:

Well, done. It looks great. Reminds me of Max Payne for some reason.
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

Simson I might need your help. I would like to use your class with irrlicht 1.2 - but there is a little problem, I used this update you posted earlier:

Code: Select all

f32 resultat = cos((CamGlow->getFOV()/2)); 

resultat = 1.09f/resultat; 

resultat = (resultat*resultat) - (1.09f*1.09f); 

resultat = sqrt(resultat); 

f32 SizeY = resultat; 

f32 ScaleX = resultat * CamGlow->getAspectRatio();
And it helped to get the effect working on whole screen (I mean, no more uncorrect FOV bug thingy) but now the glow works strangely - sometimes it makes strange white stripes in Y coordinates. (I hope you get what I mean)

Here is the screenshot of what's wrong anyway:

Image[/img]
Prott
Posts: 104
Joined: Sun Jan 14, 2007 12:01 pm

Post by Prott »

Hello.
It looks great (especially for non-shader effect), but I have one problem. I modified CEffect.cpp as you said:

Code: Select all

f32 resultat = cos((CamGlow->getFOV()/2)); 
resultat = 1.09f/resultat; 
resultat = (resultat*resultat) - (1.09f*1.09f); 
resultat = sqrt(resultat); 
f32 SizeY = resultat; 
f32 ScaleX = resultat * CamGlow->getAspectRatio(); 
but it still not working. (FOV of the effect and FOV of the game still doesn`t match each other) - I use Irrlicht 1.2 . :(
Simson
Competition winner
Posts: 95
Joined: Wed Nov 30, 2005 8:53 am
Location: France : midi pyrénées

Post by Simson »

Hello,
I have made a small change...if you want to test this new code (made for the latest svn) :

CEffects.cpp

Code: Select all


/*-----------------------------------------
Programmed by Fabre Cédric 
(Copland/simson) 02/10/2006
Thanks to the Irrlicht team  
for this good 3D engine !
This code has not been tested under Linux.
If you find any errors or corrections,
in advance thanks you for any feedbacks.
-------------------------------------------
Contact : simson2004@wanadoo.fr
-----------------------------------------*/

#include <irrlicht.h>
#include <CEffects.h>

using namespace irr;

namespace EffectsLibrary
{
    CQuadSceneNode::CQuadSceneNode(scene::ISceneNode* parent,scene::ISceneManager* mgr,s32 id): scene::ISceneNode(parent, mgr, id)
    {
        Material.DiffuseColor = video::SColor(0,0,0,0);
        Material.EmissiveColor = video::SColor(0,0,0,0);
        Material.SpecularColor = video::SColor(0,0,0,0);
        Material.ZBuffer = false;
        Material.ZWriteEnable = false;
        Material.Wireframe = false;
        Material.PointCloud = false;
        Material.Lighting = false;
        Material.BackfaceCulling = false;
        Material.FogEnable = false;
        Material.GouraudShading = false;
        Material.NormalizeNormals = true;
        Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;

        irr::video::E_DRIVER_TYPE dr = mgr->getVideoDriver()->getDriverType();

        if (dr != video::EDT_OPENGL)
        {
            video::SColor Color = video::SColor(4,40,40,40);
            VertexQuad[0]=video::S3DVertex(-1,1,0,0,0,0,Color,0,0);
            VertexQuad[1]=video::S3DVertex(1,1,0,0,0,0,Color,1,0);
            VertexQuad[2]=video::S3DVertex(-1,-1,0,0,0,0,Color,0,1);
            VertexQuad[3]=video::S3DVertex(1,-1,0,0,0,0,Color,1,1);
        }
        else
        {
            video::SColor Color = video::SColor(4,34,34,34);
            VertexQuad[0]=video::S3DVertex(-1,1,0,0,0,0,Color,0,1);
            VertexQuad[1]=video::S3DVertex(1,1,0,0,0,0,Color,1,1);
            VertexQuad[2]=video::S3DVertex(-1,-1,0,0,0,0,Color,0,0);
            VertexQuad[3]=video::S3DVertex(1,-1,0,0,0,0,Color,1,0);
        }

        Box.reset(VertexQuad[0].Pos);

        for (s32 i=1; i<4; ++i)
        {
            Box.addInternalPoint(VertexQuad[i].Pos);
        }
    }

    void CQuadSceneNode::OnPreRender()
    {
        if (IsVisible)
            SceneManager->registerNodeForRendering(this);
        ISceneNode::OnPreRender();
    }

    void CQuadSceneNode::render()
    {
        u16 indices[] = {    0,1,2, 3,2,1    };
        video::IVideoDriver* driver = SceneManager->getVideoDriver();
        driver->setMaterial(Material);
        core::matrix4 Mat;
        Mat.makeIdentity();
        
        //On sauvegarde les matrices
        core::matrix4 MatrixWorld = driver->getTransform(video::ETS_WORLD);
        core::matrix4 MatrixView = driver->getTransform(video::ETS_VIEW);
        
        //On applique les matrices de monde et de vue
        driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
        driver->setTransform(video::ETS_VIEW,Mat);
        //On dessine nos Quad ici
        driver->drawIndexedTriangleList(&VertexQuad[0], 4, &indices[0], 2);
        
        //On restaure les matrices
        driver->setTransform(video::ETS_VIEW,MatrixView);
        driver->setTransform(video::ETS_WORLD,MatrixWorld);
    }

    const core::aabbox3d<f32>& CQuadSceneNode::getBoundingBox() const
    {
        return Box;
    }

    u32 CQuadSceneNode::getMaterialCount()
    {
        return 1;
    }

    video::SMaterial& CQuadSceneNode::getMaterial(u32 i)
    {
        return Material;
    }


    //Déclaration de RTexGlow;
    video::ITexture* RTexGlow=0;
    video::ITexture* RTexDream=0;
    video::ITexture* RTexNV=0;

    //Déclaration d'un CQuadSceneNode (Node personnalisé pour créer un Quad)
    CQuadSceneNode* Quad[11];

    //Méthode de création du Glow
    void CreateGlow(scene::ICameraSceneNode* CamGlow,scene::ISceneManager* smgr,s32 GlowSize=64)
    {
        //On vérifi que la carte vidéo soit cappable d'utiliser le Render To Texture
        if (smgr->getVideoDriver()->queryFeature(video::EVDF_RENDER_TO_TARGET))
        {
            //Ici on creer notre Render Texture
            RTexGlow = smgr->getVideoDriver()->createRenderTargetTexture(core::dimension2d<s32>(GlowSize,GlowSize));

            f32 resultat = cos((CamGlow->getFOV()/2));
            resultat = 1.09f/resultat;
            resultat = (resultat*resultat) - (1.09f*1.09f);
            resultat = sqrt(resultat);
            f32 SizeY = resultat;
            f32 ScaleX = resultat * CamGlow->getAspectRatio();

            //Ici on va créer plusieurs quad pour simuler un effet de Blur
            for (int nbquad=0;nbquad<=3;nbquad++)
            {
                Quad[nbquad] = new CQuadSceneNode(smgr->getRootSceneNode(), smgr, 0);
                //Quad[nbquad]->setAutomaticCulling(false);
                Quad[nbquad]->setPosition(irr::core::vector3df(-0.003f+(nbquad/300),-0.001f+(nbquad/300),1.09f));
                Quad[nbquad]->setScale(irr::core::vector3df(ScaleX+((float)nbquad/300),SizeY+((float)nbquad/300),1));
                Quad[nbquad]->setMaterialTexture(0,RTexGlow);
                Quad[nbquad]->drop();
            }
        }
    }

    //Méthode de rendu du Glow
    void RenderGlow(scene::ISceneManager* smgr,s32 gA=0,s32 gR=0,s32 gG=0,s32 gB=0,u32 NbsOfPass=0)
    {
        //On test si le Render Texture existe bien
        if (RTexGlow)
        {
            for (int i=0;i<=10;i++)
            {
                if (Quad[i] != NULL)
                {
                    if (i==0 || i >=4){Quad[i]->setVisible(false);}else{Quad[i]->setVisible(true);}
                }
            }

            //On affiche notre scene
            smgr->getVideoDriver()->setRenderTarget(RTexGlow, true, true, video::SColor(gA,gR,gG,gB));
            smgr->drawAll();
            smgr->getVideoDriver()->setRenderTarget(0);

            switch (NbsOfPass)
            {
                case 1:
                    Quad[1]->setVisible(false);
                    Quad[2]->setVisible(false);
                    Quad[3]->setVisible(false);
                    break;
                case 2:
                    Quad[1]->setVisible(false);
                    Quad[2]->setVisible(false);
                    break;
                case 3:
                    Quad[1]->setVisible(false);
                    break;
            }

            //On affiche nos quads
            Quad[0]->setVisible(true);
        }
    }


    //Méthode de création de l'effet Dream Filter
    void CreateDreamFilter(scene::ICameraSceneNode* CamDream,scene::ISceneManager* smgr,f32 EffectSize=1.0f,s32 DreamSize=64)
    {
        //On vérifi que la carte vidéo soit cappable d'utiliser le Render To Texture
        if (smgr->getVideoDriver()->queryFeature(video::EVDF_RENDER_TO_TARGET))
        {
            //Ici on creer notre Render Texture
            RTexDream=smgr->getVideoDriver()->createRenderTargetTexture(core::dimension2d<s32>(DreamSize,DreamSize));

            f32 resultat = cos((CamDream->getFOV()/2));
            resultat = 1.09f/resultat;
            resultat = (resultat*resultat) - (1.09f*1.09f);
            resultat = sqrt(resultat);
            f32 SizeY = resultat;
            f32 ScaleX = resultat * CamDream->getAspectRatio();

            //Alors ici on va en créer plusieurs pour simuler un effet de Blur
            for (int nbquad=4;nbquad<=7;nbquad++)
            {
                Quad[nbquad] = new CQuadSceneNode(smgr->getRootSceneNode(), smgr, 0);
                //Quad[nbquad]->setAutomaticCulling(false);
                Quad[nbquad]->setPosition(irr::core::vector3df(-0.001f,-0.001f,1.09f));
                Quad[nbquad]->setScale(irr::core::vector3df((ScaleX+((float)nbquad/20)*EffectSize),(SizeY+((float)nbquad/20)*EffectSize),1));
                Quad[nbquad]->setMaterialTexture(0,RTexDream);
                Quad[nbquad]->drop();
            }
        }
    }

    //Méthode de rendu du DreamFilter
    void RenderDreamFilter(scene::ISceneManager* smgr,s32 dA=0,s32 dR=0,s32 dG=0,s32 dB=0)
    {
        //On test si le Render Texture existe bien
        if (RTexDream)
        {
            for (int i=0;i<=10;i++)
            {
                if (Quad[i] != NULL){Quad[i]->setVisible(false);}
            }

            Quad[5]->setVisible(true);
            Quad[6]->setVisible(true);
            Quad[7]->setVisible(true);

            //On affiche notre scene
            smgr->getVideoDriver()->setRenderTarget(RTexDream, true, true, video::SColor(dA,dR,dG,dB));
            smgr->drawAll();
            smgr->getVideoDriver()->setRenderTarget(0);

            Quad[4]->setVisible(true);
        }
    }

    //Méthode de création de l'effet NightVision
    void CreateNightVision(scene::ICameraSceneNode* CamNightVision,scene::ISceneManager* smgr,irr::c8* NoiseFile,s32 NightVisionSize=64)
    {
        //On vérifi que la carte vidéo soit cappable d'utiliser le Render To Texture
        if (smgr->getVideoDriver()->queryFeature(video::EVDF_RENDER_TO_TARGET))
        {
            irr::video::E_DRIVER_TYPE dr = smgr->getVideoDriver()->getDriverType();
            irr::video::ITexture* NoiseTexture = smgr->getVideoDriver()->getTexture(NoiseFile);

            //Ici on creer notre Render Texture
            RTexNV=smgr->getVideoDriver()->createRenderTargetTexture(core::dimension2d<s32>(NightVisionSize,NightVisionSize));

            f32 resultat = cos((CamNightVision->getFOV()/2));
            resultat = 1.09f/resultat;
            resultat = (resultat*resultat) - (1.09f*1.09f);
            resultat = sqrt(resultat);
            f32 SizeY = resultat;
            f32 ScaleX = resultat * CamNightVision->getAspectRatio();

            for (int nbquad=8;nbquad<=10;nbquad++)
            {
                Quad[nbquad]= new CQuadSceneNode(smgr->getRootSceneNode(), smgr, 0);
                //Quad[nbquad]->setAutomaticCulling(false);
                Quad[nbquad]->setPosition(irr::core::vector3df(-0.001f,0.001f,1.09f));
                Quad[nbquad]->setScale(irr::core::vector3df(ScaleX,SizeY,1));

                for (u32 i =0;i<=Quad[nbquad]->getMaterialCount()-1;i++)
                {
                    if(nbquad!=10)
                    {
                        //On test si on est en directx ou autre pour gérer les coloris
                        if (dr !=  video::EDT_OPENGL)
                        {
                            Quad[nbquad]->getMaterial(i).MaterialType=video::EMT_TRANSPARENT_VERTEX_ALPHA;
                            Quad[nbquad]->getMaterial(i).DiffuseColor = video::SColor(10,20,150,20);
                            Quad[nbquad]->getMaterial(i).EmissiveColor = video::SColor(10,20,150,20);
                            Quad[nbquad]->getMaterial(i).AmbientColor = video::SColor(10,20,150,20);
                            Quad[nbquad]->getMaterial(i).SpecularColor = video::SColor(10,20,150,20);
                            Quad[nbquad]->getMaterial(i).Lighting=true;
                        }
                        else
                        {
                            Quad[nbquad]->getMaterial(i).MaterialType=video::EMT_TRANSPARENT_VERTEX_ALPHA;
                            Quad[nbquad]->getMaterial(i).DiffuseColor = video::SColor(10,10,120,10);
                            Quad[nbquad]->getMaterial(i).EmissiveColor = video::SColor(10,10,120,10);
                            Quad[nbquad]->getMaterial(i).AmbientColor = video::SColor(10,10,120,10);
                            Quad[nbquad]->getMaterial(i).SpecularColor = video::SColor(10,10,120,10);
                            Quad[nbquad]->getMaterial(i).Lighting=true;
                        }
                    }
                }

                if (nbquad!=10)
                {
                    Quad[nbquad]->setMaterialTexture(0,RTexNV);
                }
                else
                {
                    core::vector3df vec = Quad[nbquad]->getPosition();
                    vec.Z = 1.05f;
                    scene::ISceneNodeAnimator* noiseAnim = smgr->createFlyCircleAnimator(vec,0.03f,0.7f);
                    Quad[nbquad]->setScale(irr::core::vector3df(ScaleX+0.05f,SizeY+0.05f,1));
                    Quad[nbquad]->addAnimator(noiseAnim);
                    Quad[nbquad]->setMaterialTexture(0,NoiseTexture);
                }

                Quad[nbquad]->drop();
            }
        }
    }

    //Méthode de rendu de l'effet NightVision
    void RenderNightVision(scene::ISceneManager* smgr)
    {
        //On test si le Render Texture existe bien
        if (RTexNV)
        {
            for (int i=0;i<=10;i++)
            {
                if (Quad[i] != NULL)
                {
                    if (i<=8){Quad[i]->setVisible(false);}else{Quad[i]->setVisible(true);}
                }
            }

            //On affiche notre scene
            smgr->getVideoDriver()->setRenderTarget(RTexNV, true, true, video::SColor(0,0,0,0));
            smgr->drawAll();
            smgr->getVideoDriver()->setRenderTarget(0);

            Quad[8]->setVisible(true);
        }
    }

    //Méthode si l'on ne veut plus rien afficher
    void RenderNothing()
    {
        for (int i =0;i<=10;i++)
        {
            if (Quad[i]!= NULL){Quad[i]->setVisible(false);}
        }
    }

    //Méthode de suppression du Glow
    void DeleteGlow()
    {
        if (RTexGlow){RTexGlow->drop();}
        for (int i=0;i<=3;i++)
        {
            if (Quad[i] != NULL){Quad[i]->remove();}
        }
    }

    //Méthode de suppression du DreamFilter
    void DeleteDream()
    {
        if (RTexDream){RTexDream->drop();}
        for (int i=4;i<=7;i++)
        {
            if (Quad[i] != NULL){Quad[i]->remove();}
        }
    }

    //Méthode de suppression du Night Vision
    void DeleteNightVision()
    {
        if (RTexNV){RTexNV->drop();}
        for (int i=8;i<=10;i++)
        {
            if (Quad[i] != NULL){Quad[i]->remove();}
        }
    }

    //Méthode de suppression
    void DeleteEffects()
    {
        //On test si notre Render Texture existe bien et on supprime
        if (RTexGlow){RTexGlow->drop();}
        if (RTexDream){RTexDream->drop();}
        if (RTexNV){RTexNV->drop();}

        for (int i=0;i<=10;i++)
        {
            if (Quad[i] != NULL){Quad[i]->remove();}
        }
    }
}

and here the CEffects.h

Code: Select all


/*-----------------------------------------
Programmed by Fabre Cédric 
(Copland/simson) 02/10/2006
Thanks to the Irrlicht team  
for this good 3D engine !
This code has not been tested under Linux.
If you find any errors or corrections,
in advance thanks you for any feedbacks.
-------------------------------------------
Contact : simson2004@wanadoo.fr
-----------------------------------------*/

using namespace irr;

namespace EffectsLibrary
{
    class CQuadSceneNode : public scene::ISceneNode
    {
    public:
        CQuadSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id);
        virtual void OnPreRender();
        virtual void render();
        virtual const core::aabbox3d<f32>& getBoundingBox() const;
        u32 getMaterialCount();
        virtual video::SMaterial& getMaterial(u32 i);
    private :
        core::aabbox3d<f32> Box;
        video::S3DVertex VertexQuad[4];
        video::SMaterial Material;
    };

    void CreateGlow(scene::ICameraSceneNode* CamGlow,scene::ISceneManager* smgr,s32 GlowSize);
    void RenderGlow(scene::ISceneManager* smgr,s32 gA,s32 gR,s32 gG,s32 gB,u32 NbsOfPass);

    void CreateDreamFilter(scene::ICameraSceneNode* CamDream,scene::ISceneManager* smgr,f32 EffectSize,s32 DreamSize);
    void RenderDreamFilter(scene::ISceneManager* smgr,s32 dA,s32 dR,s32 dG,s32 dB);

    void CreateNightVision(scene::ICameraSceneNode* CamNightVision,scene::ISceneManager* smgr,irr::c8* NoiseFile,s32 NightVisionSize);
    void RenderNightVision(scene::ISceneManager* smgr);

    void RenderNothing();

    void DeleteGlow();
    void DeleteDream();
    void DeleteNightVision();

    void DeleteEffects();
}

Prott
Posts: 104
Joined: Sun Jan 14, 2007 12:01 pm

Post by Prott »

Here is the result (compiler log):

Code: Select all

c:\moje veci\ag\CEffects.h(30) : error C2555: 'EffectsLibrary::CQuadSceneNode::getMaterialCount': overriding virtual function return type differs and is not covariant from 'irr::scene::ISceneNode::getMaterialCount'
        d:\irrlich\irrlicht-1.1\include\ISceneNode.h(322) : see declaration of 'irr::scene::ISceneNode::getMaterialCount'
AlternateGEAR-MainCPP.cpp
c:\moje veci\ag\CEffects.h(30) : error C2555: 'EffectsLibrary::CQuadSceneNode::getMaterialCount': overriding virtual function return type differs and is not covariant from 'irr::scene::ISceneNode::getMaterialCount'
        d:\irrlich\irrlicht-1.1\include\ISceneNode.h(322) : see declaration of 'irr::scene::ISceneNode::getMaterialCount'
.\AlternateGEAR-MainCPP.cpp(586) : error C3861: 'CreateGlow': identifier not found
.\AlternateGEAR-MainCPP.cpp(605) : error C3861: 'RenderGlow': identifier not found
Generating Code...
Build log was saved at "file://c:\moje veci\AG\Debug\BuildLog.htm"
Alternate Gear - Engine - 4 error(s), 0 warning(s)
Simson
Competition winner
Posts: 95
Joined: Wed Nov 30, 2005 8:53 am
Location: France : midi pyrénées

Post by Simson »

Yes, change the u32 of the material with s32 because it has changed in svn version and you can remove the namespace, because I used this code in my new project :).
Don't hesitate to contact me by mail for faster answsers.
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

Now the effect does work properly! (I mean sharpened field of view)

But UNFORTUNATELY new code affected the FOV problem badly. I mean it is rather rotation problem now. Always when I rotate in one direction the Glow works very well, but when I change the view and rotate 90 degrees left it sometimes dissapears to normal render.

Do you have any idea what can cause this ?

PS Thx for updating the code anyway Simson
Simson
Competition winner
Posts: 95
Joined: Wed Nov 30, 2005 8:53 am
Location: France : midi pyrénées

Post by Simson »

try to uncoment this :
//Quad[nbquad]->setAutomaticCulling(false);

PS: you can try with other camera type, I think that work now.
dawasw
Posts: 357
Joined: Tue Aug 10, 2004 4:39 pm
Location: Poland

Post by dawasw »

Thank you for all !!!!!!!!

It works excellent now :D :) :wink:
Eldritch
Posts: 33
Joined: Mon Feb 26, 2007 12:33 pm

Post by Eldritch »

I tried using this with Irrlicht .NET CP but it seems like it is not working that well. Here's the code:

CQuadSceneNode class

Code: Select all

using System;
using IrrlichtNETCP;
using IrrlichtNETCP.Inheritable;
using Kernel;

namespace Renderer
{
	/// <summary>
	/// A quad scene node. Used by render server for special effects.
	/// </summary>
	public class CQuadSceneNode : ISceneNode
	{
		/// <summary>Bounding box reference.</summary>
		private Box3D m_refBoundingBox;
		
		/// <summary>Quad vertices.</summary>
		private Vertex3D[] m_Vertices = new Vertex3D[4];
		
		/// <summary>Reference to material.</summary>
		private Material m_refMaterial = null;
		
		/// <summary>Constructor.</summary>
		public CQuadSceneNode(SceneNode refParent, int iId)
			: base(refParent, CKernel_s.Instance.GetScene(), iId)
		{
			m_refMaterial = new Material();
			m_refMaterial.DiffuseColor = new Color();
			m_refMaterial.EmissiveColor = new Color();
			m_refMaterial.SpecularColor = new Color();
			m_refMaterial.ZBuffer = false;
			m_refMaterial.Wireframe = false;
			m_refMaterial.Lighting = false;
			m_refMaterial.BackfaceCulling = false;
			m_refMaterial.FogEnable = false;
			m_refMaterial.GouraudShading = false;
			m_refMaterial.NormalizeNormals = true;
			m_refMaterial.MaterialType = MaterialType.TransparentVertexAlpha;
			
			DriverType dt = CKernel_s.Instance.GetScene().VideoDriver.DriverType;
			
			Color col = new Color(4, 40, 40, 40);
			m_Vertices[0] = new Vertex3D(new Vector3D(-1, 1, 0), new Vector3D(0, 0, 0), col, new Vector2D(0, 0));
			m_Vertices[1] = new Vertex3D(new Vector3D(1, 1, 0), new Vector3D(0, 0, 0), col, new Vector2D(1, 0));
			m_Vertices[2] = new Vertex3D(new Vector3D(-1, -1, 0), new Vector3D(0, 0, 0), col, new Vector2D(0, 1));
			m_Vertices[3] = new Vertex3D(new Vector3D(1, -1, 0), new Vector3D(0, 0, 0), col, new Vector2D(1, 1));
			
			m_refBoundingBox = new Box3D();
			
			for (int i = 0; i < m_Vertices.Length; i++)
				m_refBoundingBox.AddInternalPoint(m_Vertices[0].Position);
		}
		
		/// <summary>Pre-render event.</summary>
		public override void OnPreRender()
		{
			if (Visible)
				CKernel_s.Instance.GetScene().RegisterNodeForRendering(this);
			base.OnPreRender();
		}
		
		/// <summary>Rendering node.</summary>
		public override void Render()
		{
			ushort[] indices = new ushort[6];
			indices[0] = 0; indices[1] = 1; indices[2] = 2;
			indices[3] = 3; indices[4] = 2; indices[5] = 1;
			VideoDriver vd = CKernel_s.Instance.GetScene().VideoDriver;
			vd.SetMaterial(m_refMaterial);
			
			Matrix4 mat = new Matrix4();
			mat.MakeIdentity();
			Matrix4 world = vd.GetTransform(TransformationState.World);
			Matrix4 view = vd.GetTransform(TransformationState.View);
			
			vd.SetTransform(TransformationState.World, AbsoluteTransformation);
			vd.SetTransform(TransformationState.View, mat);
			vd.DrawIndexedTriangleList(m_Vertices, 4, indices, 2);
			vd.SetTransform(TransformationState.World, world);
			vd.SetTransform(TransformationState.View, view);
		}
		
		/// <summary>Gets bounding box.</summary>
		public Box3D GetBoundingBox()
		{
			return m_refBoundingBox;
		}
		
		/// <summary>Gets material count.</summary>
		public int GetMaterialCount()
		{
			return 1;
		}
		
		/// <summary>Gets a material.</summary>
		public override Material GetMaterial(int iIndex)
		{
			return m_refMaterial;
		}
	}
}

Setting up the glow stuff

Code: Select all

public void SetupGlow(int iGlowSize)
		{
			VideoDriver driver = CKernel_s.Instance.GetDriver();
			
			if (driver.QueryFeature(VideoDriverFeature.RenderToTarget))
			{
				m_refGlowTexture = driver.CreateRenderTargetTexture(new Dimension2D(iGlowSize, iGlowSize));
				int iWidth = CKernel_s.Instance.Width, iHeight = CKernel_s.Instance.Height;
				
				float resultat = (float)Math.Cos(CCamera_s.Instance.GetNode().FOV/2);
				resultat = 1.09f / resultat;
				resultat = (resultat * resultat) - (1.09f * 1.09f);
				resultat = (float)Math.Sqrt(resultat);
				float fSizeY = resultat;				
				float fScaleX = resultat * CCamera_s.Instance.GetNode().AspectRatio;
				
				for (int i = 0; i <= 3; i++)
				{
					m_refGlowQuad[i] = new CQuadSceneNode(CKernel_s.Instance.GetScene().RootSceneNode, 0);
					m_refGlowQuad[i].Position = new Vector3D(-0.003f+((float)i/300.0f), -0.001f+((float)i/300.0f), 1.09f);
					m_refGlowQuad[i].Scale = new Vector3D(fScaleX+((float)1/300), fSizeY+((float)i/300), 1);
					m_refGlowQuad[i].SetMaterialTexture(0, m_refGlowTexture);
					//found no equivalent to drop()
				}
			}
		}
Rendering with glow

Code: Select all

if (m_refGlowTexture != null)
			{
				for (int i = 0; i < 11; i++)
				{
					if (m_refGlowQuad[i] != null)
					{
						if (i == 0 || i >= 4)
							m_refGlowQuad[i].Visible = false;
						else
							m_refGlowQuad[i].Visible = true;
					}
				}
				
				CKernel_s.Instance.GetDriver().SetRenderTarget(m_refGlowTexture, true, true,
				                                               new Color(iA, iR, iG, iB));
				
				m_refDevice.SceneManager.DrawAll();
				CKernel_s.Instance.GetDriver().SetRenderTarget(null, false, false, Color.White);
				
				m_refGlowQuad[0].Visible = true;
				m_refGlowQuad[1].Visible = false;
				m_refGlowQuad[2].Visible = false;
				m_refGlowQuad[3].Visible = false;
			}
I am using Irrlicht .NET CP, and my camera is a CameraSceneNode (not FPS!), but I am sure that is not the problem. The problem is, I see nothing on the screen. If I use the m_refGlowTexture texture on another mesh, it works, but nothing else...
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

I think they had a problem with rotations so FPS is the only kind of camera that works with it, but I could be wrong.
Eldritch
Posts: 33
Joined: Mon Feb 26, 2007 12:33 pm

Post by Eldritch »

Yeah, but I got the notion that was solved. Considering that the rotation is fux0red, is there any way to map a texture onto the screen in 2D rather than trying it out with a 3D quad scene node as it is done here? I was thinking about GUIImage, but I am sure that won't do good. Any suggestions?
7h0mm4y
Posts: 3
Joined: Sat Mar 31, 2007 3:34 pm

Post by 7h0mm4y »

Hey, i'm trying to get it compatible with irrLicht 1.3
After a few modifications it now compiles and runs, but the effects don't appear. I'm just a beginner with irrLicht and i can't find the problem...

please help :cry:

I really want to use these awesome effects in a project.
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Eldritch wrote:Yeah, but I got the notion that was solved. Considering that the rotation is fux0red, is there any way to map a texture onto the screen in 2D rather than trying it out with a 3D quad scene node as it is done here? I was thinking about GUIImage, but I am sure that won't do good. Any suggestions?
I actually think that would work decently... Or use the kind in the 2d Graphics example.
hanswurst
Posts: 4
Joined: Sat Mar 31, 2007 5:22 pm

Post by hanswurst »

Hi 7h0mm4y,

i'm also having the same problem. I used Simsons updated code. Now it's not crashing my app anymore, but when i try to activate one of the effects my whole Scene is just getting black until i call RenderNothing().

I think it has something to do with the new OnAnimate()-function. I don't really know how to use that thing. No matter how many ms (tried 0-10000) i call that funtion with, the scene turns black when calling one of the effects.

Is anybody able to help out? Irrlicht 1.3 is just not compatible with that code....thx in advance :D
Post Reply