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));
}
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);
}
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;
}
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;
}
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));
}
Aggregations