Browse Source

Updated shaders with comments

pull/118/head
raysan5 8 years ago
parent
commit
bc08271da3
34 changed files with 295 additions and 159 deletions
  1. +1
    -1
      examples/resources/shaders/glsl100/bloom.fs
  2. +1
    -1
      examples/resources/shaders/glsl100/swirl.fs
  3. +1
    -1
      examples/resources/shaders/glsl330/bloom.fs
  4. +3
    -0
      examples/resources/shaders/glsl330/phong.fs
  5. +1
    -1
      examples/resources/shaders/glsl330/swirl.fs
  6. +10
    -4
      shaders/glsl100/base.vs
  7. +10
    -15
      shaders/glsl100/bloom.fs
  8. +5
    -0
      shaders/glsl100/blur.fs
  9. +4
    -1
      shaders/glsl100/cross_hatching.fs
  10. +4
    -1
      shaders/glsl100/cross_stitching.fs
  11. +3
    -0
      shaders/glsl100/dream_vision.fs
  12. +4
    -1
      shaders/glsl100/fisheye.fs
  13. +9
    -4
      shaders/glsl100/grayscale.fs
  14. +3
    -0
      shaders/glsl100/pixel.fs
  15. +3
    -0
      shaders/glsl100/posterization.fs
  16. +3
    -0
      shaders/glsl100/predator.fs
  17. +4
    -1
      shaders/glsl100/scanlines.fs
  18. +10
    -6
      shaders/glsl100/swirl.fs
  19. +4
    -0
      shaders/glsl100/template.fs
  20. +10
    -2
      shaders/glsl330/base.vs
  21. +15
    -19
      shaders/glsl330/bloom.fs
  22. +12
    -7
      shaders/glsl330/blur.fs
  23. +11
    -7
      shaders/glsl330/cross_hatching.fs
  24. +8
    -4
      shaders/glsl330/cross_stitching.fs
  25. +27
    -0
      shaders/glsl330/depth.fs
  26. +12
    -6
      shaders/glsl330/grayscale.fs
  27. +48
    -39
      shaders/glsl330/phong.fs
  28. +8
    -6
      shaders/glsl330/phong.vs
  29. +8
    -4
      shaders/glsl330/pixel.fs
  30. +14
    -9
      shaders/glsl330/posterization.fs
  31. +10
    -5
      shaders/glsl330/predator.fs
  32. +10
    -5
      shaders/glsl330/scanlines.fs
  33. +11
    -6
      shaders/glsl330/swirl.fs
  34. +8
    -3
      shaders/glsl330/template.fs

+ 1
- 1
examples/resources/shaders/glsl100/bloom.fs View File

@ -33,5 +33,5 @@ void main()
else if (texelColor.r < 0.5) tc = sum*sum*0.009 + texelColor;
else tc = sum*sum*0.0075 + texelColor;
finalColor = tc;
gl_FragColor = tc;
}

+ 1
- 1
examples/resources/shaders/glsl100/swirl.fs View File

