Created
August 1, 2013 07:39
-
-
Save neuralvis/6129249 to your computer and use it in GitHub Desktop.
Creating floating point textures in threejs. Taken from here: https://github.com/mrdoob/three.js/issues/386
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createTextureFromData ( width, height, data ) { | |
if (!gl.getExtension("OES_texture_float")) { | |
throw("Requires OES_texture_float extension"); | |
} | |
texture = new THREE.Texture( ); | |
texture.needsUpdate = false; | |
texture.__webglTexture = gl.createTexture(); | |
gl.bindTexture( gl.TEXTURE_2D, texture.__webglTexture ); | |
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.FLOAT, new Float32Array(data) ); | |
texture.__webglInit = false; | |
gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE ); | |
gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE ); | |
gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST ); | |
gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_NEAREST ); | |
gl.generateMipmap( gl.TEXTURE_2D ); | |
gl.bindTexture( gl.TEXTURE_2D, null ) | |
return texture; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment