Skip to content
Snippets Groups Projects

allow (multiplicative) color modulation of textured meshes

Merged Janis Born requested to merge born/tinted_textures into develop
Files
7
@@ -70,9 +70,9 @@ void MeshShaderBuilder::addFragmentShaderDecl(const std::string& code)
mFragmentShaderDecl += "\n";
}
void MeshShaderBuilder::addPassthrough(std::string const& type, std::string const& nameWithoutPrefix)
void MeshShaderBuilder::addPassthrough(std::string const& type, std::string const& nameWithoutPrefix, TypeHandling typeHandling)
{
mInterfaceBlockVars.push_back({type, nameWithoutPrefix});
mInterfaceBlockVars.push_back({type, nameWithoutPrefix, typeHandling});
}
MeshShaderBuilder::Variable const* MeshShaderBuilder::findMatchingAttrOrUniform(Variable const& toSearch)
@@ -97,6 +97,8 @@ glow::SharedProgram MeshShaderBuilder::createProgram()
};
// Passthroughs
addFragmentShaderDecl("vec4 padColor(vec3 v) { return vec4(v, 1); }");
addFragmentShaderDecl("vec4 padColor(vec4 v) { return v; }");
std::string vsPassthroughCode;
std::string gsPassthroughFunc = "#define PASSTHROUGH(vInIndex) "; // Function to call to pass the data for the vertex with the given index through
std::string gsPassthroughMixFunc = "void passthroughMix01(float alpha) {\n"; // Function to call to mix the data of the two vertices for passthrough
@@ -119,7 +121,20 @@ glow::SharedProgram MeshShaderBuilder::createProgram()
gsPassthroughMixFunc += " vOut." + v.name + " = mix(vIn[0]." + v.name + ", vIn[1]." + v.name + ", alpha);\n";
// Copy interface block to local variables so that they can be overridden by modular components
fsPassthroughCode += " " + v.type + " v" + v.name + " = vIn." + v.name + ";\n";
switch (v.typeHandling)
{
case TypeHandling::Default:
{
fsPassthroughCode += " " + v.type + " v" + v.name + " = vIn." + v.name + ";\n";
break;
}
case TypeHandling::ExtendToVec4Color:
{
// Special handling for color variables: Extend to vec4.
fsPassthroughCode += " vec4 v" + v.name + " = padColor(vIn." + v.name + ");\n";
break;
}
}
}
mVertexShaderDecl = "out " + interfaceBlockContent + "} vOut;\n\n" + mVertexShaderDecl;
mFragmentShaderDecl = "in " + interfaceBlockContent + "} vIn;\n\n" + mFragmentShaderDecl;
Loading