Browse Source

Added colour uniform to flat shader (event when texturing is enabled)

This enables blending and transparency
Default colour is white (and fully opaque)
pull/34/head
Miguel Martin 13 years ago
parent
commit
0670f59c95
  1. 7
      src/Shaders/Flat.cpp
  2. 16
      src/Shaders/Flat.frag
  3. 5
      src/Shaders/Flat.h

7
src/Shaders/Flat.cpp

@ -78,7 +78,7 @@ template<UnsignedInt dimensions> Flat<dimensions>::Flat(const Flags flags): tran
#endif #endif
{ {
transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix");
if(!(flags & Flag::Textured)) colorUniform = uniformLocation("color"); colorUniform = uniformLocation("color");
} }
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
@ -87,6 +87,11 @@ template<UnsignedInt dimensions> Flat<dimensions>::Flat(const Flags flags): tran
{ {
if(flags & Flag::Textured) setUniform(uniformLocation("textureData"), TextureLayer); if(flags & Flag::Textured) setUniform(uniformLocation("textureData"), TextureLayer);
} }
/* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */
#ifdef MAGNUM_TARGET_GLES
setColor(Color4(1.0f)); // Default to white, with full transperancy (so we can see the texture)
#endif
} }
template class Flat<2>; template class Flat<2>;

16
src/Shaders/Flat.frag

@ -34,12 +34,20 @@ layout(binding = 0) uniform sampler2D textureData;
#else #else
uniform sampler2D textureData; uniform sampler2D textureData;
#endif #endif
#else #endif
#ifdef EXPLICIT_UNIFORM_LOCATION #ifdef EXPLICIT_UNIFORM_LOCATION
# ifndef GL_ES
layout(location = 1) uniform vec4 color = vec4(1.0f, 1.0f, 1.0f, 1.0f);
# else
layout(location = 1) uniform vec4 color; layout(location = 1) uniform vec4 color;
# endif
#else #else
uniform lowp vec4 color; # ifndef GL_ES
#endif uniform lowp vec4 color = vec4(1.0f, 1.0f, 1.0f, 1.0f);
# else
unfirom lowp vec4 color;
# endif
#endif #endif
#ifdef TEXTURED #ifdef TEXTURED
@ -52,7 +60,7 @@ out lowp vec4 fragmentColor;
void main() { void main() {
#ifdef TEXTURED #ifdef TEXTURED
fragmentColor = texture(textureData, interpolatedTextureCoordinates); fragmentColor = color * texture(textureData, interpolatedTextureCoordinates);
#else #else
fragmentColor = color; fragmentColor = color;
#endif #endif

5
src/Shaders/Flat.h

@ -124,7 +124,8 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Flat: public Abstra
* @brief Set color * @brief Set color
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Has no effect if @ref Flag::Textured is set. * Color will be multiplied with texture
* if @ref Flag::Textured is set.
*/ */
Flat<dimensions>& setColor(const Color4& color); Flat<dimensions>& setColor(const Color4& color);
@ -144,7 +145,7 @@ typedef Flat<3> Flat3D;
CORRADE_ENUMSET_OPERATORS(Implementation::FlatFlags) CORRADE_ENUMSET_OPERATORS(Implementation::FlatFlags)
template<UnsignedInt dimensions> inline Flat<dimensions>& Flat<dimensions>::setColor(const Color4& color) { template<UnsignedInt dimensions> inline Flat<dimensions>& Flat<dimensions>::setColor(const Color4& color) {
if(!(_flags & Flag::Textured)) setUniform(colorUniform, color); setUniform(colorUniform, color);
return *this; return *this;
} }

Loading…
Cancel
Save