Skip to main content
GameDev.net gamedev.net
🔒 Locked

Find average pixel color in a texture?

Started by JackOfAllTrades Aug 24, 2011 at 1:34 AM 2 replies 2.6k views
Original Post
JackOfAllTrades
JackOfAllTrades
Basically I want to add together all of the pixels in a texture and divide them by the number of pixels to get the average color. Two reasons I want to do this. First I want to do this for HDR lighting effects. Second I want to do this to check if a texture is simi transparent so I can render it after I render all opaque objects. I assume this would be done in a shader but I'm not sure how to write it?
21st Century Moose
21st Century Moose
If the texture is mipmapped you can get the average colour by sampling the last miplevel.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
dpadam450
dpadam450
I think you have to bind that to your shader. You can set the maximum mip-map level on a texture so that it only binds specific mip levels. glReadPixels if you read the definition it will only copy stuff from the framebuffer, not from a texture.
[color=#1C2837][size=2]

[color=#1C2837][size=2]

[color=#1C2837][size=2]Second I want to do this to check if a texture is simi transparent so I can render it after I render all opaque objects.
[color=#1C2837][size=2][/quote]
[color=#1C2837][size=2]

[color=#1C2837][size=2]Huh? What I do is for every mesh it has a texture on it. When calling glTexImage2D(), you specify if the texture has alpha or not, so just remember that throughout your application. All meshes with an alpha texture, I know to draw last.
NBA2K, Madden, Maneater, Killing Floor, Sims 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.