Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added BlendMode.Subtract, fixed line endings in default shader files #477

Merged
merged 3 commits into from
Sep 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions config/shaders/default/add.frag
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Default fragment shader for ADD blend mode
uniform sampler2D texture;
void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
// multiply it by the color
gl_FragColor = gl_Color * pixel;
}
// Default fragment shader for ADD blend mode

uniform sampler2D texture;

void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);

// multiply it by the color
gl_FragColor = gl_Color * pixel;
}
24 changes: 12 additions & 12 deletions config/shaders/default/alpha.frag
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Default fragment shader for ALPHA blend mode
uniform sampler2D texture;
void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
// multiply it by the color
gl_FragColor = gl_Color * pixel;
}
// Default fragment shader for ALPHA blend mode

uniform sampler2D texture;

void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);

// multiply it by the color
gl_FragColor = gl_Color * pixel;
}
30 changes: 15 additions & 15 deletions config/shaders/default/multiply.frag
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Default fragment shader for MULTIPLY blend mode
uniform sampler2D texture;
void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
// multiply it by the color
gl_FragColor = gl_Color * pixel;
// this must be the last line in this shader
gl_FragColor.xyz *= gl_FragColor.w;
}
// Default fragment shader for MULTIPLY blend mode

uniform sampler2D texture;

void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);

// multiply it by the color
gl_FragColor = gl_Color * pixel;

// this must be the last line in this shader
gl_FragColor.xyz *= gl_FragColor.w;
}
32 changes: 16 additions & 16 deletions config/shaders/default/overlay.frag
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Default fragment shader for OVERLAY blend mode
// Texture color higher than 127,127,127 brightens the scene, lower than 127,127,127 darkens it.
uniform sampler2D texture;
void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
// multiply it by the color
gl_FragColor = gl_Color * pixel;
// this must be the last line in this shader
gl_FragColor = mix(vec4(0.5,0.5,0.5,1.0), gl_FragColor, gl_FragColor.w);
}
// Default fragment shader for OVERLAY blend mode
// Texture color higher than 127,127,127 brightens the scene, lower than 127,127,127 darkens it.

uniform sampler2D texture;

void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);

// multiply it by the color
gl_FragColor = gl_Color * pixel;

// this must be the last line in this shader
gl_FragColor = mix(vec4(0.5,0.5,0.5,1.0), gl_FragColor, gl_FragColor.w);
}
32 changes: 16 additions & 16 deletions config/shaders/default/premultiplied.frag
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Default fragment shader for PREMULTIPLIED blend mode
uniform sampler2D texture;
void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
// multiply it by the color
gl_FragColor = gl_Color * pixel;
// this must be the last line in this shader
// * sign(pixel.w) fixes the white border around some transparent pngs
gl_FragColor.xyz *= gl_Color.w * sign(pixel.w);
}
// Default fragment shader for PREMULTIPLIED blend mode

uniform sampler2D texture;

void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);

// multiply it by the color
gl_FragColor = gl_Color * pixel;

// this must be the last line in this shader
// * sign(pixel.w) fixes the white border around some transparent pngs
gl_FragColor.xyz *= gl_Color.w * sign(pixel.w);
}
30 changes: 15 additions & 15 deletions config/shaders/default/screen.frag
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Default fragment shader for SCREEN blend mode
uniform sampler2D texture;
void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
// multiply it by the color
gl_FragColor = gl_Color * pixel;
// this must be the last line in this shader
gl_FragColor.xyz *= gl_FragColor.w;
}
// Default fragment shader for SCREEN blend mode

uniform sampler2D texture;

void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);

// multiply it by the color
gl_FragColor = gl_Color * pixel;

// this must be the last line in this shader
gl_FragColor.xyz *= gl_FragColor.w;
}
12 changes: 12 additions & 0 deletions config/shaders/default/subtract.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Default fragment shader for SUBTRACT blend mode

uniform sampler2D texture;

void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);

// multiply it by the color
gl_FragColor = gl_Color * pixel;
}
7 changes: 7 additions & 0 deletions src/fe_blend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ sf::BlendMode FeBlend::get_blend_mode( int blend_mode )
case FeBlend::Add:
return sf::BlendAdd;

#if ( SFML_VERSION_INT >= FE_VERSION_INT( 2, 4, 0 ))
case FeBlend::Subtract:
return sf::BlendMode(sf::BlendMode::SrcAlpha, sf::BlendMode::One, sf::BlendMode::ReverseSubtract,
sf::BlendMode::One, sf::BlendMode::One, sf::BlendMode::ReverseSubtract);
#endif

#if ( SFML_VERSION_INT >= FE_VERSION_INT( 2, 2, 0 ))
case FeBlend::Screen:
return sf::BlendMode(sf::BlendMode::One, sf::BlendMode::OneMinusSrcColor);
Expand Down Expand Up @@ -71,6 +77,7 @@ sf::Shader* FeBlend::get_default_shader( int blend_mode )
{
case FeBlend::Alpha:
case FeBlend::Add:
case FeBlend::Subtract:
case FeBlend::None:
return NULL;
case FeBlend::Screen:
Expand Down
1 change: 1 addition & 0 deletions src/fe_blend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class FeBlend
{
Alpha,
Add,
Subtract,
Screen,
Multiply,
Overlay,
Expand Down
1 change: 1 addition & 0 deletions src/fe_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ bool FeVM::on_new_layout()
.Enum( _SC("BlendMode"), Enumeration()
.Const( _SC("Alpha"), FeBlend::Alpha )
.Const( _SC("Add"), FeBlend::Add )
.Const( _SC("Subtract"), FeBlend::Subtract )
.Const( _SC("Screen"), FeBlend::Screen )
.Const( _SC("Multiply"), FeBlend::Multiply )
.Const( _SC("Overlay"), FeBlend::Overlay )
Expand Down