Setting shader variables

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.
Post Reply
Neomex
Posts: 3
Joined: Mon Oct 22, 2012 3:21 pm

Setting shader variables

Post by Neomex »

I'm using dx9 and HLSL and I'm trying to set variable in a shader, but it says: "HLSL Variable to set not found: 'mWVP'. Available variables are:"

This is my shader code:

Code: Select all

float4x4 mWVP;
 
struct v_out
{
    float4 pos : POSITION;
};
 
v_out v_main( float4 pos : POSITION )
{
    v_out Out = (v_out)0;
    Out.pos = mul(pos, mWVP);
 
    return Out;
}
 
float4 p_main() : COLOR
{
    return float4(1.0, 0.5, 0.5, 1.0);
}
and callback with setting up:

Code: Select all

class SkyShader : public video::IShaderConstantSetCallBack
{
private:
    IrrlichtDevice *device;
 
public:
 
    SkyShader( IrrlichtDevice *_device )
    {
        device = _device;
    }
 
    virtual void OnSetConstants(video::IMaterialRendererServices* services,
                    s32 userData)
    {
        video::IVideoDriver* driver = services->getVideoDriver();
 
        core::matrix4 WVP;
        WVP = driver->getTransform(video::ETS_WORLD);
        WVP *= driver->getTransform(video::ETS_VIEW);
        WVP *= driver->getTransform(video::ETS_PROJECTION);
 
        services->setPixelShaderConstant("mWVP", WVP.pointer(), 16);
    }
};
 
//**************************
 
SkyShader *skyShader = new SkyShader(irr->device);
        s32 skyMat = irr->gpu->addHighLevelShaderMaterialFromFiles("data//shaders//sky.hlsl", "v_main", EVST_VS_3_0,
                                                                  "data//shaders//sky.hlsl", "p_main", EPST_PS_3_0,
                                                                  skyShader, EMT_SOLID);
 
        IMesh *skyMesh = irr->scene->getMesh("data//models//skysphere.x");
        scene::ISceneNode* skyNode = irr->scene->addMeshSceneNode(skyMesh);
        skyNode->setPosition(vector3df(0, 0, 0));
        skyNode->setScale(vector3df(1, 1, 1));
        skyNode->setMaterialFlag(EMF_LIGHTING, false);
        skyNode->setMaterialType((video::E_MATERIAL_TYPE)skyMat);
Why doesn't it work?
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Setting shader variables

Post by Mel »

Because it is not a variable for the pixel shader, but for the vertex shader. Set the variables for the part of the shader that is going to use them. setPixel... for the pixel shader variables and setVertex... for the vertex shader ones.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Post Reply