How to pass a texture to a shader?

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
Joe Red
Posts: 9
Joined: Tue Oct 31, 2006 11:10 am

How to pass a texture to a shader?

Post by Joe Red »

So, I would like to use a shader with irrlicht with the following line:

texture BaseTex;

How can I pass a texture to the shader? The setVertexShaderConstant function is just for matrices, and vectors, isn't it? My question is probably newbish, but I cant find it out. Please help!
miha
Posts: 32
Joined: Tue Jun 26, 2007 9:27 pm
Location: Serbia

Re: How to pass a texture to a shader?

Post by miha »

Joe Red wrote:So, I would like to use a shader with irrlicht with the following line:

texture BaseTex;

How can I pass a texture to the shader? The setVertexShaderConstant function is just for matrices, and vectors, isn't it? My question is probably newbish, but I cant find it out. Please help!
If you want to use shaders,you can set them up as the material type,
when you set the material texture...Like this:

node.SetMaterialTexture(0, BaseTex);
node.SetMaterialType(MyShader);

if you need more info about defining the shader:
http://irrlichtnetcp.sourceforge.net/ph ... hlight=cel
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Joe red in HLSL you do this:

sampler2D myTex : register(s0) ; // (Before the pixel shader function)

This will set meTex to the first texture loaded in your model in irrlicht.
You can do s1, s2 and s3 for the second, third and fourth textures.

Cheers
Kalda
Posts: 47
Joined: Wed Aug 23, 2006 1:38 pm
Location: Prostejov, Czech Republic
Contact:

Post by Kalda »

Joe red in HLSL you do this:

sampler2D myTex : register(s0) ; // (Before the pixel shader function)

This will set meTex to the first texture loaded in your model in irrlicht.
You can do s1, s2 and s3 for the second, third and fourth textures.

Cheers
And how do this in GLSL?
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Kalda wrote:
Joe red in HLSL you do this:

sampler2D myTex : register(s0) ; // (Before the pixel shader function)

This will set meTex to the first texture loaded in your model in irrlicht.
You can do s1, s2 and s3 for the second, third and fourth textures.

Cheers
And how do this in GLSL?
Its a little more complicated, in the shader you do:

uniform sampler2D myTex;

and when you pass a constant thats the name of the texture (myTex) and is the number of the texture on the model (so 0, 1, 2 or 3).
Post Reply