From slab texture to position matrix, what's most efficient?

    Mar 07 2012 | 5:05 pm
    I have a patch which does spectrum analysis and writes it to a matrix. That matrix goes to the GPU through and slabs for heavy processing. Then I want to take the output and use it as vertex position data for GL drawing, using right now.
    I'm getting a big fps drop from having to write the slab output into a jit.matrix before sending it to (also having to reformat from 4 planes to 3). Rendering stays stuck at 30fps. Which is not very bad but I know it could be lots faster given the relatively simple geometry.
    Doing the gl.pix and slab processing on the CPU and thus circumventing readback is slower. Getting around 15fps that way.
    Is there a more efficient way of doing this in Max6? Perhaps with Lua?
    Tanx, D.

    • Mar 08 2012 | 8:21 pm
    • Mar 08 2012 | 9:05 pm
      We'd probably need to see a patch first...
    • Mar 08 2012 | 11:30 pm
      I'm afraid it's not in a state to be posted right now. But hints for efficient GPU texture to GL geometry strategies don't really need the actual patch, no?
      I'll try to get it in a postable state asap anyway.
    • Mar 08 2012 | 11:34 pm
      A custom shader for your should work. You'd send a "blank slate" of vertex points as a jit.matrix to define your default positions (most people use jit.expr for this), and then associate your texture with the mesh. The vertex shader would interpret your texture as a displacement map, which should give you higher performance. I've done this for a very similar project and it works well.
      Unfortunately does not support multi-texturing, so if you want to apply additional textures for fragment processing you'll have to figure out a different route.
    • Mar 09 2012 | 12:09 am
      actually does now support multi-texturing:
    • Mar 09 2012 | 12:32 am
      Good to know! Can one specify distinct texture coordinates for each texture or do they both inherit the same coordinates?
    • Mar 09 2012 | 5:25 pm
      this sounds great, will test asap!
    • Mar 09 2012 | 10:25 pm
      Jesse, is this supposed to work? It doesn't for me. When I send the displacement map the mesh's color only changes to black. I can 't discover the logic behing it.
    • Mar 10 2012 | 4:28 pm
      whoops typo corrected, now it doesn't turn black anymore but still doesn't move either:
    • Mar 11 2012 | 3:00 am
      You still have a typo, @planes should be @planecount in jit.expr.
      Your example does not work because you are not using a shader to perform the displacement. You have to create a shader that acts on the mesh's z coordinates by defining a texture for the mesh and then performing displacement in the vertex shader.
      It's possible you could do this in but I have not implemented it there.
    • Mar 11 2012 | 1:17 pm
      weird, planecount is what i corrected, copy/paste mess up i guess...
      gonna chew on that shader technique now!
    • Mar 11 2012 | 6:57 pm
      Ok i've been on it for the whole afternoon but no cigar. I'm probably missing something basic.
      I thought tex0 should be bound to vp but that returns an error: "setting GLSL param: GL Error: Invalid operation"
      What is it I'm missing about this?
      (btw, how do you get the code block formatting in a post, these ` don't work for me)
    • Mar 12 2012 | 6:17 pm
      Your shader crashes Max6 every time for me, and I don't have time to troubleshoot it. Can you open your patch on your system?
    • Mar 12 2012 | 6:47 pm
      here's an example patch and shader for vertex displacement mapping, based on this tutorial:
      @jesse: i don't believe multiple texture coordinates are currently possible, but we can look into implementing this for a future update. can you provide an example patch showing how you would use this feature?
    • Mar 12 2012 | 7:10 pm
      tanx rob, you're the man!
      i was actually looking at that tutorial but didn't realize i could pretty much paste it in...
    • Mar 12 2012 | 7:34 pm
      one thing i don't fully grasp is why it doesn't work when i initialize the mesh with jit.expr instead of the gridshape matrixoutput like in my patch above. is it because i'm not sending a texcoord array?
    • Mar 12 2012 | 11:09 pm
    • Mar 13 2012 | 12:28 pm
    • Jun 14 2012 | 4:20 pm
      I'm tring to adapt the Robert Ramirez shader to work with rectangular texture from Andrew Benson shader ab.HSFLOW, but I get a strange behavior, maybe some error in texture coordinates, could someone have a look at my patch? Thanks micron
    • Jun 14 2012 | 6:02 pm
      hi micron. i took a look at your patch and shader. i'm not entirely sure what you are trying to achieve, and why you changed the way the vertex shader functions.
      if you revert back to the original vertex shader, and make the necessary modifications for rectangular texture sampling, it works as expected.
      i also needed to provide a normal matrix for the gl.mesh (i'm not sure why the other patch did not need this as well). this is simply a [ jit.matrix 3 float32 320 240 ] connected to the third inlet of gl.mesh, and sent the message, "setall 0 0 1", so that the normal points along the Z axis.
      here's the correct shader code
      void main(void)
      	vec4 newVertexPos;
      	vec4 dv;
      	float df;
      	texcoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
      	dv = texture2DRect(tex0,texcoord0);
      	df = 0.30*dv.x + 0.59*dv.y + 0.11*dv.z;
      	newVertexPos = vec4(gl_Normal * df * scale, 0.0) + gl_Vertex;
      	gl_Position = gl_ModelViewProjectionMatrix * newVertexPos;
    • Jun 14 2012 | 7:49 pm
      thanks helped me a lot, GLSL is not at all easy