Search in sources :

Example 36 with DefaultFieldOutput

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

the class DegreesShaderNodeBuilder 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");
    ShaderFieldType resultType = inputValue.getFieldType();
    commonShaderBuilder.addMainLine("// Degrees node");
    String name = "result_" + nodeId;
    commonShaderBuilder.addMainLine(resultType.getShaderType() + " " + name + " = degrees(" + inputValue.getRepresentation() + ");");
    return LibGDXCollections.singletonMap("output", new DefaultFieldOutput(resultType, name));
}
Also used : DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) ShaderFieldType(com.gempukku.libgdx.graph.shader.field.ShaderFieldType) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Example 37 with DefaultFieldOutput

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

the class RemapShaderNodeBuilder 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");
    FieldOutput fromValue = inputs.get("from");
    FieldOutput toValue = inputs.get("to");
    ShaderFieldType resultType = inputValue.getFieldType();
    String functionName = appendRemapFunction(commonShaderBuilder, resultType);
    commonShaderBuilder.addMainLine("// Remap node");
    String name = "result_" + nodeId;
    commonShaderBuilder.addMainLine(resultType.getShaderType() + " " + name + " = " + functionName + "(" + inputValue.getRepresentation() + ", " + fromValue.getRepresentation() + ", " + toValue.getRepresentation() + ");");
    return LibGDXCollections.singletonMap("output", new DefaultFieldOutput(resultType, name));
}
Also used : DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) ShaderFieldType(com.gempukku.libgdx.graph.shader.field.ShaderFieldType) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Example 38 with DefaultFieldOutput

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

the class RemapVectorShaderNodeBuilder 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");
    String x = processValue(data.getString("x"), inputValue);
    String y = processValue(data.getString("y"), inputValue);
    String z = processValue(data.getString("z"), inputValue);
    String w = processValue(data.getString("w"), inputValue);
    commonShaderBuilder.addMainLine("// Merge Vector Node");
    ObjectMap<String, DefaultFieldOutput> result = new ObjectMap<>();
    if (producedOutputs.contains("v2")) {
        String name = "v2_" + nodeId;
        commonShaderBuilder.addMainLine("vec2 " + name + " = vec2(" + x + ", " + y + ");");
        result.put("v2", new DefaultFieldOutput(ShaderFieldType.Vector2, name));
    }
    if (producedOutputs.contains("v3")) {
        String name = "v3_" + nodeId;
        commonShaderBuilder.addMainLine("vec3 " + name + " = vec3(" + x + ", " + y + ", " + z + ");");
        result.put("v3", new DefaultFieldOutput(ShaderFieldType.Vector3, name));
    }
    if (producedOutputs.contains("color")) {
        String name = "color_" + nodeId;
        commonShaderBuilder.addMainLine("vec4 " + name + " = vec4(" + x + ", " + y + ", " + z + ", " + w + ");");
        result.put("color", new DefaultFieldOutput(ShaderFieldType.Vector4, name));
    }
    return result;
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Example 39 with DefaultFieldOutput

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

the class PerlinNoise2DShaderNodeBuilder 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 uvValue = inputs.get("uv");
    FieldOutput progressValue = inputs.get("progress");
    FieldOutput scaleValue = inputs.get("scale");
    FieldOutput rangeValue = inputs.get("range");
    String scale = scaleValue != null ? scaleValue.getRepresentation() : "1.0";
    String name = "result_" + nodeId;
    String output;
    commonShaderBuilder.addMainLine("// Perlin noise 2D node");
    if (progressValue != null) {
        loadFragmentIfNotDefined(commonShaderBuilder, "noise/common");
        loadFragmentIfNotDefined(commonShaderBuilder, "noise/perlinNoise3d");
        if (uvValue.getFieldType().getName().equals(ShaderFieldType.Vector2)) {
            output = "perlinNoise3d(vec3(" + uvValue.getRepresentation() + " * " + scale + ", " + progressValue.getRepresentation() + "))";
        } else {
            output = "perlinNoise3d(vec3(" + uvValue.getRepresentation() + " * " + scale + ", 0.0, " + progressValue.getRepresentation() + "))";
        }
    } else {
        loadFragmentIfNotDefined(commonShaderBuilder, "noise/common");
        loadFragmentIfNotDefined(commonShaderBuilder, "noise/perlinNoise2d");
        if (uvValue.getFieldType().getName().equals(ShaderFieldType.Vector2)) {
            output = "perlinNoise2d(" + uvValue.getRepresentation() + " * " + scale + ")";
        } else {
            output = "perlinNoise2d(vec2(" + uvValue.getRepresentation() + ", 0.0) * " + scale + ")";
        }
    }
    String noiseRange = "vec2(-1.0, 1.0)";
    if (rangeValue != null) {
        String functionName = RemapShaderNodeBuilder.appendRemapFunction(commonShaderBuilder, ShaderFieldTypeRegistry.findShaderFieldType(ShaderFieldType.Float));
        commonShaderBuilder.addMainLine("float " + name + " = " + functionName + "(" + output + ", " + noiseRange + ", " + rangeValue.getRepresentation() + ");");
    } else {
        commonShaderBuilder.addMainLine("float " + name + " = " + output + ";");
    }
    return LibGDXCollections.singletonMap("output", new DefaultFieldOutput(ShaderFieldType.Float, name));
}
Also used : DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Example 40 with DefaultFieldOutput

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

