Skip to content

Commit

Permalink
#9: Created separate grayscale and font shaders.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruskiy69 committed Jul 15, 2013
1 parent 43fcfe5 commit b8e978c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 21 deletions.
15 changes: 15 additions & 0 deletions data/shaders/Grayscale.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 330 core

uniform sampler2D texture;

smooth in vec2 fs_texc;
smooth in vec4 fs_color;
out vec4 out_color;

void main()
{
vec4 color = texture2D(texture, fs_texc);
float gray = dot(color, vec3(0.299, 0.587, 0.114));
out_color = vec4(color.rgb * gray, color.a);
}

15 changes: 15 additions & 0 deletions data/shaders/SpriteSheet.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 330 core

uniform sampler2D texture;

smooth in vec2 fs_texc;
smooth in vec4 fs_color;
out vec4 out_color;

uniform vec2 offset;

void main()
{
out_color = texture2D(texture, fs_texc + normalize(offset));
}

15 changes: 0 additions & 15 deletions data/shaders/TTFRender.fs

This file was deleted.

30 changes: 25 additions & 5 deletions include/Zenderer/Graphics/Effect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace gfx
GAUSSIAN_BLUR_H, ///< A horizontal Gaussian blur effect
GAUSSIAN_BLUR_V, ///< A vertical Gaussian blur effect
GRAYSCALE, ///< Makes the target grayscale
SPRITESHEET, ///< Render texture atlases using offsets
FADE, ///< Fades the target in/out
RIPPLE, ///< Creates a centered ripple effect
ZEN_EFFECT_COUNT ///< Total amount of effects
Expand Down Expand Up @@ -75,6 +76,7 @@ namespace gfx
return (*this);
}

/// @todo Use Gaussian Blur vertex shaders.
bool Init();
bool Destroy();

Expand Down Expand Up @@ -197,8 +199,8 @@ namespace gfx
* <td><pre>GAUSSIAN_BLUR_H</pre></td>
* <td><pre>GaussianBlur.vs<br/>GaussianBlurH.fs</pre></td>
* <td>
* Vertical Gaussian blur effect<br/>This should be used in combination with<br/>
* <span>GAUSSIAN_BLUR_V</span> for optimal output
* Vertical Gaussian blur effect<br/>This should be used in a multi-pass
* combination with<br/><span>GAUSSIAN_BLUR_V</span> for optimal output
* </td>
* <td>
* <table>
Expand All @@ -213,8 +215,8 @@ namespace gfx
* <td><pre>GAUSSIAN_BLUR_H</pre></td>
* <td><pre>GaussianBlur.vs<br/>GaussianBlurV.fs</pre></td>
* <td>
* Horizontal Gaussian blur effect<br/>This should be used in combination with<br/>
* <span>GAUSSIAN_BLUR_H</span> for optimal output
* Horizontal Gaussian blur effect<br/>This should be used in a
* multi-pass with<br/><span>GAUSSIAN_BLUR_H</span> for optimal output
* </td>
* <td>
* <table>
Expand All @@ -232,7 +234,25 @@ namespace gfx
* Converts all colors to grayscale using NTSC weights<br/>
* They are (0.299, 0.587, 0.114)
* </td>
* <td></td>
* <td>n/a</td>
* </tr>
* <tr>
* <td><pre>SPRITESHEET</pre></td>
* <td><pre>Default.vs<br/>SpriteSheet.fs</pre></td>
* <td>
* Renders a texture using an offset, thus only rendering a
* portion of it. Useful for sprite sheets and other texture atlases.
* The size of the texture rendered will match the size of your sprite,
* and tiling / stretching is impossible.
* </td>
* <td>
* <table>
* <tr>
* <td><span>offset</span></td>
* <td>The offset, in pixels, with which to render the texture.</td>
* </tr>
* </table>
* </td>
* </tr>
* <tr>
* <td><pre>FADE</pre></td>
Expand Down
6 changes: 5 additions & 1 deletion src/Graphics/Effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ bool CEffect::Init()

else if(m_type == EffectType::GRAYSCALE)
m_init = m_Shader.LoadFragmentShaderFromFile(
ZENDERER_SHADER_PATH"TTFRender.fs");
ZENDERER_SHADER_PATH"Grayscale.fs");

else if(m_type == EffectType::SPRITESHEET)
m_init = m_Shader.LoadFragmentShaderFromFile(
ZENDERER_SHADER_PATH"SpriteSheet.fs");

else if(m_type == EffectType::RIPPLE)
m_init = m_Shader.LoadFragmentShaderFromFile(
Expand Down

0 comments on commit b8e978c

Please sign in to comment.