HLSL texture indexing in Irrlicht

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!
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: HLSL texture indexing in Irrlicht

Post by robmar »

thats what I thought, and there is no need to declare textures then to fade a multitextured object, right?

but in the fader sample on irrlicht, one texture is declared... and someone said it onkly worked with single texture objects..
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: HLSL texture indexing in Irrlicht

Post by hybrid »

Are you sure that you use the words mesh and meshbuffer here correctly? If you have many materials, you also have the same number of meshbuffers. A shader is applied to a single meshbuffer, referencing the textures defined in that material and for that meshbuffer. You won't access textures which are declared in other materials, even if that's for the same mesh. But of course you can access textures 2 to n also, if they exist in the current shader material. Maybe check example 11 as well, even if it's not HLSL but ASM shaders.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: HLSL texture indexing in Irrlicht

Post by robmar »

Thanks for clarifying that. Shaders can´t access textures of other mesh buffers, so then a multi-textured and multi meshbuffer object can have a simple shader to handle alpha shading simply by multiplying an externally fed float alpha to all the colors, right?

And by applying that shader to each material in the object, during render, all the objects textures get "alphered".

If that´s correct, the only complication is fading the simulated reflective set materials.

To do that the shader would have to perform the same process as the original irrlicht shader, then apply the alpha multiplication...
silence
Posts: 6
Joined: Fri Dec 28, 2012 4:14 pm
Location: United Kingdom

Re: HLSL texture indexing in Irrlicht

Post by silence »

I noticed this when switching from GLSL to HLSL.. as it turns out, HLSL has a much simpler way of setting samplers..

Code: Select all

 
                       sampler2D baseMap : register(s0);
                       sampler2D lightMap : register(s1);
                       sampler2D bumpMap : register(s2);
 
This means, while the GLSL callback has to send uniforms (0,1,2) - HLSL can just bind a sampler to the existing sampler registers inside the shader, which is more efficient. These registers correspond with the existing texture layers in the material.

So, don't bother sending uniforms for your samplers, or messing around with material callbacks, just use registers s0,s1,s2... etc..

Then you can use the samplers for texel lookups later on thusly..

Code: Select all

 
float4  fvBaseColor      = tex2D( baseMap, IN.Texcoord.xy );
 
..and so on. The result is the same, except your callbacks are not involved in any way.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: HLSL texture indexing in Irrlicht

Post by robmar »

thanks for that, so is there a way to get the number of textures that exist in the material within the shader, or do we have to pass in the count?
Post Reply