Menu

#1 Reinitializing of UniformControlView when shader changes

1.0
closed
nobody
2015-01-29
2015-01-20
No

Please add an option to reinitialize the UniformControlView from an jsx file, so I can update the controls when I change the shader-program. Ideally this should preserve the values changed in the controls for the same uniforms used in the new shader-program.

Discussion

  • Kamil Kolaczynski

    Do you use GLSLProgram created by ProgramFactory object? (like in this example: program-factory.jsx (sourceforge.net)).

    It has convenient methods for setting uniform variables (see GLSLProgram.html (synthclipse.sourceforge.net)). If you would use one of them, Uniform Controls View should be updated automatically.

    You can find example of using setUniform methods in: geometry-factory.jsx (sourceforge.net)

     
  • Mathias Henze

    Mathias Henze - 2015-01-21

    I actually used geometry-factory.jsx as an example.

    My use-case is having a scene where I can switch the shaders (texture-synthesis algorithms) using the combobox control, but if I use JSSynthclipse.createControls(program) when I recreated the shader program, the changes do not appear in the UniformControlsView.

    I checked your source and as far as I understand, it can't change after being initialized and createControls just adds the uniform controls to a list used in initView().

    Edit for clarity: I really recreate a ShaderProgram using the ProgramFactory, attach the new .vert and .frag shaders, link and use it in the display callback when the combobox changes...

     

    Last edit: Mathias Henze 2015-01-21
  • Kamil Kolaczynski

    There is 'hidden' event system in the Uniform Controls. When you set some value for an uniform variable (using GLSLProgram.setUniform()) it suppose to trigger an event which should be captured by a Uniform Control Widget. Then the Widget should be updated automatically.

    I'll check why this doesn't work and I will try to fix it. Maybe I will also add an method for explicit Uniform Controls View update.
    The fix will be available in Synthclipse 0.9.12, which I will release probably on weekend.

     
  • Mathias Henze

    Mathias Henze - 2015-01-22

    I think we still don't get each other. :)

    My problem is not, that the values of the uniform won't update. The problem is that I load, link and use a different shader program at runtime with different uniform variables (not only values) and there is no way to change the set of displayed uniform controls, once the view is initialized.

     
  • Kamil Kolaczynski

    Ok, now I get it. I will add some method to reinitialize Uniform Controls View at runtime.

     
  • Kamil Kolaczynski

    I've added following methods:
    Synthclipse.removeAllControls();
    Synthclipse.removeControls(program);
    Synthclipse.refreshControls();
    and I have made:
    Synthclipse.createControls(program);
    more dynamic, working on runtime.

    Do you think this will fulfill your needs?

     
  • Mathias Henze

    Mathias Henze - 2015-01-24

    Will check, once the release is out - thank you very much!

     
  • Kamil Kolaczynski

    The release is ready. Please check it out and let me know if it is ok now.

     
  • Mathias Henze

    Mathias Henze - 2015-01-27

    Works great, thanks a lot! Now I can do

    var Program = 0; //! combobox[0, "Default", "Simple", "Bombing" ]
    var shaderList = [
        "default.vert", "default.frag",         // Default
        "default.vert", "simple-texture.frag",  // Simple
        "default.vert", "texture-bombing.frag", // Bombing
    ]
    var lastProgram = -1;
    var programList = [];
    
    // ...
    
    renderable.init = function()
    {
        for(var i=0; i < shaderList.length/2; i++)
        {
            var lprogram = ProgramFactory.createProgram("Program");
            lprogram.attachShader("shaders/"+shaderList[i*2]);
            lprogram.attachShader("shaders/"+shaderList[i*2+1]);
            lprogram.link();
            programList[i] = lprogram;
        }
        // ...
    }
    
    // ...
    
    renderable.display = function()
    {
        if (lastProgram != Program)
        {
            if(lastProgram >= 0)
                Synthclipse.removeControls(programList[lastProgram]);
            Synthclipse.createControls(programList[Program]);
            programList[Program].use();
            lastProgram = Program;
        }
        // ...
    };
    

    it even remembers the values from the last time the uniform was adjusted: GREAT!

     
  • Mathias Henze

    Mathias Henze - 2015-01-28

    Btw. I consider this ticket resolved, so you can close it (I can't)

     
  • Kamil Kolaczynski

    Nice to hear now everything works as expected :) Ok, I will close this ticket now.

     
  • Kamil Kolaczynski

    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB