[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Public WebGL] Retrieving number of texture channels
On Feb 22, 2010, at 1:01 PM, Kenneth Russell wrote:
> On Mon, Feb 22, 2010 at 11:50 AM, Johannes Behr
> <firstname.lastname@example.org> wrote:
>>>> is there already a possibility to retrieve the number of present texture
>>>> channels (intensity, luminance-alpha, rgb or rgba texture) in WebGL?
>>>> Because according to the X3D lighting model a material's diffuse color
>>>> modulates the color of the texture in case of a one or two channel texture,
>>>> which we need to know for implementing this correctly in X3DOM. If instead
>>>> the texture has three or four channels (the typical case), the color of the
>>>> texture is used as the diffuse color.
>>>> You can find an example demonstrating this issue here:
>>> Unfortunately OpenGL ES seems to have dropped the
>>> glGetTexLevelParameter query, which is needed to query the texture's
>>> internal format, so WebGL doesn't currently contain it.
>>> We could probably emulate this call in WebGL implementations on top of
>>> OpenGL ES by tracking the internal format used when the texture was
>>> uploaded. In the short term, doing so in your library would be your
>>> best workaround.
>> But how should we track it in x3dom? AFAIK is there now method
>> to ask a HTML image for some internal type or number of channels.
> How are you uploading the image data to WebGL? At least in the WebKit
> WebGL implementation, currently all HTMLImages are uploaded as either
> RGB or RGBA textures, depending on whether they have an alpha channel.
> For example, we do not special case grayscale images as luminance
> textures, and I don't know whether any of the supported image formats
> handle two-channel images.
Ah, so then this might be the problem. We should be able to load 1 or 2 channel PNG images in HTMLElement and get those into GL using texImage2D. If that's not possible due to the specification of HTMLImageElement then we should add a 'format' param to texImge2D and define rules for converting RGB or RGBA images to ALPHA, LUMINANCE or LUMINANCE_ALPHA.
Now that I'm thinking about it, maybe we need a format param anyway, unless there's a way to distinguish an alpha-only PNG image from a single channel color PNG image.
> If you want better control over which channels you want in the
> texture, you will currently need to upload the texture data as a
> WebGLUnsignedByteArray, in which case you have explicit control over
> the internal format.
I think the most we need (in spec and implementation) is to be able to get a 1 channel PNG image in as ALPHA or LUMINANCE and a 2 channel PNG image in as ALPHA_LUMINANCE. I don't think we need to (for instance) pick out the red channel of an image and use that as LUMINANCE or anything. It could be as easy as:
1) For ALPHA, if image is RGBA, use the alpha channel. If it is RGB, convert to monochrome and use that as alpha.
2) For LUMINANCE, convert RGB channels to monochrome and use that as luminance.
3) For LUMINANCE_ALPHA, image must be RGBA. Use the alpha channel for alpha, convert RGB to monochrome and use that as luminance.
You are currently subscribe to email@example.com.
To unsubscribe, send an email to firstname.lastname@example.org with
the following command in the body of your email: