From 9a578c59624f671418a1f3b046b6b09aa4233909 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Wed, 2 Sep 2015 01:06:55 +0200 Subject: Added shaders examples resources --- examples/resources/shaders/base.vs | 14 ++++----- examples/resources/shaders/bloom.fs | 42 ++++++++++++++++++++++++++ examples/resources/shaders/custom.fs | 16 ---------- examples/resources/shaders/custom.vs | 16 ---------- examples/resources/shaders/grayscale.fs | 17 +++++++---- examples/resources/shaders/shapes_base.vs | 19 ++++++++++++ examples/resources/shaders/shapes_grayscale.fs | 15 +++++++++ examples/resources/shaders/swirl.fs | 41 +++++++++++++++++++++++++ 8 files changed, 135 insertions(+), 45 deletions(-) create mode 100644 examples/resources/shaders/bloom.fs delete mode 100644 examples/resources/shaders/custom.fs delete mode 100644 examples/resources/shaders/custom.vs create mode 100644 examples/resources/shaders/shapes_base.vs create mode 100644 examples/resources/shaders/shapes_grayscale.fs create mode 100644 examples/resources/shaders/swirl.fs (limited to 'examples/resources') diff --git a/examples/resources/shaders/base.vs b/examples/resources/shaders/base.vs index 78e543b7..59eae0a0 100644 --- a/examples/resources/shaders/base.vs +++ b/examples/resources/shaders/base.vs @@ -1,19 +1,19 @@ -#version 110 +#version 330 -attribute vec3 vertexPosition; -attribute vec2 vertexTexCoord; -attribute vec4 vertexColor; +in vec3 vertexPosition; +in vec2 vertexTexCoord; +in vec3 vertexNormal; + +out vec2 fragTexCoord; uniform mat4 projectionMatrix; uniform mat4 modelviewMatrix; -varying vec2 fragTexCoord; -varying vec4 fragColor; +// NOTE: Add here your custom variables void main() { fragTexCoord = vertexTexCoord; - fragColor = vertexColor; gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0); } \ No newline at end of file diff --git a/examples/resources/shaders/bloom.fs b/examples/resources/shaders/bloom.fs new file mode 100644 index 00000000..f9cebe18 --- /dev/null +++ b/examples/resources/shaders/bloom.fs @@ -0,0 +1,42 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 tintColor; + +// NOTE: Add here your custom variables + +void main() +{ + vec4 sum = vec4(0); + vec4 tc = vec4(0); + + for (int i = -4; i < 4; i++) + { + for (int j = -3; j < 3; j++) + { + sum += texture2D(texture0, fragTexCoord + vec2(j, i)*0.004) * 0.25; + } + } + + if (texture2D(texture0, fragTexCoord).r < 0.3) + { + tc = sum*sum*0.012 + texture2D(texture0, fragTexCoord); + } + else + { + if (texture2D(texture0, fragTexCoord).r < 0.5) + { + tc = sum*sum*0.009 + texture2D(texture0, fragTexCoord); + } + else + { + tc = sum*sum*0.0075 + texture2D(texture0, fragTexCoord); + } + } + + fragColor = tc; +} \ No newline at end of file diff --git a/examples/resources/shaders/custom.fs b/examples/resources/shaders/custom.fs deleted file mode 100644 index 1e53933b..00000000 --- a/examples/resources/shaders/custom.fs +++ /dev/null @@ -1,16 +0,0 @@ -#version 330 - -uniform sampler2D texture0; -varying vec2 fragTexCoord; - -uniform vec4 tintColor; - -void main() -{ - vec4 base = texture2D(texture0, fragTexCoord)*tintColor; - - // Convert to grayscale using NTSC conversion weights - float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114)); - - gl_FragColor = vec4(gray, gray, gray, tintColor.a); -} \ No newline at end of file diff --git a/examples/resources/shaders/custom.vs b/examples/resources/shaders/custom.vs deleted file mode 100644 index 629c954d..00000000 --- a/examples/resources/shaders/custom.vs +++ /dev/null @@ -1,16 +0,0 @@ -#version 330 - -attribute vec3 vertexPosition; -attribute vec2 vertexTexCoord; -attribute vec3 vertexNormal; - -uniform mat4 projectionMatrix; -uniform mat4 modelviewMatrix; - -varying vec2 fragTexCoord; - -void main() -{ - fragTexCoord = vertexTexCoord; - gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0); -} \ No newline at end of file diff --git a/examples/resources/shaders/grayscale.fs b/examples/resources/shaders/grayscale.fs index 1b778871..38337e00 100644 --- a/examples/resources/shaders/grayscale.fs +++ b/examples/resources/shaders/grayscale.fs @@ -1,15 +1,20 @@ -#version 110 +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; uniform sampler2D texture0; -varying vec2 fragTexCoord; -varying vec4 fragColor; +uniform vec4 tintColor; + +// NOTE: Add here your custom variables void main() { - vec4 base = texture2D(texture0, fragTexCoord)*fragColor; - + vec4 base = texture2D(texture0, fragTexCoord)*tintColor; + // Convert to grayscale using NTSC conversion weights float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114)); - gl_FragColor = vec4(gray, gray, gray, base.a); + fragColor = vec4(gray, gray, gray, tintColor.a); } \ No newline at end of file diff --git a/examples/resources/shaders/shapes_base.vs b/examples/resources/shaders/shapes_base.vs new file mode 100644 index 00000000..78e543b7 --- /dev/null +++ b/examples/resources/shaders/shapes_base.vs @@ -0,0 +1,19 @@ +#version 110 + +attribute vec3 vertexPosition; +attribute vec2 vertexTexCoord; +attribute vec4 vertexColor; + +uniform mat4 projectionMatrix; +uniform mat4 modelviewMatrix; + +varying vec2 fragTexCoord; +varying vec4 fragColor; + +void main() +{ + fragTexCoord = vertexTexCoord; + fragColor = vertexColor; + + gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0); +} \ No newline at end of file diff --git a/examples/resources/shaders/shapes_grayscale.fs b/examples/resources/shaders/shapes_grayscale.fs new file mode 100644 index 00000000..1b778871 --- /dev/null +++ b/examples/resources/shaders/shapes_grayscale.fs @@ -0,0 +1,15 @@ +#version 110 + +uniform sampler2D texture0; +varying vec2 fragTexCoord; +varying vec4 fragColor; + +void main() +{ + vec4 base = texture2D(texture0, fragTexCoord)*fragColor; + + // Convert to grayscale using NTSC conversion weights + float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114)); + + gl_FragColor = vec4(gray, gray, gray, base.a); +} \ No newline at end of file diff --git a/examples/resources/shaders/swirl.fs b/examples/resources/shaders/swirl.fs new file mode 100644 index 00000000..ba26cc05 --- /dev/null +++ b/examples/resources/shaders/swirl.fs @@ -0,0 +1,41 @@ +#version 330 + +in vec2 fragTexCoord; + +out vec4 fragColor; + +uniform sampler2D texture0; +uniform vec4 tintColor; + +// NOTE: Add here your custom variables + +const float renderWidth = 800; // HARDCODED for example! +const float renderHeight = 480; // Use uniforms instead... + +float radius = 250.0; +float angle = 0.8; + +uniform vec2 center = vec2(200, 200); + +void main (void) +{ + vec2 texSize = vec2(renderWidth, renderHeight); + vec2 tc = fragTexCoord*texSize; + tc -= center; + float dist = length(tc); + + if (dist < radius) + { + float percent = (radius - dist)/radius; + float theta = percent*percent*angle*8.0; + float s = sin(theta); + float c = cos(theta); + + tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c))); + } + + tc += center; + vec3 color = texture2D(texture0, tc/texSize).rgb; + + fragColor = vec4(color, 1.0);; +} \ No newline at end of file -- cgit v1.2.3