Search in sources :

Example 1 with ClampMethod

use of com.gempukku.libgdx.graph.shader.ClampMethod in project gdx-graph by MarcinSc.

the class GradientShaderNodeBuilder method buildCommonNode.

@Override
protected ObjectMap<String, ? extends FieldOutput> buildCommonNode(boolean designTime, String nodeId, JsonValue data, ObjectMap<String, FieldOutput> inputs, ObjectSet<String> producedOutputs, CommonShaderBuilder commonShaderBuilder, GraphShaderContext graphShaderContext, GraphShader graphShader) {
    FieldOutput inputValue = inputs.get("input");
    Array<ColorPoint> pointArray = new Array<>();
    JsonValue points = data.get("points");
    for (String point : points.asStringArray()) {
        String[] split = point.split(",");
        pointArray.add(new ColorPoint(Color.valueOf(split[0]), Float.parseFloat(split[1])));
    }
    ClampMethod clampMethod = ClampMethod.valueOf(data.getString("clamp", "Normal"));
    String remapValueFunctionName = "gradient_" + nodeId;
    String functionText = createGradientFunction(remapValueFunctionName, pointArray, clampMethod);
    commonShaderBuilder.addFunction(remapValueFunctionName, functionText);
    String name = "result_" + nodeId;
    commonShaderBuilder.addMainLine("// Gradient node");
    commonShaderBuilder.addMainLine("vec4 " + name + " = " + remapValueFunctionName + "(" + inputValue + ");");
    return LibGDXCollections.singletonMap("output", new DefaultFieldOutput(ShaderFieldType.Vector4, name));
}
Also used : Array(com.badlogic.gdx.utils.Array) ClampMethod(com.gempukku.libgdx.graph.shader.ClampMethod) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) JsonValue(com.badlogic.gdx.utils.JsonValue) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Example 2 with ClampMethod

use of com.gempukku.libgdx.graph.shader.ClampMethod in project gdx-graph by MarcinSc.

the class RemapValueShaderBoxProducer method createPipelineGraphBox.

@Override
public GraphBox createPipelineGraphBox(Skin skin, String id, JsonValue data) {
    GraphBoxImpl result = createGraphBox(id);
    addConfigurationInputsAndOutputs(result);
    final CurveWidget curveWidget = new CurveWidget(skin);
    if (data != null) {
        JsonValue points = data.get("points");
        for (String point : points.asStringArray()) {
            String[] split = point.split(",");
            curveWidget.createPoint(Float.parseFloat(split[0]), Float.parseFloat(split[1]));
        }
    } else {
        curveWidget.createPoint(0, 0);
    }
    curveWidget.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            curveWidget.fire(new GraphChangedEvent(false, true));
        }
    });
    curveWidget.setSize(300, 200);
    result.addGraphBoxPart(new GraphBoxPartImpl(curveWidget, new GraphBoxPartImpl.Callback() {

        @Override
        public void serialize(JsonValue object) {
            Array<Vector2> points = curveWidget.getPoints();
            JsonValue pointsValue = new JsonValue(JsonValue.ValueType.array);
            for (Vector2 point : points) {
                pointsValue.addChild(new JsonValue(SimpleNumberFormatter.format(point.x) + "," + SimpleNumberFormatter.format(point.y)));
            }
            object.addChild("points", pointsValue);
        }
    }));
    final VisSelectBox<ClampMethod> clampMethodSelectBox = new VisSelectBox<ClampMethod>();
    clampMethodSelectBox.setItems(ClampMethod.values());
    if (data != null)
        clampMethodSelectBox.setSelected(ClampMethod.valueOf(data.getString("clamp", "Normal")));
    clampMethodSelectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            clampMethodSelectBox.fire(new GraphChangedEvent(false, true));
        }
    });
    VisTable clampActor = new VisTable();
    clampActor.add("Clamp method:").row();
    clampActor.add(clampMethodSelectBox).growX();
    result.addGraphBoxPart(new GraphBoxPartImpl(clampActor, new GraphBoxPartImpl.Callback() {

        @Override
        public void serialize(JsonValue object) {
            object.addChild("clamp", new JsonValue(clampMethodSelectBox.getSelected().name()));
        }
    }));
    return result;
}
Also used : CurveWidget(com.talosvfx.talos.editor.widgets.CurveWidget) GraphBoxImpl(com.gempukku.libgdx.graph.ui.graph.GraphBoxImpl) GraphChangedEvent(com.gempukku.libgdx.graph.ui.graph.GraphChangedEvent) JsonValue(com.badlogic.gdx.utils.JsonValue) GraphBoxPartImpl(com.gempukku.libgdx.graph.ui.graph.GraphBoxPartImpl) VisSelectBox(com.kotcrab.vis.ui.widget.VisSelectBox) VisTable(com.kotcrab.vis.ui.widget.VisTable) Vector2(com.badlogic.gdx.math.Vector2) ClampMethod(com.gempukku.libgdx.graph.shader.ClampMethod) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Example 3 with ClampMethod

