Search in sources :

Example 51 with DefaultFieldOutput

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

the class UVTilingAndOffsetShaderNodeBuilder 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 tilingValue = inputs.get("tiling");
    FieldOutput offsetValue = inputs.get("offset");
    if (tilingValue == null)
        tilingValue = new DefaultFieldOutput(ShaderFieldType.Vector2, "vec2(1.0)");
    if (offsetValue == null)
        offsetValue = new DefaultFieldOutput(ShaderFieldType.Vector2, "vec2(0.0)");
    commonShaderBuilder.addMainLine("// UV Tiling & Offset Node");
    String resultName = "result_" + nodeId;
    commonShaderBuilder.addMainLine("vec2 " + resultName + " = " + uvValue + " * " + tilingValue + " + " + offsetValue + ";");
    return LibGDXCollections.singletonMap("output", new DefaultFieldOutput(ShaderFieldType.Vector2, resultName));
}
Also used : DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Example 52 with DefaultFieldOutput

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

the class Vector4ShaderFieldType method addAsVertexAttribute.

@Override
public GraphShaderNodeBuilder.FieldOutput addAsVertexAttribute(VertexShaderBuilder vertexShaderBuilder, JsonValue data, PropertySource propertySource) {
    String attributeName = propertySource.getAttributeName();
    vertexShaderBuilder.addAttributeVariable(new VertexAttribute(1024, 4, attributeName), getShaderType(), "Vector4 property - " + propertySource.getPropertyName());
    return new DefaultFieldOutput(getName(), attributeName);
}
Also used : VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Example 53 with DefaultFieldOutput

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

the class SkinningShaderNodeBuilder 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) {
    FieldOutput boneWeights = inputs.get("boneWeights");
    FieldOutput boneTransformations = inputs.get("boneTransformations");
    BoneTransformFieldType boneTransformFieldType = (BoneTransformFieldType) boneTransformations.getFieldType();
    String boneTransformVariableName = boneTransformations.getRepresentation();
    String boneWeightVariableName = boneWeights.getRepresentation() + "_";
    int boneTransformCount = boneTransformFieldType.getArrayLength();
    String skinningMatrixName = "skinning_" + nodeId;
    String functionName = "getSkinning_" + nodeId;
    if (!vertexShaderBuilder.containsFunction(functionName)) {
        StringBuilder getSkinning = new StringBuilder();
        getSkinning.append("mat4 " + functionName + "() {\n");
        getSkinning.append("  mat4 skinning = mat4(0.0);\n");
        for (int i = 0; i < boneTransformCount; i++) {
            getSkinning.append("  skinning += (").append(boneWeightVariableName).append(i).append(".y) * " + boneTransformVariableName + "[int(").append(boneWeightVariableName).append(i).append(".x)];\n");
        }
        getSkinning.append("  return skinning;\n");
        getSkinning.append("}\n");
        vertexShaderBuilder.addFunction(functionName, getSkinning.toString());
        vertexShaderBuilder.addMainLine("mat4 " + skinningMatrixName + " = " + functionName + "();");
    }
    ObjectMap<String, FieldOutput> result = new ObjectMap<>();
    if (producedOutputs.contains("skinnedPosition")) {
        String positionVarying = "v_skinning_position_" + nodeId;
        if (!vertexShaderBuilder.hasVaryingVariable(positionVarying)) {
            FieldOutput position = inputs.get("position");
            String positionField = (position != null) ? position.getRepresentation() : "vec3(0.0, 0.0, 0.0)";
            String variableName = "skinningPosition_" + nodeId;
            vertexShaderBuilder.addMainLine("vec3 " + variableName + " = (" + skinningMatrixName + " * vec4(" + positionField + ", 1.0)).xyz;");
            vertexShaderBuilder.addVaryingVariable(positionVarying, "vec3");
            vertexShaderBuilder.addMainLine(positionVarying + " = " + variableName + ";");
        }
        if (!fragmentShaderBuilder.hasVaryingVariable(positionVarying)) {
            fragmentShaderBuilder.addVaryingVariable(positionVarying, "vec3");
        }
        result.put("skinnedPosition", new DefaultFieldOutput(ShaderFieldType.Vector3, positionVarying));
    }
    if (producedOutputs.contains("skinnedNormal")) {
        String normalVarying = "v_skinning_normal_" + nodeId;
        if (!vertexShaderBuilder.hasVaryingVariable(normalVarying)) {
            FieldOutput normal = inputs.get("normal");
            String normalField = (normal != null) ? normal.getRepresentation() : "vec3(0.0, 1.0, 0.0)";
            String variableName = "skinningNormal_" + nodeId;
            vertexShaderBuilder.addMainLine("vec3 " + variableName + " = normalize((" + skinningMatrixName + " * vec4(" + normalField + ", 0.0)).xyz);");
            vertexShaderBuilder.addVaryingVariable(normalVarying, "vec3");
            vertexShaderBuilder.addMainLine(normalVarying + " = " + variableName + ";");
        }
        if (!fragmentShaderBuilder.hasVaryingVariable(normalVarying)) {
            fragmentShaderBuilder.addVaryingVariable(normalVarying, "vec3");
        }
        result.put("skinnedNormal", new DefaultFieldOutput(ShaderFieldType.Vector3, normalVarying));
    }
    return result;
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) BoneTransformFieldType(com.gempukku.libgdx.graph.plugin.boneanimation.property.BoneTransformFieldType) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Example 54 with DefaultFieldOutput

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

