use of com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput in project gdx-graph by MarcinSc.
the class TextureRegionShaderFieldType method addAsVertexAttribute.
@Override
public GraphShaderNodeBuilder.FieldOutput addAsVertexAttribute(VertexShaderBuilder vertexShaderBuilder, JsonValue data, final PropertySource propertySource) {
final TextureDescriptor<Texture> textureDescriptor = new TextureDescriptor<>();
if (data.has("minFilter"))
textureDescriptor.minFilter = Texture.TextureFilter.valueOf(data.getString("minFilter"));
if (data.has("magFilter"))
textureDescriptor.magFilter = Texture.TextureFilter.valueOf(data.getString("magFilter"));
if (data.has("uWrap"))
textureDescriptor.uWrap = Texture.TextureWrap.valueOf(data.getString("uWrap"));
if (data.has("vWrap"))
textureDescriptor.vWrap = Texture.TextureWrap.valueOf(data.getString("vWrap"));
String textureVariableName = propertySource.getUniformName();
String uvTransformAttributeName = propertySource.getAttributeName();
vertexShaderBuilder.addUniformVariable(textureVariableName, "sampler2D", false, new UniformRegistry.UniformSetter() {
@Override
public void set(BasicShader shader, int location, ShaderContext shaderContext) {
Object value = propertySource.getPropertyName();
value = propertySource.getValueToUse(value);
if (value == null)
value = new TextureRegion(shader.getDefaultTexture());
textureDescriptor.texture = ((TextureRegion) value).getTexture();
shader.setUniform(location, textureDescriptor);
}
}, "Texture property - " + propertySource.getPropertyName());
vertexShaderBuilder.addAttributeVariable(new VertexAttribute(1024, 4, uvTransformAttributeName), "vec4", "TextureUV property - " + propertySource.getPropertyName());
return new DefaultFieldOutput(ShaderFieldType.TextureRegion, uvTransformAttributeName, textureVariableName);
}
use of com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput in project gdx-graph by MarcinSc.
the class TextureRegionShaderFieldType method addAsLocalUniform.
@Override
public GraphShaderNodeBuilder.FieldOutput addAsLocalUniform(CommonShaderBuilder commonShaderBuilder, JsonValue data, final PropertySource propertySource) {
final String name = propertySource.getPropertyName();
final TextureDescriptor<Texture> textureDescriptor = new TextureDescriptor<>();
if (data.has("minFilter"))
textureDescriptor.minFilter = Texture.TextureFilter.valueOf(data.getString("minFilter"));
if (data.has("magFilter"))
textureDescriptor.magFilter = Texture.TextureFilter.valueOf(data.getString("magFilter"));
if (data.has("uWrap"))
textureDescriptor.uWrap = Texture.TextureWrap.valueOf(data.getString("uWrap"));
if (data.has("vWrap"))
textureDescriptor.vWrap = Texture.TextureWrap.valueOf(data.getString("vWrap"));
String textureVariableName = propertySource.getUniformName();
String uvTransformVariableName = "u_uvTransform_" + propertySource.getPropertyIndex();
commonShaderBuilder.addUniformVariable(textureVariableName, "sampler2D", false, new UniformRegistry.UniformSetter() {
@Override
public void set(BasicShader shader, int location, ShaderContext shaderContext) {
Object value = shaderContext.getLocalProperty(name);
value = propertySource.getValueToUse(value);
if (value == null)
value = new TextureRegion(shader.getDefaultTexture());
textureDescriptor.texture = ((TextureRegion) value).getTexture();
shader.setUniform(location, textureDescriptor);
}
}, "Texture property - " + name);
commonShaderBuilder.addUniformVariable(uvTransformVariableName, "vec4", false, new UniformRegistry.UniformSetter() {
@Override
public void set(BasicShader shader, int location, ShaderContext shaderContext) {
Object value = shaderContext.getLocalProperty(name);
value = propertySource.getValueToUse(value);
if (value == null)
value = new TextureRegion(shader.getDefaultTexture());
TextureRegion region = (TextureRegion) value;
shader.setUniform(location, region.getU(), region.getV(), region.getU2() - region.getU(), region.getV2() - region.getV());
}
}, "Texture UV property - " + name);
return new DefaultFieldOutput(getName(), uvTransformVariableName, textureVariableName);
}
use of com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput in project gdx-graph by MarcinSc.
the class ValueColorShaderNodeBuilder 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) {
final Color color = Color.valueOf(data.getString("color"));
String value = "vec4(" + format(color.r) + ", " + format(color.g) + ", " + format(color.b) + ", " + format(color.a) + ")";
return LibGDXCollections.singletonMap("value", new DefaultFieldOutput(ShaderFieldType.Vector4, value));
}
use of com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput in project gdx-graph by MarcinSc.
the class ValueVector3ShaderNodeBuilder 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) {
float v1 = data.getFloat("v1");
float v2 = data.getFloat("v2");
float v3 = data.getFloat("v3");
return LibGDXCollections.singletonMap("value", new DefaultFieldOutput(ShaderFieldType.Vector3, "vec3(" + format(v1) + ", " + format(v2) + ", " + format(v3) + ")"));
}
use of com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput in project gdx-graph by MarcinSc.
the class Sampler2DShaderNodeBuilder 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 textureValue = inputs.get("texture");
FieldOutput uvValue = inputs.get("uv");
commonShaderBuilder.addMainLine("// Sampler2D Node");
ObjectMap<String, FieldOutput> result = new ObjectMap<>();
String colorName = "color_" + nodeId;
commonShaderBuilder.addMainLine("vec4 " + colorName + " = texture2D(" + textureValue.getSamplerRepresentation() + ", " + textureValue.getRepresentation() + ".xy + " + uvValue.getRepresentation() + " * " + textureValue.getRepresentation() + ".zw);");
result.put("color", new DefaultFieldOutput(ShaderFieldType.Vector4, colorName));
if (producedOutputs.contains("r")) {
String name = "r_" + nodeId;
commonShaderBuilder.addMainLine("float " + name + " = " + colorName + ".r;");
result.put("r", new DefaultFieldOutput(ShaderFieldType.Float, name));
}
if (producedOutputs.contains("g")) {
String name = "g_" + nodeId;
commonShaderBuilder.addMainLine("float " + name + " = " + colorName + ".g;");
result.put("g", new DefaultFieldOutput(ShaderFieldType.Float, name));
}
if (producedOutputs.contains("b")) {
String name = "b_" + nodeId;
commonShaderBuilder.addMainLine("float " + name + " = " + colorName + ".b;");
result.put("b", new DefaultFieldOutput(ShaderFieldType.Float, name));
}
if (producedOutputs.contains("a")) {
String name = "a_" + nodeId;
commonShaderBuilder.addMainLine("float " + name + " = " + colorName + ".a;");
result.put("a", new DefaultFieldOutput(ShaderFieldType.Float, name));
}
return result;
}
Aggregations