Browse Source

Shaders: ability to specify background color in Vector shader.

Makes it possible to use the shader without blending.
pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
00a8383214
  1. 3
      src/Shaders/Vector.cpp
  2. 6
      src/Shaders/Vector.frag
  3. 15
      src/Shaders/Vector.h

3
src/Shaders/Vector.cpp

@ -38,7 +38,7 @@ namespace {
template<> constexpr const char* vertexShaderName<3>() { return "AbstractVector3D.vert"; }
}
template<UnsignedInt dimensions> Vector<dimensions>::Vector(): transformationProjectionMatrixUniform(0), colorUniform(1) {
template<UnsignedInt dimensions> Vector<dimensions>::Vector(): transformationProjectionMatrixUniform(0), backgroundColorUniform(1), colorUniform(2) {
Utility::Resource rs("MagnumShaders");
#ifndef MAGNUM_TARGET_GLES
@ -76,6 +76,7 @@ template<UnsignedInt dimensions> Vector<dimensions>::Vector(): transformationPro
#endif
{
transformationProjectionMatrixUniform = AbstractShaderProgram::uniformLocation("transformationProjectionMatrix");
backgroundColorUniform = AbstractShaderProgram::uniformLocation("backgroundColor");
colorUniform = AbstractShaderProgram::uniformLocation("color");
}

6
src/Shaders/Vector.frag

@ -29,8 +29,10 @@
#endif
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 1) uniform vec4 color;
layout(location = 1) uniform vec4 backgroundColor;
layout(location = 2) uniform vec4 color;
#else
uniform lowp vec4 backgroundColor;
uniform lowp vec4 color;
#endif
@ -48,5 +50,5 @@ out lowp vec4 fragmentColor;
void main() {
lowp float intensity = texture(vectorTexture, fragmentTextureCoordinates).r;
fragmentColor = intensity*color;
fragmentColor = mix(backgroundColor, color, intensity);
}

15
src/Shaders/Vector.h

@ -56,9 +56,23 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Vector: public Abst
return *this;
}
/**
* @brief Set background color
* @return Reference to self (for method chaining)
*
* Default is transparent black.
* @see @ref setColor()
*/
Vector& setBackgroundColor(const Color4& color) {
AbstractShaderProgram::setUniform(backgroundColorUniform, color);
return *this;
}
/**
* @brief Set fill color
* @return Reference to self (for method chaining)
*
* @see @ref setBackgroundColor()
*/
Vector& setColor(const Color4& color) {
AbstractShaderProgram::setUniform(colorUniform, color);
@ -67,6 +81,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Vector: public Abst
private:
Int transformationProjectionMatrixUniform,
backgroundColorUniform,
colorUniform;
};

Loading…
Cancel
Save