raytk icon indicating copy to clipboard operation
raytk copied to clipboard

RayTK as standalone or webGL possible?

Open felipeinfantino opened this issue 3 years ago • 5 comments

Hi,

Is there a way to run the RayTK library without Touchdesigner ? Maybe in C++ or compile/export the shaders for running them on WebGL or something like that? It would be awesome to run RayTK on a Rasperry Pi and create an audioreactive synth.

Please let me know if that would be possible, and if it is possible and there is not implemented yet, please guide me on how to do it, I'm a developer too. (Javascript background).

Imaging being able to run RayTK on WebGL and use it through some modern looking UI, something like this: https://rete.js.org/#/examples/basic

Thank you so much for creating this amazing library.

felipeinfantino avatar Feb 26 '22 22:02 felipeinfantino

Thanks for reaching out!

The most feasible approach would be shader export. I started work on that a while back (see #14) but shifted focus to other areas. It would involve taking a snapshot of the generated shader, replacing portions of it, and wiring up parameters to uniforms so whatever hosts the shader can control them.

There are two types of parameters:

  • Parameters that can be adjusted live, which are passed to the shader as uniforms. These can be handled pretty easily.
  • Parameters that influence the generated code, causing the shader to recompile. This includes most menu parameters. These would need to be frozen during the export, since the compiler wouldn't be available outside TD.

So there would be a lot of limitations, but some parts of it could be done.

t3kt avatar Feb 27 '22 00:02 t3kt

There are some other web-based tools that could work as an alternative.

  • https://github.com/stasilo/retrace.gl
  • https://github.com/charlieroberts/marching
  • https://cables.gl/

t3kt avatar Feb 27 '22 00:02 t3kt

Thanks for the fast reply. I checked the other alternatives but i find rayTK way better.

Goal would it be to have a general shader exporter.

So let me summarize the steps in order to achieve this:

  • Parse the raymarchRender3D shader output (shader_code DAT) and replace the #include libraries with the actual code (like a javascript bundler) so its only in a single file.
  • Replace the TD built in glsl functions with the "host" built in functions
  • On the host fill the exposed uniforms

Is that the right way?

I imagine the end goal something like a tox with a path to a json. The json contains the mapping of TD built in glsl functions and the host implementations. (in that way every json would be the config file to export the shader to a specific platform, and the community could just build those jsons for the platform of their choice ex: shaderToy.json , threeJs.json , unrealEngine.json, unity.json, blender.json) . Then a export button which parse the passed json, replace the TD built in function and hopefully exports a working shader that can be run out of the box in the desired platform.

So end result would be a single shader file with the uniforms exposed for live modification.

Let me know your thoughts, Im still learning the shader world and trying to fill the gaps on how shaders actually work and their depedencies of platforms.

felipeinfantino avatar Feb 27 '22 12:02 felipeinfantino

Replacing the uses of TD built-in functions would cover one of the smaller obstacles. But in general it doesn't use a whole lot of them. It's mostly just utilities like TDRotateOnAxis() which have fairly simple implementations.

The main challenges are around the compiler, handling of macro-based parameters, parameter value processing (parts of which are done with CHOPs), python expression-based macros, etc.

t3kt avatar Apr 11 '22 00:04 t3kt

If you're interested in working on development for the toolkit to support those kind of things, let me know.

t3kt avatar Apr 11 '22 00:04 t3kt