The problem with shader tutorial 10
Re: The problem with shader tutorial 10
Hi The_Glitch,
The problem is that I don't really understand what Irrlicht is doing in the code, and on top of that I have to learn how to make a shader.
The biggest problem is the tutorial that tries to do everything, but teaches you nothing.
This is exactly the problem I had with Neoaxis. They basically had one demo which is supposed to teach you everything, but was impossible to separate the code.
If you could make me a bare bones shader that worked, that would be great. It would be a good starting point.
There is a lot of documentation on shaders, but not much documenation on implementing them in irrlicht, apart from tutorial 10 which gives an overload of imformation.
The problem is that I don't really understand what Irrlicht is doing in the code, and on top of that I have to learn how to make a shader.
The biggest problem is the tutorial that tries to do everything, but teaches you nothing.
This is exactly the problem I had with Neoaxis. They basically had one demo which is supposed to teach you everything, but was impossible to separate the code.
If you could make me a bare bones shader that worked, that would be great. It would be a good starting point.
There is a lot of documentation on shaders, but not much documenation on implementing them in irrlicht, apart from tutorial 10 which gives an overload of imformation.
-
- Competition winner
- Posts: 523
- Joined: Tue Jan 15, 2013 6:36 pm
Re: The problem with shader tutorial 10
http://www.datafilehost.com/d/d7442171
Here's a very simple shader I made for you with comments. It simple returns a model with one texture.
Here's your new shader callback, erase your old one:
Here's where you setup your new shader callback.
Here's a very simple shader I made for you with comments. It simple returns a model with one texture.
Here's your new shader callback, erase your old one:
Code: Select all
class MyShaderCallBack : public video::IShaderConstantSetCallBack
{
public:
virtual void OnSetConstants(video::IMaterialRendererServices* services,
s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
// set clip matrix
core::matrix4 worldViewProj;
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("matViewProjection", worldViewProj.pointer(), 16);
// set camera position
core::vector3df pos = device->getSceneManager()->getActiveCamera()->getAbsolutePosition();
}
};
Here's where you setup your new shader callback.
Code: Select all
if (UseHighLevelShaders)
{
const video::E_GPU_SHADING_LANGUAGE shadingLanguage = video::EGSL_DEFAULT;
// create material from high level shaders (hlsl, glsl or cg)
newMaterialType1 = gpu->addHighLevelShaderMaterialFromFiles(
vsFileName, "vs_main", video::EVST_VS_2_0,
psFileName, "ps_main", video::EPST_PS_2_0,
mc, video::EMT_SOLID, 0, shadingLanguage);
newMaterialType2 = gpu->addHighLevelShaderMaterialFromFiles(
vsFileName, "vs_main", video::EVST_VS_2_0,
psFileName, "ps_main", video::EPST_PS_2_0,
mc, video::EMT_TRANSPARENT_ADD_COLOR, 0 , shadingLanguage);
}
mc->drop();
}
Re: The problem with shader tutorial 10
Hi The_Glitch,
Will be looking at your code properly tomorrow.
Just had to do a lot of php/mysql work, to get it ready for the morning.
Little bit tired now so will look into it fresh tomorrow.
PS. That datafile host was annoying. It changed my webpage search engine in both mozilla and internet explorer, and then added a pile of add-ons for shopping I didn't want. Not quite sure if you were aware of this. Took me 20 minutes to get rid of the add-ons.
PPS. Avast is now reporting malware viruses and trojans since I downloaded that file. Will have to do a complete scan.
Will be looking at your code properly tomorrow.
Just had to do a lot of php/mysql work, to get it ready for the morning.
Little bit tired now so will look into it fresh tomorrow.
PS. That datafile host was annoying. It changed my webpage search engine in both mozilla and internet explorer, and then added a pile of add-ons for shopping I didn't want. Not quite sure if you were aware of this. Took me 20 minutes to get rid of the add-ons.
PPS. Avast is now reporting malware viruses and trojans since I downloaded that file. Will have to do a complete scan.
-
- Competition winner
- Posts: 523
- Joined: Tue Jan 15, 2013 6:36 pm
Re: The problem with shader tutorial 10
No I was not aware. All it was, was a shader file.
Are you sure you did not hit some spam link and downloaded something else??
I tested the link just before I posted it and didn't have those problems.
Are you sure you did not hit some spam link and downloaded something else??
I tested the link just before I posted it and didn't have those problems.
Re: The problem with shader tutorial 10
Hi The_Glitch,
I was worried when I clicked on my shader.exe, as I didn't expect to be downloading an exe, but an hlsl file, anyway as soon as I run the exe my browser settings changed. It installed a pile of adware crap, and I had to spend ages scanning my computer with malwarebytes. I eventually got it. Will look at the shader tomorrow.
Normally I wouldn't go near a downloader with a bargepole LOL.
I was worried when I clicked on my shader.exe, as I didn't expect to be downloading an exe, but an hlsl file, anyway as soon as I run the exe my browser settings changed. It installed a pile of adware crap, and I had to spend ages scanning my computer with malwarebytes. I eventually got it. Will look at the shader tomorrow.
Normally I wouldn't go near a downloader with a bargepole LOL.
-
- Competition winner
- Posts: 523
- Joined: Tue Jan 15, 2013 6:36 pm
Re: The problem with shader tutorial 10
Yeag I'm pretty sure you hit a spam download button instead of the actual file download button.
I'll try to use something else next time.
Did you get it up and going?
I'll try to use something else next time.
Did you get it up and going?
Re: The problem with shader tutorial 10
Hi,
After I spoke to you I spend an hour running malwarebytes, and it showed up again today.
So all I have done is run avast, then malwarebytes, and spent ages trawling through my startup to see if anything new has sneaked in.
Hopefully I have got rid of the pesky virus, and I can look at your code now.
PS.. I run the code and it seems to be crashing. I am probably missing something. btw I renamed your shader to simple.hlsl
After I spoke to you I spend an hour running malwarebytes, and it showed up again today.
So all I have done is run avast, then malwarebytes, and spent ages trawling through my startup to see if anything new has sneaked in.
Hopefully I have got rid of the pesky virus, and I can look at your code now.
PS.. I run the code and it seems to be crashing. I am probably missing something. btw I renamed your shader to simple.hlsl
Code: Select all
#include <irrlicht.h>
#include <iostream>
#include "driverChoice.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
IrrlichtDevice* device = 0;
bool UseHighLevelShaders = true;
class MyShaderCallBack : public video::IShaderConstantSetCallBack
{
public:
virtual void OnSetConstants(video::IMaterialRendererServices* services,
s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
// set clip matrix
core::matrix4 worldViewProj;
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("matViewProjection", worldViewProj.pointer(), 16);
// set camera position
core::vector3df pos = device->getSceneManager()->getActiveCamera()->getAbsolutePosition();
}
};
int main()
{
// create device
IrrlichtDevice *device = createDevice(EDT_DIRECT3D9, dimension2d<u32>(800, 600),32, false, true, false);
if (device == 0) return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* gui = device->getGUIEnvironment();
io::path vsFileName; // filename for the vertex shader
io::path psFileName; // filename for the pixel shader
psFileName = "simple.hlsl";
vsFileName = psFileName; // both shaders are in the same file
if (!driver->queryFeature(video::EVDF_PIXEL_SHADER_1_1) && !driver->queryFeature(video::EVDF_ARB_FRAGMENT_PROGRAM_1))
{
device->getLogger()->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))
{
device->getLogger()->log("WARNING: Vertex shaders disabled "\
"because of missing driver/hardware support.");
vsFileName = "";
}
// create materials
video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();
s32 newMaterialType1 = 0;
s32 newMaterialType2 = 0;
if (gpu)
{
MyShaderCallBack* mc = new MyShaderCallBack();
if (UseHighLevelShaders)
{
const video::E_GPU_SHADING_LANGUAGE shadingLanguage = video::EGSL_DEFAULT;
// create material from high level shaders (hlsl, glsl or cg)
newMaterialType1 = gpu->addHighLevelShaderMaterialFromFiles(
vsFileName, "vs_main", video::EVST_VS_2_0,
psFileName, "ps_main", video::EPST_PS_2_0,
mc, video::EMT_SOLID, 0, shadingLanguage);
newMaterialType2 = gpu->addHighLevelShaderMaterialFromFiles(
vsFileName, "vs_main", video::EVST_VS_2_0,
psFileName, "ps_main", video::EPST_PS_2_0,
mc, video::EMT_TRANSPARENT_ADD_COLOR, 0 , shadingLanguage);
}
mc->drop();
}
scene::ISceneNode* node = smgr->addCubeSceneNode(50);
node->setPosition(core::vector3df(0,0,0));
node->setMaterialTexture(0, driver->getTexture("wall.bmp"));
node->setMaterialTexture(1, driver->getTexture("wall.bmp"));
node->setMaterialFlag(video::EMF_LIGHTING, false);
node->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType1);
scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator(core::vector3df(0,0.3f,0));
node->addAnimator(anim);
anim->drop();
// Same for the second cube, but with the second material we created.
node = smgr->addCubeSceneNode(50);
node->setPosition(core::vector3df(0,-10,50));
node->setMaterialTexture(0, driver->getTexture("wall.bmp"));
node->setMaterialFlag(video::EMF_LIGHTING, false);
node->setMaterialFlag(video::EMF_BLEND_OPERATION, true);
node->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType2);
anim = smgr->createRotationAnimator(core::vector3df(0,0.3f,0));
node->addAnimator(anim);
anim->drop();
scene::ILightSceneNode* node_sun = 0;
node_sun = smgr->addLightSceneNode(0,core::vector3df(0,0,0),video::SColorf(0.5,0.5,0.5,0.0),5000.0f);
node_sun->setLightType(ELT_POINT);
smgr->addSkyDomeSceneNode(driver->getTexture("skydome.jpg"),16,16,1.0f,2.5f);
smgr->addCameraSceneNode(0,vector3df(-100,50,100), vector3df(0,0,0));
/*
Now draw everything. That's all.
*/
int lastFPS = -1;
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(255,0,0,0));
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Irrlicht Engine - Vertex and pixel shader example [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
device->drop();
return 0;
}
-
- Competition winner
- Posts: 523
- Joined: Tue Jan 15, 2013 6:36 pm
Re: The problem with shader tutorial 10
I'm not sure what your doing but I took your source and made a new project and made a small change in the shader callback to work with my version and everything works fine and the shader I made you loads and works fine no errors in the console and the output is as expected.
I'm not to sure how to help as the source doesn't have any issues??
What's the console say when it crashes??
I'm not to sure how to help as the source doesn't have any issues??
What's the console say when it crashes??
Re: The problem with shader tutorial 10
HI The Glitch,
So either the small change you made stopped it crashing, or it can't find the shader. Going to look back into this.
PS. managed to move the console window. Well it loads the skydome texture and the wall texture and then crashes.
Heh the console is always hidden behind the other window when it crashes, and I can never read what it says.What's the console say when it crashes??
So either the small change you made stopped it crashing, or it can't find the shader. Going to look back into this.
PS. managed to move the console window. Well it loads the skydome texture and the wall texture and then crashes.
Re: The problem with shader tutorial 10
You can also start from console. DOS-Box if you have to. Although personally I install MinGW as that get's me a console on Windows with nearly all the power of a Unix console (you can't really work in DOS-Box...). Makes it easier to see such messages as they stay then on screen independent of your own application.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Competition winner
- Posts: 523
- Joined: Tue Jan 15, 2013 6:36 pm
Re: The problem with shader tutorial 10
My change was necessary as I use shaderpipeline your using the default version of Irrlicht. In your case the source was fine. I'm not sure why your program is crashing.
{EDIT}: Make sure your shader is in the same folder of the application it will crash if it doesn't find it.
{EDIT}: Make sure your shader is in the same folder of the application it will crash if it doesn't find it.
Re: The problem with shader tutorial 10
Hi The_Glitch,
Yes it is in the same folder.{EDIT}: Make sure your shader is in the same folder of the application it will crash if it doesn't find it.