the class TimeGraphShaderNodeBuilder method buildCommonNode.

@Override
protected ObjectMap<String, ? extends FieldOutput> buildCommonNode(boolean designTime, String nodeId, JsonValue data, ObjectMap<String, FieldOutput> inputs, ObjectSet<String> producedOutputs, CommonShaderBuilder commonShaderBuilder, final GraphShaderContext graphShaderContext, GraphShader graphShader) {
    float multiplier = data.getFloat("multiplier", 1f);
    ObjectMap<String, FieldOutput> result = new ObjectMap<>();
    if (producedOutputs.contains("time")) {
        commonShaderBuilder.addUniformVariable("u_time", "float", true, UniformSetters.time, "Time");
        result.put("time", new DefaultFieldOutput(ShaderFieldType.Float, "(u_time * " + SimpleNumberFormatter.format(multiplier) + ")"));
    }
    if (producedOutputs.contains("sinTime")) {
        String name = "u_sinTime_" + nodeId;
        commonShaderBuilder.addUniformVariable(name, "float", true, new UniformSetters.SinTime(multiplier), "sin(Time)");
        result.put("sinTime", new DefaultFieldOutput(ShaderFieldType.Float, name));
    }
    if (producedOutputs.contains("cosTime")) {
        String name = "u_cosTime_" + nodeId;
        commonShaderBuilder.addUniformVariable(name, "float", true, new UniformSetters.CosTime(multiplier), "cos(Time)");
        result.put("cosTime", new DefaultFieldOutput(ShaderFieldType.Float, name));
    }
    if (producedOutputs.contains("deltaTime")) {
        String name = "u_deltaTime_" + nodeId;
        commonShaderBuilder.addUniformVariable(name, "float", true, new UniformSetters.DeltaTime(multiplier), "Delta time");
        result.put("deltaTime", new DefaultFieldOutput(ShaderFieldType.Float, name));
    }
    return result;
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) UniformSetters(com.gempukku.libgdx.graph.shader.UniformSetters) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Aggregations

DefaultFieldOutput (com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)106 ShaderFieldType (com.gempukku.libgdx.graph.shader.field.ShaderFieldType)43 ObjectMap (com.badlogic.gdx.utils.ObjectMap)17 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)7 Texture (com.badlogic.gdx.graphics.Texture)6 TextureDescriptor (com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor)6 Array (com.badlogic.gdx.utils.Array)6 LightColor (com.gempukku.libgdx.graph.plugin.lighting3d.LightColor)5 Lighting3DEnvironment (com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment)5 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)4 Lighting3DPrivateData (com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DPrivateData)4 Lights3DProvider (com.gempukku.libgdx.graph.plugin.lighting3d.provider.Lights3DProvider)4 BasicShader (com.gempukku.libgdx.graph.shader.BasicShader)4 ShaderContext (com.gempukku.libgdx.graph.shader.ShaderContext)4 UniformRegistry (com.gempukku.libgdx.graph.shader.UniformRegistry)4 JsonValue (com.badlogic.gdx.utils.JsonValue)2 BoneTransformFieldType (com.gempukku.libgdx.graph.plugin.boneanimation.property.BoneTransformFieldType)2 ClampMethod (com.gempukku.libgdx.graph.shader.ClampMethod)2 Color (com.badlogic.gdx.graphics.Color)1 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1