/** * Append a variable initialization to the code * * @param source the StringBuilder to use * @param var the variable to initialize * @param initValue the init value to assign to the variable */ protected void initVariable(StringBuilder source, ShaderNodeVariable var, String initValue) { appendIndent(source); source.append(var.getNameSpace()); source.append("_"); source.append(var.getName()); source.append(" = "); source.append(initValue); source.append(";\n"); } }
/** * {@inheritDoc} * * only vertex shader output are mapped here, since fragment shader outputs * must have been mapped in the main section. */ @Override protected void generateEndOfMainSection(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) { if (type == Shader.ShaderType.Vertex) { appendOutput(source, "gl_Position", info.getVertexGlobal()); } unIndent(); appendIndent(source); source.append("}\n"); }
/** * {@inheritDoc} * * Fragment shader outputs are declared before the "void main(){" with the * "out" keyword. * * after the "void main(){", the vertex output are declared and initialized * and the fragment outputs are declared */ @Override protected void generateStartOfMainSection(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) { source.append("\n"); if (type == Shader.ShaderType.Fragment) { for (ShaderNodeVariable global : info.getFragmentGlobals()) { declareVariable(source, global, null, true, "out"); } } source.append("\n"); appendIndent(source); source.append("void main(){\n"); indent(); if (type == Shader.ShaderType.Vertex) { declareGlobalPosition(info, source); } else if (type == Shader.ShaderType.Fragment) { for (ShaderNodeVariable global : info.getFragmentGlobals()) { initVariable(source, global, "vec4(1.0)"); } } }
/** * Append a variable initialization to the code * * @param source the StringBuilder to use * @param var the variable to initialize * @param initValue the init value to assign to the variable */ protected void initVariable(StringBuilder source, ShaderNodeVariable var, String initValue) { appendIndent(source); source.append(var.getNameSpace()); source.append("_"); source.append(var.getName()); source.append(" = "); source.append(initValue); source.append(";\n"); } }
/** * {@inheritDoc} * * only vertex shader output are mapped here, since fragment shader outputs * must have been mapped in the main section. */ @Override protected void generateEndOfMainSection(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) { if (type == Shader.ShaderType.Vertex) { appendOutput(source, "gl_Position", info.getVertexGlobal()); } unIndent(); appendIndent(source); source.append("}\n"); }
/** * {@inheritDoc} * * Fragment shader outputs are declared before the "void main(){" with the * "out" keyword. * * after the "void main(){", the vertex output are declared and initialized * and the fragment outputs are declared */ @Override protected void generateStartOfMainSection(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) { source.append("\n"); if (type == Shader.ShaderType.Fragment) { for (ShaderNodeVariable global : info.getFragmentGlobals()) { declareVariable(source, global, null, true, "out"); } } source.append("\n"); appendIndent(source); source.append("void main(){\n"); indent(); if (type == Shader.ShaderType.Vertex) { declareGlobalPosition(info, source); } else if (type == Shader.ShaderType.Fragment) { for (ShaderNodeVariable global : info.getFragmentGlobals()) { initVariable(source, global, "vec4(1.0)"); } } }