The problem with shader tutorial 10

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

The problem with shader tutorial 10

Post by Asimov »

Hi all,

I have just run the shader tutorial 10 that comes with irrlicht.
Now here is the problems I am having with the tutorial. First of all it is showing 3 shaders

So because I have never done shaders before I am having a hard time trying to work out which bit of code goes with each shader.

Also this is an OpenGL shader, and there is no example of an HLSL shader.

What I need is an example of an HLSL shader, just one shader, with no bells or whistles, on it's own so that I can work out the structure of a shader.

I think that is the problem with some of the tutorial code. There is a menu with everything thrown in, so that when you have to work out which part does what, it is hard for a beginner.

Could somebody give me an example of an HLSL shader, just to start me off.
Once I know how to set one up, perhaps I can learn how to do these shaders.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: The problem with shader tutorial 10

Post by CuteAlien »

There is also a hlsl shader in there (just search for hlsl). The corresponding shader is d3d9.hlsl in the media folder. That file contains both - the vertex and the pixel shader.

To give you the quick basics:

The vertex shader is run for each vertex which is rendered.
The pixel shader is run for each pixel rendered.
Shader code runs in parallel - meaning the same vertex shader code is run for many vertices at the same time.
Same for pixel shaders - each pixel runs the pixel shader code and it can run all in parallel.

Pixel shaders run after vertex shaders. You generally have to pass some info from vertex shader to pixel shader. That's what the VS_OUTPUT is for. It's the same as the input to the pixel shader. The amount of information which can be passed that way is limited (you have to check hlsl documentation to find how much limited - I think around 8 variables or so). If you need more you have to pass the information inside textures.
The PS_OUTPUT is the result of the pixel shader (the pixel color to render).

Note that shaders are not much Irrlicht related. Meaning - you can use any shader tutorial about hlsl you find on the web.
The main difference is probably the way the variables are passed from your c++ code to the hsls shaders.

Irrlicht specific:
As the example shows your shader-code needs to implement one callback (derived from IShaderConstantSetCallBack). That is called each frame before the shaders run. This is used to pass variables from c++ running on the cpu to the shader code running on the graphic card. In the shader code (d3d9.hlsl) those variables are marked as "Global variables". Your callback get's some id's to find those variables on the first call and then uses those id's to pass the corresponding info's to the shader.

I suspect there might be one more Irrlicht specific part. The setup used when you create the shader-material with addHighLevelShaderMaterialFromFiles takes a base-material as parameter. I never did dig that deep into the implementation of Irrlicht shaders, but my guess is that depending on which base-material is used there might be different kind of setup. Unfortunately it's not documented and I never found the time to figure out what exactly is done with that parameter - maybe others know more about that. I suspect it set's at least if alpha-values are supported or not as the example uses one time a base-material without alpha and one time with alpha.
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
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: The problem with shader tutorial 10

Post by Asimov »

Hi CuteAlien,

Thank you for your explanation.

That is why I couldn't find any shader code. It is loaded in from the d3d9.hlsl file which I have now found and had a look at.
I was wondering why I couldn't find the shader code in there. I presume you don't have to load it in like this. I presume you could have the shader code
in the file itself.

I am still finding it difficult to pull the code apart and see what each part does.
Normally at this point I usually google for code for the engine, but I notice this doesn't always work with irrlicht.
You end up finding lots of examples for xna and and other engines but not much on irrlicht.

At the moment I am not trying to understand the shader code. I am trying to understand how the shader code is implemented.
Once I understand that then I can learn how shader code works.

I have watched some tutorials on Unity shaders, and I think I could work some of that out, but I need to know how irrlicht works.

I understand what a vertex shader is, but that doesn't mean I know how to apply it.

I would appreciate it if someone could give me just the code for the HLSL shader, as I am having a hard time with this.
Really I want to make a shader to load a diffuse and a normalmap, and that is all at the moment.

PS. I have never used callbacks in C++. I am wondering if a callback is similar to Jquery callback when the code waits for a function to finish and then it calls the callback?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: The problem with shader tutorial 10

Post by CuteAlien »

Not sure what you mean. d3d9.hlsl is the whole HLSL shader code. vertexMain is the vertex shader and pixelMain is the pixel shader. Having the shader code in the c++ file is not a good idea as it's not c++ code but hlsl code. Keep cpp code in .cpp files and hlsl code in .hlsl files or things get confusing. And like you compile your .cpp code with your compiler to get an exe, the hlsl code is passed to a compiler inside DirectX at runtime which uploads the resulting binary then to the graphic card.

