WebGLSamples / WebGL2Samples

Short and easy to understand samples demonstrating WebGL 2 features
Other
1.01k stars 143 forks source link

texture 3d not working [Feb 29, 16] #97

Closed trungtle closed 8 years ago

trungtle commented 8 years ago

Revisited texture 3d sample again and it's currently not working on Chrome 51.0 and Firefox 46.0 with OSX 10.10. Reasons unclear.

kenrussell commented 8 years ago

Do you have a smaller test case which demonstrates the problem?

trungtle commented 8 years ago

Let me throw something together really quick

trungtle commented 8 years ago

@kenrussell I have a simple sample in tle/test_texture3D (I believe this is the simplest setup for texture3D)

pjcozzi commented 8 years ago

@trungtle did you update the able in README.md?

ghost commented 8 years ago

In texture3d.html set mipmap filters to:

gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);

Update: you also need to comment out the generateMipmap() call

trungtle commented 8 years ago

@lambdor Thanks for the suggestion. Does this display 3D texture for you? This does work on Windows with Canary, but not consistently. I still get "Can not generate mips" error. Also doesn't work on OSX nor Firefox so far neither.

ghost commented 8 years ago

Yes, works for me on Windows x64 + Firefox. I see 4 viewports with a rotating red blocky texture. Firefox complains about "Texture at base level is not unsized internal format or is not color-renderable or texture-filterable.". Maybe it's due to the float format. You could use RGB textures instead:

var SIZE = 32;
var data = new Uint8Array(3 * SIZE * SIZE * SIZE);
for (var k = 0; k < SIZE; ++k) {
    for (var j = 0; j < SIZE; ++j) {
        for (var i = 0; i < SIZE; ++i) {
            data[3 * i + 3 * j * SIZE + 3 * k * SIZE * SIZE + 0] = snoise([i, j, k]) * 256;
        }
    }
}

var texture = gl.createTexture();
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_3D, texture);
gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_BASE_LEVEL, 0);
gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MAX_LEVEL, Math.log2(SIZE));
gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
gl.texParameteri(gl.TEXTURE_3D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
//gl.generateMipmap( gl.TEXTURE_3D);

gl.texImage3D(
    gl.TEXTURE_3D,  // target
    0,              // level
    gl.RGB8,        // internalformat
    SIZE,           // width
    SIZE,           // height
    SIZE,           // depth
    0,              // border
    gl.RGB,         // format
    gl.UNSIGNED_BYTE,       // type
    data            // pixel
    );

gl.generateMipmap(gl.TEXTURE_3D);

Updated: use RGB8 as internalformat instead of just RGB

kenrussell commented 8 years ago

Please change the internalformat parameter to gl.RGB8 from gl.RGB. For ES 3.0 and upward, the sized internalformats (shown in table 3.13 of the OpenGL ES 3.0.4 specification) should be used, as opposed to the legacy, unsized internal formats. Please tell me if that change improves the situation. (This should behave consistently across platforms and browsers regardless, but let's see what happens.)

shrekshao commented 8 years ago

Hmm... I can't make it work changing to RGB and UNSIGNED_BYTE for either Chrome Canary or Firefox developer edition on Windows 10. @kenrussell @lambdor will it be helpful that you provide your gpu info?

kenrussell commented 8 years ago

@shrekshao this will be a useful exercise in debugging for you. Change the min and mag filters to NEAREST (so you don't have to worry about generating mipmaps for floating-point textures) and prove to yourself that the texture is actually being rendered (by setting its contents to some well-known value, like 1.0). Hint: there is a bug in the use of the glMatrix API.

shrekshao commented 8 years ago

:cry: Thanks for your patience Ken. I should take a closer look at this sample before posting that comment. It's due to incorrect gl-Matrix API call in the noise3D.js

Now with internal format set to RGB8 and format set to RGB, it works fine. But with internal format R32F and format RED, it cannot generate mipmap

[.CommandBufferContext.Offscreen-MainThread-0000023B779348A0]GL ERROR :GL_INVALID_OPERATION : glGenerateMipmap: Can not generate mips

Is it still in development or it is expected that Floating type texture won't generate mipmap?

kenrussell commented 8 years ago

It's expected. In order to be able to generate mipmaps for floating-point textures it's necessary to enable the EXT_color_buffer_float extension: https://www.khronos.org/registry/gles/extensions/EXT/EXT_color_buffer_float.txt . To keep this sample simple, I recommend (as you've done in your follow-on pull request) changing to use an 8-bit unsigned byte texture.