use of com.gempukku.libgdx.graph.shader.ClampMethod in project gdx-graph by MarcinSc.

the class GradientShaderBoxProducer method createPipelineGraphBox.

@Override
public GraphBox createPipelineGraphBox(Skin skin, String id, JsonValue data) {
    final GraphBoxImpl result = createGraphBox(id);
    addConfigurationInputsAndOutputs(result);
    final GradientWidget gradientWidget = new GradientWidget();
    gradientWidget.setSize(300, 40);
    if (data != null) {
        JsonValue points = data.get("points");
        for (String point : points.asStringArray()) {
            String[] split = point.split(",");
            gradientWidget.createPoint(Color.valueOf(split[0]), Float.parseFloat(split[1]));
        }
    } else {
        gradientWidget.createPoint(Color.WHITE, 0);
    }
    gradientWidget.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            gradientWidget.fire(new GraphChangedEvent(false, true));
        }
    });
    gradientWidget.setListener(new GradientWidget.GradientWidgetListener() {

        @Override
        public void colorPickerShow(final ColorPoint point, final Runnable onSuccess) {
            final ColorPicker picker = new ColorPicker();
            picker.setColor(point.color);
            picker.setListener(new ColorPickerAdapter() {

                @Override
                public void finished(Color newColor) {
                    point.color.set(newColor);
                    picker.dispose();
                    onSuccess.run();
                    result.getActor().fire(new GraphChangedEvent(false, true));
                }

                @Override
                public void canceled(Color oldColor) {
                    picker.dispose();
                }
            });
            gradientWidget.getStage().addActor(picker.fadeIn());
        }
    });
    result.addGraphBoxPart(new GraphBoxPartImpl(gradientWidget, new GraphBoxPartImpl.Callback() {

        @Override
        public void serialize(JsonValue object) {
            Array<ColorPoint> points = gradientWidget.getPoints();
            JsonValue pointsValue = new JsonValue(JsonValue.ValueType.array);
            for (ColorPoint point : points) {
                pointsValue.addChild(new JsonValue(point.color.toString() + "," + SimpleNumberFormatter.format(point.pos)));
            }
            object.addChild("points", pointsValue);
        }
    }));
    final VisSelectBox<ClampMethod> clampMethodSelectBox = new VisSelectBox<ClampMethod>();
    clampMethodSelectBox.setItems(ClampMethod.values());
    if (data != null)
        clampMethodSelectBox.setSelected(ClampMethod.valueOf(data.getString("clamp", "Normal")));
    clampMethodSelectBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            result.getActor().fire(new GraphChangedEvent(false, true));
        }
    });
    VisTable clampActor = new VisTable();
    clampActor.add("Clamp method:").row();
    clampActor.add(clampMethodSelectBox).growX();
    result.addGraphBoxPart(new GraphBoxPartImpl(clampActor, new GraphBoxPartImpl.Callback() {

        @Override
        public void serialize(JsonValue object) {
            object.addChild("clamp", new JsonValue(clampMethodSelectBox.getSelected().name()));
        }
    }));
    return result;
}
Also used : GraphBoxImpl(com.gempukku.libgdx.graph.ui.graph.GraphBoxImpl) GraphChangedEvent(com.gempukku.libgdx.graph.ui.graph.GraphChangedEvent) ColorPicker(com.kotcrab.vis.ui.widget.color.ColorPicker) Color(com.badlogic.gdx.graphics.Color) JsonValue(com.badlogic.gdx.utils.JsonValue) GraphBoxPartImpl(com.gempukku.libgdx.graph.ui.graph.GraphBoxPartImpl) VisSelectBox(com.kotcrab.vis.ui.widget.VisSelectBox) VisTable(com.kotcrab.vis.ui.widget.VisTable) GradientWidget(com.talosvfx.talos.editor.widgets.GradientWidget) ClampMethod(com.gempukku.libgdx.graph.shader.ClampMethod) ColorPoint(com.talosvfx.talos.runtime.values.ColorPoint) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) ColorPickerAdapter(com.kotcrab.vis.ui.widget.color.ColorPickerAdapter)