Just going quickly over the shader-code (note that I'm not an expert in that stuff... I usually work with the fixed function pipeline):

First the vertex shader transforms the vertex (which comes from your models) into screen coordinates and put's int into Output.Position. You can just copy-paste that line as it's always the same. This is probably the most important line the vertex shader. Then the math starts. In this example it calculates the influence of a single diffuse light (mLightPos and mLightColor) at a vertex position. This light-value is passed on as Output.Diffuse to the pixel shader. And lastly it passes on the TexCoord of the first uv-coordinates. For normal maps you will need a second uv-coordinate set.

The pixel shader is simpler. First it get's the texture-color for it's pixel. Then it multiplies it by the diffuse light color which was calculated earlier in the vertex-shader (I think it is already automatically interpolated across the polygon when you receive it in the pixel-shader). And then another multiplication by 4 for unknown reasons - probably the result was just too dark otherwise in the example (thought a brighter light would make more sense imho, but maybe I'm missing something).

Your diffuse and normalmaps are more complicated math. You probably should find a hlsl shader doing that on the web. Notice that you can use the hlsl-part from other tutorials - the only thing you usually have to do on Irrlicht side is to pass on variables to the shader (in that callback class). The shaders themself might look the same. One difference is sometimes the way matrices are passed around - different programmers have different preferences for which calculation to do on the CPU and which to do on the GPU.

I don't say it's easy. Shaders are flexible but definitely more work than using the fixed function pipeline. You have to write every piece of code which the fixed function pipeline otherwise offers yourself. Meaning especially the light calculations. And it's hell to debug when things go wrong.

Unfortunately I can't tell why your normal-maps don't work with the fixed function pipeline. I know normal maps look OK in the example, so I always guessed they are fine. Maybe it's just some format thing...
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
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: The problem with shader tutorial 10

Post by Asimov »

Hi all,

Woohoo I got my first shader to work. Ok it isn't my shader, but I typed it in, and it worked.

I found this really good simple tutorial
http://www.irrlicht3d.org/pivot/entry.php?id=158

This is the one that should be in shader tutorial 10, because it is simple. I only had trouble with one line. Had to change

Code: Select all

scene::ISceneNode* node = device->getSceneManager()->addTestSceneNode(50);
to this

Code: Select all

scene::ISceneNode* node =device->getSceneManager()->addCubeSceneNode(50);
 
And for some reason it is refusing to load in wall.bmp, even though the path is correct.

I am pleased though.

I presume

Code: Select all

float4 pixelShader( float2 texCoord : TEXCOORD0,      \
                    float4 color  : COLOR0 ) : COLOR0 \
the 0 here is the same zero that is in this line

Code: Select all

node->setMaterialTexture(0, driver->getTexture("wall.bmp"));
Now I need to learn how to make a shader class, so I can keep my code tidy, and then I can learn more about shaders.

PS.
Unfortunately I can't tell why your normal-maps don't work with the fixed function pipeline. I know normal maps look OK in the example, so I always guessed they are fine. Maybe it's just some format thing...
I literary tried everything with normalmaps. Spent a whole week on it. Tried every setting in exporting the objs. The output window says its loading the normalmaps in, but they don't show on the model.
I got really down about it. I just baked a down a model with 70 million polygons to use as a normalmap and it won't work. So now I have decided if I can't get it to work, perhaps a shader will help.
I have used normalmaps successfully in 3 other game engines.
Last edited by Asimov on Tue Jan 13, 2015 12:00 am, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: The problem with shader tutorial 10

Post by CuteAlien »

I don't know Jquery, but I guess callback means the same in all programming languages. It's code which you can pass to some function so it's called later on. Later on means in this case MyShaderCallBack::OnSetConstants is called before every draw call (I suppose it means once per meshbuffer in each rendering, but not sure). Additionally you could also overload the OnSetMaterial function (not done in this example) which would then be called probably each time this material is activated.

But just copy-paste the whole MyShaderCallBack class. The only thing you have to change is if you need to pass other variables to the shader. If you need one then ask again and we can probably help you how to pass it.

And you can kick out everything that is not about "UseHighLevelShaders". HLSL is a high-level shader. Meaning hlsl is a high-level language which is then compiled to assembler (if you are curious how the assembler code itself could look like then check the .psh and .vsh codes in the media folder - but you really don't need those anymore unless you enjoy assembly coding or try to get the last bit of optimization out of specific graphic-cards).
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
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: The problem with shader tutorial 10

Post by CuteAlien »

*sigh* forum is so slow today, it's a real pain writing anything - so this wil be my last post for today.

The 0 above is not exactly the same as the one in setMaterialTexture. pixelMain has the same parameters which are returned by vertexMain. Meaning everything in struct VS_OUTPUT. So the values in there depend on whatever you return in your vertex shader. In this case the texture-coordinate is indeed the one for the first texture - as it simply passes that one from the vertex shader. But the color is the light-value calculated inside the vertex shader.

I hope this info is correct (I know GLSL slightly better, so I might be wrong occassionally... although in general they work more or less the same).

And well - don't know about normalmaps except that they do work in the example (you can check by running it). So Irrlicht has some support for normal-maps. Maybe your other model used already 2 textures - and current fixed-function materials don't work with 3 textures. For those you need currently shaders.
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
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: The problem with shader tutorial 10

Post by Asimov »

Hi Cutealien,

Thanks for the help anyway. Sometimes it is sooooooo lonely trying to learn this stuff on your own.
I have always tried to avoid shaders, but I think I need to get it work, because I can't make a metal doggy for my monopoly game without a normal map LOL.

My main room obj, has about 6 diffuse, and 4 normalmaps, but my grenade I was using for test purposes only had one diffuse map and one normlmap.
Well it has an ambient occlusion map as well, but I would be happy if the normalmap worked LOL.

Going to keep playing with it until I got something working heh heh.

If not I am going to give up and learn the gui part.

I am pleased I made my first 2D graphics class, well in this engine anyway.
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: The problem with shader tutorial 10

Post by Asimov »

Hi all,

Well after my failure with normalmaps I am thinking learning shaders is the only way.

So back to tutorial 10. I am using windows, and directx. So I thought I would remove any code which isn't for this, and successfully it compiles and runs, but unsuccessfully for some reason the shader is failing to initialize for some reason.

I am thinking if I can get this to work, perhaps I can later get a normalmap shader to work properly. I have also downloaded the nvidia fx composer, and have been playing with that, but not getting far LOL.
Anyway here is a pic of the error I am getting and below that is the code.
Image

And here is the code

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;
 //   bool UseCgShaders = false;
 
    class MyShaderCallBack : 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("matView", invWorld.pointer(), 16);
 
            // 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();
 
            services->setVertexShaderConstant("fvEyePosition", reinterpret_cast<f32*>(&pos), 3);
 
            services->setVertexShaderConstant("fvLightPosition", reinterpret_cast<f32*>(&pos), 3);
 
            // set transposed world matrix
            core::matrix4 world = driver->getTransform(video::ETS_WORLD);
            world = world.getTransposed();
 
            // set texture, for textures you can use both an int and a float setPixelShaderConstant interfaces (You need it only for an OpenGL driver).
            s32 TextureLayerID = 0;
 
            services->setPixelShaderConstant("baseMap", &TextureLayerID, 0);
            services->setPixelShaderConstant("bumpMap", &TextureLayerID, 1);
 
        }
    };
 
    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 = "d3d9.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();
       }
 
        // create test scene node 1, with the new created material type 1
        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;
    }
 
