Search in sources :

Example 46 with DefaultFieldOutput

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

the class TextureRegionShaderFieldType method addAsVertexAttribute.

@Override
public GraphShaderNodeBuilder.FieldOutput addAsVertexAttribute(VertexShaderBuilder vertexShaderBuilder, JsonValue data, final PropertySource propertySource) {
    final TextureDescriptor<Texture> textureDescriptor = new TextureDescriptor<>();
    if (data.has("minFilter"))
        textureDescriptor.minFilter = Texture.TextureFilter.valueOf(data.getString("minFilter"));
    if (data.has("magFilter"))
        textureDescriptor.magFilter = Texture.TextureFilter.valueOf(data.getString("magFilter"));
    if (data.has("uWrap"))
        textureDescriptor.uWrap = Texture.TextureWrap.valueOf(data.getString("uWrap"));
    if (data.has("vWrap"))
        textureDescriptor.vWrap = Texture.TextureWrap.valueOf(data.getString("vWrap"));
    String textureVariableName = propertySource.getUniformName();
    String uvTransformAttributeName = propertySource.getAttributeName();
    vertexShaderBuilder.addUniformVariable(textureVariableName, "sampler2D", false, new UniformRegistry.UniformSetter() {

        @Override
        public void set(BasicShader shader, int location, ShaderContext shaderContext) {
            Object value = propertySource.getPropertyName();
            value = propertySource.getValueToUse(value);
            if (value == null)
                value = new TextureRegion(shader.getDefaultTexture());
            textureDescriptor.texture = ((TextureRegion) value).getTexture();
            shader.setUniform(location, textureDescriptor);
        }
    }, "Texture property - " + propertySource.getPropertyName());
    vertexShaderBuilder.addAttributeVariable(new VertexAttribute(1024, 4, uvTransformAttributeName), "vec4", "TextureUV property - " + propertySource.getPropertyName());
    return new DefaultFieldOutput(ShaderFieldType.TextureRegion, uvTransformAttributeName, textureVariableName);
}
Also used : BasicShader(com.gempukku.libgdx.graph.shader.BasicShader) Texture(com.badlogic.gdx.graphics.Texture) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) UniformRegistry(com.gempukku.libgdx.graph.shader.UniformRegistry) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) ShaderContext(com.gempukku.libgdx.graph.shader.ShaderContext) TextureDescriptor(com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor)

Example 47 with DefaultFieldOutput

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

the class TextureRegionShaderFieldType method addAsLocalUniform.

@Override
public GraphShaderNodeBuilder.FieldOutput addAsLocalUniform(CommonShaderBuilder commonShaderBuilder, JsonValue data, final PropertySource propertySource) {
    final String name = propertySource.getPropertyName();
    final TextureDescriptor<Texture> textureDescriptor = new TextureDescriptor<>();
    if (data.has("minFilter"))
        textureDescriptor.minFilter = Texture.TextureFilter.valueOf(data.getString("minFilter"));
    if (data.has("magFilter"))
        textureDescriptor.magFilter = Texture.TextureFilter.valueOf(data.getString("magFilter"));
    if (data.has("uWrap"))
        textureDescriptor.uWrap = Texture.TextureWrap.valueOf(data.getString("uWrap"));
    if (data.has("vWrap"))
        textureDescriptor.vWrap = Texture.TextureWrap.valueOf(data.getString("vWrap"));
    String textureVariableName = propertySource.getUniformName();
    String uvTransformVariableName = "u_uvTransform_" + propertySource.getPropertyIndex();
    commonShaderBuilder.addUniformVariable(textureVariableName, "sampler2D", false, new UniformRegistry.UniformSetter() {

        @Override
        public void set(BasicShader shader, int location, ShaderContext shaderContext) {
            Object value = shaderContext.getLocalProperty(name);
            value = propertySource.getValueToUse(value);
            if (value == null)
                value = new TextureRegion(shader.getDefaultTexture());
            textureDescriptor.texture = ((TextureRegion) value).getTexture();
            shader.setUniform(location, textureDescriptor);
        }
    }, "Texture property - " + name);
    commonShaderBuilder.addUniformVariable(uvTransformVariableName, "vec4", false, new UniformRegistry.UniformSetter() {

        @Override
        public void set(BasicShader shader, int location, ShaderContext shaderContext) {
            Object value = shaderContext.getLocalProperty(name);
            value = propertySource.getValueToUse(value);
            if (value == null)
                value = new TextureRegion(shader.getDefaultTexture());
            TextureRegion region = (TextureRegion) value;
            shader.setUniform(location, region.getU(), region.getV(), region.getU2() - region.getU(), region.getV2() - region.getV());
        }
    }, "Texture UV property - " + name);
    return new DefaultFieldOutput(getName(), uvTransformVariableName, textureVariableName);
}
Also used : BasicShader(com.gempukku.libgdx.graph.shader.BasicShader) Texture(com.badlogic.gdx.graphics.Texture) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) UniformRegistry(com.gempukku.libgdx.graph.shader.UniformRegistry) ShaderContext(com.gempukku.libgdx.graph.shader.ShaderContext) TextureDescriptor(com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor)

Example 48 with DefaultFieldOutput

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

the class ValueColorShaderNodeBuilder 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) {
    final Color color = Color.valueOf(data.getString("color"));
    String value = "vec4(" + format(color.r) + ", " + format(color.g) + ", " + format(color.b) + ", " + format(color.a) + ")";
    return LibGDXCollections.singletonMap("value", new DefaultFieldOutput(ShaderFieldType.Vector4, value));
}
Also used : Color(com.badlogic.gdx.graphics.Color) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Example 49 with DefaultFieldOutput

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

the class ValueVector3ShaderNodeBuilder 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) {
    float v1 = data.getFloat("v1");
    float v2 = data.getFloat("v2");
    float v3 = data.getFloat("v3");
    return LibGDXCollections.singletonMap("value", new DefaultFieldOutput(ShaderFieldType.Vector3, "vec3(" + format(v1) + ", " + format(v2) + ", " + format(v3) + ")"));
}
Also used : DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Example 50 with DefaultFieldOutput

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

the class Sampler2DShaderNodeBuilder 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 textureValue = inputs.get("texture");
    FieldOutput uvValue = inputs.get("uv");
    commonShaderBuilder.addMainLine("// Sampler2D Node");
    ObjectMap<String, FieldOutput> result = new ObjectMap<>();
    String colorName = "color_" + nodeId;
    commonShaderBuilder.addMainLine("vec4 " + colorName + " = texture2D(" + textureValue.getSamplerRepresentation() + ", " + textureValue.getRepresentation() + ".xy + " + uvValue.getRepresentation() + " * " + textureValue.getRepresentation() + ".zw);");
    result.put("color", new DefaultFieldOutput(ShaderFieldType.Vector4, colorName));
    if (producedOutputs.contains("r")) {
        String name = "r_" + nodeId;
        commonShaderBuilder.addMainLine("float " + name + " = " + colorName + ".r;");
        result.put("r", new DefaultFieldOutput(ShaderFieldType.Float, name));
    }
    if (producedOutputs.contains("g")) {
        String name = "g_" + nodeId;
        commonShaderBuilder.addMainLine("float " + name + " = " + colorName + ".g;");
        result.put("g", new DefaultFieldOutput(ShaderFieldType.Float, name));
    }
    if (producedOutputs.contains("b")) {
        String name = "b_" + nodeId;
        commonShaderBuilder.addMainLine("float " + name + " = " + colorName + ".b;");
        result.put("b", new DefaultFieldOutput(ShaderFieldType.Float, name));
    }
    if (producedOutputs.contains("a")) {
        String name = "a_" + nodeId;
        commonShaderBuilder.addMainLine("float " + name + " = " + colorName + ".a;");
        result.put("a", new DefaultFieldOutput(ShaderFieldType.Float, 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)

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