@ -20,7 +20,7 @@ float angle = 0.8;
uniform vec2 center = vec2(200.0, 200.0);
void nf">main (void)
void err">main()
{
vec2 texSize = vec2(renderWidth, renderHeight);
vec2 tc = fragTexCoord*texSize;

+ 1
- 1
examples/resources/shaders/glsl330/bloom.fs View File

@ -17,7 +17,7 @@ void main()
{
vec4 sum = vec4(0);
vec4 tc = vec4(0);
for (int i = -4; i < 4; i++)
{
for (int j = -3; j < 3; j++)

+ 3
- 0
examples/resources/shaders/glsl330/phong.fs View File

@ -29,6 +29,9 @@ uniform float matGlossiness = 50.0;
uniform vec3 lightPosition;
uniform vec3 cameraPosition;
// Fragment shader output data
out vec4 fragColor;
// Calculate ambient lighting component
vec3 AmbientLighting()
{

+ 1
- 1
examples/resources/shaders/glsl330/swirl.fs View File

@ -21,7 +21,7 @@ float angle = 0.8;
uniform vec2 center = vec2(200.0, 200.0);
void nf">main (void)
void err">main()
{
vec2 texSize = vec2(renderWidth, renderHeight);
vec2 tc = fragTexCoord*texSize;

+ 10
- 4
shaders/glsl100/base.vs View File

@ -1,20 +1,26 @@
#version 100
// Input vertex attributes
attribute vec3 vertexPosition;
attribute vec2 vertexTexCoord;
attribute vec3 vertexNormal;
attribute vec4 vertexColor;
varying vec2 fragTexCoord;
// Input uniform values
uniform mat4 mvpMatrix;
// Output vertex attributes (to fragment shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// NOTE: Add here your custom variables
void main()
{
vec3 normal = vertexNormal;
// Send vertex attributes to fragment shader
fragTexCoord = vertexTexCoord;
fragColor = vertexColor;
// Calculate final vertex position
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
}

+ 10
- 15
shaders/glsl100/bloom.fs View File

@ -2,8 +2,11 @@
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
@ -22,21 +25,13 @@ void main()
}
}
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);
}
}
// Texel color fetching from texture sampler
vec4 texelColor = texture(texture0, fragTexCoord);
// Calculate final fragment color
if (texelColor.r < 0.3) tc = sum*sum*0.012 + texelColor;
else if (texelColor.r < 0.5) tc = sum*sum*0.009 + texelColor;
else tc = sum*sum*0.0075 + texelColor;
gl_FragColor = tc;
}

+ 5
- 0
shaders/glsl100/blur.fs View File

@ -2,7 +2,11 @@
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
@ -16,6 +20,7 @@ float weight[3] = float[]( 0.2270270270, 0.3162162162, 0.0702702703 );
void main()
{
// Texel color fetching from texture sampler
vec3 tc = texture2D(texture0, fragTexCoord).rgb*weight[0];
for (int i = 1; i < 3; i++)

+ 4
- 1
shaders/glsl100/cross_hatching.fs View File

@ -2,12 +2,15 @@
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
// NOTE: Add here your custom nf">variables
// NOTE: Add here your custom err">variables
float hatchOffsetY = 5.0f;
float lumThreshold01 = 0.9f;

+ 4
- 1
shaders/glsl100/cross_stitching.fs View File

@ -2,8 +2,11 @@
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
@ -46,7 +49,7 @@ vec4 PostFX(sampler2D tex, vec2 uv)
return c;
}
void main(void)
void main()
{
vec3 tc = PostFX(texture0, fragTexCoord).rgb;

+ 3
- 0
shaders/glsl100/dream_vision.fs View File

@ -2,8 +2,11 @@
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;

+ 4
- 1
shaders/glsl100/fisheye.fs View File

@ -2,12 +2,15 @@
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
// NOTE: Add here your custom nf">variables
// NOTE: Add here your custom err">variables
const float PI = 3.1415926535;

+ 9
- 4
shaders/glsl100/grayscale.fs View File

@ -2,8 +2,11 @@
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
@ -11,10 +14,12 @@ uniform vec4 fragTintColor;
void main()
{
vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor;
// Texel color fetching from texture sampler
vec4 texelColor = texture(texture0, fragTexCoord)*fragTintColor*fragColor;
// Convert to grayscale using NTSC conversion weights
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
// Convert nf">texel color to grayscale using NTSC conversion weights
float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114));
gl_FragColor = vec4(gray, gray, gray, fragTintColor.a);
// Calculate final fragment color
gl_FragColor = vec4(gray, gray, gray, texelColor.a);
}

+ 3
- 0
shaders/glsl100/pixel.fs View File

@ -2,8 +2,11 @@
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;

+ 3
- 0
shaders/glsl100/posterization.fs View File

@ -2,8 +2,11 @@
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;

+ 3
- 0
shaders/glsl100/predator.fs View File

@ -2,8 +2,11 @@
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;

+ 4
- 1
shaders/glsl100/scanlines.fs View File

