Intoduction
I start this blog, just to keep me motivated on making a tool
I wish to built a tool/editor to simplify making stuff in Defold. The most tedious and complex for me is rendering pipeline - render script is so powerful, but so difficult to tame and understand. It’s very easy to make a mistake in a render script that is very hard to debug. Yet, if you work with it for a longer period, you open up amazing opportunities and also recognize repeatable patterns.
Visual Render Script Concept
The idea is to build a visual scripting tool to simplify making render scripts. I believe render script can be presented in a more interesting way and simulataneously allow to simplify making render pipelines in it.
Remember, that idea behind visual scripting isn’t being an answer to “how to write less code”, but “how to make better interface for programming”.
First sketches were drawn on paper, where I just wanted to understand available render scripts. Then I moved it computer to draw how such a tool can look like and what should be its elements.
Imagine that the whole update function of the render script is represented as a table with rows being code lines.
A very basic and most easiest render script would just draw stuff on screen with some default settings:
But more complex could look like this:
Some of the “tiles”/“bricks”/“rows” in this visual scripting tool would be 1:1 render API function calls, some would be simplified functions/wrappers, that will utilise a helper lua module, however those are stateless and preferably should not change the given data in parameters - parameters should be read only, those could then eventually return new values (kind of setters, constructors).
It should generate a whole render script based on the setup in the above visual scripting tool that represents in a form of a list - an update function of the render script. And it’s a main panel of such a tool.
Additional panels to be added are:
- A list of all available functions (bricks) to include here - a drag and drop solution to add bricks to this main view.
- A view of all the allocated/created stuff - predicates, render targets, variables, matrices, cameras, etc. This view represents what is created and how it is initialized in init of the render script. It’s a kind of a configurator of the render script. Some of the stuff should be read from “.render” file - the associated materials.
- A special view/(tab?/popup?) that represents on_message. What functions are handled and in what way. It’s similar to update, but no render API should be used here. On message callbacks should allow to change certain data or receive data from e.g. camera component, but it shouldn’t render anything. I don’t know yet how to do it precisely, most probably a lot of “Custom Lua line” bricks will be added here, because rest should be simple setters of allocated/created data/variables.
A concept view of the window with 3 of the above panes (without on_message pane):
Or it could be horizontal, more of a configurator, yet linear, so that each panel is actually convertible to lines of code in generated render script, something like:
Rules for the tool
- Allocate everything upfront. Don’t allocate in update. Allocate everything upfront. Even if not all render scripts made in Defold are following this rule to not create/allocate anything new in the update(), I will let this rule be my number one. It works perfectly with second rule.
- Only created stuff can be used in update. If everything is created in init, update function consists only of functions that can modify values or state of the renderer (through render API). When you add a brick/row that should use some data and you don’t have it yet defined, you should have a possibility in that particular place to quickly add this data and initialize it by default, that could be later changed.
-
Only correct code is generated. This might be very hard to accomplish, but it doesn’t mean it creates a correct pipeline - only the syntax is correct, usage is correct, correct data is used etc. It means that when running the code it should not assert and produce
ERROR
s. This will not apply to “Custom Lua code” brick that has to be added in the visual script for all the stuff that is not available (yet or never) among the pre-defined bricks. - Rules might change. I’m only thinking/prototyping.
Execution
I initially wanted and many times started creating such a tool in Defold, with barebone GUI, then with Gooey, then with Druid, but as you know - none of them are finished. I wanted a seamless integration with Defold. I think, maybe, just MAYBE, the best will be to do it with the amazing stuff that will be soon available in Defold as presented by @vlaaad:
https://twitter.com/v1aaad/status/1821850332537749642
Just posted it now to check it out with you, what you think about it, do you have some ideas/insights/tips on something like this?
Order restrictions?
For example, some things are need to be done in render script in particular order for it to work. If user just randomly put functions in it, it doesn’t mean the code will not compile if the syntax is correct and data is correct (Rule 3), but the output of such render pipeline will be not as user might think. Should I somehow restrict order of things? What are possible corner cases here? The tool imho shouldn’t be limiting, e.g. you should be able to write any rendering pipeline. But for beginners it’s hard without guidance.
Reverse generation?
Other thing is that - I could make it so that I can parse actually existing script to create its version in such tool, but if there would be any Lua modules used - I would pass. Too complex I think. What are other corner cases here? Strange Lua lines of code? E.g. for loops, ifs, etc? Not aligned with the rules above? I would most probably put them in a “Custom Lua code” bricks, if I couldn’t parse such lines. It would be on user to the either refactor it or recreate it with predefined blocks instead in that tool.
P.S. Yes, obviously name was one of the first thing that I came up with, now years ago
P.S.2. Yeah, years, the doc with those sketches (moved to PC form paper) was created in January 2021…
P.S.3. I prototyped already a strange parser, that extrudes all data from a Lua script: all named variables (even from tables or function parameters (if there are annotations) or functions themselves and it knows a lot of stuff from Defold API) and its data type (if determinable):
→