I feel like this should be covered somewhere in a tutorial, and if so, sorry if I didn’t search hard enough.
I am trying to figure out how to wire a geometry into a shader. I want the shader to take a top as an input to use as a displacement map and either a geo comp or a sop as the surface (I am noob enough not to know which one is preferablefor this).
Now I can write a GLSL shader that does that in normal openGL, but how does the wiring go in TD? What uniforms/varyings are inputs to make those calculations?
Specifically I’d like to read the normals out of geometry, the rgb out of the texture, and displace in GLSL the vertex by the amount of displacement.
Hmm have you checked out the GLSL chapter of our book. It doesn’t get that deep on the 3D side of things, but does have a primer of using all the different elements in TouchDesigner.
Wire a SOP into a Texture SOP and then into your Geo. Create a GLSL Mat and assign it as your Geo material. Create a TOP for displacement and assign it as a Sampler in your GLSL Mat. A simple vertex shader accomplishing what you want is below…
// pass color sample to pixel shader
out vec4 color;
// sample displacement texture
vec4 sample = texture(displacementTOP, uv[0].st);
// use sampled red brightness value to displace points along normal
float depth = sample.r;
vec3 newP = P + N * depth;
// store sampled RGBA
color = sample;
// deform points
gl_Position = TDWorldToProj(TDDefor(newP));
}
Then create a pixel shader to shade pixels. Below is a simple example using the sampled texture as RGBA values…
// declare output
out vec4 fragColor;
// pass in color sample
in vec4 color;
void main(){
fragColor = color;
}
This should get you started. I can post an example later tonight if you would like…
I hope you are having nice celebrations for those of you who celebrate. I am doing a fluid vertex shader on an exr point-cloud and can’t really understand how to write velocity values in real-time to an exr texture in order to use them to move particles. I get the usual uniform part, but not the pixel shader writing values to the texture… How does that configure in TD? Do I use a GLSLTop and wire it somewhere?
Thanks in advance! P
@priam
Hello,
If I want to move particule, I use GLSL top.
– input one with the initial position top
– input two with a feedback loop on the position
– input three with a velocitiy top
And I instance particles with the resulting output.
I dont know if its possible to do that with GLSL mat.
Jacques
a very quickly made dynamic system with velocity and acceleration quickGLSLparticles.toe (5.2 KB)