Sign in to follow this  
Pryme8

Transform feedback buffer

Recommended Posts

What would be the equivalent of:

 var gl = this.gl, w = this.statesize.x, h = this.statesize.y;
    gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffers.step);
    gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
                            gl.TEXTURE_2D, this.textures.front, 0);
    var rgba = new Uint8Array(w * h * 4);
    gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, rgba);
    return rgba;

which you would then use this rgba value to draw to a buffer with glTexSubImage2D();

How would I go about this with bjs?

  Is this what I am looking for?

I would know how to do it if the shader filled up the whole screen, but I am struggling on how to grab that pixel data on a shader on a mesh.

Share this post


Link to post
Share on other sites

Im still trying to figure this out.

I basically want to be able to provide a texture to a shader and have it manipulate it in some way and then return the modified output wash, rinse and repeat.

trying to figure out a Game of Life simulation on the GPU just to get started.

Share this post


Link to post
Share on other sites

Yeah that's what I am trying to figure out.  I want to be able to pass a texture to a "simulation shader" grab what the fragments is outputing on that frame convert that to a texture/array have that be passed to a second shader that just displays it, then repeat.

https://www.babylonjs-playground.com/#X465WT#11

I just dont know how to grab that data... figured transform buffer would be the way to go but I have no clue how to work that.

Share this post


Link to post
Share on other sites

You should be able to work like postprocesses actually:

- create a first render target

- create a data raw texture

- use the data texture and give it to the simulation shader

- output to the render target

- give the render target to the render shader

- copy render target content to data texture

- repeat

Share this post


Link to post
Share on other sites

Ill give that a shot.

can you show me how to do that last part the copy render target content to data texture?

Am I going to have to do my calculations in textel space instead of pixel?

I'm pretty confused now actually...  there is really no documentation I can find on render targets.

Share this post


Link to post
Share on other sites

So ok, if I make a render target at the same size as my simulation, and then I would need to set the simulation shader on that?   So I make a post process and attach that to the new render target correct? Which then the post process has a default sampler which I assume is where I set the first texture and then use that post process as the simulation? 

How do I then convert that custom render target to a texture to repeat the simulation steps after I get this all set up?  That sounds like I am still gonn a need to use some cpu stuff to convert the textures.  I was hoping to do this all on the gpu.

Share this post


Link to post
Share on other sites

So you can use the TextureTools.CreateResizedCopy function to clone the rtt using GPU:

http://doc.babylonjs.com/classes/3.1/texturetools#static-createresizedcopy-texture-width-height-usebilinearmode-rarr-undefined

of you may just want to use part of the code to do your own optimized version:

https://github.com/BabylonJS/Babylon.js/blob/master/src/Tools/babylon.textureTools.ts

Share this post


Link to post
Share on other sites

https://www.babylonjs-playground.com/#X465WT#14

if you click on the plane it will file the step function, which goes ok as far as I can tell and is based off of the textureTools function.  

But when I try to swap the buffers I get this error:
 

Uncaught TypeError: this._textures[c].isReady is not a function
    at i.isReady (babylon.js:30)
    at i.r.render (babylon.js:16)
    at i.render (babylon.js:17)
    at t.renderUnsorted (babylon.js:11)
    at t.render (babylon.js:11)
    at t.render (babylon.js:11)
    at i._renderForCamera (babylon.js:13)
    at i._processSubCameras (babylon.js:13)
    at i.render (babylon.js:14)
    at index.js:431

so I must be missing a step.  I was looking to see if the step function actually generated a texture that I could use and I have not been able to establish that yet.

Share this post


Link to post
Share on other sites

https://www.babylonjs-playground.com/#X465WT#15

If I change the sampler to the rtt, the error stops but I effectively get no output so I think the sim shader is not being applied

Gotta be really close, I just don't think the shader is effecting the rtt because I was able to just use the TextureTools.CreateResizedCopy to clone the buffers and swap them.

@Deltakosh, sorry to ping you but I am having trouble having a shader effect the rtt and you seem to be the only one with any input on this.

Share this post


Link to post
Share on other sites

http://www.babylonjs-playground.com/#I30SDL#14

One last hitch and I think I got it.
any idea why the passData function is not compiling a rtt that is a clone of the Show Shader Data.
Line 201-269;

Basically it should grab the two buffers (the state and the inState) assign them to the postProccess pass, and set that as the data for the simulation.  Then the simulation does a rtt, and passes that back to the Show Shaders state.
Its hard to debug it when it seems the rtt only ever returns black when as far as I can tell I am following the correct steps as the above post.



If you click on the plane and modify the data the simulation will try to kick over and you will see what I mean.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.