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

HLSL texture indexing in Irrlicht

Post by robmar »

In DX9 it is necessary, so says an introduction, to set the textures used by the shader.

I.e.

m_pEffect->SetTexture("tVolumeNoise", m_pVolumeNoiseTexture);

I can´t find any reference to setting texture refs in Irrlicht, and wonder if someone could clarify, especially when many textures are used.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: HLSL texture indexing in Irrlicht

Post by Nadro »

As I know for HLSL You don't need any special binding call to enable texture in a shader, just use semantic.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: HLSL texture indexing in Irrlicht

Post by robmar »

semantic, you mean first declared texture is from material 0...?

this must be handled soemwhere in the irrlicht code then?
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: HLSL texture indexing in Irrlicht

Post by Nadro »

Yes, this is handle in CD3D9Driver::setActiveTexture at line 750.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: HLSL texture indexing in Irrlicht

Post by robmar »

thanks, I´ll take a look!
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: HLSL texture indexing in Irrlicht

Post by Mel »

More exactly, each texture in the material is placed on the corresponding sampler stage, which means that material texture 0 will be on sampler stage 0, material texture 1 will go to the sampler stage 1, and so on.

You don't have to do anything at all, But, what you have to keep in mind also is that when you set material textures 0 and 3, the samplers 1 and 2 won't be set and if you have 4 samplers declared in your shader, the only samplers used will be 0 and 1, unless you specify the register you want each sampler2D to read from. (sampler2D texture:register(0) for register 0, and so on);
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: HLSL texture indexing in Irrlicht

Post by robmar »

Okay, so any scene node textures not set will cause a displacement in indexing in the shader. Good to know.

On a side issue, I have a strange shader thing going on, which I have yet to explain. Maybe you might know what it might be...

Basically, I have a reflective plane surface node, when used with the GLSL shader it works fine all the time, but with the HLSL shader, which looks pretty standard, the texture image gets tiled twice across the plane (4 images).

However, if I drop any new node into the scene (where it will be visible) using the standard example Gooch shader, then the plane node image stops being tiled and works perfectly!

Why should the presence of the Gooch HLSL shader affect the node using the reflective shader? They don´t share the same texture, or any varaibles... its weird!
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: HLSL texture indexing in Irrlicht

Post by robmar »

@Nadro: I sorta meant the code which sets up the textures for the HLSL shaders through DX9.

I´d like to see how Irrlicht does it so that I can try to "extrapolate" the best method for handling the processing of multiple textures (like 32 or even 256 of them) in the HLSL shader code.

The aim is to develop a fader that works with nodes up to 256 textures... if only there was a hardware feature in GPUs to set the alpha for a whole mesh... without having to set thousands of vertex alphas using the CPU
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: HLSL texture indexing in Irrlicht

Post by Granyte »

to have 256 texture in dx9 you would need to make your irrlicht capable of handeling 16 texture ( some transformation matrix are missing) then 16 is the absolute maximum possible with dx9 so you would need to make each texture you bind an atlass that contai 16 texture
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: HLSL texture indexing in Irrlicht

Post by robmar »

can´t use atlas textures because user can select any texture from a library... guess I could post process the images into mosaics... sort of messy though.

so it must be possible to fade a 3D object rapidly, and I mean in hardware!! not by processing thousands of vertex alphas...

all that GPU technology ... there must be a way...
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: HLSL texture indexing in Irrlicht

Post by Nadro »

So please forget about 256 textures on DX9 hardware (even 3D textures will not help, because filtering for them works differently than for 2D textures). For 256 textures You need texture arrays. If You need the same alpha value for a whole mesh just use shader uniform.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: HLSL texture indexing in Irrlicht

Post by robmar »

I have an externally varying alpha level 0 - 255 to be applied to all meshes of an object, hence all materials.

I just need a shader to process all the materials, that does the alpha multiply, using the external variable.

Can I access the texture from the material... bfff, think I´m getting confused!!

Why can´t the shader just access the texture for the current material being rendered?
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: HLSL texture indexing in Irrlicht

Post by Nadro »

robmar wrote:Why can´t the shader just access the texture for the current material being rendered?
It exactly works in this way.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: HLSL texture indexing in Irrlicht

Post by robmar »

I think we have a language issue, and I don´t mean c++! :)

A shader will render using the texture passed. If that is one texture, that will be the texture of material 1. Right?

If the object has many materials, many sub meshes, and I set the shader to each material, will the shader reference the texture from the 1st material, or will it be the texture of each material... which sort of seems to break the texture indexing mentioned above...
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: HLSL texture indexing in Irrlicht

Post by Mel »

the textures and shaders are bound to the materials. so, the shaders will reference the textures from the material they are asigned to.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Post Reply