JavaScript Executables (JSX)

JSX scripts are JavaScript executable files with .jsx extension. They allow you to exploit full potential of desktop OpenGL in WebGL manner. In JSX scripts you can create all types of shaders: Fragment, Vertex, Geometry, Tessellation and Compute. You can create them using using raw OpenGL API or with higher-level, more convenient Synth API. With JSX scripts you can render and mix Fragx shaders as well.

Synthclipse uses by default Mozilla Rhino JavaScript engine, but it is possible to switch to Oracle Nashorn in the preferences:
Window -> Preferences -> Synthclipse -> JavaScript engine.
Unfortunatelly Nashorn engine is unstable. After couple of successive runs it could hang whole Eclipse for few to tens of seconds. I've tried very hard to fix it but without any success. (It seems like there is some kind of thread lock in JVM natvie code while this happens).


Examples

The best way to learn how to write JSX scripts is to walk through some examples. To get the examples choose from the main menu Synthclipse -> JSX Examples... and select one or more items. (You might need to create a project first).


To get taste how does a JSX script look like, below is presented one of the examples (Synth API/ProgramFactory):

// Sample script

"use strict";

var renderable = {};

var program = null;
var model = null;

function initShaders() {
        program = ProgramFactory.createProgram("MyProgram");

        program.attachShader("shaders/program-factory.frag");
        program.attachShader("shaders/program-factory.vert");

        program.link();
        program.use();

        // print some debug information:
        program.printActiveAttributes();
        out.println();
        program.printActiveUniforms();

        // We can load saved preset:
        program.loadPreset("SomePreset");

        // If we want to have controls in the Uniform Controls View
        // we must create them explicitly:
        Synthclipse.createControls(program);
}

renderable.init = function() {
        initShaders();
        model = GeometryFactory.createTorus(0.5, 1.0, 32, 32);

        gl.clearColor(0.9, 0.8, 0.77, 1.0);
        gl.enable(gl.DEPTH_TEST);

        var freeCamera = CameraManager.getFreeCamera();
        freeCamera.setPosition(0, 0, -10);
        CameraManager.invertMouse = false;

        CameraManager.useFreeCamera();
};

renderable.display = function() {
        gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

        program.use();
        program.applyUniforms();

        model.render();
};

Synthclipse.setRenderable(renderable);