use of com.gempukku.libgdx.graph.shader.field.ShaderFieldType 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;
}
use of com.gempukku.libgdx.graph.shader.field.ShaderFieldType in project gdx-graph by MarcinSc.
the class SplitShaderNodeBuilder 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 fieldType = inputValue.getFieldType();
String x, y, z, w;
if (fieldType.getName().equals(ShaderFieldType.Vector4)) {
x = inputValue.getRepresentation() + ".r";
y = inputValue.getRepresentation() + ".g";
z = inputValue.getRepresentation() + ".b";
w = inputValue.getRepresentation() + ".a";
} else if (fieldType.getName().equals(ShaderFieldType.Vector3)) {
x = inputValue.getRepresentation() + ".x";
y = inputValue.getRepresentation() + ".y";
z = inputValue.getRepresentation() + ".z";
w = "0.0";
} else if (fieldType.getName().equals(ShaderFieldType.Vector2)) {
x = inputValue.getRepresentation() + ".x";
y = inputValue.getRepresentation() + ".y";
z = "0.0";
w = "0.0";
} else {
throw new UnsupportedOperationException();
}
ObjectMap<String, DefaultFieldOutput> result = new ObjectMap<>();
if (producedOutputs.contains("x")) {
result.put("x", new DefaultFieldOutput(ShaderFieldType.Float, x));
}
if (producedOutputs.contains("y")) {
result.put("y", new DefaultFieldOutput(ShaderFieldType.Float, y));
}
if (producedOutputs.contains("z")) {
result.put("z", new DefaultFieldOutput(ShaderFieldType.Float, z));
}
if (producedOutputs.contains("w")) {
result.put("w", new DefaultFieldOutput(ShaderFieldType.Float, w));
}
return result;
}
use of com.gempukku.libgdx.graph.shader.field.ShaderFieldType in project gdx-graph by MarcinSc.
the class NormalizeShaderNodeBuilder 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("// Normalize node");
String name = "result_" + nodeId;
commonShaderBuilder.addMainLine(resultType.getShaderType() + " " + name + " = normalize(" + inputValue.getRepresentation() + ");");
return LibGDXCollections.singletonMap("output", new DefaultFieldOutput(resultType, name));
}
use of com.gempukku.libgdx.graph.shader.field.ShaderFieldType in project gdx-graph by MarcinSc.
the class ArcsinShaderNodeBuilder 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("// Arcsine node");
String name = "result_" + nodeId;
commonShaderBuilder.addMainLine(resultType.getShaderType() + " " + name + " = asin(" + inputValue.getRepresentation() + ");");
return LibGDXCollections.singletonMap("output", new DefaultFieldOutput(resultType, name));
}
use of com.gempukku.libgdx.graph.shader.field.ShaderFieldType in project gdx-graph by MarcinSc.
the class DegreesShaderNodeBuilder 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("// Degrees node");
String name = "result_" + nodeId;
commonShaderBuilder.addMainLine(resultType.getShaderType() + " " + name + " = degrees(" + inputValue.getRepresentation() + ");");
return LibGDXCollections.singletonMap("output", new DefaultFieldOutput(resultType, name));
}
Aggregations