Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Strange HLSL shader behaviour(passing textures into shader)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Tank202   Members   -  Reputation: 182

Like
0Likes
Like

Posted 30 October 2013 - 02:55 AM

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;
	};

Attached Thumbnails

  • Screen.png


Sponsor:

#2 MJP   Moderators   -  Reputation: 12649

Like
0Likes
Like

Posted 30 October 2013 - 03:13 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS