Open thejmazz opened 7 years ago
@thejmazz Is there a three.js example that explains DataTexture
?
/ping @hirako2000
There is not much to explain - works the same as a normal texture except you construct the array buffer yourself (thats why need to set encoding, e.g. rgb
vs rgba
).
It can be used to create height map textures on CPU for example - or use Math.random()
to make noise textures rather than using a shader and texture render target.
Let's have generateTextureArray
and dataMaker
as static methods of DataTextureModules
because it's better to keep module as one exported (default) class
defaults
seems a bit complicated (yep, those are not required) but there we just copy three.js params. I think THREE.DataTexture
should already handle undefined params.
module should not return this.dataTexture
because this way it is not a module (will not work)
who creates/loads texture from (bytes?) arrays? What is the benefit?
@hirako2000 for cpu generative textures like this https://jmazz.me/codevember/2016/19/
Useful to use CPU based random functions since there are some quirks with GPU implementations of PRNG. But for simplex/perlin noise, GPU is a lot faster (and then you need to use render target to texture).
You could also imagine storing a heightmap in a buffer like that.
Also just realized that demo could be a good one to port to WHS and for the demo for this module
@sasha240100 you can assign this issue to me
@thejmazz I'd like to see an example with it. How about making a fractal? could you make a simple one?
I have a module for data textures from whs v1. I think either a
DataTextureModule
andTextureModule
(see #213) can exist, or there can be one generic one. Here is the code for reference, I will make a v2 version soon. Also included some utils I used, but probably would not want those in the module. But maybe the data texture module could have some param options which are callback functions used to construct the texture. Something that gives you(x,y)
of current position, and you return a[r, g, b, a]
, etc.Version:
Issue type:
Tested on:
###### Desktop - [ ] Chrome - [ ] Chrome Canary - [ ] Chrome dev-channel - [ ] Firefox - [ ] Opera - [ ] Microsoft IE - [ ] Microsoft Edge ###### Android - [ ] Chrome - [ ] Firefox - [ ] Opera ###### IOS - [ ] Chrome - [ ] Firefox - [ ] Opera