Added support for vertex shaders in sf::Shader
Rewrote the Shader example
This commit is contained in:
parent
4d0a6a299a
commit
c9b87ec8a9
20 changed files with 893 additions and 486 deletions
9
examples/shader/resources/blink.frag
Normal file
9
examples/shader/resources/blink.frag
Normal file
|
@ -0,0 +1,9 @@
|
|||
uniform sampler2D texture;
|
||||
uniform float blink_alpha;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 pixel = gl_Color;
|
||||
pixel.a = blink_alpha;
|
||||
gl_FragColor = pixel;
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
uniform sampler2D texture;
|
||||
uniform float offset;
|
||||
uniform float blur_radius;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 offx = vec2(offset, 0.0);
|
||||
vec2 offy = vec2(0.0, offset);
|
||||
vec2 offx = vec2(blur_radius, 0.0);
|
||||
vec2 offy = vec2(0.0, blur_radius);
|
||||
|
||||
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy) * 1.0 +
|
||||
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy) * 4.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offx) * 2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx) * 2.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy - offy) * 2.0 +
|
||||
|
@ -16,5 +16,5 @@ void main()
|
|||
texture2D(texture, gl_TexCoord[0].xy + offx - offy) * 1.0 +
|
||||
texture2D(texture, gl_TexCoord[0].xy + offx + offy) * 1.0;
|
||||
|
||||
gl_FragColor = gl_Color * (pixel / 13.0);
|
||||
gl_FragColor = gl_Color * (pixel / 16.0);
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
uniform sampler2D texture;
|
||||
uniform vec3 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy) * gl_Color;
|
||||
float gray = pixel.r * 0.39 + pixel.g * 0.50 + pixel.b * 0.11;
|
||||
|
||||
gl_FragColor = vec4(gray * color, 1.0) * 0.6 + pixel * 0.4;
|
||||
gl_FragColor.a = pixel.a;
|
||||
}
|
BIN
examples/shader/resources/devices.png
Normal file
BIN
examples/shader/resources/devices.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 50 KiB |
|
@ -1,5 +1,5 @@
|
|||
uniform sampler2D texture;
|
||||
uniform float threshold;
|
||||
uniform float edge_threshold;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
@ -23,9 +23,10 @@ void main()
|
|||
|
||||
vec3 result = sqrt(hEdge.rgb * hEdge.rgb + vEdge.rgb * vEdge.rgb);
|
||||
float edge = length(result);
|
||||
if (edge > threshold)
|
||||
gl_FragColor.rgb = vec3(0, 0, 0);
|
||||
vec4 pixel = gl_Color * texture2D(texture, gl_TexCoord[0].xy);
|
||||
if (edge > edge_threshold * 8)
|
||||
pixel.rgb = vec3(0.0, 0.0, 0.0);
|
||||
else
|
||||
gl_FragColor.rgb = vec3(1, 1, 1);
|
||||
gl_FragColor.a = gl_Color.a * texture2D(texture, gl_TexCoord[0].xy).a;
|
||||
pixel.a = edge_threshold;
|
||||
gl_FragColor = pixel;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
uniform sampler2D texture;
|
||||
uniform vec2 mouse;
|
||||
|
||||
void main()
|
||||
{
|
||||
float len = distance(gl_TexCoord[0].xy, mouse) * 7.0;
|
||||
|
||||
vec2 coords = gl_TexCoord[0].xy;
|
||||
if (len < 1.0)
|
||||
coords += (gl_TexCoord[0].xy - mouse) * len;
|
||||
|
||||
gl_FragColor = texture2D(texture, coords) * gl_Color;
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
uniform sampler2D texture;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(texture, gl_TexCoord[0].xy) * gl_Color;
|
||||
}
|
|
@ -1,10 +1,9 @@
|
|||
uniform sampler2D texture;
|
||||
uniform vec2 mouse;
|
||||
uniform float pixel_threshold;
|
||||
|
||||
void main()
|
||||
{
|
||||
float factor = 5.0 + 100.0 * length(mouse);
|
||||
float factor = 1.0 / (pixel_threshold + 0.001);
|
||||
vec2 pos = floor(gl_TexCoord[0].xy * factor + 0.5) / factor;
|
||||
|
||||
gl_FragColor = texture2D(texture, pos) * gl_Color;
|
||||
}
|
BIN
examples/shader/resources/sfml.png
Normal file
BIN
examples/shader/resources/sfml.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
Binary file not shown.
Before Width: | Height: | Size: 6.1 KiB |
19
examples/shader/resources/storm.vert
Normal file
19
examples/shader/resources/storm.vert
Normal file
|
@ -0,0 +1,19 @@
|
|||
uniform vec2 storm_position;
|
||||
uniform float storm_total_radius;
|
||||
uniform float storm_inner_radius;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 vertex = gl_ModelViewMatrix * gl_Vertex;
|
||||
vec2 offset = vertex.xy - storm_position;
|
||||
float len = length(offset);
|
||||
if (len < storm_total_radius)
|
||||
{
|
||||
float push_distance = storm_inner_radius + len / storm_total_radius * (storm_total_radius - storm_inner_radius);
|
||||
vertex.xy = storm_position + normalize(offset) * push_distance;
|
||||
}
|
||||
|
||||
gl_Position = gl_ProjectionMatrix * vertex;
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
gl_FrontColor = gl_Color;
|
||||
}
|
BIN
examples/shader/resources/text-background.png
Normal file
BIN
examples/shader/resources/text-background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 745 B |
Binary file not shown.
Before Width: | Height: | Size: 23 KiB |
|
@ -1,12 +0,0 @@
|
|||
uniform sampler2D texture;
|
||||
uniform sampler2D wave;
|
||||
uniform vec2 offset;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texoffset = vec2(texture2D(wave, (gl_TexCoord[0].xy * offset).xy));
|
||||
texoffset -= vec2(0.5, 0.5);
|
||||
texoffset *= 0.05;
|
||||
|
||||
gl_FragColor = texture2D(texture, gl_TexCoord[0].xy + texoffset) * gl_Color;
|
||||
}
|
15
examples/shader/resources/wave.vert
Normal file
15
examples/shader/resources/wave.vert
Normal file
|
@ -0,0 +1,15 @@
|
|||
uniform float wave_phase;
|
||||
uniform vec2 wave_amplitude;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 vertex = gl_Vertex;
|
||||
vertex.x += cos(gl_Vertex.y * 0.02 + wave_phase * 3.8) * wave_amplitude.x
|
||||
+ sin(gl_Vertex.y * 0.02 + wave_phase * 6.3) * wave_amplitude.x * 0.3;
|
||||
vertex.y += sin(gl_Vertex.x * 0.02 + wave_phase * 2.4) * wave_amplitude.y
|
||||
+ cos(gl_Vertex.x * 0.02 + wave_phase * 5.2) * wave_amplitude.y * 0.3;
|
||||
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vertex;
|
||||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
|
||||
gl_FrontColor = gl_Color;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue