1

This is a question, not an issue.

I'm working in a terrain with atlas texture. To mitigate the color bleeding i want to feed the terrain texture with mipmaps built in an external tool.

For the time being I'm using ...

terrainTexture = THREE.ImageUtils.loadTexture 

... to load every mipmap level and adding them to the level 0 texture ...

terrainTexture.mipmaps[mipsTexs[tex.sourceFile]] = tex.image;

... mipsTexs is just an associateve array to know which position corresponds to each texture.

The real problem is that the terrain appers all black when i feed manual mipmaps and colored but with the color bleeding artifacts with webgl generated mipmaps.

The only example of manual mipmaps is in the examples, but the mipmaps feed to the texture are canvas. I wanted to know if the all black problem that i'm seeing can be due to the use of JS Images instead of Canvases.

mrdoob
  • 19,334
  • 4
  • 63
  • 62

1 Answers1

3

This example shows how to build your own mipmaps:

function mipmap( size, color ) {

    var imageCanvas = document.createElement( "canvas" ),
    context = imageCanvas.getContext( "2d" );

    imageCanvas.width = imageCanvas.height = size;

    context.fillStyle = "#444";
    context.fillRect( 0, 0, size, size );

    context.fillStyle = color;
    context.fillRect( 0, 0, size / 2, size / 2 );
    context.fillRect( size / 2, size / 2, size / 2, size / 2 );
    return imageCanvas;

}

var canvas = mipmap( 128, '#f00' );
var textureCanvas1 = new THREE.Texture( canvas, THREE.UVMapping, THREE.RepeatWrapping, THREE.RepeatWrapping );
textureCanvas1.repeat.set( 1000, 1000 );
textureCanvas1.mipmaps[ 0 ] = canvas;
textureCanvas1.mipmaps[ 1 ] = mipmap( 64, '#0f0' );
textureCanvas1.mipmaps[ 2 ] = mipmap( 32, '#00f' );
textureCanvas1.mipmaps[ 3 ] = mipmap( 16, '#400' );
textureCanvas1.mipmaps[ 4 ] = mipmap( 8,  '#040' );
textureCanvas1.mipmaps[ 5 ] = mipmap( 4,  '#004' );
textureCanvas1.mipmaps[ 6 ] = mipmap( 2,  '#044' );
textureCanvas1.mipmaps[ 7 ] = mipmap( 1,  '#404' );
textureCanvas1.needsUpdate = true;
mrdoob
  • 19,334
  • 4
  • 63
  • 62
  • Thanks for the response. For the record i want to say that either canvas o images can be feed as mipmaps. In my case the problem was due to some badly generated mipmaps, the size of the last 3 levels of the mipmap piramid didn't have the correct size, so the entire texture was seen black, discarded as a correct texture. – Bernardo Falese Feb 08 '13 at 03:02