glsl texture lookup performance (multitexturing)

Started by
12 comments, last by Erik Rufelt 14 years, 5 months ago
i actualy trying to create a shader for terrain rendering for this i use a multitexture technik... the idee is to have a mapping texture where the 4 paths (RGBA) defines the composit of a fragment out of 4 different textures. my fist adoption was to take the 4 textures together to one which has double the size. where the 4 textures are in the 4 quaters of the bigger on. this is my code: ----------------------------------------------------------- vec3 color; vec2 coord = gl_TexCoord[0].st; vec4 map = texture2D(mapTex, coord); coord = coord / 2.0; color += texture2D(tex, coord + vec2(0.0, 0.0)).xyz * map.r; color += texture2D(tex, coord + vec2(0.5, 0.0)).xyz * map.g; color += texture2D(tex, coord + vec2(0.0, 0.5)).xyz * map.b; color += texture2D(tex, coord + vec2(0.5, 0.5)).xyz * map.a; ----------------------------------------------------------- but the lookup calls lead to a big drop of the performance if i outcomment the 3 last lines and use only one texture i get 180fps with 2 textures 150 fps with 3 texture 120 fps. and if i use all 4 textures the performance drops to 2 FPS. why is there a big drop between 3 and 4 lookups on the same texture ? are there any idees to make this faster ? thanks [Edited by - mede on December 2, 2009 2:18:25 PM]
Advertisement
OS, GPU, Driver, GL/GLSL version?
macbook GMA 950
mac os 10.4.11
GL_VERSION: 1.2 APPLE-1.4.58
is the lookup depended on the size of texture ?
would it help to use smaller texture (mipmapping) for farer terrain cells ?

if the texture is saved to the graphic card the lookup is more or less only a memory acces or not ?
Yes it can depend on the texture size. Definitely try with smaller textures, and try keeping 4 different textures instead of one large and see if it makes a difference. I'm not sure on the specifics, but that's not a very fast graphics card, and only supports shader model 2.0, which has quite a few restrictions. It might also be better to simply use the vertex color for the blending, if that is enough. Keep the first texture alpha in R, second in G, etc. This will save you a texture lookup in the map texture.
Quote:Original post by mede
GMA 950
This particular graphics card (and to a lesser extent, the newer GMA X3100) takes a huge hit from enabling multi-texturing. There really isn't anyway round this (apart from buying a new laptop), so you either have to live with the performance hit, or reduce to one texture sample per fragment.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

for me it is not undersandable why the performance drops drasticaly when i do several lookups on the same texture... i tryed with a small texture

vec4 tempTexture = texture2D(multiTexMap, coord);
diffuseMaterial = texture2D(multiTex1, coord).xyz * tempTexture.x;
diffuseMaterial += texture2D(multiTex1, coord).xyz * tempTexture.y;
//diffuseMaterial += texture2D(multiTex1, coord).xyz * tempTexture.z;

if the last line is outcommented i get 100fps with this line it drops to 1fps...
the result is the same when i use 3 different texures.

jep i will try the same on my faster desktop. think i will go back to the solution with 4 textures in a bigger one, so i can do in a additional texture also normalmapping for the 4 texture. otherwise i will use 9 texture units for 4 different subtextures



i have also a problem with scaling
when i scale the textures this ends in gaps between texture repetition.

coord = mod(coord * 16, 1) / 0.5;
color += texture2D(tex, coord + vec2(0.0, 0.0)).xyz * map.r;
color += texture2D(tex, coord + vec2(0.5, 0.0)).xyz * map.g;
color += texture2D(tex, coord + vec2(0.0, 0.5)).xyz * map.b;
color += texture2D(tex, coord + vec2(0.5, 0.5)).xyz * map.a;

think this must be because of rounding in the mod function ??
Quote:Original post by mede
for me it is not undersandable why the performance drops drasticaly when i do several lookups on the same texture...
Because each pixel-shader unit in that GPU can only sample once every N clock-cycles (I don't have exact numbers to hand). This means that as soon as you request a second sample, you have to wait an entire extra N cycles before continuing.

In other words, the bottleneck is the number of samples - not the number of unique textures. You should see exactly the same performance if you sample from 4 different textures, as if you sample 4 times from the same texture.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Quote:Original post by mede
i have also a problem with scaling
when i scale the textures this ends in gaps between texture repetition.

coord = mod(coord * 16, 1) / 0.5;
color += texture2D(tex, coord + vec2(0.0, 0.0)).xyz * map.r;
color += texture2D(tex, coord + vec2(0.5, 0.0)).xyz * map.g;
color += texture2D(tex, coord + vec2(0.0, 0.5)).xyz * map.b;
color += texture2D(tex, coord + vec2(0.5, 0.5)).xyz * map.a;

think this must be because of rounding in the mod function ??
Why not just set the texture filtering wrap/clamp mode to GL_REPEAT?

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement