Page 4 of 5
Posted: Tue Jul 10, 2007 1:11 pm
by Nadro
This code work properly

I add 2 cameras and render all in 2 steps:)
Code: Select all
scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(0,100.0f,100.0f);
cam->setPosition(core::vector3df(120,0,0));
cam->setTarget(core::vector3df(0,0,0));
scene::ICameraSceneNode* cam2 = smgr->addCameraSceneNodeFPS(0,100.0f,100.0f);
cam2->setPosition(core::vector3df(0,0,120));
cam2->setTarget(core::vector3df(0,0,90));
device->getCursorControl()->setVisible(false);
int lastFPS = -1;
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(255,0,0,0));
smgr->setActiveCamera(cam);
driver->setViewPort(rect<s32>(0,0,400,600));
smgr->drawAll();
smgr->setActiveCamera(cam2);
driver->setViewPort(rect<s32>(400,0,800,600));
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = "";
if (driverType == video::EDT_DIRECT3D9)
str = L"Chernobyl Shaders: Plastic [HLSL] VS: 1.1 PS: 2.0 FPS:";
if (driverType == video::EDT_OPENGL)
str = L"Chernobyl Shaders: Plastic [GLSL] VS: 1.1 PS: 1.1 FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
Posted: Tue Jul 10, 2007 3:01 pm
by Masterhawk
No success at all....
I think that isn't a problem with the camera position, but perhaps with the Transformation. Because when I fix the cam pos with
Code: Select all
core::vector3df pos = core::vector3df(100.f,100.f,0.f);
services->setVertexShaderConstant("Camera_Position", reinterpret_cast<f32*>(&pos), 3);
There is the same effect....
Also when I access the cam directly there's no change...
Code: Select all
tCam->updateAbsolutePosition();
core::vector3df pos = tCam->getAbsolutePosition();
services->setVertexShaderConstant("Camera_Position", reinterpret_cast<f32*>(&pos), 3);
Posted: Tue Jul 10, 2007 7:32 pm
by Nadro
OK. Send to You on pm all source code

Compile this my code and look:) Now it work?

