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) */ /* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */
#ifdef MAGNUM_TARGET_GLES #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 #endif
} }

32
src/Magnum/Shaders/Flat.frag

@ -31,25 +31,19 @@
#ifdef TEXTURED #ifdef TEXTURED
#ifdef EXPLICIT_TEXTURE_LAYER #ifdef EXPLICIT_TEXTURE_LAYER
layout(binding = 0) uniform sampler2D textureData; layout(binding = 0)
#else
uniform sampler2D textureData;
#endif #endif
uniform lowp sampler2D textureData;
#endif #endif
#ifdef EXPLICIT_UNIFORM_LOCATION #ifdef EXPLICIT_UNIFORM_LOCATION
# ifndef GL_ES layout(location = 1)
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
#endif #endif
uniform lowp vec4 color
#if !defined(GL_ES) && defined(TEXTURED)
= vec4(1.0)
#endif
;
#ifdef TEXTURED #ifdef TEXTURED
in mediump vec2 interpolatedTextureCoordinates; in mediump vec2 interpolatedTextureCoordinates;
@ -60,9 +54,9 @@ out lowp vec4 fragmentColor;
#endif #endif
void main() { void main() {
#ifdef TEXTURED fragmentColor =
fragmentColor = color * texture(textureData, interpolatedTextureCoordinates); #ifdef TEXTURED
#else texture(textureData, interpolatedTextureCoordinates)*
fragmentColor = color; #endif
#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 need to provide @ref Position attribute in your triangle mesh and call at least
@ref setTransformationProjectionMatrix() and @ref setColor(). @ref setTransformationProjectionMatrix() and @ref setColor().
If you want to use texture instead of color, you need to provide also If you want to use texture, you need to provide also @ref TextureCoordinates
@ref TextureCoordinates attribute. Pass @ref Flag::Textured to constructor and attribute. Pass @ref Flag::Textured to constructor and then at render time
then at render time don't forget to set also the texture via @ref setTexture(). don't forget to set also the texture via @ref setTexture(). The texture is
The texture will be multiplied with the color (which is white by default, thus multipled by the color, which is by default set to fully opaque white if
it doesn't change texture color). texturing is enabled.
For coloring the texture based on intensity you can use the @ref Vector shader. 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 * @brief Set color
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
* *
* If not set, default value is fully opaque white. Color will be * If @ref Flag::Textured is set, default value is `{1.0f, 1.0f, 1.0f}`
* multiplied with texture if @ref Flag::Textured is set. * and the color will be multiplied with texture.
* @see @ref setTexture() * @see @ref setTexture()
*/ */
/* MSVC needs inline also here to avoid linkage conflicts */ Flat<dimensions>& setColor(const Color4& color){
inline Flat<dimensions>& setColor(const Color4& color); setUniform(colorUniform, color);
return *this;
}
/** /**
* @brief Set texture * @brief Set texture
@ -216,11 +218,6 @@ 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) {
setUniform(colorUniform, color);
return *this;
}
}} }}
#endif #endif

Loading…
Cancel
Save