Strange problem with GLSL
Posted: Mon Feb 25, 2008 12:43 pm
I did run in to strange problem which I can describe on this test shader:
vertex shader code (file "shader_v.glsl"):
fragment shader code (file "shader_f.glsl"):
And finally simple Irrlicht code using that shader on simple sphere:
It does nothing special, its just for testing my problem since it seems somehow related to combination of uniform variable with if() and for() loops. Code runs fine like this.
However if I replace vertex shader code with:FPS suddenly drops from 1900 to 44! That something I don't understand. I did spend some hours reading GLSL docs and testing but did not find any reason for such behavior.
Here is another combination of code, which cause same FPS drop:???!
On the other hand this code works again fine:
I don't see any reason for such huge FPS differences. Does somebody have idea of what's going on? ...Or at last verify the same behavior on his machine?
vertex shader code (file "shader_v.glsl"):
Code: Select all
uniform int Lighting;
void main()
{
vec4 color = vec4(0,0,0,1);
int a = 0;
int b = 5;
if(Lighting == 0)
{
for(int i=0; i<5; i++)
{
color.r += 0.1;
}
}
gl_FrontColor = color;
gl_Position = ftransform();
}
Code: Select all
void main()
{
gl_FragColor = gl_Color;
}
Code: Select all
#include <irrlicht.h>
using namespace irr;
int main()
{
IrrlichtDevice *Device = createDevice(video::EDT_OPENGL,
core::dimension2d<s32>(640, 480), 16, false, false, false, NULL);
video::IVideoDriver* driver = Device->getVideoDriver();
scene::ISceneManager* smgr = Device->getSceneManager();
gui::IGUIEnvironment* guienv = Device->getGUIEnvironment();
video::IGPUProgrammingServices *services = driver->getGPUProgrammingServices();
s32 CMT_SHADER = services->addHighLevelShaderMaterialFromFiles(
"shader_v.glsl", "main", video::EVST_VS_1_1,
"shader_f.glsl", "main", video::EPST_PS_1_1,
0, video::EMT_SOLID);
scene::ISceneNode *node = smgr->addSphereSceneNode(5, 16);
node->setMaterialType((video::E_MATERIAL_TYPE)CMT_SHADER);
scene::ICameraSceneNode* camera = smgr->addCameraSceneNode(0, core::vector3df(0,0,-20));
gui::IGUIStaticText *text = guienv->addStaticText(L"", core::rect<s32>(10,10,200,200));
while(Device->run())
{
driver->beginScene(true, true, video::SColor(0,100,100,150));
core::stringw tmp("FPS: ");
tmp += driver->getFPS();
text->setText(tmp.c_str());
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
Device->drop();
return 0;
}
However if I replace vertex shader code with:
Code: Select all
uniform int Lighting;
void main()
{
vec4 color = vec4(0,0,0,1);
int a = 0;
int b = 5;
if(Lighting == 0)
{
for(int i=0; i<b; i++)
{
color.r += 0.1;
}
}
gl_FrontColor = color;
gl_Position = ftransform();
}
Here is another combination of code, which cause same FPS drop:
Code: Select all
uniform int Lighting;
void main()
{
vec4 color = vec4(0,0,0,1);
int a = Lighting;
int b = 5;
if(a == 0)
{
for(int i=0; i<b; i++)
{
color.r += 0.1;
}
}
gl_FrontColor = color;
gl_Position = ftransform();
}
On the other hand this code works again fine:
Code: Select all
uniform int Lighting;
void main()
{
vec4 color = vec4(0,0,0,1);
int a = 0;
int b = 5;
if(a == 0)
{
for(int i=0; i<b; i++)
{
color.r += 0.1;
}
}
gl_FrontColor = color;
gl_Position = ftransform();
}