   Texture format Questions
  I am trying to figure out an OpenGL example and I am used to Directx, so this is very confusing. There does not seem to be good documentation on OpenGL like there is for directx so its no fun! Here are my questions:float dataarray[64*64];// pretend I put some data in here glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, 64, 64, 0, GL_RGBA, GL_FLOAT, dataarray);In the above code, OpenGL converts the 32 bit float dataarray to a 16 bit float format clamped to [0, 1] and stores that into the texture I am creating?glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA16F_ARB, 64, 64, 4, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, dataarray); What exactly does Luminance do? Is this like an Alpha blending for the texture I am generating? In the example I am going over, the Luminance texture is bound as a render target and the output in the pixel shader is vec2 outfrag;// doesnt matter whats inside gl_FragColor = outfrag.xxxy;Now, my question is, what is happening? What is being drawn to the render target? Is the there an alpha blending going on? Again, the documentation sucks.   
Quote:float dataarray[64*64];// pretend I put some data in hereglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, 64, 64, 0, GL_RGBA, GL_FLOAT, dataarray);In the above code, OpenGL converts the 32 bit float dataarray to a 16 bit float format clamped to [0, 1] and stores that into the texture I am creating?That's mostly right, but your array is the wrong size. You're specifying GL_RGBA as your format, so it's expecting 4 floats per pixel (one each for R,G,B,A). You'd need to make your dataarray 64*64*4, where elements 0,1,2,3, are the RGBA for pixel 0,0. These will be internally stored as 16bit floats in gpu memory (instead of the typical 8 bit color).Quote:glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA16F_ARB, 64, 64, 4, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, dataarray);What exactly does Luminance do? Is this like an Alpha blending for the texture I am generating? In the example I am going over, the Luminance texture is bound as a render target and the output in the pixel shader isvec2 outfrag;// doesnt matter whats insidegl_FragColor = outfrag.xxxy;I wouldn't concern yourself too much with this, luminance is just a combination of RGB that represents how bright something is. Id imagine the luminance alpha texture target is just some old legacy target that you don't really need.Sayeth the documentation:Quote:GL_LUMINANCEEach element is a single luminance value. The GL converts it to floating point, then assembles it into an RGBA element by replicating the luminance value three times for red, green, and blue and attaching 1 for alpha. Each component is then multiplied by the signed scale factor GL_c_SCALE, added to the signed bias GL_c_BIAS, and clamped to the range [0,1] (see glPixelTransfer). GL_LUMINANCE_ALPHAEach element is a luminance/alpha pair. The GL converts it to floating point, then assembles it into an RGBA element by replicating the luminance value three times for red, green, and blue. Each component is then multiplied by the signed scale factor GL_c_SCALE, added to the signed bias GL_c_BIAS, and clamped to the range [0,1] (see glPixelTransfer). Basically luminance target is a 3 element target that repeats the luminance value three times for r,g, and b. Luminance alpha is the same but it also stores an alpha value.Luminance itself doesn't have anything to do with alpha. And the Luminance_alpha target just holds some extra alpha information if you want it.Quote:gl_FragColor = outfrag.xxxy;Now, my question is, what is happening? What is being drawn to the render target?It's taking your outfrag 2d vector which is [luminance, alpha] and expanding it into the 4 value fragcolor vector [luminance,luminance,luminance,alpha] (see the swizzle operator). Its writing this vec4 to your texture target.Don't ask me why it duplicates the luminance 3 times, like I said I guess this is just some old legacy holdover from before shaders were common, but I've never really had any interaction with it before.;  Thanks for the reply. I wonder if anyone else can help: What does this luminance stuff do? Can anyone answer what is being stored in the 3d luminance buffer?   ;  Just like RGB is a three channel color where each channel corresponds to the red, green and blue contribution to the final color, luminance is just a single channel gray scale "color". The single luminance value is the shade of gray (0 is black, 1 is white, and gray is everything between).   ;  Thanks Brother Bob, that helps, but is there any blending going on in the following ?glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA16F_ARB, 64, 64, 4, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, dataarray);What exactly does Luminance do? Is this like an Alpha blending for the texture I am generating? In the example I am going over, the Luminance texture is bound as a render target and the output in the pixel shader isvec2 outfrag;// doesnt matter whats insidegl_FragColor = outfrag.xxxy;Now, my question is, what is happening? What is being drawn to the render target? Is the there an alpha blending going on?What do you suppose the gl_fragcolor would be?   I mean, would the result be outfrag.x*outfrag.y? Or would it just be outfrag.x and the rest dropped? Or since the texture is GL_LUMINANCE_ALPHA, would that mean the stored component would be the fourth component, as in outfrag.y?   ;  Luminance doesn't 'do' anything. It's just a texture format with a special name. If you want to do anything with the value, than you have to read the value in a shader and perform kind of computation with it.There's no 'blending' here, this is purely a texture with 4 components. It is totally orthogonal to any alpha testing/blending. glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA16F_ARB, 64, 64, 4, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, dataarray);Just think of this command as filling a texture with some floating point data. There's nothing special going on here, you're just taking some floats in dataarray and making a texture out of it. Its up to the renderer to do something with this information. Quote:vec2 outfrag;// doesnt matter whats insidegl_FragColor = outfrag.xxxy;Now, my question is, what is happening? What is being drawn to the render target? Is the there an alpha blending going on?What do you suppose the gl_fragcolor would be? I mean, would the result be outfrag.x*outfrag.y? Or would it just be outfrag.x and the rest dropped? Or since the texture is GL_LUMINANCE_ALPHA, would that mean the stored component would be the fourth component, as in outfrag.y?As I posted earlier, the luminance texture has 4 components. Each pixel in the luminance texture is represented by a float[4]. Therefore gl_fragcolor is also an array of four floats.This command:gl_FragColor = outfrag.xxxy;Is essentially this:gl_FragColor[0] = outfrag.x;gl_FragColor[1] = outfrag.x;gl_FragColor[2] = outfrag.x;gl_FragColor[3] = outfrag.y;There's no alpha multiplication, and nothing is dropped. It's merely storing four floats into a texture with four components. Lookup the swizzle operatior, that is what is the ".xxxy". Its essentially a way to shuffle the bits of a vector around in hardware for free.   ;  karwosts, thanks for the reply. I think I didn't explain myself as well as I should. I understand the swizzle operator, and the shader. Specifically, glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE_ALPHA16F_ARB, 64, 64, 4, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, dataarray);The GL_LUMINANCE_ALPHA16F_ARB is the internal format of the texture ( the 16 meaning 16 bits of data?), now you said it was a 4 component, so that means each component takes up 4 bits of data? Wouldn't the GL_LUMINANCE_ALPHA suggest a single component?  I am not challenging you, just trying to figure out the strangeness that is OpenGL :P   ;Quote:GL_LUMINANCE_ALPHAEach element is a luminance/alpha pair. The GL converts it to floating point, then assembles it into an RGBA element by replicating the luminance value three times for red, green, and blue. Each component is then multiplied by the signed scale factor GL_c_SCALE, added to the signed bias GL_c_BIAS, and clamped to the range [0,1] (see glPixelTransfer).16f is the per-channel usage, not 16 bits for the whole texture. It means a 16-bit floating point value, (as opposed to 32f which is typical float). Each of the 4 components is a half-float, so the texture requires 64 bits per pixel. Again this does seem strange, but like I said this is probably a legacy texture type. OpenGL is not like directX where there is a new version that breaks compatibility with the old. Every OpenGL program ever written will still run, which is why you may see some strange things from time to time. This is probably around from before GPU even supported textures that weren't 4 channel, so thats why it holds seemingly redundant data. If you just want to store luminance and alpha, you can use a generic 2 channel texture type. But if you want to use this particular texture format, it is stored internally as a 4 component texture.   ;  Blending takes place after a shader, so it is outputting a value that has rgb all the same value (making it gray scale), and then using the alpha channel as alpha. If you have enabled blending outside of this, then yes it will blend that pixel with the current pixel on the screen, otherwise without blending enabled outside of the shader, the alpha is simply not used.   ;  Thanks for the speedy reply karwosts, that makes sense.   