From slab texture to jit.gl.mesh position matrix, what's most efficient?

Mar 7, 2012 at 5:05pm

From slab texture to jit.gl.mesh position matrix, what's most efficient?

Hi,

I have a patch which does spectrum analysis and writes it to a matrix. That matrix goes to the GPU through jit.gl.pix and slabs for heavy processing. Then I want to take the output and use it as vertex position data for GL drawing, using jit.gl.mesh right now.

I’m getting a big fps drop from having to write the slab output into a jit.matrix before sending it to jit.gl.mesh (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.

#62212
Mar 8, 2012 at 8:21pm

bump.

#224698
Mar 8, 2012 at 9:05pm

We’d probably need to see a patch first…

#224699
Mar 8, 2012 at 11:30pm

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.

#224700
Mar 8, 2012 at 11:34pm

A custom shader for your jit.gl.mesh 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 jit.gl.mesh 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.

#224701
Mar 9, 2012 at 12:09am

actually jit.gl.mesh does now support multi-texturing:

– Pasted Max Patch, click to expand. –
#224702
Mar 9, 2012 at 12:32am

Good to know! Can one specify distinct texture coordinates for each texture or do they both inherit the same coordinates?

#224703
Mar 9, 2012 at 5:25pm

this sounds great, will test asap!

#224704
Mar 9, 2012 at 10:25pm

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.

– Pasted Max Patch, click to expand. –
#224705
Mar 10, 2012 at 4:28pm

whoops typo corrected, now it doesn’t turn black anymore but still doesn’t move either:

– Pasted Max Patch, click to expand. –
#224706
Mar 11, 2012 at 3:00am

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 jit.gl.pix but I have not implemented it there.

– Pasted Max Patch, click to expand. –
#224707
Mar 11, 2012 at 1:17pm

weird, planecount is what i corrected, copy/paste mess up i guess…

gonna chew on that shader technique now!

#224708
Mar 11, 2012 at 6:57pm

Ok i’ve been on it for the whole afternoon but no cigar. I’m probably missing something basic.

uniform sampler2DRect tex0;
varying vec2 texcoord0;

void main()
{

vec4 position;
vec4 position2;

vec4 delta = texture2DRect(tex0, texcoord0);

// transform matrix
position = gl_ModelViewProjectionMatrix * gl_Vertex;

// offset
position2 = vec4(position.x+delta.x,position.y+delta.y,position.z+delta.z,position.w);

// copy to output position
gl_Position = position2;

// no lighting calculated in this shader
gl_FrontColor = gl_Color;
}
]]>

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?

Patch:

– Pasted Max Patch, click to expand. –

(btw, how do you get the code block formatting in a post, these ` don’t work for me)

#224709
Mar 12, 2012 at 6:17pm

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?

#224710
Mar 12, 2012 at 6:47pm

here’s an example patch and shader for vertex displacement mapping, based on this tutorial:

http://www.ozone3d.net/tutorials/vertex_displacement_mapping.php

@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?

– Pasted Max Patch, click to expand. –
Attachments:
  1. vertdisplace.jxs
#224711
Mar 12, 2012 at 7:10pm

tanx rob, you’re the man!

i was actually looking at that tutorial but didn’t realize i could pretty much paste it in…

#224712
Mar 12, 2012 at 7:34pm

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?

#224713
Mar 12, 2012 at 11:09pm

exactly:

– Pasted Max Patch, click to expand. –
#224714
Mar 13, 2012 at 12:28pm

tanx!

#224716
Jun 14, 2012 at 4:20pm

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

Attachments:
  1. RJDISPLACE.zip
#224718
Jun 14, 2012 at 6:02pm

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;
}
#224719
Jun 14, 2012 at 7:49pm

thanks helped me a lot, GLSL is not at all easy

#224720

You must be logged in to reply to this topic.