The_Glitch
Competition winner
Posts: 523
Joined: Tue Jan 15, 2013 6:36 pm

Re: The problem with shader tutorial 10

Post by The_Glitch »

Don't use fx Composer.
It has a lot of extra stuff that will throw off a beginner. Like defines that some shaders rely on.
If you were to copy those shaders from fx composer as they are and try to use in Irrlicht you will run into a lot of issues.
The_Glitch
Competition winner
Posts: 523
Joined: Tue Jan 15, 2013 6:36 pm

Re: The problem with shader tutorial 10

Post by The_Glitch »

Also your entry point for your vertex shader is not defined properly in your main cpp file.

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,                            //  This line here "vs_main"             // Make sure they match in your shader file.
                    psFileName, "ps_main",video::EPST_PS_2_0,                             // This line here "ps_main"
                    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();
       }
 
 
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: The problem with shader tutorial 10

Post by Asimov »

Hi the_glitch,

The strange thing is that the bit you said was wrong is from the shader tutoiral, and I have not changed it.
eg

Code: Select all

                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);
Anyway I tried your code

Code: Select all

 newMaterialType1 = gpu->addHighLevelShaderMaterialFromFiles(
                    vsFileName, [color=#FF0000]"vs_main", [/color]video::EVST_VS_2_0,                            //  This line here "vs_main"             // Make sure they match in your shader file.
                    psFileName, [color=#BF0000]"ps_main", [/color]video::EPST_PS_2_0,                             // This line here "ps_main"
                    mc, video::EMT_SOLID, 0, shadingLanguage);
And I get a lot of errors

Code: Select all

||=== Build: Debug in shadertest (compiler: GNU GCC Compiler) ===|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp|105|error: stray '#' in program|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp|106|error: stray '#' in program|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp||In function 'int main()':|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp|105|error: 'FF0000' was not declared in this scope|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp|105|error: expected '{' before string constant|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp||In function 'int main()':|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp|105|warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp|105|error: expected identifier before '/' token|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp|105|error: expected '{' before 'video'|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp||In function 'int main()':|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp|105|warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp|105|error: expected ')' before 'video'|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp|106|error: 'BF0000' was not declared in this scope|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp|106|error: expected '{' before string constant|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp||In function 'int main()':|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp|106|warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp|106|error: expected identifier before '/' token|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp|106|error: expected '{' before 'video'|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp||In function 'int main()':|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp|106|warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]|
H:\Codeblock_Games\Irrlicht\Shaderfolder\shadertest_2\main.cpp|106|error: expected ')' before 'video'|
||=== Build failed: 12 error(s), 4 warning(s) (0 minute(s), 0 second(s)) ===|
 
The shader I am using is the d3d9.hlsl from the tutorial 10.

My idea was to get this working first, and then I can start altering it to see what stuff does, but alas I have done something wrong obviously.
The_Glitch
Competition winner
Posts: 523
Joined: Tue Jan 15, 2013 6:36 pm

Re: The problem with shader tutorial 10

Post by The_Glitch »

No No No LOL....

I didn't change anything in the code you posted I was simply saying

Code: Select all

vs_main
and

Code: Select all

ps_main
in your shader callback make sure those are the entry point in the shader you made.
I assumed you made a new simple shader.

Don't copy and paste my code snippet as it is just quoted from your post above LOL.


Here try this, this assumes you didn't mess up the shader file in anyway.

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, "vertexMain", video::EVST_VS_2_0,
                    psFileName, "pixelMain", video::EPST_PS_2_0,
                    mc, video::EMT_SOLID, 0, shadingLanguage);
 
                newMaterialType2 = gpu->addHighLevelShaderMaterialFromFiles(
                    vsFileName, "vertexMain", video::EVST_VS_2_0,
                    psFileName, "pixelMain", video::EPST_PS_2_0,
                    mc, video::EMT_TRANSPARENT_ADD_COLOR, 0 , shadingLanguage);
            }
            mc->drop();
       }
 
 
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: The problem with shader tutorial 10

