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?