jit.gl.path vertex displacement?
Hello,
I'm trying to learn jitter finally - I'm using jit.gl.path to render some points as a tube and I'd like to displace the path with jit.gl.bfg noise functions. I've found examples of using a jit.gl.mesh, but nothing that uses jit.gl.path. Is it possible? Is there a better approach?
Thanks!
Jit.gl.path takes only jitter matrices as input, not textures. Although it is possible, it would be counter-productive to use jit.gl.bfg to generate noise textures that you would have to read back from the GPU to the CPU as a jitter matrix. You would better use jit.bfg instead. To me it is the most flexible and easy to use way. See red path.
This said, there are ways to displace a path while staying on the GPU and using jit.gl.bfg.
The most simple is by using jit.gl.material @heightmap vtf and use the noise texture as heightmap, although I'm not sure why but it only effects half of the path. And it's just a heightmap, not full vertex control like with the solution above. See the blue path.
Another method, not represented here, would be to set jit.gl.path to render your path as you like, then send it a get_shader message, then save the generated shader file as something like my_custom_path_shader.jxs, and use it as a source file for a [jit.gl.shader] that you would apply to a [jit.gl.mesh], which should act just like your jit.gl.path at this point. Then, you can modify the shader file to get an extra texture to sample from and do vertex displacement however you want. But now you have to deal with glsl code and you might need to handle more things like normals re-calculation, which might be out of the scope of this thread.
Thank you for the thoughtful reply!
The red path solution is really nice - however, what I'm looking for is full vertex displacement of the tube mesh, rather than displacing the central route coordinates themselves.
So your blue approach is closer, however since it's just a heightmap, as you said, the uniformity of the displacement is not quite what I want.
So I'm going to try the custom shader approach (I have some experience writing glsl in a previous life).
I've not figured out quite how to use the mesh with the shader from the jit.gl.path - the shader is saved and loaded correctly, perhaps I'm wiring it up wrong?
It seems that you forgot to link the shader file!
Here is a "working" template to start with.
I've written a few mistakes in my previous post. From my understanding, jit.gl.path generates the tube mesh on the CPU from the matrix it gets, and send the vertices to the GPU for rendering. When sending get_shader
to jit.gl.path, you don't get the code that converts a path to a tube mesh, but just the code to render it.
So what I did to build my example is the following:
Attach a
jit.gl.material @heightmap_mode vtf_normals
tojit.gl.path @pathstyle tube
Send the noise texture to the heightmap input of jit.gl.material
Realize that the vtf_normals mode is broken (gives a full black shape)
Send
get_shader
to jit.gl.path. This will give you the shader generated by jit.gl.material. The reason why I use heightmap_mode vtf_normals is that it gives you a shader with a preconfigured input texture and I find it easier to work with.Modify the patch to rely on the new shader instead of jit.gl.material
Tweak the shader to try to fix things
Manage to get the colors back (check commented lines), but we still have broken geometry.
From that point, you'll most likely want to modify the sample_vertex function to do whatever you want, but then you might need to recalculate the normals accordingly for proper lighting.
Good luck with that!
I'll go ahead and report the issue I found to C74.
Really appreciate the help! I'm going to get stuck in and see what I can come up with.
Another option with jit.bfg is to not only displace position, but also distort scale and orientation, which can go pretty wild:
To make it work you need to use @pathstyle contour
instead of tube, but you can still make a circle shaped contour for a tube-like effect.
Looking forward for your results with the custom shader way!