Post by Asimov »

Hi The_Glitch,

No I haven't changed any of the shader code from the tutorial, apart from in the cpp of course. My first mission is to get a baseline that works. Once I get it working, then I play and learn how to do the shader code.
I have never ever written a shader before, so I am new at this. I need to get the standard shader working, before I start messing with it. Then if I screw it up, I know it was me that did it LOL.

However the tutorial is confusing because it has too much in it. As I only want to use this shader on windows, using directx and hlsl.

I believe a lot of the tutorials would benifit from only showing you one thing at a time instead of having a menu at the start and trying to show you everything in one go.
That is great if you know what you are doing, but not so great if you are new at it.

Anyway the new code you provides crashes again. I believe I know why you used those names,it is because this is in the shader eg

Code: Select all

VS_OUTPUT vertexMain(in float4 vPosition : POSITION,
                    in float3 vNormal    : NORMAL,
                    float2 texCoord      : TEXCOORD0 )
{
So the name of the struct is the name you asked me to change in the code, and the same with pixelMain.
I understand why you asked me to change those, but it crashes regardless.

So I have zipped it all up, and maybe you can see if I have done something wrong elsewhere.
http://www.asimoventerprises.co.uk/test ... test_2.zip

Once I have this working. I have a few books on shaders downloaded, and I can start learning the shader stuff.
I would like to learn a lot about it, but my primary goal is to make a shader with one diffuse map, and one normalmap.

Later I would like to make shaders with lightmaps.
The_Glitch
Competition winner
Posts: 523
Joined: Tue Jan 15, 2013 6:36 pm

Re: The problem with shader tutorial 10

Post by The_Glitch »

I took a look at your program there are several things wrong.

First your shader callback is all wrong, not the callback itself but the info your trying to pass between Irrlicht and your shader don't match even in the slightest :/.

For example your shader callback has the matrix's getting setup:

Code: Select all

 
 
services->setVertexShaderConstant("matView", invWorld.pointer(), 16);
 
services->setVertexShaderConstant("matViewProjection", worldViewProj.pointer(), 16);
 
 
but in your shader file itself the actual shader your trying to use with Irrlicht in your case d3d9.hlsl has the following matrix's in the file:

Code: Select all

float4x4 mWorldViewProj; // World * View * Projection transformation
float4x4 mInvWorld;      // Inverted world matrix
float4x4 mTransWorld;    // Transposed world matrix
There not even close. I also check out that other shader you copied off line don't even think about trying to use that one it's missing so many thing's in the file itself.

based off your d3d9 shader file your callback should have these instead of the ones above.

Code: Select all

 
 
services->setVertexShaderConstant("mInvWorld", invWorld.pointer(), 16);
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);
 
 
Seems like your trying to just pass any shader to Irrlicht and hope it works.

I understand it's confusing at first but you should try to load a very simple shader first perhaps one that returns a color. Once you get the hang of it then try to move to more advanced shaders.
If you try normal mapping shader as your first shader your bound to fail every time.

Let me know if you need a barebones shader I will make you one.
Post Reply