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!
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:
- How many texture lookups is too many? - Graphics and GPU Programming - GameDev.net
- performance - Why is accessing textures much slower when calculating the texture coordinate in the fragment shader? - Computer Graphics Stack Exchange
- performance - How expensive is fetching a texture in GLSL? - Stack Overflow
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
256x256=0.348mb
512x512=1.396mb
1024x1024=5.56mb
2048x2048=20.96mb
4096x4096=88.08mb
8192x8192=356.48mb
16384x16384=1.4280mb
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’ );
diffuseMap.format=THREE.LuminanceFormat;
diffuseMap.type=THREE.UnsignedByteType;
diffuseMap.needsUpdate=true;