Forums > Jitter

Using jit.gl.pix for particle system entirely on the GPU


Jan 10 2017 | 9:08 am

Hi,

I’m currently working on some experiments where I’m using jit.gl.pix to run a particle system which stays entirely on the GPU. I’m pleased with what I’m seeing so far, but have hit a bit of a dead end and have been banging my head against a brick wall trying to get past this, so wondered if somebody with some more jit.gl.pix or glsl experience could help me out…

The principle appears to work fine, and I’ve been able to make nice looking particle systems with well over 500,000 points that run at 30fps on my iMac, with a single texture holding particles x, y, age and opacity. However, I’m now wanting to use the particle x and y positions to look up data from another texture, and this is where I’m hitting trouble. The attached patch illustrates this: I am taking a camera input, passing this into a texture, and then I want the particles to take their opacity value from the nearest corresponding pixel in the camera image. I can achieve the effect that I want when I have the particles arranged in a nice neat grid (with coordinates generated from a jit.gencoord ) but when I use noise to generate the particle positions, it reveals that there’s something going wrong in the sampling process. In the attached patch, I’d like the image from the camera to remain readable even as the particles positions become randomly spread: the jit.gl.pix is supposed to be sampling the camera texture based on the x and y positions of each particle. Try crossfading from the noise to the grid and see what happens.

Any input on this would be very much appreciated! I’m planning to combine this with a stam fluid implementation on the GPU and will share here if I get it all working!

Tom

— Pasted Max Patch, click to expand. —

code for texturetogeo shader:

<jittershader name="texturetogeo.jxs">
<description>Geometry from texture</description>
<param name="amount" type="vec3" default="0. 0. 0.">
</param>
<param name="tex0" type="int" default="0" />
<language name="glsl" version="1.2">
<bind param="tex0" program="vp" />
<program name="vp" type="vertex">
<![CDATA[

#version 120

uniform sampler2D tex0;
varying vec2 texcoord0;

void main(void)
{
texcoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
vec4 particleposition = texture2D(tex0, texcoord0.xy);
vec4 normal = vec4(gl_NormalMatrix * gl_Normal, 1.);
vec4 v = vec4(particleposition.x,particleposition.y,-1., 1.);
vec4 pos = gl_ModelViewMatrix * v;
gl_Position =gl_ProjectionMatrix * (pos + normalize(normal));
gl_FrontColor = vec4(1.,1.,1.,particleposition.a);
}

]]>
</program>
<program name="fp" type="fragment">
<![CDATA[

varying vec2 texcoord0;

void main (void)
{
gl_FragColor = gl_Color;
}

]]>
</program>
</language>
</jittershader>

Jan 10 2017 | 9:23 am

OK. Why is it that 5 minutes after asking for help here, I always seem to find the solution? At least, I think I’ve found the solution. The problem was not with the jit.gl.pix at all, but with the shader that was transforming the texture data into vertex data: it was interpolating the incoming texture, and I found on the forums that sending a message ‘sendoutput filter none’ to the jit.gl.pix immediately before the jit.gl.mesh solved the problem. Hope this might be useful for somebody else in the future…

Jan 10 2017 | 11:01 am

Asking for help teaches humility. Finding the solution for yourself 5 minutes after being humble teaches you patience and impulse control. :-)

Jan 11 2017 | 3:24 am

I’m sure it also has something to do with turning my usual chaotic patchers into something that I hope that other people might be able to understand: in doing so, I begin to understand them a little more myself…

Feb 18 2017 | 10:15 pm

Hey Tom, I saw on your Vimeo page that you got this particle system linked up to a GPU fluid solver. The clips that you posted look fantastic! Would you consider posting your patch here? I’ve been looking at other GPU-based fluid sims (most recently, the one posted over here: https://cycling74.com/forums/topic/sharing-is-fun-fluid-simulation-on-the-gpu/ ) and would love to see what’s going on in your implementation.

Feb 20 2017 | 7:09 am

Hi Syrinx,

I’m planning to share the patch here, but will need to do some tidying up first… once my current project calms down a bit I hope to get on to it.

Cheers

Tom

Viewing 6 posts - 1 through 6 (of 6 total)

Forums > Jitter