what kind of performance hit

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

what kind of performance hit

Post by Klunk »

can I expect using GLSL shaders with the irrlicht engine compared to the built in lighting and materials ?
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post by ent1ty »

That's the same like asking: can i have a scene of a certain size unknown to you and expect it to run fast?
In a nutshell, it depends how complex the shader is. If you plan to do per vertex lighting or even optimized per pixel lighting, it's possible it will be even faster than irrlicht materials.
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Post by Klunk »

see there's the rub, running a very simple 1 light per vertex lambert lighting shader (3 constants, light, diffuse & ambient) runs 30-40% slower than the default irrlicht material with 5 lights.
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

You must have a terribly coded shader. Perhaps show us the code or supply us with an example. My normal map shader with two lights supported runs about 25% slower, so it's certainly not impossible to get the shaders running quickly.
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Post by Klunk »

I don't know how badly coded it is but the vertex frag...

Code: Select all

uniform int  glight;
uniform vec4 gAmbient;			
uniform vec4 gDiffuse;				

void main()
{
	gl_Position = ftransform();
	vec3 N = gl_NormalMatrix * gl_Normal;	
	vec3 L =  gl_LightSource[glight].position;
	gl_FrontColor = gl_LightSource[glight].diffuse * (gAmbient + gDiffuse * dot(N,L));
}

with the fragment shader like this

Code: Select all

void main()
{
	gl_FragColor = gl_Color;
}
Last edited by Klunk on Wed Apr 13, 2011 8:41 am, edited 1 time in total.
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Post by Klunk »

Code: Select all


#include "stdafx.h"
#include <irrlicht.h>

#define _USE_GLSL_SHADERS_	1


#ifdef _MSC_VER
	#pragma comment(lib, "Irrlicht.lib")
#endif

using namespace irr;
using namespace core;
using namespace scene;
using namespace io;
using namespace video;

class BasicShaderCallBack : public IShaderConstantSetCallBack
{
public:

	int			light;
	SColorf		ambient;
	SColorf		diffuse;

	virtual void OnSetConstants(IMaterialRendererServices* services, s32 userData)
	{
		services->setVertexShaderConstant("gDiffuse", (float*)(&diffuse), 4);
		services->setVertexShaderConstant("gAmbient", (float*)(&ambient), 4);
		services->setVertexShaderConstant("glight", (float*)(&light), 1);
	}
};

//*********************************************************************************************************

int main()
{

	IrrlichtDevice* device = createDevice(EDT_OPENGL, dimension2d<u32>(640, 480),16,false,false,false,0);
	if (device == 0)
		return 1; 
	IVideoDriver* driver = device->getVideoDriver();
	if(!driver)
		return 1;

	ISceneManager* smgr = device->getSceneManager();
	ILogger* thelog = device->getLogger();
	IFileSystem* fileSys = device->getFileSystem();


	path psFileName = "/shaders/pv_flat_lambert.frag";
	path vsFileName = "/shaders/pv_flat_lambert.vert";

	if (!driver->queryFeature(video::EVDF_PIXEL_SHADER_1_1) &&
		!driver->queryFeature(video::EVDF_ARB_FRAGMENT_PROGRAM_1))
	{
		thelog->log("WARNING: Pixel shaders disabled "\
			"because of missing driver/hardware support.");
		psFileName = "";
	}

	if (!driver->queryFeature(video::EVDF_VERTEX_SHADER_1_1) &&
		!driver->queryFeature(video::EVDF_ARB_VERTEX_PROGRAM_1))
	{
		thelog->log("WARNING: Vertex shaders disabled "\
			"because of missing driver/hardware support.");
		vsFileName = "";
	}

	IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();
	s32 materialType = 0;

	if (gpu)
	{
		BasicShaderCallBack* cb = new BasicShaderCallBack();

		cb->ambient = SColorf(0.1f,0.1f,0.1f,1.0f);
		cb->diffuse = SColorf(0.8f,0.2f,0.1f,1.0f);
		cb->light = 0;

		materialType = gpu->addHighLevelShaderMaterialFromFiles(vsFileName, "main", EVST_VS_1_1,
																	psFileName, "main", EPST_PS_1_1,
																	cb, EMT_SOLID);
		cb->drop();
	}

	for(int i = 0;i < 10;i++)
		for(int j = 0;j < 10;j++)
		{	

			ISceneNode* node = smgr->addSphereSceneNode(10);
			node->setPosition(vector3df(i * 20.0f, 0.0f, j * 20.0f));

#ifdef _USE_GLSL_SHADERS_

			node->setMaterialFlag(EMF_LIGHTING, false);
			node->setMaterialType((E_MATERIAL_TYPE)materialType);

#endif
		}

	ILightSceneNode* lightnode = smgr->addLightSceneNode();
	lightnode->setLightType(ELT_DIRECTIONAL);
	lightnode->setRotation(vector3df(32.0026f, -10.93793f, -84.9814f));


	ICameraSceneNode* cam = smgr->addCameraSceneNodeMaya();
	cam->setPosition(vector3df(150,150,150));
	cam->setTarget(vector3df(0,0,0));

	int lastFPS = -1;
	while(device->run())
	{
		if (device->isWindowActive())
		{
			driver->beginScene(true, true,SColor(255,128,128,128));
			smgr->drawAll();
			driver->endScene();


			int fps = driver->getFPS();
			if (lastFPS != fps)
			{
				stringw str = L"Irrlicht Engine [";
				str += driver->getName();
				str += "] FPS:";
				str += fps;
				device->setWindowCaption(str.c_str());
				lastFPS = fps;
			}
		}
	}
	device->drop();
	return 0;
}
running the above with #define _USE_GLSL_SHADERS_ line commented out gives a frame rate of 202 fps with it in 107 fps
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Seems you have an empty scene. I'm wondering why you have any change in FPS at all, and why your default rendering wouldn't output 2000 FPS. What kind of system setup do you have?
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Post by Klunk »

it's not an empty scene from this end...

shaders on
Image

shaders off
Image

running on 2.4 dual core with a 8800 GTS
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Oh sorry, seems that the scrolling jumped over that part all the time :wink: Maybe try to enable ambient and diffuse lighting for the fixed pipeline as well. This might be due to early out optimizations in the render pipeline then.
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Post by Klunk »

and how would i do that ?
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Post by Klunk »

makes no difference.

oh and by the way it's worth noting that you need to set the following flag...

Code: Select all

node->setMaterialFlag(EMF_COLOR_MATERIAL, false);
before

Code: Select all

node->getMaterial(0).AmbientColor=SColorf(0.1f,0.1f,0.1f,1.0f).toSColor();
			node->getMaterial(0).DiffuseColor = SColorf(0.2f,0.2f,0.8f,1.0f).toSColor();
has any effect
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Post by Klunk »

in fact a bare minimum no lighting shader comes out slower

vertex...

Code: Select all

void main()
{
	gl_Position = ftransform();
}
fragment...

Code: Select all

void main()
{
	gl_FragColor = vec4(0.8f,0.2f,0.1f,1.0f);
}
Image

it's almost as if it's (fixed function time) + (shader time)
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

Hmm, that seems weird. Have you tried using directx and hlsl if you are able?
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Post by Klunk »

no i've not tried directx & hlsl. I'd rather not take it down that road though.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Maybe update your video drivers? Please post the full console log.
Post Reply