Example 4 with ClampMethod

use of com.gempukku.libgdx.graph.shader.ClampMethod in project gdx-graph by MarcinSc.

the class RemapValueShaderNodeBuilder method buildCommonNode.

@Override
protected ObjectMap<String, ? extends FieldOutput> buildCommonNode(boolean designTime, String nodeId, JsonValue data, ObjectMap<String, FieldOutput> inputs, ObjectSet<String> producedOutputs, CommonShaderBuilder commonShaderBuilder, GraphShaderContext graphShaderContext, GraphShader graphShader) {
    FieldOutput inputValue = inputs.get("input");
    Array<Vector2> pointArray = new Array<>();
    JsonValue points = data.get("points");
    for (String point : points.asStringArray()) {
        String[] split = point.split(",");
        pointArray.add(new Vector2(Float.parseFloat(split[0]), Float.parseFloat(split[1])));
    }
    ClampMethod clampMethod = ClampMethod.valueOf(data.getString("clamp", "Normal"));
    String remapValueFunctionName = "remapValue_" + nodeId;
    String functionText = createRemapValueFunction(remapValueFunctionName, pointArray, clampMethod);
    commonShaderBuilder.addFunction(remapValueFunctionName, functionText);
    String name = "result_" + nodeId;
    commonShaderBuilder.addMainLine("// Remap Value node");
    commonShaderBuilder.addMainLine("float " + name + " = " + remapValueFunctionName + "(" + inputValue + ");");
    return LibGDXCollections.singletonMap("output", new DefaultFieldOutput(ShaderFieldType.Float, name));
}
Also used : Array(com.badlogic.gdx.utils.Array) Vector2(com.badlogic.gdx.math.Vector2) ClampMethod(com.gempukku.libgdx.graph.shader.ClampMethod) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) JsonValue(com.badlogic.gdx.utils.JsonValue) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Aggregations

JsonValue (com.badlogic.gdx.utils.JsonValue)4 ClampMethod (com.gempukku.libgdx.graph.shader.ClampMethod)4 Vector2 (com.badlogic.gdx.math.Vector2)2 Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)2 Array (com.badlogic.gdx.utils.Array)2 DefaultFieldOutput (com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)2 GraphBoxImpl (com.gempukku.libgdx.graph.ui.graph.GraphBoxImpl)2 GraphBoxPartImpl (com.gempukku.libgdx.graph.ui.graph.GraphBoxPartImpl)2 GraphChangedEvent (com.gempukku.libgdx.graph.ui.graph.GraphChangedEvent)2 VisSelectBox (com.kotcrab.vis.ui.widget.VisSelectBox)2 VisTable (com.kotcrab.vis.ui.widget.VisTable)2 Color (com.badlogic.gdx.graphics.Color)1 ColorPicker (com.kotcrab.vis.ui.widget.color.ColorPicker)1 ColorPickerAdapter (com.kotcrab.vis.ui.widget.color.ColorPickerAdapter)1 CurveWidget (com.talosvfx.talos.editor.widgets.CurveWidget)1 GradientWidget (com.talosvfx.talos.editor.widgets.GradientWidget)1 ColorPoint (com.talosvfx.talos.runtime.values.ColorPoint)1