Browse Source

Shaders: clean up Flat, set default color only for textured one.

Also probably fixed a few issues when compiling the shader on older GLSL
and GLSL ES (floating point literal suffixed, missing precision qualifiers).
And less crazy preprocessor.
pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
f52a086f8e
  1. 3
      src/Magnum/Shaders/Flat.cpp
  2. 32
      src/Magnum/Shaders/Flat.frag
  3. 25
      src/Magnum/Shaders/Flat.h

3
src/Magnum/Shaders/Flat.cpp

@ -100,7 +100,8 @@ template<UnsignedInt dimensions> Flat<dimensions>::Flat(const Flags flags): tran
/* 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)
/* Default to fully opaque white so we can see the texture */
if(flags & Flag::Textured) setColor(Color4(1.0f));
#endif
}

32
src/Magnum/Shaders/Flat.frag

@ -31,25 +31,19 @@
#ifdef TEXTURED
#ifdef EXPLICIT_TEXTURE_LAYER
layout(binding = 0) uniform sampler2D textureData;
#else
uniform sampler2D textureData;
layout(binding = 0)
#endif
uniform lowp sampler2D textureData;
#endif
#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;
# endif
#else
# ifndef GL_ES
uniform lowp vec4 color = vec4(1.0f, 1.0f, 1.0f, 1.0f);
# else
uniform lowp vec4 color;
# endif
layout(location = 1)
#endif
uniform lowp vec4 color
#if !defined(GL_ES) && defined(TEXTURED)
= vec4(1.0)
#endif
;
#ifdef TEXTURED
in mediump vec2 interpolatedTextureCoordinates;
@ -60,9 +54,9 @@ out lowp vec4 fragmentColor;
#endif
void main() {
#ifdef TEXTURED
fragmentColor = color * texture(textureData, interpolatedTextureCoordinates);
#else
fragmentColor = color;
#endif
fragmentColor =
#ifdef TEXTURED
texture(textureData, interpolatedTextureCoordinates)*
#endif
color;
}

25
src/Magnum/Shaders/Flat.h

@ -50,11 +50,11 @@ Draws whole mesh with given unshaded color or texture. For colored mesh you
need to provide @ref Position attribute in your triangle mesh and call at least
@ref setTransformationProjectionMatrix() and @ref setColor().
If you want to use texture instead of color, you need to provide also
@ref TextureCoordinates attribute. Pass @ref Flag::Textured to constructor and
then at render time don't forget to set also the texture via @ref setTexture().
The texture will be multiplied with the color (which is white by default, thus
it doesn't change texture color).
If you want to use texture, you need to provide also @ref TextureCoordinates
attribute. Pass @ref Flag::Textured to constructor and then at render time
don't forget to set also the texture via @ref setTexture(). The texture is
multipled by the color, which is by default set to fully opaque white if
texturing is enabled.
For coloring the texture based on intensity you can use the @ref Vector shader.
@ -185,12 +185,14 @@ template<UnsignedInt dimensions> class MAGNUM_SHADERS_EXPORT Flat: public Abstra
* @brief Set color
* @return Reference to self (for method chaining)
*
* If not set, default value is fully opaque white. Color will be
* multiplied with texture if @ref Flag::Textured is set.
* If @ref Flag::Textured is set, default value is `{1.0f, 1.0f, 1.0f}`
* and the color will be multiplied with texture.
* @see @ref setTexture()
*/
/* MSVC needs inline also here to avoid linkage conflicts */
inline Flat<dimensions>& setColor(const Color4& color);
Flat<dimensions>& setColor(const Color4& color){
setUniform(colorUniform, color);
return *this;
}
/**
* @brief Set texture
@ -216,11 +218,6 @@ typedef Flat<3> Flat3D;
CORRADE_ENUMSET_OPERATORS(Implementation::FlatFlags)
template<UnsignedInt dimensions> inline Flat<dimensions>& Flat<dimensions>::setColor(const Color4& color) {
setUniform(colorUniform, color);
return *this;
}
}}
#endif

Loading…
Cancel
Save