Search in sources :

Example 96 with DefaultFieldOutput

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

the class VoronoiBorder2DShaderNodeBuilder 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 scaleValue = inputs.get("scale");
    FieldOutput progressValue = inputs.get("progress");
    String scale = (scaleValue != null) ? scaleValue.getRepresentation() : "1.0";
    String progress = (progressValue != null) ? progressValue.getRepresentation() : "0.0";
    loadFragmentIfNotDefined(commonShaderBuilder, "voronoiBorder2d");
    commonShaderBuilder.addMainLine("// Voronoi border 2D node");
    String name = "result_" + nodeId;
    String output;
    if (uvValue.getFieldType().getName().equals(ShaderFieldType.Vector2)) {
        output = "voronoiBorder2d(" + uvValue.getRepresentation() + " * " + scale + ", " + progress + ")";
    } else {
        output = "voronoiBorder2d(vec2(" + uvValue.getRepresentation() + ", 0.0) * " + scale + ", " + progress + ")";
    }
    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 97 with DefaultFieldOutput

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

the class SceneColorShaderNodeBuilder 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) {
    graphShader.setUsingColorTexture(true);
    String textureName = "u_" + nodeId;
    String transformName = "u_UV" + nodeId;
    final TextureDescriptor<Texture> textureDescriptor = new TextureDescriptor<>();
    if (data != null && data.has("minFilter"))
        textureDescriptor.minFilter = Texture.TextureFilter.valueOf(data.getString("minFilter"));
    if (data != null && data.has("magFilter"))
        textureDescriptor.magFilter = Texture.TextureFilter.valueOf(data.getString("magFilter"));
    if (data != null && data.has("uWrap"))
        textureDescriptor.uWrap = Texture.TextureWrap.valueOf(data.getString("uWrap"));
    if (data != null && data.has("vWrap"))
        textureDescriptor.vWrap = Texture.TextureWrap.valueOf(data.getString("vWrap"));
    commonShaderBuilder.addUniformVariable(textureName, "sampler2D", true, new UniformRegistry.UniformSetter() {

        @Override
        public void set(BasicShader shader, int location, ShaderContext shaderContext) {
            textureDescriptor.texture = shaderContext.getColorTexture();
            shader.setUniform(location, textureDescriptor);
        }
    }, "Scene color texture");
    commonShaderBuilder.addUniformVariable(transformName, "vec4", false, new UniformRegistry.UniformSetter() {

        @Override
        public void set(BasicShader shader, int location, ShaderContext shaderContext) {
            shader.setUniform(location, 0f, 0f, 1f, 1f);
        }
    }, "Scene color texture UVs");
    return LibGDXCollections.singletonMap("texture", new DefaultFieldOutput(ShaderFieldType.TextureRegion, transformName, textureName));
}
Also used : TextureDescriptor(com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor) Texture(com.badlogic.gdx.graphics.Texture) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Example 98 with DefaultFieldOutput

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

the class ScreenPositionShaderNodeBuilder method buildFragmentNodeSingleInputs.

@Override
protected ObjectMap<String, ? extends FieldOutput> buildFragmentNodeSingleInputs(boolean designTime, String nodeId, JsonValue data, ObjectMap<String, FieldOutput> inputs, ObjectSet<String> producedOutputs, VertexShaderBuilder vertexShaderBuilder, FragmentShaderBuilder fragmentShaderBuilder, GraphShaderContext graphShaderContext, GraphShader graphShader) {
    fragmentShaderBuilder.addUniformVariable("u_pixelSize", "vec2", true, UniformSetters.pixelSize, "Pixel size");
    String name = "result_" + nodeId;
    fragmentShaderBuilder.addMainLine("// Screen Position node");
    fragmentShaderBuilder.addMainLine("vec2 " + name + " = gl_FragCoord.xy * u_pixelSize;");
    return LibGDXCollections.singletonMap("output", new DefaultFieldOutput(ShaderFieldType.Vector2, name));
}
Also used : DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Example 99 with DefaultFieldOutput

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

the class RectangleShapeShaderNodeBuilder 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 sizeValue = inputs.get("size");
    FieldOutput borderValue = inputs.get("border");
    if (sizeValue != null && sizeValue.getFieldType().getName().equals(ShaderFieldType.Float))
        sizeValue = new DefaultFieldOutput(ShaderFieldType.Vector2, "vec2(" + sizeValue.getRepresentation() + ")");
    String uv = uvValue.getRepresentation();
    String size = sizeValue != null ? sizeValue.getRepresentation() : "vec2(1.0)";
    String border = borderValue != null ? borderValue.getRepresentation() : "0.0";
    commonShaderBuilder.addMainLine("// Rectangle shape node");
    String temp1 = "temp_" + nodeId;
    String name = "result_" + nodeId;
    String resultType = ShaderFieldType.Float;
    commonShaderBuilder.addMainLine("vec2 " + temp1 + " = abs(" + uv + " * 2.0 - 1.0);");
    commonShaderBuilder.addMainLine("float " + name + " = smoothstep(0.0, " + border + ", min(" + size + ".x - " + temp1 + ".x, " + size + ".y - " + temp1 + ".y));");
    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 100 with DefaultFieldOutput

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

the class ArctanShaderNodeBuilder 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("// Arctangent node");
    String name = "result_" + nodeId;
    commonShaderBuilder.addMainLine(resultType.getShaderType() + " " + name + " = atan(" + 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)

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