shader error, too many texture loads

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
esaptonor
Posts: 145
Joined: Sat May 06, 2006 11:59 pm

Post by esaptonor »

yeah thats the one, and thanks for the tip, i wasn't aware of a leak, so i will go and fix it.

here is a better example of the HDR that i made:
Image
Image

is it good enough to use though? does the bloom effect look good enough?
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

yes it looks better in last example.

so what are your FPS when render to Texture 4 times ? and did yoy still use 2 blure passes ?
esaptonor
Posts: 145
Joined: Sat May 06, 2006 11:59 pm

Post by esaptonor »

In my room with per pixel lighting etc the frames per second drop was roughly 10 frames per second when i turned it on.
With just the test scene node, frames went from about 2200 to 450. I dont know how much of a difference that is. Doesn't seem too bad though. I have a radeon X1900XT graphics card.

Yes, i am using 2 blur passes, so in total it is 4 render to textures.
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

that is exactlly why i have tried to avoid rendering to texture , and making one shader pass.

so i will try my latest idea and make a comparsion between it and your render-to-texture method.
esaptonor
Posts: 145
Joined: Sat May 06, 2006 11:59 pm

Post by esaptonor »

yes ill be interested in seeing the difference, but In my opnion a frame drop from 65 to 55 frames per second is not too bad. If your using a single shader pass the drop will probably be tiny....but would it look as good?
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

i did it , but do not know about FPS so i want you to convert it to HLSL and try it.

for the blur effect , i take 8 points to caculate the blur instead of 4 points
and the result is very good , if you like to test the only blur apply the part of blur in shader program.

here is a screenshot of your example but with my MagicLibrary
Image

here is the code including CG shader porgram.

Code: Select all

/****************************************************
             hdrEffect with CG

               By Emil Halim
****************************************************/

#include <MagicIncludes.h>

// global declration of Irrlicht interfaces
IrrlichtDevice* device;
IVideoDriver*   driver;
ISceneManager*  smgr;


bool ProgramRun;

int main()
{
    device = createDevice(EDT_OPENGL, dimension2d<s32>(640, 480), 32);
    bool rslt = InitMagic(device);
    if(rslt == false)
          printf("Magic Library will only work with OpenGL driver");

	driver = device->getVideoDriver();
	smgr = device->getSceneManager();

	TCGShader* cgProg = new TCGShader;

    cgProg->AddToPixelProgram("void main(  float2 TexCoord0     : TEXCOORD0,         ");
    cgProg->AddToPixelProgram("            out float4 color     : COLOR,             ");
    cgProg->AddToPixelProgram("            uniform sampler2D txtr0)                  ");
    cgProg->AddToPixelProgram("{                                                     ");
    cgProg->AddToPixelProgram("   float2 v    =  float2(0.0,0.005);                  ");
    cgProg->AddToPixelProgram("   float2 u    =  float2(0.005,0.0);                  ");
    cgProg->AddToPixelProgram("   float2 uv   =  float2(0.005,0.005);                ");
    cgProg->AddToPixelProgram("   float2 uv1  =  float2(0.005,-0.005);               ");
    cgProg->AddToPixelProgram("   float4 Col1 = tex2D(txtr0,TexCoord0+u);            ");
    cgProg->AddToPixelProgram("   float4 Col2 = tex2D(txtr0,TexCoord0-u);            ");
    cgProg->AddToPixelProgram("   float4 Col3 = tex2D(txtr0,TexCoord0+v);            ");
    cgProg->AddToPixelProgram("   float4 Col4 = tex2D(txtr0,TexCoord0-v);            ");
    cgProg->AddToPixelProgram("   float4 Col5 = tex2D(txtr0,TexCoord0+uv);           ");
    cgProg->AddToPixelProgram("   float4 Col6 = tex2D(txtr0,TexCoord0-uv);           ");
    cgProg->AddToPixelProgram("   float4 Col7 = tex2D(txtr0,TexCoord0+uv1);          ");
    cgProg->AddToPixelProgram("   float4 Col8 = tex2D(txtr0,TexCoord0-uv1);          ");
    cgProg->AddToPixelProgram("   float4 drkCol1 = Col1 * Col1 ;                     ");
    cgProg->AddToPixelProgram("   float4 drkCol2 = Col2 * Col2 ;                     ");
    cgProg->AddToPixelProgram("   float4 drkCol3 = Col3 * Col3 ;                     ");
    cgProg->AddToPixelProgram("   float4 drkCol4 = Col4 * Col4 ;                     ");
    cgProg->AddToPixelProgram("   float4 drkCol5 = Col5 * Col5 ;                     ");
    cgProg->AddToPixelProgram("   float4 drkCol6 = Col6 * Col6 ;                     ");
    cgProg->AddToPixelProgram("   float4 drkCol7 = Col7 * Col7 ;                     ");
    cgProg->AddToPixelProgram("   float4 drkCol8 = Col8 * Col8 ;                     ");

    cgProg->AddToPixelProgram("   float4 avrCol1 = drkCol1 + drkCol2 + drkCol3 + drkCol4;   ");
    cgProg->AddToPixelProgram("   float4 avrCol2 = drkCol5 + drkCol6 + drkCol7 + drkCol8;   ");
    cgProg->AddToPixelProgram("   float4 avrCol  =  (avrCol1 + avrCol2) / 8.0;        ");

    cgProg->AddToPixelProgram("   float4 oCol = tex2D(txtr0, TexCoord0);             ");
    cgProg->AddToPixelProgram("   color  =  oCol + avrCol * 0.35 ;                   ");
    cgProg->AddToPixelProgram("}                                                     ");

    cgProg->setPixelProfile(CG_PROFILE_ARBFP1);
    cgProg->CompilePixelProgram("main");
    printf("%s \n", cgProg->GetCompiledPixelProgram());

    SMaterial img;
    img.Texture1 = driver->getTexture("../../MagicLibrary/media/hdrtest.bmp");

    ProgramRun = true;
    int lastFPS = -1;

	while(device->run()&& ProgramRun)
	{

		driver->beginScene(true, true, SColor(0,0,0,0));

                 if(KeyDown(KEY_ESCAPE))ProgramRun=false;

                 ViewOrtho();
                 SetBlend(MASKBLEND);

                 driver->setMaterial(img);
                 DrawImage(img,180,240);

                 cgProg->StartShaderProgram();

                 driver->setMaterial(img);
                 DrawImage(img,480,240);

                 cgProg->StopShaderProgram();

                 ViewPerspective();

                 smgr->drawAll();

		driver->endScene();
		int fps = driver->getFPS();
        if (lastFPS != fps)
         {
            wchar_t tmp[1024];
            swprintf(tmp, 1024, L"Glow effect with CG (%s)(fps:%d)",driver->getName(), fps);
            device->setWindowCaption(tmp);
            lastFPS = fps;
         }
	}

	device->drop();

	return 0;
}
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