Posted: Tue Jul 10, 2007 9:56 pm
by Masterhawk
Yes, until I modify this code a little
try this piece of code and look what happens...
Code: Select all
#include <irrlicht.h>
#include <iostream>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
IrrlichtDevice* device = 0;
class CGE_Shaders:public video::IShaderConstantSetCallBack
{
public:
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
core::matrix4 invWorld = driver->getTransform(video::ETS_WORLD);
invWorld.makeInverse();
services->setVertexShaderConstant("mInvWorld", invWorld.pointer(), 16);
core::matrix4 worldViewProj;
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);
core::vector3df pos = device->getSceneManager()->getActiveCamera()->getAbsolutePosition();
services->setVertexShaderConstant("Camera_Position", reinterpret_cast<f32*>(&pos), 3);
video::SColorf col(1.0,0.9031,0.1536,1.0);
services->setVertexShaderConstant("Color", reinterpret_cast<f32*>(&col), 4);
}
};
int main()
{
video::E_DRIVER_TYPE driverType;
printf("\n Please select the driver you want for this demo:\n\n"\
" (a) Direct3D 9.0c\n (b) OpenGL 1.5\n"\
" (otherKey) exit\n\n");
char i;
std::cin >> i;
switch(i)
{
case 'a': driverType = video::EDT_DIRECT3D9;break;
case 'b': driverType = video::EDT_OPENGL; break;
default: return 1;
}
device = createDevice(driverType,dimension2d<s32>(800, 600),32,false,false,false,0);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* gui = device->getGUIEnvironment();
printf("\n*** Chernobyl Shaders by Nadro ***\n\n");
c8* vsFileName = 0;
c8* psFileName = 0;
if (driverType == video::EDT_DIRECT3D9)
{
psFileName = "HLSL/Plastic.hlsl";
vsFileName = psFileName;
}
if (driverType == video::EDT_OPENGL)
{
psFileName = "GLSL/Plastic.frag";
vsFileName = "GLSL/Plastic.vert";
}
video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();
s32 CGE_Shader_Plastic = 0;
CGE_Shaders* mc = new CGE_Shaders();
if (driverType == video::EDT_DIRECT3D9)
CGE_Shader_Plastic = gpu->addHighLevelShaderMaterialFromFiles(vsFileName,"vertexMain",video::EVST_VS_1_1,psFileName,"pixelMain",video::EPST_PS_2_0,mc,video::EMT_SOLID);
if (driverType == video::EDT_OPENGL)
CGE_Shader_Plastic = gpu->addHighLevelShaderMaterialFromFiles(vsFileName,"main",video::EVST_VS_1_1,psFileName,"main",video::EPST_PS_1_1,mc,video::EMT_SOLID);
//IAnimatedMesh* mesh = smgr->getMesh("Models/Elephant.obj");
//IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
ISceneNode* node = smgr->addSphereSceneNode(10.f,16.f);
node->setPosition(core::vector3df(0,0,0));
node->setRotation(core::vector3df(0,0,0));
node->setScale(core::vector3df(1,1,1));
node->setMaterialFlag(video::EMF_LIGHTING, false);
node->setMaterialType((video::E_MATERIAL_TYPE)CGE_Shader_Plastic);
//scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(0,100.0f,100.0f);
scene::ICameraSceneNode* cam = smgr->addCameraSceneNode();
cam->setPosition(core::vector3df(120,0,0));
cam->setTarget(core::vector3df(0,0,0));
//IOrbitCamCtrl* OrbCam = new IOrbitCamCtrl(cam,vector3df(0,0,0),device);
//scene::ICameraSceneNode* cam2 = smgr->addCameraSceneNodeFPS(0,100.0f,100.0f);
//cam2->setPosition(core::vector3df(0,0,120));
//cam2->setTarget(core::vector3df(0,0,90));
//device->getCursorControl()->setVisible(false);
//driver->setViewPort(rect<s32>(0,0,ResX/2,ResY/2));
/*skyboxNode = */smgr->addSkyBoxSceneNode(
driver->getTexture("sky/irrlicht2_up.jpg"),
driver->getTexture("sky/irrlicht2_dn.jpg"),
driver->getTexture("sky/irrlicht2_lf.jpg"),
driver->getTexture("sky/irrlicht2_rt.jpg"),
driver->getTexture("sky/irrlicht2_ft.jpg"),
driver->getTexture("sky/irrlicht2_bk.jpg"));
int lastFPS = -1;
vector3df rot = vector3df(0,0,0);
while(device->run())
if (device->isWindowActive())
{
//OrbCam->PreRender();
driver->beginScene(true, true, video::SColor(255,0,0,0));
smgr->setActiveCamera(cam);
/*driver->setViewPort(rect<s32>(0,0,400,600));
smgr->drawAll();
smgr->setActiveCamera(cam2);
driver->setViewPort(rect<s32>(400,0,800,600));*/
smgr->drawAll();
driver->endScene();
rot += vector3df(0.1,0.08,0.15);
node->setRotation(rot);
//OrbCam->UpdateCam(-0.02,-0,0,vector3df(0,0,0));
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = "";
if (driverType == video::EDT_DIRECT3D9)
str = L"Chernobyl Shaders: Plastic [HLSL] VS: 1.1 PS: 2.0 FPS:";
if (driverType == video::EDT_OPENGL)
str = L"Chernobyl Shaders: Plastic [GLSL] VS: 1.1 PS: 1.1 FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
device->drop();
return 0;
}
The only thing I changed is to rotate the sphere....did you see the same ugly effect I see?
Posted: Wed Jul 11, 2007 9:16 am
by Nadro
Yes now I see... We have to repair this error

Posted: Wed Jul 11, 2007 10:29 am
by Masterhawk
Yeah, sure...but this is not a problem with your shader, but with the callback I think. I provided the shadertut from Irrlicht and got the same effect. Perhaps the callback misses the rotation-matrix of the mesh.
I really have no clue about shaders, so I only post my ideas. Maybe they are completely wrong

Posted: Wed Jul 11, 2007 11:14 am
by Nadro
This is only shader problem

You must add other calculation

Posted: Thu Jul 12, 2007 10:24 pm
by Masterhawk
Argh...does anyone got an idea about this problem. Does anyone ever fixed it?
Posted: Fri Jul 13, 2007 12:44 am
by omaremad
Post the code you are using and ill have a look, most of the shader examples from render monkey use shortcuts when it comes to matrices (in a flxible envirnoment like irrlicht you need more matrices to cover all the transform types you can do), so you might get bad lighting if you say scale your golf ball in irrlicht because the shader uses the world matrix rather than the inverse tanspose of it.
Keep up the good work nadro.
Posted: Fri Jul 13, 2007 11:13 am
by Nadro
I add some Irr matrices but is too litle I think. This is GLSL code:
Code: Select all
[VERTEX]
uniform mat4 mWorldViewProj;
uniform mat4 mInvWorld;
uniform mat4 mTransWorld;
uniform vec3 Camera_Position;
varying vec4 vNormal;
varying vec3 vViewVec;
void main(void)
{
gl_Position = mWorldViewProj * gl_Vertex;
vec4 normal = vec4(gl_Normal, 0.0);
vNormal = mInvWorld * normal;
vNormal = normalize(vNormal);
vec4 worldpos = gl_Vertex * mTransWorld;
vViewVec = Camera_Position - worldpos.xyz;
}
vViewVec isn't calculate with some irr matrices I think.
and this is good:
Code: Select all
[FRAGMENT]
uniform vec4 Color;
varying vec4 vNormal;
varying vec3 vViewVec;
void main(void)
{
float v = 0.5 * (1.0 + dot(normalize(vViewVec), vNormal.xyz));
gl_FragColor = v * Color;
}
Posted: Sun Jul 15, 2007 3:15 pm
by Masterhawk
Hey, now I'm back at home and I tried the new code.
But it seems the shader don't work for me, I don't see anything but a black sphere. Do I have to change something in the shader callback, too? The console doesn't give an error while loading the shader, so it should work...
Posted: Sun Jul 15, 2007 9:50 pm
by omaremad
try changing this
vec4 normal = vec4(gl_Normal, 0.0);
vNormal = mInvWorld * normal;
vNormal = normalize(vNormal);
to
vec4 normal = vec4(gl_NormalMatrix * gl_Normal,0);
I also reccomend that the normal uses a vec3
Posted: Sun Jul 15, 2007 10:09 pm
by xDan
Is this "HDR" the same thing as bloom? It looks like it in rendermonkey.
It would be really great if you could get bloom working for irrlicht

I so need it in my next project

Posted: Sun Jul 15, 2007 10:20 pm
by omaremad
Well i already have bloom and "a bit Higher dynamic range" working with irrlicht. The dyanamic range of something is how many levels of brightness you can get (hence the word range), use your eyes to look at the sun it burns doesnt it? photograph or film the sun and display on your monitor it dosesnt burn your eyes. Your monitor doesnt have enough dynamic range to generate that much light. So how does the sun still look bright in pictures.. not just a yellow circle. Thats because of bloom, your capture circuitry, film or retina will add bloom if the brightness of the source is beyond their dynamic range since there is so much light it floods your neighbouring receptors too.
Higher dyanmic range pipelines ussually stor colours in a float texture that doesnt get clipped to a mxiumum of 1 per colour componenet, thses are impractical on some older cards and come with sevral restrictions(though not anymore) so they are not in irrlicht.
In my Hdr code i used stored colours in textures and used the alpha channel to store brightness and hence getting extra information. I dont really think 16 bit or above are really needed for HDR until we get HDR monitors, since in the end the extra lighting info is presented as bloom (you cant see the extra info unless your monitor is as bright as the sun)
Posted: Mon Jul 16, 2007 8:29 am
by Nadro
Thanks omaremad

With
Code: Select all
vec4 normal = vec4(gl_NormalMatrix * gl_Normal,0);
is some problems, bacause Irrlicht don't calcualte it in each frame eg. gl_ModelViewMatrix etc. only gl_Vertex are good

other gl definitions must be put in callback. Use Your sugestion I add:
Code: Select all
vNormal = vec4(gl_Normal,0)*mInvWorld;
And now it's work properly

Now I'm rebuilding HLSL version
New Irrlicht Callback for this shader:
Code: Select all
class CGE_Shaders:public video::IShaderConstantSetCallBack
{
public:
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
core::matrix4 worldViewProj;
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);
core::matrix4 invWorld = driver->getTransform(video::ETS_WORLD);
invWorld.makeInverse();
services->setVertexShaderConstant("mInvWorld", invWorld.pointer(), 16);
core::matrix4 world = driver->getTransform(video::ETS_WORLD);
world = world.getTransposed();
services->setVertexShaderConstant("mTransWorld", world.pointer(), 16);
core::vector3df pos = device->getSceneManager()->getActiveCamera()->getAbsolutePosition();
services->setVertexShaderConstant("Camera_Position", reinterpret_cast<f32*>(&pos), 3);
video::SColorf col(1.0,0.9031,0.1536,1.0);
services->setVertexShaderConstant("Color", reinterpret_cast<f32*>(&col), 4);
}
};
New Vertex Shader in GLSL:
Code: Select all
uniform mat4 mWorldViewProj;
uniform mat4 mInvWorld;
uniform mat4 mTransWorld;
uniform vec3 Camera_Position;
varying vec4 vNormal;
varying vec3 vViewVec;
void main(void)
{
gl_Position = mWorldViewProj * gl_Vertex;
vNormal = vec4(gl_Normal,0)*mInvWorld;
vec4 worldpos = gl_Vertex * mTransWorld;
vViewVec = Camera_Position - worldpos.xyz;
}
New HLSL shader:
Please wait
