Search in sources :

Example 21 with ShaderFieldType

use of com.gempukku.libgdx.graph.shader.field.ShaderFieldType 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 22 with ShaderFieldType

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

the class StepShaderNodeBuilder 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 edgeValue = inputs.get("edge");
    if (edgeValue == null)
        edgeValue = new DefaultFieldOutput(ShaderFieldType.Float, "1.0");
    ShaderFieldType resultType = inputValue.getFieldType();
    commonShaderBuilder.addMainLine("// Step node");
    String name = "result_" + nodeId;
    commonShaderBuilder.addMainLine(resultType.getShaderType() + " " + name + " = step(" + edgeValue.getRepresentation() + ", " + 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 23 with ShaderFieldType

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

the class LogarithmBase2ShaderNodeBuilder 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("// Logarithm base 2 node");
    String name = "result_" + nodeId;
    commonShaderBuilder.addMainLine(resultType.getShaderType() + " " + name + " = log2(" + inputValue.getRepresentation() + ");");
    return LibGDXCollections.singletonMap("output", new DefaultFieldOutput(ShaderFieldType.Float, 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 24 with ShaderFieldType

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

the class NaturalLogarithmShaderNodeBuilder 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("// Natural logarithm node");
    String name = "result_" + nodeId;
    commonShaderBuilder.addMainLine(resultType.getShaderType() + " " + name + " = log(" + inputValue.getRepresentation() + ");");
    return LibGDXCollections.singletonMap("output", new DefaultFieldOutput(ShaderFieldType.Float, 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 25 with ShaderFieldType

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

the class LimitedCapacitySpriteBatchModel method updateSpriteData.

private void updateSpriteData(RenderableSprite sprite, int spriteIndex) {
    int spriteDataStart = getSpriteDataStart(spriteIndex);
    for (VertexAttribute vertexAttribute : vertexAttributes) {
        PropertySource propertySource = vertexPropertySources.get(vertexAttribute);
        int attributeOffset = vertexAttribute.offset / 4;
        ShaderFieldType shaderFieldType = propertySource.getShaderFieldType();
        Object attributeValue = sprite.getPropertyContainer().getValue(propertySource.getPropertyName());
        if (attributeValue instanceof ValuePerVertex) {
            for (int vertexIndex = 0; vertexIndex < 4; vertexIndex++) {
                int vertexOffset = spriteDataStart + vertexIndex * floatCountPerVertex;
                Object vertexValue = ((ValuePerVertex) attributeValue).getValue(vertexIndex);
                shaderFieldType.setValueInAttributesArray(vertexData, vertexOffset + attributeOffset, propertySource.getValueToUse(vertexValue));
            }
        } else {
            attributeValue = propertySource.getValueToUse(attributeValue);
            for (int vertexIndex = 0; vertexIndex < 4; vertexIndex++) {
                int vertexOffset = spriteDataStart + vertexIndex * floatCountPerVertex;
                shaderFieldType.setValueInAttributesArray(vertexData, vertexOffset + attributeOffset, attributeValue);
            }
        }
    }
    markSpriteUpdated(spriteIndex);
}
Also used : ShaderFieldType(com.gempukku.libgdx.graph.shader.field.ShaderFieldType) ValuePerVertex(com.gempukku.libgdx.graph.util.ValuePerVertex) PropertySource(com.gempukku.libgdx.graph.shader.property.PropertySource)

Aggregations

ShaderFieldType (com.gempukku.libgdx.graph.shader.field.ShaderFieldType)55 DefaultFieldOutput (com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)43 ObjectMap (com.badlogic.gdx.utils.ObjectMap)7 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)3 FrameBuffer (com.badlogic.gdx.graphics.glutils.FrameBuffer)3 Array (com.badlogic.gdx.utils.Array)3 GraphProperty (com.gempukku.libgdx.graph.data.GraphProperty)3 DefaultTimeKeeper (com.gempukku.libgdx.graph.util.DefaultTimeKeeper)3 PropertyContainer (com.gempukku.libgdx.graph.pipeline.producer.rendering.producer.PropertyContainer)2 PropertySource (com.gempukku.libgdx.graph.shader.property.PropertySource)2 ValuePerVertex (com.gempukku.libgdx.graph.util.ValuePerVertex)2 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 Texture (com.badlogic.gdx.graphics.Texture)1 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)1 VertexAttributes (com.badlogic.gdx.graphics.VertexAttributes)1 TextureDescriptor (com.badlogic.gdx.graphics.g3d.utils.TextureDescriptor)1 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1 IntArray (com.badlogic.gdx.utils.IntArray)1 JsonValue (com.badlogic.gdx.utils.JsonValue)1 PropertyNodeConfiguration (com.gempukku.libgdx.graph.config.PropertyNodeConfiguration)1