what kind of performance hit
what kind of performance hit
can I expect using GLSL shaders with the irrlicht engine compared to the built in lighting and materials ?
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.
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!
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!
-
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
I don't know how badly coded it is but the vertex frag...
with the fragment shader like this
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.
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;
}
makes no difference.
oh and by the way it's worth noting that you need to set the following flag...
before
has any effect
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);
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();
in fact a bare minimum no lighting shader comes out slower
vertex...
fragment...
it's almost as if it's (fixed function time) + (shader time)
vertex...
Code: Select all
void main()
{
gl_Position = ftransform();
}
Code: Select all
void main()
{
gl_FragColor = vec4(0.8f,0.2f,0.1f,1.0f);
}
it's almost as if it's (fixed function time) + (shader time)
-
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm