multitexture and GLSL samplers: bug or ignorance?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
casty
Posts: 11
Joined: Sun Aug 27, 2006 10:40 am

multitexture and GLSL samplers: bug or ignorance?

Post by casty »

Hi,

Yesterday I posted this in the Bugs report, but I'm maybe missing something, because no one else complains about that.
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=12651

I'm just trying to access two diferent textures in a pixel program, here is a copy of the post.
----------------------------
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, add:

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!
-----------------------

Could I be missing anything ??

PS: irrlicht 1.1 + VS2005
mandrav
Posts: 117
Joined: Sat Aug 27, 2005 8:29 pm
Contact:

Post by mandrav »

Try this:

Code: Select all

int a = 1;
services->setPixelShaderConstant("wall", (const float*)&a, 1);
Notice that "a" is an integer, not a float. That's because in the driver (at least the OpenGL that I know) there is an implicit cast to integer for the case of sampler2D uniforms.
You can imagine that casting a (float*) to (int*) won't give you what you would expect ;).
casty
Posts: 11
Joined: Sun Aug 27, 2006 10:40 am

Post by casty »

It works!! Thanks!

I think they should use extGlUniform1iARB instead extGlUniform1ivARB, to avoid such a counterintuitive format.
Cosmin
Posts: 3
Joined: Tue May 31, 2011 11:54 am
Location: Romania

Post by Cosmin »

Hello it seams that i have the same problem but i do not understand why if i use the dx shader works just fine(i use 3 textures: 2 texture to blend by vertex color values and 1 as normal map for the second texture)
And this is the only code i use for multitexture(no IShaderConstantSetCallBack)

Code: Select all

stringc shaderPath = curentPath + "\\shaders\\OGL\\OGLalphablend.txt";//DX\\alphablendPSH.txt";
		video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();
		s32 newMaterialType1 = 0;
		if(gpu)
		{
			newMaterialType1 = gpu->addHighLevelShaderMaterialFromFiles(vShaderPath,"",video::EVST_VS_1_1,shaderPath,"main",video::EPST_PS_2_0);
		}
		Model->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType1);
........................

for(int i = 0;i<_IRR_MATERIAL_MAX_TEXTURES_;i++)
		{
			index = materialTextures.findFirstChar(";",1);
			int textureId = 0;
			if(index==-1)
				textureId = atoi(materialTextures.subString(0,materialTextures.size()).c_str());
			else
			{
				textureId = atoi(materialTextures.subString(0,index).c_str());
				materialTextures = materialTextures.subString(index+1,materialTextures.size());
			}
			stringc tex = curentPath + (stringc)"\\media\\textures\\" + getTexture(textureId).Name();
			Model->getMaterial(matNumber).setTexture(i,Device->getVideoDriver()->getTexture( tex.c_str() ));// applying the texture
			if(index==-1)// no more textures for this material
				break;
		}
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

I dont know about the dx issue, but..
glUniform1i and
glUniform1iv are the only two functions
that may be used to load uniform variables defined as sampler
types. Loading samplers with any other function will result in a
GL_INVALID_OPERATION error.
http://www.opengl.org/sdk/docs/man/xhtml/glUniform.xml
If you don't have anything nice to say, don't say anything at all.
Cosmin
Posts: 3
Joined: Tue May 31, 2011 11:54 am
Location: Romania

Post by Cosmin »

So from what you are saying i really need to implement a IShaderConstantSetCallBack or i am wrong?? If so... pls tell me what i need to do exactly

Tnx
Post Reply