Added shaders examples resources
This commit is contained in:
parent
0a345a6128
commit
9a578c5962
7 changed files with 179 additions and 23 deletions
|
@ -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);
|
||||
}
|
42
examples/resources/shaders/bloom.fs
Normal file
42
examples/resources/shaders/bloom.fs
Normal file
|
@ -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;
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -1,16 +1,19 @@
|
|||
#version 330
|
||||
#version 110
|
||||
|
||||
attribute vec3 vertexPosition;
|
||||
attribute vec2 vertexTexCoord;
|
||||
attribute vec3 vertexNormal;
|
||||
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);
|
||||
}
|
|
@ -1,16 +1,15 @@
|
|||
#version 330
|
||||
#version 110
|
||||
|
||||
uniform sampler2D texture0;
|
||||
varying vec2 fragTexCoord;
|
||||
|
||||
uniform vec4 tintColor;
|
||||
varying vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 base = texture2D(texture0, fragTexCoord)*tintColor;
|
||||
|
||||
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, tintColor.a);
|
||||
gl_FragColor = vec4(gray, gray, gray, base.a);
|
||||
}
|
41
examples/resources/shaders/swirl.fs
Normal file
41
examples/resources/shaders/swirl.fs
Normal file
|
@ -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);;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue