PDA

View Full Version : How can I lower my program size if all of my assets are one chanell?



CalebK
09-02-2016, 03:03 PM
All of the assets in my game are white gradients. Essentially they could easily be stored inside of an alpha channel only texture.

How can I use this to speed up rendering/texturing and the size of my program?

Lower Size:
I know of programs that can find the optimal format for an image maybe lowering its channels somehow. Is this the only way?

Texturing Faster:
Would texture2D calls be faster if I just put texture2D(coolTex, uv).x? Or would that be ultimately slower or cause code branching of some sort?

Hermannicus
09-04-2016, 08:46 AM
I didn't test it, but I would guess that the easiest way is to just create a texture with a 8-bit format.

One of those: GL_R8UI, GL_R8I, GL_R8, GL_R8_SNORM

https://www.opengl.org/wiki/Texture_Storage#View_texture_aliases

GClements
09-04-2016, 11:39 AM
All of the assets in my game are white gradients. Essentially they could easily be stored inside of an alpha channel only texture.
Alpha-channel textures are deprecated in modern OpenGL. Use a GL_RED texture instead.

You can obtain behaviour equivalent to a legacy GL_LUMINANCE texture by using glTexParameter() with GL_TEXTURE_SWIZZLE_* so that green and blue are both taken from the red channel. This may be useful if you need to use such textures with a shader which is expecting RGB. But it's better if you can write the shader to use a single float rather than a vec3 whose components will always be identical.


Would texture2D calls be faster if I just put texture2D(coolTex, uv).x? Or would that be ultimately slower or cause code branching of some sort?
Reading one component from a three-component texture won't be any faster than reading all three components. Using a single-component texture will be faster as it will reduce the memory bandwidth. Subsequent processing may be faster if you're using a single float rather than a vec3.