+++ /dev/null
-package com.badlogic.gdx.graphics.g3d.shaders.graph;
-
-public class ShaderConnection {
- private final ShaderNode outputNode;
- private final ShaderOutput output;
- private final ShaderNode inputNode;
- private final ShaderInput input;
-
- ShaderConnection(ShaderNode outputNode, ShaderOutput output, ShaderNode inputNode, ShaderInput input) {
- this.outputNode = outputNode;
- this.output = output;
- this.inputNode = inputNode;
- this.input = input;
- }
-
- public ShaderNode getOutputNode () {
- return outputNode;
- }
-
- public ShaderOutput getOutput () {
- return output;
- }
-
- public ShaderNode getInputNode () {
- return inputNode;
- }
-
- public ShaderInput getInput () {
- return input;
- }
-}
+++ /dev/null
-package com.badlogic.gdx.graphics.g3d.shaders.graph;
-
-public class ShaderDefine {
- private final String name;
- private final int value;
-
- ShaderDefine(String name, int value) {
- this.name = name;
- this.value = value;
- }
-
- public String getName () {
- return name;
- }
-
- public int getValue () {
- return value;
- }
-}
+++ /dev/null
-package com.badlogic.gdx.graphics.g3d.shaders.graph;
-
-import java.util.Arrays;
-
-import com.badlogic.gdx.graphics.g3d.shaders.graph.ShaderNode.ShaderNodeType;
-import com.badlogic.gdx.utils.Array;
-import com.badlogic.gdx.utils.GdxRuntimeException;
-import com.badlogic.gdx.utils.ObjectMap;
-import com.badlogic.gdx.utils.ObjectSet;
-
-public class ShaderGraph {
- private final ShaderNodeType type;
- private final ObjectMap<String, ShaderNode> nodeTypes = new ObjectMap<String, ShaderNode>();
- private final ObjectSet<ShaderNode> nodeSet = new ObjectSet<ShaderNode>();
- private final Array<ShaderNode> nodes = new Array<ShaderNode>();
- private final Array<ShaderConnection> connections = new Array<ShaderConnection>();
- private final ObjectMap<ShaderNode, Array<ShaderConnection>> connectionMap = new ObjectMap<ShaderNode, Array<ShaderConnection>>();
-
- public ShaderGraph(ShaderNodeType type) {
- this.type = type;
- }
-
- public ShaderNodeType getType () {
- return type;
- }
-
- public void addNodeType(ShaderNode node) {
- if(node.getType() != type) throw new GdxRuntimeException("graph type " + type + " != node type " + node.getType());
- if(nodeTypes.get(node.getName()) != null) throw new GdxRuntimeException("Node type with name '" + node.getName() + "' already in graph");
- nodeTypes.put(node.getName(), node);
- }
-
- public ShaderNode newNode(String nodeType) {
- ShaderNode node = nodeTypes.get(nodeType);
- if(node == null) throw new GdxRuntimeException("Node type '" + nodeType + "' not in graph, add it with addNodeType() first!");
- node = node.copy();
- nodes.add(node);
- nodeSet.add(node);
- return node;
- }
-
- public void connect(ShaderNode outputNode, String outputName, ShaderNode inputNode, String inputName) {
- if(!nodeSet.contains(outputNode)) throw new GdxRuntimeException("output node not in graph");
- if(!nodeSet.contains(inputNode)) throw new GdxRuntimeException("input node not in graph");
- ShaderOutput output = outputNode.getOutput(outputName);
- if(output == null) throw new GdxRuntimeException("shader output '" + outputName + "' not in node '" + outputNode.getName() + "'");
- ShaderInput input = inputNode.getInput(inputName);
- if(input == null) throw new GdxRuntimeException("shader input '" + inputName + "' not in node '" + inputNode.getName() + "'");
- if(!output.getType().equals(input.getType())) throw new GdxRuntimeException("shader output '" + output.getName() + "' has type '" + output.getType() + "'"
- + ", does not match shader input '" + input.getName() + "' type '" + input.getType() + "'");
- ShaderConnection connection = new ShaderConnection(outputNode, output, inputNode, input);
- connections.add(connection);
- addConnection(outputNode, connection);
- addConnection(inputNode, connection);
- }
-
- private void addConnection(ShaderNode node, ShaderConnection connection) {
- Array<ShaderConnection> connections = connectionMap.get(node);
- if(connections == null) {
- connections = new Array<ShaderConnection>();
- connectionMap.put(node, connections);
- }
- connections.add(connection);
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("types {\n");
- for(String type: nodeTypes.keys()) {
- builder.append(" {\n");
- String[] lines = nodeTypes.get(type).toString().split("\n");
- for(String line: lines) {
- builder.append(" " + line + "\n");
- }
- builder.append(" }\n");
- }
- builder.append("\n}\n");
-
- builder.append("nodes {\n");
- int i = 0;
- for(ShaderNode node: nodes) {
- builder.append(" node " + node.getName() + "_" + i + ";\n");
- ++i;
- }
- builder.append("\n}\n");
-
- builder.append("connections {\n");
- for(ShaderConnection con: connections) {
- int outputIdx = nodes.indexOf(con.getOutputNode(), true);
- int inputIdx = nodes.indexOf(con.getInputNode(), true);
- builder.append(" " + con.getOutputNode().getName() + "_" + outputIdx + con.getOutput().getName() + " -> ");
- builder.append(con.getInputNode().getName() + "_" + inputIdx + con.getInput().getName() + ";\n");
- ++i;
- }
- builder.append("\n}\n");
-
- return builder.toString();
- }
-}
+++ /dev/null
-package com.badlogic.gdx.graphics.g3d.shaders.graph;
-
-public class ShaderInput {
- public static enum ShaderInputQualifier {
- Attribute,
- Uniform,
- Local
- }
-
- private final String name;
- private final String type;
- private final ShaderInputQualifier qualifier;
-
- ShaderInput(String name, String type, ShaderInputQualifier qualifier) {
- this.name = name;
- this.type = type;
- this.qualifier = qualifier;
- }
-
- public String getName () {
- return name;
- }
-
- public String getType () {
- return type;
- }
-
- public ShaderInputQualifier getQualifier () {
- return qualifier;
- }
-
- public ShaderInput copy () {
- return new ShaderInput(name, type, qualifier);
- }
-}
+++ /dev/null
-package com.badlogic.gdx.graphics.g3d.shaders.graph;
-
-import com.badlogic.gdx.graphics.g3d.shaders.graph.ShaderInput.ShaderInputQualifier;
-import com.badlogic.gdx.utils.Array;
-
-public class ShaderNode {
- public static enum ShaderNodeType {
- Vertex,
- Fragment
- }
-
- protected String name;
- protected ShaderNodeType type;
- protected Array<ShaderInput> inputs;
- protected Array<ShaderOutput> outputs;
- protected String code;
- protected Array<String> requires;
- protected Array<ShaderDefine> defines;
-
- ShaderNode() {
- }
-
- ShaderNode(String name, ShaderNodeType type, Array<String> requires, Array<ShaderDefine> defines, Array<ShaderInput> inputs, Array<ShaderOutput> outputs, String code) {
- this.name = name;
- this.type = type;
- this.requires = requires;
- this.defines = defines;
- this.inputs = inputs;
- this.outputs = outputs;
- this.code = code;
- }
-
- public String getName () {
- return name;
- }
-
- public ShaderNodeType getType () {
- return type;
- }
-
- public Array<ShaderInput> getInputs () {
- return inputs;
- }
-
- public ShaderInput getInput(String name) {
- for(ShaderInput input: inputs) {
- if(input.getName().equals(name)) return input;
- }
- return null;
- }
-
- public Array<ShaderOutput> getOutputs () {
- return outputs;
- }
-
- public ShaderOutput getOutput(String name) {
- for(ShaderOutput output: outputs) {
- if(output.getName().equals(name)) return output;
- }
- return null;
- }
-
- public String getCode () {
- return code;
- }
-
- public ShaderNode copy() {
- Array<ShaderInput> copiedInputs = new Array<ShaderInput>();
- for(ShaderInput input: inputs) {
- copiedInputs.add(input.copy());
- }
- Array<ShaderOutput> copiedOutputs = new Array<ShaderOutput>();
- for(ShaderOutput output: outputs) {
- copiedOutputs.add(output.copy());
- }
- return new ShaderNode(name, type, new Array<String>(requires), new Array<ShaderDefine>(defines), copiedInputs, copiedOutputs, code);
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("name ");
- builder.append(name);
- builder.append(";\n");
-
- builder.append("type ");
- builder.append(type);
- builder.append(";\n");
-
- for(String require: requires) {
- builder.append("requires ");
- builder.append(require);
- builder.append(";\n");
- }
-
- for(ShaderDefine define: defines) {
- builder.append("define ");
- builder.append(define.getName());
- builder.append("=");
- builder.append(define.getValue());
- builder.append(";\n");
- }
-
- builder.append("inputs {\n");
- for(ShaderInput input: inputs) {
- builder.append(" ");
- if(input.getQualifier() != ShaderInputQualifier.Local) {
- builder.append(input.getQualifier().toString().toLowerCase());
- builder.append(" ");
- }
- builder.append(input.getType());
- builder.append(" ");
- builder.append(input.getName());
- builder.append(";\n");
- }
- builder.append("}\n");
-
- builder.append("outputs {\n");
- for(ShaderOutput output: outputs) {
- builder.append(" ");
- if(output.isVarying()) {
- builder.append("varying ");
- }
- builder.append(output.getType());
- builder.append(" ");
- builder.append(output.getName());
- builder.append(";\n");
- }
- builder.append("}\n");
-
- builder.append("code {\n");
- String[] lines = code.split("\n");
- for(String line: lines) {
- builder.append(" " + line);
- }
- builder.append("\n}\n");
-
- return builder.toString();
- }
-}
\ No newline at end of file
+++ /dev/null
-package com.badlogic.gdx.graphics.g3d.shaders.graph;
-
-import com.badlogic.gdx.graphics.g3d.shaders.graph.ShaderInput.ShaderInputQualifier;
-import com.badlogic.gdx.graphics.g3d.shaders.graph.ShaderNode.ShaderNodeType;
-import com.badlogic.gdx.utils.Array;
-import com.badlogic.gdx.utils.GdxRuntimeException;
-
-public class ShaderNodeBuilder {
- private String name;
- private ShaderNodeType type;
- private Array<ShaderInput> inputs = new Array<ShaderInput>();
- private Array<ShaderOutput> outputs = new Array<ShaderOutput>();
- private Array<String> requires = new Array<String>();
- private Array<ShaderDefine> defines = new Array<ShaderDefine>();
- private String code;
-
- public ShaderNodeBuilder name(String name) {
- if(name == null) throw new GdxRuntimeException("name must not be null");
- if(name.length() == 0) throw new GdxRuntimeException("name must not be empty string");
- this.name = name;
- return this;
- }
-
- public ShaderNodeBuilder type(ShaderNodeType type) {
- if(type == null) throw new GdxRuntimeException("type must not be null");
- this.type = type;
- return this;
- }
-
- public ShaderNodeBuilder define(String define, int value) {
- if(define == null) throw new GdxRuntimeException("define must not be null");
- if(define.length() == 0) throw new GdxRuntimeException("define must not be zero");
- defines.add(new ShaderDefine(define, value));
- return this;
- }
-
- public ShaderNodeBuilder require(String require) {
- if(require == null) throw new GdxRuntimeException("requires must not be null");
- if(require.length() == 0) throw new GdxRuntimeException("requires must not be zero");
- requires.add(require);
- return this;
- }
-
- public ShaderNodeBuilder input(String name, String type) {
- return input(name, type, ShaderInputQualifier.Local);
- }
-
- public ShaderNodeBuilder input(String name, String type, ShaderInputQualifier qualifier) {
- if(name == null) throw new GdxRuntimeException("name must not be null");
- if(name.length() == 0) throw new GdxRuntimeException("name must not be empty string");
- if(type == null) throw new GdxRuntimeException("type must not be null");
- if(type.length() == 0) throw new GdxRuntimeException("type must not be empty string");
- if(qualifier == null) throw new GdxRuntimeException("qualifier must not be null");
-
- for(ShaderInput i: inputs) {
- if(i.getName().equals(name)) {
- throw new GdxRuntimeException("input with name '" + i.getName() + "' already in shader node");
- }
- }
- inputs.add(new ShaderInput(name, type, qualifier));
- return this;
- }
-
- public ShaderNodeBuilder output(String name, String type) {
- return output(name, type, false);
- }
-
- public ShaderNodeBuilder output(String name, String type, boolean isVarying) {
- if(name == null) throw new GdxRuntimeException("name must not be null");
- if(name.length() == 0) throw new GdxRuntimeException("name must not be empty string");
- if(type == null) throw new GdxRuntimeException("type must not be null");
- if(type.length() == 0) throw new GdxRuntimeException("type must not be empty string");
- for(ShaderOutput o: outputs) {
- if(o.getName().equals(name)) {
- throw new GdxRuntimeException("output with name '" + o.getName() + "' already in shader node");
- }
- }
- outputs.add(new ShaderOutput(name, type, isVarying));
- return this;
- }
-
- public ShaderNodeBuilder code(String code) {
- if(code == null) throw new GdxRuntimeException("code must not be null");
- if(code.length() == 0) throw new GdxRuntimeException("code must not be empty string");
- this.code = code;
- return this;
- }
-
- public ShaderNode build() {
- if(name == null) throw new GdxRuntimeException("name is not set");
- if(type == null) throw new GdxRuntimeException("type is not set");
- if(code == null) throw new GdxRuntimeException("code is not set");
- if(inputs.size == 0 && outputs.size == 0) throw new GdxRuntimeException("node has neither inputs nor outputs");
- return new ShaderNode(name, type, new Array<String>(requires), new Array<ShaderDefine>(defines), new Array<ShaderInput>(inputs), new Array<ShaderOutput>(outputs), code);
- }
-
- public void clear() {
- this.name = null;
- this.type = null;
- this.code = null;
- this.inputs.clear();
- this.outputs.clear();
- this.requires.clear();
- this.defines.clear();
- }
-}
+++ /dev/null
-package com.badlogic.gdx.graphics.g3d.shaders.graph;
-
-public class ShaderOutput {
- private final String name;
- private final String type;
- private final boolean isVarying;
-
- ShaderOutput(String name, String type, boolean isVarying) {
- this.name = name;
- this.type = type;
- this.isVarying = isVarying;
- }
-
- public String getName () {
- return name;
- }
-
- public String getType () {
- return type;
- }
-
- public boolean isVarying () {
- return isVarying;
- }
-
- public ShaderOutput copy () {
- return new ShaderOutput(name, type, isVarying);
- }
-}
+++ /dev/null
-package com.badlogic.gdx.graphics.g3d.shaders.graph;
-
-import com.badlogic.gdx.utils.Array;
-
-public class UniformNode extends ShaderNode {
- public UniformNode(String name, String type) {
- this.name = name;
- this.defines = new Array<ShaderDefine>();
- this.requires = new Array<String>();
- this.inputs = new Array<ShaderInput>();
- this.outputs = new Array<ShaderOutput>();
- }
-}
import com.badlogic.gdx.tests.TimerTest;\r
import com.badlogic.gdx.tests.g3d.Basic3DSceneTest;\r
import com.badlogic.gdx.tests.g3d.Basic3DTest;\r
+import com.badlogic.gdx.tests.g3d.MaterialTest;\r
import com.badlogic.gdx.tests.g3d.ModelLoaderTest;\r
import com.badlogic.gdx.tests.g3d.ModelTest;\r
import com.badlogic.gdx.tests.g3d.voxel.VoxelTest;\r
// new SharedLibraryLoader("../../extensions/gdx-controllers/gdx-controllers-desktop/libs/gdx-controllers-desktop-natives.jar").load("gdx-controllers-desktop");\r
// new SharedLibraryLoader("../../gdx/libs/gdx-natives.jar").load("gdx");\r
\r
- GdxTest test = new DelaunayTriangulatorTest();\r
+ GdxTest test = new MaterialTest();\r
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();\r
config.useGL20 = test.needsGL20();\r
config.width = 1024;\r
+++ /dev/null
-package com.badlogic.gdx.tests.g3d.graph;
-
-import com.badlogic.gdx.graphics.g3d.shaders.graph.ShaderGraph;
-import com.badlogic.gdx.graphics.g3d.shaders.graph.ShaderNode;
-import com.badlogic.gdx.graphics.g3d.shaders.graph.ShaderNodeBuilder;
-import com.badlogic.gdx.graphics.g3d.shaders.graph.ShaderInput.ShaderInputQualifier;
-import com.badlogic.gdx.graphics.g3d.shaders.graph.ShaderNode.ShaderNodeType;
-import com.badlogic.gdx.graphics.glutils.ShaderProgram;
-
-public class ShaderGraphTest {
- public static void main (String[] args) {
- ShaderNodeBuilder builder = new ShaderNodeBuilder();
-
- ShaderGraph graph = new ShaderGraph(ShaderNodeType.Vertex);
-
- builder.name("positionAttr").type(ShaderNodeType.Vertex)
- .input(ShaderProgram.POSITION_ATTRIBUTE, "vec3", ShaderInputQualifier.Attribute)
- .output("position", "vec4")
- .code("position = vec4(a_position, 1.0);");
- ShaderNode positionAttr = builder.build();
- graph.addNodeType(positionAttr);
-
- builder.clear();
- builder.name("normalAttr").type(ShaderNodeType.Vertex)
- .input(ShaderProgram.NORMAL_ATTRIBUTE, "vec3", ShaderInputQualifier.Attribute)
- .output("normal", "vec4")
- .code("normal = vec4(a_normal, 0.0);");
- ShaderNode normalAttr = builder.build();
- graph.addNodeType(normalAttr);
-
- builder.clear();
- builder.name("uv0Attr").type(ShaderNodeType.Vertex)
- .input(ShaderProgram.TEXCOORD_ATTRIBUTE + "0", "vec2", ShaderInputQualifier.Attribute)
- .output("uv0", "vec2")
- .code("uv0 = a_texCoord0;");
- ShaderNode uv0Attr = builder.build();
- graph.addNodeType(uv0Attr);
-
- builder.clear();
- builder.name("uv1Attr").type(ShaderNodeType.Vertex)
- .input(ShaderProgram.TEXCOORD_ATTRIBUTE + "1", "vec2", ShaderInputQualifier.Attribute)
- .output("uv1", "vec2")
- .code("uv1 = a_texCoord1;");
- ShaderNode uv1Attr = builder.build();
- graph.addNodeType(uv1Attr);
-
- builder.clear();
- builder.name("transform").type(ShaderNodeType.Vertex)
- .input("position", "vec4")
- .input("projectionView", "mat4")
- .output("transformedPosition", "vec4")
- .code("position = projectionView * transformedPosition;");
- ShaderNode transform = builder.build();
- graph.addNodeType(transform);
- System.out.println(graph);
- }
-}