Multi-Texture Blend

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
Max Power
Posts: 98
Joined: Wed Mar 14, 2012 10:09 am

Multi-Texture Blend

Post by Max Power »

I am trying to create a new terrain object with any number of different textures and automatic transition-blending. First I thought I could simply prepare transition-textures, but the number of possible blends would be too high. So now the idea is to use a custom shader to create the blend dynamically with up to 4 different textures per pixel (every pixel being located between 4 terrain-grid-nodes).


The first problem I am having is that I can't seem to pass a sampler-array to my GLSL shader:

uniform sampler2D mTexture[4];// from the fragment-shader, compiles fine

s32 texture[4] = {0,1,2,3};
services->setPixelShaderConstant("mTexture", texture, 4);// from the shader-callback, returns false! using single sampler works, but I want to access samplers directly by index


Problem two would be the 4-texture restriction on irrlicht-materials. Is there a way to have more than that?
Granyte
Posts: 849
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Multi-Texture Blend

Post by Granyte »

in IrrCompileConfig.h

Code: Select all

#define _IRR_MATERIAL_MAX_TEXTURES_ 4

change the value to what ever you need

how ever you are limited to 8 on dx due to a bug in the engine

and to 16 on ogl due to the texture matrix defines i think but i'm not as familiar with OGL
Max Power
Posts: 98
Joined: Wed Mar 14, 2012 10:09 am

Re: Multi-Texture Blend

Post by Max Power »

Thanks! I only wish there was a way without having to recompile the engine :(

Now there's still the question of how I get a sampler-array into my shader.



edit: kind of unrelated, but when I try to compile Irrlicht using the msvc10 sln project file, it tells me d3dx9shader.h (include) is missing.
Granyte
Posts: 849
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Multi-Texture Blend

Post by Granyte »

sampler array are not availible for dx9 they can be emulated or faked using atlasses or other technique

the dx11 driver when completed will have support for those

ogl i cannot help you there




if you try to build with directx you neeed the dxsdk june 2010
kklouzal
Posts: 343
Joined: Sun Mar 28, 2010 8:14 pm
Location: USA - Arizona

Re: Multi-Texture Blend

Post by kklouzal »

Sorry for the off-topic,
Is June 2010 the latest version of DX we can have installed to compile Irrlicht with DX9.0 support? I assume that is 9.0C or..?
Dream Big Or Go Home.
Help Me Help You.
Granyte
Posts: 849
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Multi-Texture Blend

Post by Granyte »

Yes that contain dx9.0c and dx11 it how ever does not contain dx11.1 so the current irrlicht driver will not compile without windows 8 sdk
Max Power
Posts: 98
Joined: Wed Mar 14, 2012 10:09 am

Re: Multi-Texture Blend

Post by Max Power »

I've been busy with other stuff the last couple of days. Now that I want to get back to this I realize it's probably not as simple as I thought...

I was planning to use vertex-data (alpha value probably) as a texture index (0, 1, 2, 3...), but it's no use if I get an interpolated value for these into the pixel shader. And vertex 4 isn't involved at all in the individual polygon.

Any suggestions how I could actually do this? I will probably need one vertex-value for each texture to be interpolated, but creating a blend involving 4 vertices doesn't seem possible :?


edit: I guess I could use tex-coords to let the pixel know what grid-position it is in. Each vertex would get a tex-coord.x equal to its column index and y equal to its row, which wouldn't have any visual effect afaik. Then in the pixel shader I would cut off the interpolated float-part (use as int) to know the terrain-vertex to the upper left. But then I would still need a uniform array [columns][rows] inside the pixel-shader to look up the 4 texture indices from x/y to x+1/y+1... maybe I could pass a sampler instead acting as that array: prepare a texture of scale columns*rows and set one color-value to the tex-index of the corresponding terrain-vertex. Good idea? Hmm... maybe I should do this whenever I need an array inside a shader :mrgreen:


edit2: another question - in the IShaderConstantSetCallBack, is it possible to pass textures to the shaders that are not part of the material? In that case I wouldn't mind how many textures are allowed per material, I would just set them constantly for the terrain-material-shader.
Post Reply