Passing texture to shader

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
tank202
Competition winner
Posts: 40
Joined: Mon Jan 21, 2013 8:34 pm
Location: Lithuania, Kaunas

Passing texture to shader

Post by tank202 »

Hi,

I'm trying to pass some textures to the shader but irrlicht console says my textures doesnt exist in the shader. My other shaders with one texture work normally.

Any ideas what causes this?

Code: Select all

float4x4 WVP : WorldViewProjection;
 
texture source;
texture mapping;
 
float2 move = float2(0, 0);
float stepSize = 0.01;
int samples = 10;
 
sampler2D RSS = sampler_state
{
    texture = <source>;
    addressU = CLAMP;
    addressV = CLAMP;
    minFilter = ANISOTROPIC;
    magFilter = ANISOTROPIC;
};
 
sampler2D MAP = sampler_state
{
    texture = <mapping>;
    addressU = CLAMP;
    addressV = CLAMP;
    minFilter = ANISOTROPIC;
    magFilter = ANISOTROPIC;
};

Code: Select all

    irr::s32 texture = 0;
    services->setPixelShaderConstant("source", &texture, 1);
    irr::s32 map = 1;
    services->setPixelShaderConstant("mapping", &map, 1);
Console :
HLSL Variable to set not found : 'source'. Available variables are:
'MAP' - Sampler
'RSS' - Sampler
'move' - variable(float2)
'samples' - variable(int)
'samples' - Strange, I didn't declare it twice...
'stepSize' - variable(float)
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Passing texture to shader

Post by mongoose7 »

Well, I can tell you that this will happen if the variable is not used in the shader, as the compiler will remove it. But you haven't provided a shader - are you using some kind of scripting like XNA? Your "shader" has no code.
tank202
Competition winner
Posts: 40
Joined: Mon Jan 21, 2013 8:34 pm
Location: Lithuania, Kaunas

Re: Passing texture to shader

Post by tank202 »

Ok I'm posting the full shader :D As I understand I use those texture when initalising samplers so it should exist ...

Code: Select all

float4x4 WVP : WorldViewProjection;
 
texture source;
texture mapping;
 
float2 move = float2(0, 0);
float stepSize = 0.01;
int samples = 10;
 
sampler2D RSS = sampler_state
{
    texture = <source>;
    addressU = CLAMP;
    addressV = CLAMP;
    minFilter = ANISOTROPIC;
    magFilter = ANISOTROPIC;
};
 
sampler2D MAP = sampler_state
{
    texture = <mapping>;
    addressU = CLAMP;
    addressV = CLAMP;
    minFilter = ANISOTROPIC;
    magFilter = ANISOTROPIC;
};
 
float4 MotionBlur(sampler2D renderSource, sampler2D mapper, float4 color, float2 texCoord, float2 move,
                  float stepSize, int samples) : COLOR
{
    for(int i = 0; i < samples; i++)
    {
        float intensity = tex2D(mapper, texCoord).x;
        color += tex2D(renderSource,
        float2(texCoord.x - move.x * stepSize * i * intensity,
        texCoord.y - move.y * stepSize * i * intensity));
    }
    
    return color / (samples + 1);
}
 
struct VOUT
{
    float4 pos : POSITION;
    float2 tex : TEXCOORD;
};
 
VOUT mainVS(float4 pos : POSITION, float2 tex : TEXCOORD)
{
    VOUT vOut;
    
    vOut.pos = mul(pos, WVP);
    vOut.tex = tex;
    
    return vOut;
}
 
float4 mainPS(VOUT vOut) : COLOR
{
    float4 color = float4(1.0, 0.0, 0.0, 1.0);
    color = tex2D(RSS, vOut.tex);
    color = MotionBlur(RSS, MAP, color, vOut.tex, move, stepSize, samples);
    return color;
}
 
technique Main
{
    pass PostProcessing
    {
        VertexShader = compile vs_3_0 mainVS();
        PixelShader = compile ps_3_0 mainPS();
    }
}
 
Post Reply