the class SkinningShaderNodeBuilder method buildVertexNodeSingleInputs.

@Override
protected ObjectMap<String, ? extends FieldOutput> buildVertexNodeSingleInputs(boolean designTime, String nodeId, JsonValue data, ObjectMap<String, FieldOutput> inputs, ObjectSet<String> producedOutputs, VertexShaderBuilder vertexShaderBuilder, GraphShaderContext graphShaderContext, GraphShader graphShader) {
    FieldOutput boneWeights = inputs.get("boneWeights");
    BoneWeightFieldType boneWeightFieldType = (BoneWeightFieldType) boneWeights.getFieldType();
    FieldOutput boneTransformations = inputs.get("boneTransformations");
    BoneTransformFieldType boneTransformFieldType = (BoneTransformFieldType) boneTransformations.getFieldType();
    String boneTransformVariableName = boneTransformations.getRepresentation();
    String boneWeightVariableName = boneWeights.getRepresentation() + "_";
    int boneWeightCount = boneWeightFieldType.getArrayLength();
    String functionName = "getSkinning_" + nodeId;
    String skinningMatrixName = "skinning_" + nodeId;
    if (!vertexShaderBuilder.containsFunction(functionName)) {
        StringBuilder getSkinning = new StringBuilder();
        getSkinning.append("mat4 " + functionName + "() {\n");
        getSkinning.append("  mat4 skinning = mat4(0.0);\n");
        for (int i = 0; i < boneWeightCount; i++) {
            getSkinning.append("  skinning += (").append(boneWeightVariableName).append(i).append(".y) * " + boneTransformVariableName + "[int(").append(boneWeightVariableName).append(i).append(".x)];\n");
        }
        getSkinning.append("  return skinning;\n");
        getSkinning.append("}\n");
        vertexShaderBuilder.addFunction(functionName, getSkinning.toString());
        vertexShaderBuilder.addMainLine("mat4 " + skinningMatrixName + " = " + functionName + "();");
    }
    ObjectMap<String, FieldOutput> result = new ObjectMap<>();
    if (producedOutputs.contains("skinnedPosition")) {
        String positionVarying = "v_skinning_position_" + nodeId;
        if (!vertexShaderBuilder.hasVaryingVariable(positionVarying)) {
            FieldOutput position = inputs.get("position");
            String positionField = (position != null) ? position.getRepresentation() : "vec3(0.0, 0.0, 0.0)";
            String variableName = "skinningPosition_" + nodeId;
            vertexShaderBuilder.addMainLine("vec3 " + variableName + " = (" + skinningMatrixName + " * vec4(" + positionField + ", 1.0)).xyz;");
            vertexShaderBuilder.addVaryingVariable(positionVarying, "vec3");
            vertexShaderBuilder.addMainLine(positionVarying + " = " + variableName + ";");
            result.put("skinnedPosition", new DefaultFieldOutput(ShaderFieldType.Vector3, variableName));
        }
    }
    if (producedOutputs.contains("skinnedNormal")) {
        String normalVarying = "v_skinning_normal_" + nodeId;
        if (!vertexShaderBuilder.hasVaryingVariable(normalVarying)) {
            FieldOutput normal = inputs.get("normal");
            String normalField = (normal != null) ? normal.getRepresentation() : "vec3(0.0, 1.0, 0.0)";
            String variableName = "skinningNormal_" + nodeId;
            vertexShaderBuilder.addMainLine("vec3 " + variableName + " = normalize((" + skinningMatrixName + " * vec4(" + normalField + ", 0.0)).xyz);");
            vertexShaderBuilder.addVaryingVariable(normalVarying, "vec3");
            vertexShaderBuilder.addMainLine(normalVarying + " = " + variableName + ";");
            result.put("skinnedNormal", new DefaultFieldOutput(ShaderFieldType.Vector3, variableName));
        }
    }
    return result;
}
Also used : BoneWeightFieldType(com.gempukku.libgdx.graph.plugin.boneanimation.property.BoneWeightFieldType) ObjectMap(com.badlogic.gdx.utils.ObjectMap) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) BoneTransformFieldType(com.gempukku.libgdx.graph.plugin.boneanimation.property.BoneTransformFieldType) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Example 55 with DefaultFieldOutput

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

the class ModelFragmentCoordinateShaderNodeBuilder 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) {
    commonShaderBuilder.addUniformVariable("u_viewportSize", "vec2", true, UniformSetters.viewportSize, "Viewport size");
    commonShaderBuilder.addUniformVariable("u_projViewTrans", "mat4", true, UniformSetters.projViewTrans, "Projection-view transformation");
    commonShaderBuilder.addUniformVariable("u_worldTrans", "mat4", false, ModelsUniformSetters.worldTrans, "Model to world transformation");
    String tmpName = "tmp_" + nodeId;
    String resultName = "result_" + nodeId;
    commonShaderBuilder.addMainLine("// Model Fragment Coordinate Node");
    commonShaderBuilder.addMainLine("vec4 " + tmpName + " = u_projViewTrans * u_worldTrans * vec4(0.0, 0.0, 0.0, 1.0);");
    commonShaderBuilder.addMainLine("vec2 " + resultName + " = u_viewportSize * (" + tmpName + ".xy / " + tmpName + ".w + 1.0) / 2.0;");
    return LibGDXCollections.singletonMap("output", new DefaultFieldOutput(ShaderFieldType.Vector2, resultName));
}
Also used : 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