Updated shaders with comments

This commit is contained in:
raysan5 2016-05-18 12:04:27 +02:00
commit bc08271da3
34 changed files with 295 additions and 159 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -2,8 +2,11 @@
precision mediump float; precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord; varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0; uniform sampler2D texture0;
uniform vec4 fragTintColor; uniform vec4 fragTintColor;
@ -11,10 +14,12 @@ uniform vec4 fragTintColor;
void main() 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 // Convert texel color to grayscale using NTSC conversion weights
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114)); 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);
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -2,26 +2,30 @@
precision mediump float; precision mediump float;
// Input vertex attributes (from vertex shader)
varying vec2 fragTexCoord; varying vec2 fragTexCoord;
varying vec4 fragColor;
// Input uniform values
uniform sampler2D texture0; uniform sampler2D texture0;
uniform vec4 fragTintColor; uniform vec4 fragTintColor;
// NOTE: Add here your custom variables // NOTE: Add here your custom variables
const float renderWidth = 1280; const float renderWidth = 800.0; // HARDCODED for example!
const float renderHeight = 720; const float renderHeight = 480.0; // Use uniforms instead...
float radius = 250.0; float radius = 250.0;
float angle = 0.8; float angle = 0.8;
uniform vec2 center = vec2(200, 200); uniform vec2 center = vec2(200.0, 200.0);
void main (void) void main()
{ {
vec2 texSize = vec2(renderWidth, renderHeight); vec2 texSize = vec2(renderWidth, renderHeight);
vec2 tc = fragTexCoord*texSize; vec2 tc = fragTexCoord*texSize;
tc -= center; tc -= center;
float dist = length(tc); float dist = length(tc);
if (dist < radius) if (dist < radius)

View file

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

View file

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

Some files were not shown because too many files have changed in this diff Show more