Search in sources :

Example 21 with DefaultFieldOutput

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

the class ShadowPhongLightingShaderNodeBuilder method buildFragmentNodeSingleInputs.

@Override
public ObjectMap<String, ? extends FieldOutput> buildFragmentNodeSingleInputs(boolean designTime, String nodeId, final JsonValue data, ObjectMap<String, FieldOutput> inputs, ObjectSet<String> producedOutputs, VertexShaderBuilder vertexShaderBuilder, FragmentShaderBuilder fragmentShaderBuilder, final GraphShaderContext graphShaderContext, final GraphShader graphShader) {
    final String environmentId = data.getString("id", "");
    fragmentShaderBuilder.addStructure("Lighting", "  vec3 diffuse;\n" + "  vec3 specular;\n");
    Lighting3DUtils.configureShadowInformation(fragmentShaderBuilder, nodeId, environmentId, maxNumberOfDirectionalLights, graphShader.getDefaultTexture());
    Lighting3DUtils.configureAmbientLighting(fragmentShaderBuilder, nodeId, environmentId);
    loadFragmentIfNotDefined(fragmentShaderBuilder, "unpackVec3ToFloat");
    String isLightedFunctionName = "isLighted_" + nodeId;
    String probeShadowMapFunctionName = "probeShadowMap_" + nodeId;
    fragmentShaderBuilder.addFunction(probeShadowMapFunctionName, createProbeShadowMapFunction(nodeId));
    ObjectMap<String, String> variables = new ObjectMap<>();
    variables.put("NUM_SPOT_LIGHTS", String.valueOf(maxNumberOfSpotlights));
    variables.put("NUM_POINT_LIGHTS", String.valueOf(maxNumberOfPointLights));
    variables.put("NUM_DIRECTIONAL_LIGHTS", String.valueOf(maxNumberOfDirectionalLights));
    variables.put("SHADOW_ACNE_VALUE", SimpleNumberFormatter.format(shadowAcneValue));
    variables.put("SHADOW_SOFTNESS", String.valueOf(shadowSoftness));
    variables.put("SHADOW_PROBE_COUNT", SimpleNumberFormatter.format((shadowSoftness + 1) * (shadowSoftness + 1)));
    variables.put("NODE_ID", nodeId);
    fragmentShaderBuilder.addFunction(isLightedFunctionName, GLSLFragmentReader.getFragment("isLighted", variables));
    if (maxNumberOfDirectionalLights > 0)
        passDirectionalLights(environmentId, fragmentShaderBuilder, nodeId, variables);
    if (maxNumberOfPointLights > 0)
        passPointLights(environmentId, fragmentShaderBuilder, nodeId, variables);
    if (maxNumberOfSpotlights > 0)
        passSpotLights(environmentId, fragmentShaderBuilder, nodeId, variables);
    FieldOutput positionValue = inputs.get("position");
    FieldOutput normalValue = inputs.get("normal");
    FieldOutput albedoValue = inputs.get("albedo");
    FieldOutput emissionValue = inputs.get("emission");
    FieldOutput specularValue = inputs.get("specular");
    FieldOutput ambientOcclusionValue = inputs.get("ambientOcclusion");
    FieldOutput shininessValue = inputs.get("shininess");
    String position = positionValue.getRepresentation();
    String normal = normalValue.getRepresentation();
    String albedo = albedoValue != null ? albedoValue.getRepresentation() : "vec3(0.0)";
    String emission = emissionValue != null ? emissionValue.getRepresentation() : "vec3(0.0)";
    String specular = specularValue != null ? specularValue.getRepresentation() : "vec3(1.0)";
    String ambientOcclusion = ambientOcclusionValue != null ? ambientOcclusionValue.getRepresentation() : "1.0";
    String shininess = shininessValue != null ? shininessValue.getRepresentation() : "32.0";
    fragmentShaderBuilder.addMainLine("// Phong Lighting node");
    String calculateLightingFunctionName = "calculatePhongLightingFunction_" + nodeId;
    fragmentShaderBuilder.addFunction(calculateLightingFunctionName, createCalculateLightingFunction(nodeId));
    String lightingVariable = "lighting_" + nodeId;
    fragmentShaderBuilder.addMainLine("Lighting " + lightingVariable + " = " + calculateLightingFunctionName + "(" + position + ", " + normal + ", " + shininess + ");");
    ShaderFieldType resultType = ShaderFieldTypeRegistry.findShaderFieldType(ShaderFieldType.Vector3);
    ObjectMap<String, DefaultFieldOutput> result = new ObjectMap<>();
    if (producedOutputs.contains("output")) {
        String name = "color_" + nodeId;
        fragmentShaderBuilder.addMainLine(resultType.getShaderType() + " " + name + " = " + emission + ".rgb + " + ambientOcclusion + " * u_ambientLight_" + nodeId + " * " + albedo + ".rgb;");
        fragmentShaderBuilder.addMainLine(name + " += " + lightingVariable + ".diffuse * " + albedo + ".rgb + " + lightingVariable + ".specular * " + specular + ".rgb;");
        result.put("output", new DefaultFieldOutput(resultType.getName(), name));
    }
    if (producedOutputs.contains("diffuse")) {
        result.put("diffuse", new DefaultFieldOutput(resultType.getName(), lightingVariable + ".diffuse"));
    }
    if (producedOutputs.contains("specularOut")) {
        result.put("specularOut", new DefaultFieldOutput(resultType.getName(), lightingVariable + ".specular"));
    }
    return result;
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) 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 DefaultFieldOutput

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