@ -2,8 +2,11 @@
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
@ -14,7 +17,7 @@ float frequency = 720/3.0;
uniform float time;
void nf">main (void)
void err">main()
{
/*
// Scanlines method 1

+ 10
- 6
shaders/glsl100/swirl.fs View File

@ -2,28 +2,32 @@
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280;
const float renderHeight = 720;
const float renderWidth = 800.0; // HARDCODED for example!
const float renderHeight = 480.0; // Use uniforms instead...
float radius = 250.0;
float angle = 0.8;
uniform vec2 center = vec2(200, 200);
uniform vec2 center = vec2(200.0, 200.0);
void nf">main (void)
void err">main()
{
vec2 texSize = vec2(renderWidth, renderHeight);
vec2 tc = fragTexCoord*texSize;
tc -= center;
float dist = length(tc);
float dist = length(tc);
if (dist < radius)
{
float percent = (radius - dist)/radius;
@ -33,7 +37,7 @@ void main (void)
tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c)));
}
tc += center;
vec3 color = texture2D(texture0, tc/texSize).rgb;

+ 4
- 0
shaders/glsl100/template.fs View File

@ -2,8 +2,11 @@
precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
@ -11,6 +14,7 @@ uniform vec4 fragTintColor;
void main()
{
// Texel color fetching from texture sampler
vec4 texelColor = texture2D(texture0, fragTexCoord);
// NOTE: Implement here your fragment shader code

+ 10
- 2
shaders/glsl330/base.vs View File

@ -1,18 +1,26 @@
#version 330
// Input vertex attributes
in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec3 vertexNormal;
in vec4 vertexColor;
out vec2 fragTexCoord;
// Input uniform values
uniform mat4 mvpMatrix;
// Output vertex attributes (to fragment shader)
out vec2 fragTexCoord;
out vec4 fragColor;
// NOTE: Add here your custom variables
void main()
{
// Send vertex attributes to fragment shader
fragTexCoord = vertexTexCoord;
fragColor = vertexColor;
// Calculate final vertex position
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
}

+ 15
- 19
shaders/glsl330/bloom.fs View File

@ -1,12 +1,16 @@
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
out vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
// Output fragment color
out vec4 finalColor;
// NOTE: Add here your custom variables
void main()
@ -18,25 +22,17 @@ void main()
{
for (int j = -3; j < 3; j++)
{
sum += texture(texture0, fragTexCoord + vec2(j, nf">i)*0.004) * 0.25;
sum += texture(texture0, fragTexCoord + vec2(j, err">i)*0.004)*0.25;
}
}
if (texture(texture0, fragTexCoord).r < 0.3)
{
tc = sum*sum*0.012 + texture(texture0, fragTexCoord);
}
else
{
if (texture(texture0, fragTexCoord).r < 0.5)
{
tc = sum*sum*0.009 + texture(texture0, fragTexCoord);
}
else
{
tc = sum*sum*0.0075 + texture(texture0, fragTexCoord);
}
}
// Texel color fetching from texture sampler
vec4 texelColor = texture(texture0, fragTexCoord);
fragColor = tc;
// Calculate final fragment color
if (texelColor.r < 0.3) tc = sum*sum*0.012 + texelColor;
else if (texelColor.r < 0.5) tc = sum*sum*0.009 + texelColor;
else tc = sum*sum*0.0075 + texelColor;
finalColor = tc;
}

+ 12
- 7
shaders/glsl330/blur.fs View File

@ -1,12 +1,16 @@
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
out vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
// Output fragment color
out vec4 finalColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280.0;
@ -17,13 +21,14 @@ float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);
void main()
{
vec3 tc = texture(texture0, fragTexCoord).rgb*weight[0];
// Texel color fetching from texture sampler
vec3 texelColor = texture(texture0, fragTexCoord).rgb*weight[0];
for (int i = 1; i < 3; i++)
{
tc += texture(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
tc += texture(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
texelColor += texture(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
texelColor += texture(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
}
fragColor = vec4(tc, 1.0);
finalColor = vec4(texelColor, 1.0);
}

+ 11
- 7
shaders/glsl330/cross_hatching.fs View File

@ -1,13 +1,17 @@
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
out vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
// Output fragment color
out vec4 finalColor;
// NOTE: Add here your custom variables
float hatchOffsetY = 5.0;
float lumThreshold01 = 0.9;
@ -27,18 +31,18 @@ void main()
if (lum < lumThreshold02)
{
if (mod(gl_FragCoord .x - gl_FragCoord .y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
}
if (lum < lumThreshold03)
{
if (mod(gl_FragCoord .x + gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
if (mod(gl_FragCoord.x + gl_FragCoord.y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
}
if (lum < lumThreshold04)
{
if (mod(gl_FragCoord .x - gl_FragCoord .y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
if (mod(gl_FragCoord.x - gl_FragCoord.y - hatchOffsetY, 10.0) == 0.0) tc = vec3(0.0, 0.0, 0.0);
}
fragColor = vec4(tc, 1.0);
finalColor = vec4(tc, 1.0);
}

+ 8
- 4
shaders/glsl330/cross_stitching.fs View File

@ -1,12 +1,16 @@
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
out vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
// Output fragment color
out vec4 finalColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280.0;
@ -46,9 +50,9 @@ vec4 PostFX(sampler2D tex, vec2 uv)
return c;
}
void main(void)
void main()
{
vec3 tc = PostFX(texture0, fragTexCoord).rgb;
fragColor = vec4(tc, 1.0);
finalColor = vec4(tc, 1.0);
}

+ 27
- 0
shaders/glsl330/depth.fs View File

@ -0,0 +1,27 @@
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
// Input uniform values
uniform sampler2D texture0; // Depth texture
uniform vec4 fragTintColor;
// Output fragment color
out vec4 finalColor;
// NOTE: Add here your custom variables
void main()
{
float zNear = 0.01; // camera z near
float zFar = 10.0; // camera z far
float z = texture(texture0, fragTexCoord).x;
// Linearize depth value
float depth = (2.0*zNear)/(zFar + zNear - z*(zFar - zNear));
// Calculate final fragment color
finalColor = vec4(depth, depth, depth, 1.0f);
}

+ 12
- 6
shaders/glsl330/grayscale.fs View File

@ -1,20 +1,26 @@
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
out vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
// Output fragment color
out vec4 finalColor;
// NOTE: Add here your custom variables
void main()
{
vec4 base = texture(texture0, fragTexCoord)*fragTintColor;
// Texel color fetching from texture sampler
vec4 texelColor = texture(texture0, fragTexCoord)*fragTintColor*fragColor;
// Convert to grayscale using NTSC conversion weights
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
// Convert nf">texel color to grayscale using NTSC conversion weights
float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114));
fragColor = vec4(gray, gray, gray, fragTintColor.a);
// Calculate final fragment color
finalColor = vec4(gray, gray, gray, texelColor.a);
}

+ 48
- 39
shaders/glsl330/phong.fs View File

@ -1,76 +1,85 @@
#version 330
// Vertex shader input data
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec3 fragNormal;
// Diffuse data
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
// Light attributes
uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0);
uniform vec3 light_diffuseColor = vec3(1, 0.5, 0);
uniform vec3 light_specularColor = vec3(0, 1, 0);
uniform float light_intensity = 1;
uniform float light_specIntensity = 1;
// Output fragment color
out vec4 finalColor;
// Material attributes
uniform vec3 mat_ambientColor = vec3(1, 1, 1);
uniform vec3 mat_specularColor = vec3(1, 1, 1);
uniform float mat_glossiness = 50;
// NOTE: Add here your custom variables
// World attributes
uniform vec3 lightPos;
uniform vec3 cameraPos;
// Light uniform values
uniform vec3 lightAmbientColor = vec3(0.6, 0.3, 0.0);
uniform vec3 lightDiffuseColor = vec3(1.0, 0.5, 0.0);
uniform vec3 lightSpecularColor = vec3(0.0, 1.0, 0.0);
uniform float lightIntensity = 1.0;
uniform float lightSpecIntensity = 1.0;
// Material uniform values
uniform vec3 matAmbientColor = vec3(1.0, 1.0, 1.0);
uniform vec3 matSpecularColor = vec3(1.0, 1.0, 1.0);
uniform float matGlossiness = 50.0;
// World uniform values
uniform vec3 lightPosition;
uniform vec3 cameraPosition;
// Fragment shader output data
out vec4 fragColor;
// Calculate ambient lighting component
vec3 AmbientLighting()
{
return mat_ambientColor * light_ambientColor;
return (matAmbientColor*lightAmbientColor);
}
// Calculate diffuse lighting component
vec3 DiffuseLighting(in vec3 N, in vec3 L)
{
// Lambertian reflection calculation
float diffuse = clamp(dot(N, L), 0, 1);
return tintColor.xyz * light_diffuseColor * light_intensity * diffuse;
// Lambertian reflection calculation
float diffuse = clamp(dot(N, L), 0, 1);
return (fragTintColor.xyz*lightDiffuseColor*lightIntensity*diffuse);
}
// Calculate specular lighting component
vec3 SpecularLighting(in vec3 N, in vec3 L, in vec3 V)
{
float specular = 0;
// Calculate specular reflection only if the surface is oriented to the light source
if(dot(N, L) > 0)
{
// Calculate half vector
vec3 H = normalize(L + V);
// Calculate specular intensity
specular = pow(dot(N, H), 3 + mat_glossiness);
}
float specular = 0.0;
// Calculate specular reflection only if the surface is oriented to the light source
if (dot(N, L) > 0)
{
// Calculate half vector
vec3 H = normalize(L + V);
// Calculate specular intensity
specular = pow(dot(N, H), 3 + matGlossiness);
}
return mat_specularColor * light_specularColor * light_specIntensity * specular;
return (matSpecularColor*lightSpecularColor*lightSpecIntensity*specular);
}
void main()
{
// Normalize input vectors
vec3 L = normalize(lightPos);
vec3 V = normalize(cameraPos);
vec3 L = normalize(lightPosition);
vec3 V = normalize(cameraPosition);
vec3 N = normalize(fragNormal);
// Calculate lighting components
vec3 ambient = AmbientLighting();
vec3 diffuse = DiffuseLighting(N, L);
vec3 specular = SpecularLighting(N, L, V);
// Get base color from texture
vec4 textureColor = texture(texture0, fragTexCoord);
vec3 finalColor = textureColor.rgb;
fragColor = vec4(finalColor * (ambient + diffuse + specular), textrr">urlass="err">eColor.a);
// Texel color fetching from texture sampler
vec4 texelColor = texture(texture0, fragTexCoord);
// Calculate final fragment color
finalColor = vec4(texelColor.rgb*(ambient + diffuse + specular), texelColor.a);
}

+ 8
- 6
shaders/glsl330/phong.vs View File

@ -1,23 +1,25 @@
#version 330
// Vertex input data
// Input vertex attributes
in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec3 vertexNormal;
// Projection and model data
// Input uniform values
uniform mat4 mvpMatrix;
uniform mat4 modelMatrix;
// Attributes to fragment shader
// Output vertex attributes (to fragment shader)
out vec2 fragTexCoord;
out vec3 fragNormal;
// NOTE: Add here your custom variables
uniform mat4 modelMatrix;
void main()
{
// Send texture coord to fragment shader
// Send vertex attributes to fragment shader
fragTexCoord = vertexTexCoord;
// Calculate view vector normal from model
mat3 normalMatrix = transpose(inverse(mat3(modelMatrix)));
fragNormal = normalize(normalMatrix*vertexNormal);

+ 8
- 4
shaders/glsl330/pixel.fs View File

@ -1,13 +1,17 @@
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
out vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
// Output fragment color
out vec4 finalColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280.0;
const float renderHeight = 720.0;
@ -24,5 +28,5 @@ void main()
vec3 tc = texture(texture0, coord).rgb;
fragColor = vec4(tc, 1.0);
finalColor = vec4(tc, 1.0);
}

+ 14
- 9
shaders/glsl330/posterization.fs View File

@ -1,12 +1,16 @@
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
out vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
// Output fragment color
out vec4 finalColor;
// NOTE: Add here your custom variables
float gamma = 0.6;
@ -14,13 +18,14 @@ float numColors = 8.0;
void main()
{
vec3 color = texture(texture0, fragTexCoord.xy).rgb;
// Texel color fetching from texture sampler
vec3 texelColor = texture(texture0, fragTexCoord.xy).rgb;
color = pow(color, vec3(gamma, gamma, gamma));
color = color*numColors;
color = floor(color);
color = color/numColors;
color = pow(color, vec3(1.0/gamma));
texelColor = pow(texelColor, vec3(gamma, gamma, gamma));
texelColor = tclass="err">exelColor*numColors;
texelColor = floor(tclass="err">exelColor);
texelColor = tclass="err">exelColor/numColors;
texelColor = pow(texelColor, vec3(1.0/gamma));
fragColor = vec4(color, 1.0);
finalColor = vec4(texelColor, 1.0);
}

+ 10
- 5
shaders/glsl330/predator.fs View File

@ -1,27 +1,32 @@
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
out vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
// Output fragment color
out vec4 finalColor;
// NOTE: Add here your custom variables
void main()
{
vec3 color = texture(texture0, fragTexCoord).rgb;
// Texel color fetching from texture sampler
vec3 texelColor = texture(texture0, fragTexCoord).rgb;
vec3 colors[3];
colors[0] = vec3(0.0, 0.0, 1.0);
colors[1] = vec3(1.0, 1.0, 0.0);
colors[2] = vec3(1.0, 0.0, 0.0);
float lum = (color.r + color.g + color.b)/3.0;
float lum = (texelColor.r + texelColor.g + tclass="err">exelColor.b)/3.0;
int ix = (lum < 0.5)? 0:1;
vec3 tc = mix(colors[ix], colors[ix + 1], (lum - float(ix)*0.5)/0.5);
fragColor = vec4(tc, 1.0);
finalColor = vec4(tc, 1.0);
}

+ 10
- 5
shaders/glsl330/scanlines.fs View File

@ -1,12 +1,16 @@
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
out vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
// Output fragment color
out vec4 finalColor;
// NOTE: Add here your custom variables
float offset = 0.0;
@ -14,7 +18,7 @@ float frequency = 720.0/3.0;
uniform float time;
void nf">main (void)
void err">main()
{
/*
// Scanlines method 1
@ -35,7 +39,8 @@ void main (void)
float globalPos = (fragTexCoord.y + offset) * frequency;
float wavePos = cos((fract(globalPos) - 0.5)*3.14);
vec4 color = texture(texture0, fragTexCoord);
// Texel color fetching from texture sampler
vec4 texelColor = texture(texture0, fragTexCoord);
fragColor = mix(vec4(0.0, 0.3, 0.0, 0.0), color, wavePos);
finalColor = mix(vec4(0.0, 0.3, 0.0, 0.0), texelColor, wavePos);
}

+ 11
- 6
shaders/glsl330/swirl.fs View File

@ -1,27 +1,32 @@
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
out vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
// Output fragment color
out vec4 finalColor;
// NOTE: Add here your custom variables
const float renderWidth = 1280.0;
const float renderHeight = 720.0;
const float renderWidth = 800.0; // HARDCODED for example!
const float renderHeight = 480.0; // Use uniforms instead...
float radius = 250.0;
float angle = 0.8;
uniform vec2 center = vec2(200.0, 200.0);
void nf">main (void)
void err">main()
{
vec2 texSize = vec2(renderWidth, renderHeight);
vec2 tc = fragTexCoord*texSize;
tc -= center;
float dist = length(tc);
if (dist < radius)
@ -37,5 +42,5 @@ void main (void)
tc += center;
vec3 color = texture(texture0, tc/texSize).rgb;
fragColor = vec4(color, 1.0);;
finalColor = vec4(color, 1.0);;
}

+ 8
- 3
shaders/glsl330/template.fs View File

@ -1,19 +1,24 @@
#version 330
// Input vertex attributes (from vertex shader)
in vec2 fragTexCoord;
in vec4 fragColor;
out vec4 fragColor;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 fragTintColor;
// Output fragment color
out vec4 finalColor;
// NOTE: Add here your custom variables
void main()
{
// Texel color fetching from texture sampler
vec4 texelColor = texture(texture0, fragTexCoord);
// NOTE: Implement here your fragment shader code
fragColor = texelColor*fragTintColor;
finalColor = texelColor*fragTintColor;
}

Loading…
Cancel
Save