[closed] shader problem with multiple texture

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
magoon
Posts: 7
Joined: Wed Mar 16, 2016 9:58 pm

[closed] shader problem with multiple texture

Post by magoon »

hello,
i´ve googled a lot and have read all the threads about this. But nothing works for me, so here´s my problem:

I cannot access a second, third.. texture within the shader. Only the first texture is being used :(

What I´ve got:
Shader Class

Code: Select all

 
class ShaderMergeResults : public scene::ISceneNode
{
 
public:
   video::SMaterial Material;
...
 
  virtual void OnSetConstants(...)
  {
   ....
 
    int texture1 = 0;
    services->setPixelShaderConstant("tex1",(const float*)&texture1,1);
    int texture2 = 1;
    services->setPixelShaderConstant("tex2",(const float*)&texture2,1);
    int texture3 = 2;
    services->setPixelShaderConstant("tex3",(const float*)&texture3,1);
  }
 
  void initiate(...)
  {
      ...
      Material.setTexture(0, rendertarget_depth);
      Material.setTexture(1, rendertarget_blur);
      Material.setTexture(2, rendertarget_normal);
 
      Material.MaterialType=(E_MATERIAL_TYPE)gpu->addHighLevelShaderMaterialFromFiles
        (
               vsFileName, "main", video::EVST_VS_1_1,
               psFileName, "main", video::EPST_PS_1_1,
               callback, (video::EMT_SOLID)
        );
  }
   virtual void render()
   {
      u16 indices[] = {0,1,2,3,4,5};
      video::IVideoDriver* driver = SceneManager->getVideoDriver();
 
      driver->setMaterial(Material);
      driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
      driver->drawIndexedTriangleList(&Vertices[0], 6, &indices[0], 2);
   }
 
Fragment Shader:

Code: Select all

 
uniform sampler2D tex1;
uniform sampler2D tex2;
uniform sampler2D tex3;
 
varying vec2 vTexCoord;
 
void main (void)
{
  gl_FragColor = texture2D(tex2, vTexCoord);
}
 
Thank you in advance!!!

BR,
magoon
Last edited by magoon on Thu Mar 17, 2016 9:03 am, edited 1 time in total.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: shader problem with multiple texture

Post by mongoose7 »

Change

Code: Select all

(const float*)&texture1
to

Code: Select all

&texture1
Samplers have to be integers, not floats!
magoon
Posts: 7
Joined: Wed Mar 16, 2016 9:58 pm

Re: shader problem with multiple texture

Post by magoon »

Thanks! That worked! :)
Post Reply