Expanding 4 pixels components into new pixels

Started by
3 comments, last by Ashaman73 13 years, 6 months ago
Hi Everyone,

I've got a problem I hoped would be simple..

I've got a GL texture (that is storage for an FBO and exists only in VRAM) that contains 4 alpha values, packed in RGBA components. I need to expand that out to another fbo target so that each component in turn gets converted into a new pixel with 0,0,0,x. This means the final fbo will be 4 times wider horizontally than the input. Simply scaling it obviously won't work because i need the exact alpha value from the original texture.

I'd like to do this without a pixel shader (if possible) -- does anyone have any suggestions of how to do it efficiently, with or without a shader.

Thanks alot!
Advertisement
Is this purely a technique to save vram? I'm certain you couldn't achieve the unpack you're asking for without a pixel shader, and even with one I'm having a hard time thinking of an exact solution that doesn't have floating point rounding issues that require a lot of extra instructions to address.

If you are trying to save vram, couldn't you just convert your image from a 4 channel to a 1 channel image of the correct resolution? It should require the same amount of memory.

Or can you explain more what is going on? Does your packed texture dynamically change? Is it static? Why is it 1/4 the width? If I understood better your situation I could maybe have a better idea.

[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Of course - sorry for being so brief.

I'm implementing drop shadow in a 2D application, and I'm only blurring the alpha component of four pixels at once to save bandwidth; it's a multiple pass shader that is very expensive, so the 4 at once really saves time.
A shader can only output one pixel. (MRT makes this an exception but that's sooo not a solution for your current problem)

So you must read the values from your source as you step across something that's the final size. Basically, you use your packed format for a "read" operation later on, as opposed to using it for a "write" operation.

------------------------------Great Little War Game
When you render a fullscreen quadm tehn this could work (pseudo-glsl):
// tex_coord, texture width = 4*source texture widthvarying vec2 tex_coord;// remap texture coord to source texturevec2 new_tex_coord = tex_coord * vec2(4.0,1.0);int index = int(floor(new_tex_coord.x));new_tex_coord.x = fract(tmp_tex_coord);// get alpha valuesvec4 alpha_tex_values = tex2d(texture, new_tex_coord);const vec4 filters = {vec4(0,0,0,1),vec4(0,0,1,0),vec4(0,1,0,0),vec4(1,0,0,0)};// calculate final alphafloat final_alpha = dot(filters[index],alpha_tex_values);

This topic is closed to new replies.

Advertisement