• Advertisement
Sign in to follow this  

glsl texture lookup performance (multitexturing)

This topic is 3000 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
macbook GMA 950
mac os 10.4.11
GL_VERSION: 1.2 APPLE-1.4.58

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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



Share this post


Link to post
Share on other sites
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 ??

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
because i dont want to repeat over the hole texture, only a quater.
OK but this is a reason to forget the solution with 4 textures in one.

Share this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
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.


thanxs this explains a lot !


Share this post


Link to post
Share on other sites
Quote:
Original post by Erik Rufelt
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.


how i bring the values from the map texture to the vertex color ?
in the vertex shader ?

i will also try to bring the mapping values to the alpha path of the subtextures because at the moment there are unused. with this i also can save a lookup but i have to split up the mapping texture for the terrain cells because the mapping texture normally is larger than the subtextures.

Share this post


Link to post
Share on other sites
Quote:
Original post by mede
how i bring the values from the map texture to the vertex color ?
in the vertex shader ?


No you pre-calculate it and store it in your vertex array or VBO (or glColor4f).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement