GLSL - setting samplers

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
DeusXL
Posts: 114
Joined: Sun Mar 14, 2004 9:37 am
Contact:

Post by DeusXL »

hybrid wrote:Hmm, shouldn't Uniform1iv perform the same as Uniform1i if count is 1 (and of course passing int or pointer)?! Maybe the missing return false might make some errors harder to recognize, but the basic functionality should be there.
That's what I thought first but I'm not a specialist of shaders in OpenGL :?
Perhaps it is a bug due to my wrapper but as all the rest work I doubt.
Irrlicht .NET complete and Cross Platform Wrapper
The kid on my avatar wrote:A painless lesson is one without any meaning
casty
Posts: 11
Joined: Sun Aug 27, 2006 10:40 am

It doesn't work

Post by casty »

I'm not able to get it to work.

this is my IShaderConstantSetCallBack

Code: Select all

class MyShaderCallBack : public video::IShaderConstantSetCallBack
{
public:

	virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
	{
		for (int i = 0; i < 4; i++) m_samplers[i] = i;
		video::IVideoDriver* driver = services->getVideoDriver();
		services->setPixelShaderConstant("mLightColor", reinterpret_cast<f32*>(&m_color), 4);
		services->setPixelShaderConstant("toon", m_samplers[0], 1);
		services->setPixelShaderConstant("wall", m_samplers[1], 1);
	}
	video::SColorf	m_color;
protected:
	float			m_samplers[4];
};
I used samplers attributes instead of allocating float[]'s eachs frame.


And my fragment program:

Code: Select all

//uniform sampler2D myTexture;
uniform sampler2D toon;
uniform sampler2D wall;
uniform sampler2D pepe;
uniform vec4 mLightColor;
void main(void)
{
   gl_FragColor = texture2D(toon, vec2(gl_TexCoord[0])) + texture2D(wall, vec2(gl_TexCoord[1]));
}
I only see the same texture added over itself (while they are not the same). No matter what sampler2D name use in the texture2D caller, it always returns a sample of texture 0. Even if I call with "pepe" which is not defined in the SetConstants, I receive the texture 0.
The constant mLightColor arrives right to the fragment program.

Code: Select all

	node->setMaterialTexture(0, driver->getTexture("wall.bmp"));
	node->setMaterialTexture(1, driver->getTexture("toon.bmp"));
What could I be missing?
casty
Posts: 11
Joined: Sun Aug 27, 2006 10:40 am

Simpler version.

Post by casty »

Ok here's a simpler version of my problem with irrlicht shaders example.

In main.cpp, test scene node1 initialization, change:

Code: Select all

	node->setMaterialTexture(0,driver->getTexture("../../media/wall.bmp"));
by

Code: Select all

	node->setMaterialTexture(0, driver->getTexture("../../media/water.jpg"));
	node->setMaterialTexture(1, driver->getTexture("../../media/wall.bmp"));
So it shows the water texture by default.
In OnSetConstants:

Code: Select all

float a = 1;
services->setPixelShaderConstant("wall", &a, 1);
(y assume UseHighLevelShaders of course)
And finally, in the fragment program:

Code: Select all

uniform sampler2D myTexture;
uniform sampler2D wall;

...

vec4 e_col = texture2D(wall, vec2(gl_TexCoord[0]));
It keeps showing the /&%$ water!
casty
Posts: 11
Joined: Sun Aug 27, 2006 10:40 am

Post by casty »

Well, mandrav solved my problem in the Advanced Help here:

http://irrlicht.sourceforge.net/phpBB2/ ... 8640#88640

I think this is a very good reason to switch to Uniform1i instead of Uniform1iv (only for samplers). I have changed it to:

Code: Select all

Driver->estGlUniform1iARB(i, (GLint)*floats);
with Spintz's modifications, and now I can call setPixelShaderConstant without a fake float.

I would like to know the reasons for using Uniform1iv, or at least not changing the 2nd parameter of setPixelShaderConstant to a void* to be more fair.

Regards!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The solution with 1i is not 64bit safe, because you would cast to 64bit and back to 32bit during the call. A change to void would be good, this was not updated after the addition of integer calls. Before all calls used floats.
Post Reply