| @ -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); | |||
| } | |||
| @ -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); | |||
| } | |||
| @ -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); | |||
| } | |||
| @ -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); | |||
| } | |||
| @ -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); | |||
| } | |||
| @ -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); | |||
| } | |||
| @ -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; | |||
| } | |||