Emil both My HDR and esaptonor's method use render to texture combined with a postprocessor so the blur radiates outside the object, your methdod creates glow which stays inside the object.

Each method has its advantages.

Your method is fast But:
1-glow doesnt radiates or get obscured by non glowing objects
2-its is fast on a few objects but 8 texture operations ofr evry object in the scene can get slow fast.

My method
1-glow radiates/interacts with non glowing things too
2- render to texture locks the frame rate low no matter how complex the scene :cry: but it doesnt slow much with lots of meshes because its already slow :wink: and each mesh doesnt need 8 texture operations
Emil_halim
Posts: 518
Joined: Tue Mar 29, 2005 9:02 pm
Location: Alex,Egypt
Contact:

Post by Emil_halim »

ok Omer

forget about shader program perObject and look to the shader itself.

as i told you my goal to make the effect as fast as posibale , by avoiding
render to texture , as you know each call to set texture to the driver takes much time from CPU and reduce the FPS but if manage to made one shader pass it makes things more good.

in your opinion which is faster render to texture or use 8 texture operations or more!!!!!!
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

It depend son the scene complexity

The RTT method only does 8 texture operations on one HDR node, your method needs it done per object and on complex scenes that can get slow.

Yes i am aware RTT is slow but i think the radiation is worth it because it looks nice, moreover the RTT method allows say a plane to be surrounded by the suns glow(the suns glow overrides the colour of the plane) this is HDR since bright parts dont get clamped but overflow into the next light sensitive unit wheather it is a cone in our retina or other wise.

Your method the glow spread within the polygon but it doesnt exit it.

I have ben writing a document about includeinng lots of effects with minimal number of RTT's it might interest you, and also im sure you might help improve some of the methods.

omaremad.gdlib.net/doc.pdf
esaptonor
Posts: 145
Joined: Sat May 06, 2006 11:59 pm

Post by esaptonor »

the way i am doing it is giving some rather bad aliasing, or at least not very sharp lines, even with no blur on. I think its due to the filter, is there a way to minimise or get rid of this side effect? Omaremad, do you get this problem with your irrCinema?
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

thats to do with the RTT texture resolution, if the RTT texture resolution is lower than your viewport resolution you will definitly get some blockyness
( i wouldnt call it aliasing since the hardware performs texture filtering on the RTT texture which means you still get blur unless the RTT is bigger than the view res)
esaptonor
Posts: 145
Joined: Sat May 06, 2006 11:59 pm

Post by esaptonor »

well i made the target textures all the same size as the viewport window and its still a noticable more blocky picture than with post processing off. Is something else at fault? or can it not be fixed any better than when the textures are the same size as the viewport?
Ico
Posts: 289
Joined: Tue Aug 22, 2006 11:35 pm

Post by Ico »

I'd say it's acting this way because the rtt doesn't have a size of 2^n x 2^n when it's as big as your screen size.
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

Its impossible to RTT to non power of two textures correctly, the extra pixels are recoded as black.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You mean impossible in Irrlicht, or in general? I don't think that it is impossible in general, at least not with OpenGL. DirectX has some additional restrictions for render targets, but I doubt that this is one.
But for the moment it is not possible to use NPOT textures in Irrlicht, as mentioned in several other threads already.
Post Reply