Search in sources :

Example 1 with ShaderBuilder

use of com.talosvfx.talos.runtime.shaders.ShaderBuilder in project talos by rockbite.

the class ShaderNodeStage method getFragShader.

public String getFragShader() {
    ShaderBuilder builder = new ShaderBuilder();
    if (colorOutput == null)
        return "";
    colorOutput.buildFragmentShader(builder);
    return builder.getFragmentString();
}
Also used : ShaderBuilder(com.talosvfx.talos.runtime.shaders.ShaderBuilder)

Example 2 with ShaderBuilder

use of com.talosvfx.talos.runtime.shaders.ShaderBuilder in project talos by rockbite.

the class ShaderNodeStage method getShaderData.

public String getShaderData() {
    ShaderBuilder builder = new ShaderBuilder();
    if (colorOutput == null)
        return "";
    colorOutput.buildFragmentShader(builder);
    String methods = builder.generateMethods();
    String main = builder.getMainContent();
    StringWriter writer = new StringWriter();
    XmlWriter xml = new XmlWriter(writer);
    try {
        XmlWriter shader = xml.element("shader");
        XmlWriter uniforms = shader.element("uniforms");
        ObjectMap<String, ShaderBuilder.UniformData> declaredUniforms = builder.getDeclaredUniforms();
        for (String uniformName : declaredUniforms.keys()) {
            XmlWriter uniform = uniforms.element("uniform");
            uniform.attribute("name", uniformName);
            uniform.attribute("type", declaredUniforms.get(uniformName).type.getTypeString());
            ShaderBuilder.UniformData uniformData = declaredUniforms.get(uniformName);
            if (uniformData.type == ShaderBuilder.Type.TEXTURE) {
                uniform.text(uniformData.payload.getValueDescriptor());
            }
            uniform.pop();
        }
        uniforms.pop();
        XmlWriter methodsElem = shader.element("methods");
        methodsElem.text("<![CDATA[" + methods + "]]>");
        methodsElem.pop();
        XmlWriter mainElem = shader.element("main");
        mainElem.text("<![CDATA[" + main + "]]>");
        mainElem.pop();
        shader.pop();
        return writer.toString();
    } catch (IOException e) {
        e.printStackTrace();
        return "";
    }
}
Also used : StringWriter(java.io.StringWriter) ShaderBuilder(com.talosvfx.talos.runtime.shaders.ShaderBuilder) IOException(java.io.IOException)

Example 3 with ShaderBuilder

use of com.talosvfx.talos.runtime.shaders.ShaderBuilder in project talos by rockbite.

the class UIKit method create.

@Override
public void create() {
    super.create();
    TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("skin/uiskin.atlas"));
    skin = new Skin(Gdx.files.internal("skin/uiskin.json"));
    skin.addRegions(atlas);
    table = new Table();
    AbstractShaderNode shaderNode = new AbstractShaderNode() {

        @Override
        public void prepareDeclarations(ShaderBuilder shaderBuilder) {
        }

        @Override
        public String writeOutputCode(String slotId) {
            return null;
        }
    };
    shaderNode.init(skin, null);
    XmlReader reader = new XmlReader();
    XmlReader.Element root = reader.parse(Gdx.files.internal("addons/shader/nodes.xml"));
    shaderNode.constructNode(root.getChild(0).getChild(0));
    table.add(shaderNode);
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    table.setFillParent(true);
    stage.addActor(table);
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ShaderBuilder(com.talosvfx.talos.runtime.shaders.ShaderBuilder) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) XmlReader(com.badlogic.gdx.utils.XmlReader) AbstractShaderNode(com.talosvfx.talos.editor.addons.shader.nodes.AbstractShaderNode)

Aggregations

ShaderBuilder (com.talosvfx.talos.runtime.shaders.ShaderBuilder)3 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 XmlReader (com.badlogic.gdx.utils.XmlReader)1 AbstractShaderNode (com.talosvfx.talos.editor.addons.shader.nodes.AbstractShaderNode)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1