Strange HLSL shader behaviour(passing textures into shader)

Started by
0 comments, last by MJP 10 years, 5 months ago

Hi everyone,

I'm writing this specific motion blur shader where I have to pass 2 textures and some variables into the shader. The probem is that irrlicht engine console shows that it can't find my texture variables in the shader. Instead of texture variables it offers me to set samplers of those textures...

My previous shaders with one texture, pass it without problems, but now even if I pass textures from program to samplers in the shader, I get black screen(no output).

What can cause this?

I'm posting some code as it will describe the problem more clearly.

shader


//Initialising part of the shader
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;
};

class for passing variables


//Shader callback for setting shader variables
class IMotionBlurShaderCallback : public irr::video::IShaderConstantSetCallBack
	{
	public:
		IMotionBlurShaderCallback(irr::video::IVideoDriver* pDriver, float fStepSize = 0.001, int nSamples = 10)
		{
			driver = pDriver;
			move = std::auto_ptr<float>(new float[2]);
			stepSize = fStepSize;
			samples = nSamples;
		}

		virtual void OnSetConstants(irr::video::IMaterialRendererServices* services,
			irr::s32 userData)
		{
			WVP = driver->getTransform(irr::video::ETS_PROJECTION);
			WVP *= driver->getTransform(irr::video::ETS_VIEW);
			WVP *= driver->getTransform(irr::video::ETS_WORLD);
			services->setVertexShaderConstant("WVP", WVP.pointer(), 16);

			irr::s32 texture = 0;
			services->setPixelShaderConstant("source", &texture, 1);
			irr::s32 map = 1;
			services->setPixelShaderConstant("mapping", &map, 1);

			services->setPixelShaderConstant("move", move.get(), 2);
			services->setPixelShaderConstant("stepSize", &stepSize, 1);
			services->setPixelShaderConstant("samples", &samples, 1);
		}

		irr::video::IVideoDriver* driver;
		std::auto_ptr<float> move;
		irr::core::matrix4 WVP;
		float stepSize;
		int samples;
	};
Advertisement

Does irrlicht use the effects framework? I'm guessing it doesn't, which is why your shader code isn't working. The "texture" type is specific to the effects framework, and doesn't work with normal HLSL shaders. Also everything in your "sampler_state" block is also specific to effects, and can't be used. Just change it be like this:

//Initialising part of the shader
float4x4 WVP : WorldViewProjection;

float2 move = float2(0, 0);
float stepSize = 0.01;
int samples = 10;

sampler2D RSS;
sampler2D MAP;

Then bind your textures to "RSS" and "MAP" in your C++ code.

This topic is closed to new replies.

Advertisement