Three.js: Using native WebGLTexture as a RawShaderMaterial uniform

Created on 24 Aug 2014  路  7Comments  路  Source: mrdoob/three.js

Do you have any clue for passing a native WebGLTexture to one Shader in a Three material?

We are sharing the Three gl context to do a series of calculations and stuff on the GPU, but the main purpose is to render the final data with three, so I need to put my output texture (WebGLTexture) as a Sampler2D uniform in a THREE.RawShaderMaterial. I don't know if this is possible using the available API of the engine.

Thanks in advance and keep up the great work!

Suggestion

Most helpful comment

This seems to work in r85:

var texture = new THREE.Texture();
var properties = renderer.properties.get( texture );
properties.__webglTexture = myWebGLNativeTexture;
properties.__webglInit = true;

All 7 comments

Ops, I just found a way :

var texture = new THREE.Texture();
texture.__webglInit = true;
texture.__webglTexture = myWebGLNativeTexture;

Is there anything wrong with this workaround?

Hmmm, what's wrong is that there isn't a better API for it :P
It's not a WebGLRenderTarget, is it?

Maybe we can do some sort of THREE.WebGLTexture?

Yes, a THREE.WebGLTexture would be great, but is not as easy as I thought.. there are some issues when using this approach, while another Three geometry is at the viewport, the webglTexture seems like removed from the material :( I think this should be because the texture slot of the webGLTexture is static and the engine doesn't know nothing about it so probably is overriding it.

I still looking for a good approach to solve this and being able to use our GPU stuff within Three.js without issues :)

I'd like to put in a vote for a variety of Texture that uses a WebGLTexture as the source image. It would be much more flexible than passing it directly to a RawShaderMaterial because you'd still be able to use the Texture as a source for other kinds of material.

Is there any progress on this issue?
Would it be hard to overload the THREE.Texture constructor to use a WebGLTexture as an argument?

This seems to work in r85:

var texture = new THREE.Texture();
var properties = renderer.properties.get( texture );
properties.__webglTexture = myWebGLNativeTexture;
properties.__webglInit = true;
Was this page helpful?
0 / 5 - 0 ratings

Related issues

boyravikumar picture boyravikumar  路  3Comments

jlaquinte picture jlaquinte  路  3Comments

zsitro picture zsitro  路  3Comments

alexprut picture alexprut  路  3Comments

filharvey picture filharvey  路  3Comments