How expensive are texture lookups in a fragment shader?

I’m creating a terrain shader that blends between several different grass textures, rock textures, and dirt textures, along with height masks for each one. I’ve been organizing the code such that for any given pixel it’s only making a handful of texture lookup calls that it needs rather than doing a lookup for every texture and doing a mass blending. But I’m wondering, is there any value in this optimization? Can a shader make an arbitrary number of texture lookups without any performance hit? Would something like 16 lookups not even be noticeable in terms of performance even on a lower end gpu? Any insight you guys have would be much appreciated!

1 Like

I don’t think I’d be able to guess what the limit is — it’s certainly hardware dependent, and would also depend on lookup coordinates for cache efficiency — but texture lookups can indeed be expensive. If you can’t measure that cost when profiling then it’s probably too early to worry about it, but here are a few links that discuss (but don’t really answer) the question:


If your FPS is 60 and without lags, then it’s not expensive. Big textures expensive.
Textures with “RGBA” format 4 channel (default in three.js)
128px x 128px=0.085mb in video memory and ram
Textures with format “luminance” in 4 times smaller, because 1 channel.
RGBA 8192x8192=356.48 mb Luminance 8192x8192=89.12 mb

var loader = new THREE.TextureLoader();
var diffuseMap = loader.load( ‘…/examples/textures/abc.png’ );