the class ApplyNormalMapShaderNodeBuilder 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.addMainLine("// Apply normal map");
    loadFragmentIfNotDefined(commonShaderBuilder, "applyNormalMap");
    FieldOutput normal = inputs.get("normal");
    FieldOutput tangent = inputs.get("tangent");
    FieldOutput normalMap = inputs.get("normalMap");
    FieldOutput strength = inputs.get("strength");
    String strengthValue = strength != null ? strength.getRepresentation() : "1.0";
    String name = "result_" + nodeId;
    commonShaderBuilder.addMainLine("vec3 " + name + " = applyNormalMap(" + tangent.getRepresentation() + ", " + normal.getRepresentation() + ", " + normalMap.getRepresentation() + ".xyz, " + strengthValue + ");");
    return LibGDXCollections.singletonMap("output", new DefaultFieldOutput(ShaderFieldType.Vector3, name));
}
Also used : DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput) DefaultFieldOutput(com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput)

Example 23 with DefaultFieldOutput

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

the class PhongLightingShaderNodeBuilder method buildFragmentNodeSingleInputs.

@Override
public ObjectMap<String, ? extends FieldOutput> buildFragmentNodeSingleInputs(boolean designTime, String nodeId, final JsonValue data, ObjectMap<String, FieldOutput> inputs, ObjectSet<String> producedOutputs, VertexShaderBuilder vertexShaderBuilder, FragmentShaderBuilder fragmentShaderBuilder, final GraphShaderContext graphShaderContext, GraphShader graphShader) {
    String environmentId = data.getString("id", "");
    fragmentShaderBuilder.addStructure("Lighting", "  vec3 diffuse;\n" + "  vec3 specular;\n");
    Lighting3DUtils.configureAmbientLighting(fragmentShaderBuilder, nodeId, environmentId);
    ObjectMap<String, String> variables = new ObjectMap<>();
    variables.put("NUM_SPOT_LIGHTS", String.valueOf(maxNumberOfSpotlights));
    variables.put("NUM_POINT_LIGHTS", String.valueOf(maxNumberOfPointLights));
    variables.put("NUM_DIRECTIONAL_LIGHTS", String.valueOf(maxNumberOfDirectionalLights));
    variables.put("NODE_ID", nodeId);
    if (maxNumberOfDirectionalLights > 0)
        passDirectionalLights(environmentId, fragmentShaderBuilder, nodeId, variables);
    if (maxNumberOfPointLights > 0)
        passPointLights(environmentId, fragmentShaderBuilder, nodeId, variables);
    if (maxNumberOfSpotlights > 0)
        passSpotLights(environmentId, fragmentShaderBuilder, nodeId, variables);
    FieldOutput positionValue = inputs.get("position");
    FieldOutput normalValue = inputs.get("normal");
    FieldOutput albedoValue = inputs.get("albedo");
    FieldOutput emissionValue = inputs.get("emission");
    FieldOutput specularValue = inputs.get("specular");
    FieldOutput ambientOcclusionValue = inputs.get("ambientOcclusion");
    FieldOutput shininessValue = inputs.get("shininess");
    String position = positionValue.getRepresentation();
    String normal = normalValue.getRepresentation();
    String albedo = albedoValue != null ? albedoValue.getRepresentation() : "vec3(0.0)";
    String emission = emissionValue != null ? emissionValue.getRepresentation() : "vec3(0.0)";
    String specular = specularValue != null ? specularValue.getRepresentation() : "vec3(1.0)";
    String ambientOcclusion = ambientOcclusionValue != null ? ambientOcclusionValue.getRepresentation() : "1.0";
    String shininess = shininessValue != null ? shininessValue.getRepresentation() : "32.0";
    fragmentShaderBuilder.addMainLine("// Phong Lighting node");
    String calculateLightingFunctionName = "calculatePhongLightingFunction_" + nodeId;
    String calculateLightingFunction = createCalculateLightingFunction(nodeId);
    fragmentShaderBuilder.addFunction(calculateLightingFunctionName, calculateLightingFunction);
    String lightingVariable = "lighting_" + nodeId;
    fragmentShaderBuilder.addMainLine("Lighting " + lightingVariable + " = " + calculateLightingFunctionName + "(" + position + ", " + normal + ", " + shininess + ");");
    ShaderFieldType resultType = ShaderFieldTypeRegistry.findShaderFieldType(ShaderFieldType.Vector3);
    ObjectMap<String, DefaultFieldOutput> result = new ObjectMap<>();
    if (producedOutputs.contains("output")) {
        String name = "color_" + nodeId;
        fragmentShaderBuilder.addMainLine(resultType.getShaderType() + " " + name + " = " + emission + ".rgb + " + ambientOcclusion + " * u_ambientLight_" + nodeId + " * " + albedo + ".rgb;");
        fragmentShaderBuilder.addMainLine(name + " += " + lightingVariable + ".diffuse * " + albedo + ".rgb + " + lightingVariable + ".specular * " + specular + ".rgb;");
        result.put("output", new DefaultFieldOutput(resultType.getName(), name));
    }
    if (producedOutputs.contains("diffuse")) {
        result.put("diffuse", new DefaultFieldOutput(resultType.getName(), lightingVariable + ".diffuse"));
    }
    if (producedOutputs.contains("specularOut")) {
        result.put("specularOut", new DefaultFieldOutput(resultType.getName(), lightingVariable + ".specular"));
    }
    return result;
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) 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 DefaultFieldOutput

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

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

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

the class ViewportSizeShaderNodeBuilder 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");
    ObjectMap<String, DefaultFieldOutput> result = new ObjectMap<>();
    if (producedOutputs.contains("size")) {
        result.put("size", new DefaultFieldOutput(ShaderFieldType.Vector2, "u_viewportSize"));
    }
    if (producedOutputs.contains("x")) {
        result.put("x", new DefaultFieldOutput(ShaderFieldType.Float, "u_viewportSize.x"));
    }
    if (producedOutputs.contains("y")) {
        result.put("y", new DefaultFieldOutput(ShaderFieldType.Float, "u_viewportSize.y"));
    }
    return result;
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) 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