Jump to content
  • Advertisement
Sign in to follow this  

Texture Lookup Cost?

This topic is 2578 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

[font="arial, verdana, tahoma, sans-serif"]I've been working on Terrain rendering for a bit and I wanted to ask my professor today a few questions so I took the project in to show to him. Unfortunately I hadn't run it on my laptop before and much to my dismay the frame rate had dropped from 90 - 100 on my desktop to about 7 on my laptop when rendering similar scenes. For reference my desktop has a Radeon 5970 and my laptop has a Radeon HD 3400 (mobile card). Clearly there is a difference there in horsepower but I didn't think the difference would be so drastic when rendering a relatively simple scene.

After tinkering with a few things it turns out the largest performance killer is my terrain fragment shader. These are my terrain shaders, it's nothing complicated:[/font]


attribute vec3 in_Vertex;
attribute vec2 in_TexCoord0;
attribute vec4 in_BlendWeights1;
attribute vec4 in_BlendWeights2;

varying vec3 var_Vertex;
varying vec2 var_TexCoord0;
varying vec4 var_BlendWeights1;
varying vec4 var_BlendWeights2;

void main() {
var_Vertex = in_Vertex;
var_TexCoord0 = in_TexCoord0;
var_BlendWeights1 = in_BlendWeights1;
var_BlendWeights2 = in_BlendWeights2;

gl_Position = gl_ModelViewProjectionMatrix * vec4(in_Vertex, 1.0f);


varying vec3 var_Vertex;
varying vec2 var_TexCoord0;
varying vec4 var_BlendWeights1;
varying vec4 var_BlendWeights2;

// up to 8 terrain textures
uniform sampler2D texture0;
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;
uniform sampler2D texture4;
uniform sampler2D texture5;
uniform sampler2D texture6;
uniform sampler2D texture7;

void main() {
gl_FragColor = (texture2D(texture0, var_TexCoord0.st) * var_BlendWeights1.r) +
(texture2D(texture1, var_TexCoord0.st) * var_BlendWeights1.g) +
(texture2D(texture2, var_TexCoord0.st) * var_BlendWeights1.b) +
(texture2D(texture3, var_TexCoord0.st) * var_BlendWeights1.a) +
(texture2D(texture4, var_TexCoord0.st) * var_BlendWeights2.r) +
(texture2D(texture5, var_TexCoord0.st) * var_BlendWeights2.g) +
(texture2D(texture6, var_TexCoord0.st) * var_BlendWeights2.b) +
(texture2D(texture7, var_TexCoord0.st) * var_BlendWeights2.a);

The Terrain generator calculates blending weights for each texture per-vertex and the fragment shader simply applies those weights, as you can see. Is this a poor approach? Perhaps the actual performance answers that question for me. It looks like on my laptop I lose ~20 fps per texture2D call and ~30 on my desktop. Is it just way too many lookups per fragment? I'm trying to figure out if I should be totally reworking the Terrain engine or if it's still salvageable.


Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!