t3kt / raytk

Raymarching shader toolkit for TouchDesigner
https://raytk.net
Other
238 stars 15 forks source link

RayTK as standalone or webGL possible? #824

Open felipeinfantino opened 2 years ago

felipeinfantino commented 2 years ago

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.

t3kt commented 2 years ago

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:

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

t3kt commented 2 years ago

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

felipeinfantino commented 2 years ago

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:

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.

t3kt commented 2 years ago

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 commented 2 years ago

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