-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from andy840119/pixel-shader
Implement pixel shader
- Loading branch information
Showing
6 changed files
with
101 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Framework.Graphics.OpenGL.Buffers; | ||
using osuTK; | ||
|
||
namespace osu.Framework.Graphics.Shaders | ||
{ | ||
public class PixelShader : CustomizedShader | ||
{ | ||
public const string SHADER_NAME = "Pixel"; | ||
|
||
public Vector2 Size { get; set; } = new Vector2(5); | ||
|
||
public PixelShader(IShader originShader) | ||
: base(originShader) | ||
{ | ||
} | ||
|
||
public override void ApplyValue(FrameBuffer current) | ||
{ | ||
var size = Size; | ||
GetUniform<Vector2>(@"g_Size").UpdateValue(ref size); | ||
|
||
var textureSize = current.Size; | ||
GetUniform<Vector2>(@"g_TexSize").UpdateValue(ref textureSize); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// see the demo: https://www.geeks3d.com/20101029/shader-library-pixelation-post-processing-effect-glsl/ | ||
|
||
varying mediump vec2 v_TexCoord; | ||
|
||
uniform lowp sampler2D m_Sampler; | ||
|
||
uniform mediump vec2 g_TexSize; | ||
uniform mediump vec2 g_Size; | ||
|
||
void main(void) | ||
{ | ||
vec2 separaorParts = g_TexSize / g_Size; | ||
vec2 uv = v_TexCoord; | ||
uv = uv * separaorParts; | ||
uv = floor(uv); | ||
uv = uv / separaorParts; | ||
gl_FragColor = texture2D(m_Sampler, uv); | ||
} |