use of com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput 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));
}
use of com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput 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));
}
use of com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput in project gdx-graph by MarcinSc.
the class RemapVectorShaderNodeBuilder 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");
String x = processValue(data.getString("x"), inputValue);
String y = processValue(data.getString("y"), inputValue);
String z = processValue(data.getString("z"), inputValue);
String w = processValue(data.getString("w"), inputValue);
commonShaderBuilder.addMainLine("// Merge Vector Node");
ObjectMap<String, DefaultFieldOutput> result = new ObjectMap<>();
if (producedOutputs.contains("v2")) {
String name = "v2_" + nodeId;
commonShaderBuilder.addMainLine("vec2 " + name + " = vec2(" + x + ", " + y + ");");
result.put("v2", new DefaultFieldOutput(ShaderFieldType.Vector2, name));
}
if (producedOutputs.contains("v3")) {
String name = "v3_" + nodeId;
commonShaderBuilder.addMainLine("vec3 " + name + " = vec3(" + x + ", " + y + ", " + z + ");");
result.put("v3", new DefaultFieldOutput(ShaderFieldType.Vector3, name));
}
if (producedOutputs.contains("color")) {
String name = "color_" + nodeId;
commonShaderBuilder.addMainLine("vec4 " + name + " = vec4(" + x + ", " + y + ", " + z + ", " + w + ");");
result.put("color", new DefaultFieldOutput(ShaderFieldType.Vector4, name));
}
return result;
}
use of com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput in project gdx-graph by MarcinSc.
the class PerlinNoise2DShaderNodeBuilder 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 progressValue = inputs.get("progress");
FieldOutput scaleValue = inputs.get("scale");
FieldOutput rangeValue = inputs.get("range");
String scale = scaleValue != null ? scaleValue.getRepresentation() : "1.0";
String name = "result_" + nodeId;
String output;
commonShaderBuilder.addMainLine("// Perlin noise 2D node");
if (progressValue != null) {
loadFragmentIfNotDefined(commonShaderBuilder, "noise/common");
loadFragmentIfNotDefined(commonShaderBuilder, "noise/perlinNoise3d");
if (uvValue.getFieldType().getName().equals(ShaderFieldType.Vector2)) {
output = "perlinNoise3d(vec3(" + uvValue.getRepresentation() + " * " + scale + ", " + progressValue.getRepresentation() + "))";
} else {
output = "perlinNoise3d(vec3(" + uvValue.getRepresentation() + " * " + scale + ", 0.0, " + progressValue.getRepresentation() + "))";
}
} else {
loadFragmentIfNotDefined(commonShaderBuilder, "noise/common");
loadFragmentIfNotDefined(commonShaderBuilder, "noise/perlinNoise2d");
if (uvValue.getFieldType().getName().equals(ShaderFieldType.Vector2)) {
output = "perlinNoise2d(" + uvValue.getRepresentation() + " * " + scale + ")";
} else {
output = "perlinNoise2d(vec2(" + uvValue.getRepresentation() + ", 0.0) * " + scale + ")";
}
}
String noiseRange = "vec2(-1.0, 1.0)";
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));
}
use of com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput in project gdx-graph by MarcinSc.
the class TimeGraphShaderNodeBuilder method buildCommonNode.
@Override
protected ObjectMap<String, ? extends FieldOutput> buildCommonNode(boolean designTime, String nodeId, JsonValue data, ObjectMap<String, FieldOutput> inputs, ObjectSet<String> producedOutputs, CommonShaderBuilder commonShaderBuilder, final GraphShaderContext graphShaderContext, GraphShader graphShader) {
float multiplier = data.getFloat("multiplier", 1f);
ObjectMap<String, FieldOutput> result = new ObjectMap<>();
if (producedOutputs.contains("time")) {
commonShaderBuilder.addUniformVariable("u_time", "float", true, UniformSetters.time, "Time");
result.put("time", new DefaultFieldOutput(ShaderFieldType.Float, "(u_time * " + SimpleNumberFormatter.format(multiplier) + ")"));
}
if (producedOutputs.contains("sinTime")) {
String name = "u_sinTime_" + nodeId;
commonShaderBuilder.addUniformVariable(name, "float", true, new UniformSetters.SinTime(multiplier), "sin(Time)");
result.put("sinTime", new DefaultFieldOutput(ShaderFieldType.Float, name));
}
if (producedOutputs.contains("cosTime")) {
String name = "u_cosTime_" + nodeId;
commonShaderBuilder.addUniformVariable(name, "float", true, new UniformSetters.CosTime(multiplier), "cos(Time)");
result.put("cosTime", new DefaultFieldOutput(ShaderFieldType.Float, name));
}
if (producedOutputs.contains("deltaTime")) {
String name = "u_deltaTime_" + nodeId;
commonShaderBuilder.addUniformVariable(name, "float", true, new UniformSetters.DeltaTime(multiplier), "Delta time");
result.put("deltaTime", new DefaultFieldOutput(ShaderFieldType.Float, name));
}
return result;
}
Aggregations