From 68675c6a606cd85b522bd4024d3ea519d0119568 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 30 Jan 2020 13:52:46 +0100 Subject: Updated web examples to latest raylib --- examples/web/shaders/shaders_postprocessing.data | 922 +++++++++++++++-------- 1 file changed, 613 insertions(+), 309 deletions(-) (limited to 'examples/web/shaders/shaders_postprocessing.data') diff --git a/examples/web/shaders/shaders_postprocessing.data b/examples/web/shaders/shaders_postprocessing.data index 0943ddd..2ba729d 100644 --- a/examples/web/shaders/shaders_postprocessing.data +++ b/examples/web/shaders/shaders_postprocessing.data @@ -6879,7 +6879,122 @@ void main() // Calculate final vertex position gl_Position = mvp*vec4(vertexPosition, 1.0); -}#version 100 +}#version 330 + +// Input vertex attributes (from vertex shader) +in vec3 fragPosition; +in vec2 fragTexCoord; +in vec4 fragColor; +in vec3 fragNormal; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// Output fragment color +out vec4 finalColor; + +// NOTE: Add here your custom variables + +#define MAX_LIGHTS 4 +#define LIGHT_DIRECTIONAL 0 +#define LIGHT_POINT 1 + +struct MaterialProperty { + vec3 color; + int useSampler; + sampler2D sampler; +}; + +struct Light { + int enabled; + int type; + vec3 position; + vec3 target; + vec4 color; +}; + +// Input lighting values +uniform Light lights[MAX_LIGHTS]; +uniform vec4 ambient; +uniform vec3 viewPos; + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord); + vec3 lightDot = vec3(0.0); + vec3 normal = normalize(fragNormal); + vec3 viewD = normalize(viewPos - fragPosition); + vec3 specular = vec3(0.0); + + // NOTE: Implement here your fragment shader code + + for (int i = 0; i < MAX_LIGHTS; i++) + { + if (lights[i].enabled == 1) + { + vec3 light = vec3(0.0); + + if (lights[i].type == LIGHT_DIRECTIONAL) + { + light = -normalize(lights[i].target - lights[i].position); + } + + if (lights[i].type == LIGHT_POINT) + { + light = normalize(lights[i].position - fragPosition); + } + + float NdotL = max(dot(normal, light), 0.0); + lightDot += lights[i].color.rgb*NdotL; + + float specCo = 0.0; + if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewD, reflect(-(light), normal))), 16); // 16 refers to shine + specular += specCo; + } + } + + finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0))); + finalColor += texelColor*(ambient/10.0); + + // Gamma correction + finalColor = pow(finalColor, vec4(1.0/2.2)); +} +#version 330 + +// Input vertex attributes +in vec3 vertexPosition; +in vec2 vertexTexCoord; +in vec3 vertexNormal; +in vec4 vertexColor; + +// Input uniform values +uniform mat4 mvp; +uniform mat4 matModel; + +// Output vertex attributes (to fragment shader) +out vec3 fragPosition; +out vec2 fragTexCoord; +out vec4 fragColor; +out vec3 fragNormal; + +// NOTE: Add here your custom variables + +void main() +{ + // Send vertex attributes to fragment shader + fragPosition = vec3(matModel*vec4(vertexPosition, 1.0f)); + fragTexCoord = vertexTexCoord; + fragColor = vertexColor; + + mat3 normalMatrix = transpose(inverse(mat3(matModel))); + fragNormal = normalize(normalMatrix*vertexNormal); + + // Calculate final vertex position + gl_Position = mvp*vec4(vertexPosition, 1.0); +} +#version 100 precision mediump float; @@ -7056,6 +7171,90 @@ void main() precision mediump float; +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Custom variables +const float PI = 3.14159265358979323846; +uniform float uTime; + +float divisions = 5.0; +float angle = 0.0; + +vec2 VectorRotateTime(vec2 v, float speed) +{ + float time = uTime*speed; + float localTime = fract(time); // The time domain this works on is 1 sec. + + if ((localTime >= 0.0) && (localTime < 0.25)) angle = 0.0; + else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4.0*sin(2.0*PI*localTime - PI/2.0); + else if ((localTime >= 0.50) && (localTime < 0.75)) angle = PI*0.25; + else if ((localTime >= 0.75) && (localTime < 1.00)) angle = PI/4.0*sin(2.0*PI*localTime); + + // Rotate vector by angle + v -= 0.5; + v = mat2(cos(angle), -sin(angle), sin(angle), cos(angle))*v; + v += 0.5; + + return v; +} + +float Rectangle(in vec2 st, in float size, in float fill) +{ + float roundSize = 0.5 - size/2.0; + float left = step(roundSize, st.x); + float top = step(roundSize, st.y); + float bottom = step(roundSize, 1.0 - st.y); + float right = step(roundSize, 1.0 - st.x); + + return (left*bottom*right*top)*fill; +} + +void main() +{ + vec2 fragPos = fragTexCoord; + fragPos.xy += uTime/9.0; + + fragPos *= divisions; + vec2 ipos = floor(fragPos); // Get the integer coords + vec2 fpos = fract(fragPos); // Get the fractional coords + + fpos = VectorRotateTime(fpos, 0.2); + + float alpha = Rectangle(fpos, 0.216, 1.0); + vec3 color = vec3(0.3, 0.3, 0.3); + + gl_FragColor = vec4(color, alpha); +}#version 100 + +precision mediump float; + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; // Depth texture +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +void main() +{ + float zNear = 0.01; // camera z near + float zFar = 10.0; // camera z far + float z = texture2D(texture0, fragTexCoord).x; + + // Linearize depth value + float depth = (2.0*zNear)/(zFar + zNear - z*(zFar - zNear)); + + // Calculate final fragment color + gl_FragColor = vec4(depth, depth, depth, 1.0f); +}#version 100 + +precision mediump float; + // Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; @@ -7146,6 +7345,66 @@ void main() precision mediump float; +/************************************************************************************* + + The Sieve of Eratosthenes -- a simple shader by ProfJski + An early prime number sieve: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes + + The screen is divided into a square grid of boxes, each representing an integer value. + Each integer is tested to see if it is a prime number. Primes are colored white. + Non-primes are colored with a color that indicates the smallest factor which evenly divdes our integer. + + You can change the scale variable to make a larger or smaller grid. + Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers. + + WARNING: If you make scale too large, your GPU may bog down! + +***************************************************************************************/ + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Make a nice spectrum of colors based on counter and maxSize +vec4 Colorizer(float counter, float maxSize) +{ + float red = 0.0, green = 0.0, blue = 0.0; + float normsize = counter/maxSize; + + red = smoothstep(0.3, 0.7, normsize); + green = sin(3.14159*normsize); + blue = 1.0 - smoothstep(0.0, 0.4, normsize); + + return vec4(0.8*red, 0.8*green, 0.8*blue, 1.0); +} + +void main() +{ + vec4 color = vec4(1.0); + float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid. + float value = scale*floor(fragTexCoord.y*scale) + floor(fragTexCoord.x*scale); // Group pixels into boxes representing integer values + int valuei = int(value); + + //if ((valuei == 0) || (valuei == 1) || (valuei == 2)) gl_FragColor = vec4(1.0); + //else + { + //for (int i = 2; (i < int(max(2.0, sqrt(value) + 1.0))); i++) + // NOTE: On GLSL 100 for loops are restricted and loop condition must be a constant + // Tested on RPI, it seems loops are limited around 60 iteractions + for (int i = 2; i < 48; i++) + { + if ((value - float(i)*floor(value/float(i))) <= 0.0) + { + gl_FragColor = Colorizer(float(i), scale); + //break; // Uncomment to color by the largest factor instead + } + } + } +} +#version 100 + +precision mediump float; + // Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; varying vec4 fragColor; @@ -7184,344 +7443,162 @@ void main() } gl_FragColor = texture2D(texture0, uv); -}#version 100 - -precision mediump float; - -// Input vertex attributes (from vertex shader) -varying vec2 fragTexCoord; -varying vec4 fragColor; - -// Input uniform values -uniform sampler2D texture0; -uniform vec4 colDiffuse; - -// NOTE: Add here your custom variables - -void main() -{ - // Texel color fetching from texture sampler - vec4 texelColor = texture2D(texture0, fragTexCoord)*colDiffuse*fragColor; - - // Convert texel color to grayscale using NTSC conversion weights - float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114)); - - // Calculate final fragment color - gl_FragColor = vec4(gray, gray, gray, texelColor.a); -}#version 100 - -precision mediump float; - -// Input vertex attributes (from vertex shader) -varying vec2 fragTexCoord; -varying vec4 fragColor; - -// Input uniform values -uniform sampler2D texture0; -uniform vec4 colDiffuse; - -// NOTE: Add here your custom variables - -// NOTE: Render size values must be passed from code -const float renderWidth = 800.0; -const float renderHeight = 450.0; - -float pixelWidth = 5.0; -float pixelHeight = 5.0; - -void main() -{ - float dx = pixelWidth*(1.0/renderWidth); - float dy = pixelHeight*(1.0/renderHeight); - - vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy)); - - vec3 tc = texture2D(texture0, coord).rgb; - - gl_FragColor = vec4(tc, 1.0); -}#version 100 - -precision mediump float; - -// Input vertex attributes (from vertex shader) -varying vec2 fragTexCoord; -varying vec4 fragColor; - -// Input uniform values -uniform sampler2D texture0; -uniform vec4 colDiffuse; - -// NOTE: Add here your custom variables - -float gamma = 0.6; -float numColors = 8.0; - -void main() -{ - vec3 color = texture2D(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)); - - gl_FragColor = vec4(color, 1.0); -}#version 100 - -precision mediump float; +}#version 330 // Input vertex attributes (from vertex shader) -varying vec2 fragTexCoord; -varying vec4 fragColor; +in vec2 fragTexCoord; +in vec4 fragColor; +in vec3 fragPosition; +in vec3 fragNormal; // Input uniform values uniform sampler2D texture0; uniform vec4 colDiffuse; -// NOTE: Add here your custom variables - -void main() -{ - vec3 color = texture2D(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; - - vec3 tc = vec3(0.0, 0.0, 0.0); - - if (lum < 0.5) tc = mix(colors[0], colors[1], lum/0.5); - else tc = mix(colors[1], colors[2], (lum - 0.5)/0.5); - - gl_FragColor = vec4(tc, 1.0); -}#version 100 - -precision mediump float; - -// Input vertex attributes (from vertex shader) -varying vec2 fragTexCoord; -varying vec4 fragColor; - -// Input uniform values -uniform sampler2D texture0; -uniform vec4 colDiffuse; +// Output fragment color +out vec4 finalColor; // NOTE: Add here your custom variables -float offset = 0.0; -float frequency = 450.0/3.0; - -uniform float time; +#define MAX_LIGHTS 4 +#define LIGHT_DIRECTIONAL 0 +#define LIGHT_POINT 1 + +struct MaterialProperty { + vec3 color; + int useSampler; + sampler2D sampler; +}; + +struct Light { + int enabled; + int type; + vec3 position; + vec3 target; + vec4 color; +}; + +// Input lighting values +uniform Light lights[MAX_LIGHTS]; +uniform vec4 ambient; +uniform vec3 viewPos; +uniform float fogDensity; void main() { -/* - // Scanlines method 1 - float tval = 0; //time - vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval)); - - vec4 color = texture2D(texture0, fragTexCoord); - - color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0); - color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y); - color *= vec4(0.8, 1.0, 0.7, 1); - color *= 0.9 + 0.1*sin(10.0*tval + uv.y*1000.0); - color *= 0.97 + 0.03*sin(110.0*tval); - - fragColor = color; -*/ - // Scanlines method 2 - float globalPos = (fragTexCoord.y + offset) * frequency; - float wavePos = cos((fract(globalPos) - 0.5)*3.14); - - vec4 color = texture2D(texture0, fragTexCoord); - - gl_FragColor = mix(vec4(0.0, 0.3, 0.0, 0.0), color, wavePos); -}#version 100 + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord); + vec3 lightDot = vec3(0.0); + vec3 normal = normalize(fragNormal); + vec3 viewD = normalize(viewPos - fragPosition); + vec3 specular = vec3(0.0); -precision mediump float; + // NOTE: Implement here your fragment shader code -// Input vertex attributes (from vertex shader) -varying vec2 fragTexCoord; -varying vec4 fragColor; + for (int i = 0; i < MAX_LIGHTS; i++) + { + if (lights[i].enabled == 1) + { + vec3 light = vec3(0.0); + if (lights[i].type == LIGHT_DIRECTIONAL) { + light = -normalize(lights[i].target - lights[i].position); + } + if (lights[i].type == LIGHT_POINT) { + light = normalize(lights[i].position - fragPosition); + } + float NdotL = max(dot(normal, light), 0.0); + lightDot += lights[i].color.rgb * NdotL; -// Input uniform values -uniform sampler2D texture0; -uniform vec4 colDiffuse; + float specCo = 0.0; + if(NdotL > 0.0) + specCo = pow(max(0.0, dot(viewD, reflect(-(light), normal))), 16);//16 =shine + specular += specCo; -// NOTE: Add here your custom variables -vec2 resolution = vec2(800.0, 450.0); + } + } -void main() -{ - float x = 1.0/resolution.x; - float y = 1.0/resolution.y; - - vec4 horizEdge = vec4(0.0); - horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; - horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0; - horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; - horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; - horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0; - horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; + finalColor = (texelColor * ((colDiffuse+vec4(specular,1)) * vec4(lightDot, 1.0))); + finalColor += texelColor * (ambient/10.0); - vec4 vertEdge = vec4(0.0); - vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; - vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0; - vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; - vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; - vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0; - vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; + // Gamma correction + finalColor = pow(finalColor, vec4(1.0/2.2)); - vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb)); - - gl_FragColor = vec4(edge, texture2D(texture0, fragTexCoord).a); -}#version 100 + // Fog calculation + float dist = length(viewPos - fragPosition); -precision mediump float; + // these could be parameters... + const vec4 fogColor = vec4(0.5, 0.5, 0.5, 1.0); + //const float fogDensity = 0.16; -// Input vertex attributes (from vertex shader) -varying vec2 fragTexCoord; -varying vec4 fragColor; + // Exponential fog + float fogFactor = 1.0/exp((dist*fogDensity)*(dist*fogDensity)); -// Custom variables -#define PI 3.14159265358979323846 -uniform float uTime = 0.0; + // Linear fog (less nice) + //const float fogStart = 2.0; + //const float fogEnd = 10.0; + //float fogFactor = (fogEnd - dist)/(fogEnd - fogStart); -float divisions = 5.0; -float angle = 0.0; + fogFactor = clamp(fogFactor, 0.0, 1.0); -vec2 VectorRotateTime(vec2 v, float speed) -{ - float time = uTime*speed; - float localTime = fract(time); // The time domain this works on is 1 sec. - - if ((localTime >= 0.0) && (localTime < 0.25)) angle = 0.0; - else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4*sin(2*PI*localTime - PI/2); - else if ((localTime >= 0.50) && (localTime < 0.75)) angle = PI*0.25; - else if ((localTime >= 0.75) && (localTime < 1.00)) angle = PI/4*sin(2*PI*localTime); - - // Rotate vector by angle - v -= 0.5; - v = mat2(cos(angle), -sin(angle), sin(angle), cos(angle))*v; - v += 0.5; - - return v; -} - -float Rectangle(in vec2 st, in float size, in float fill) -{ - float roundSize = 0.5 - size/2.0; - float left = step(roundSize, st.x); - float top = step(roundSize, st.y); - float bottom = step(roundSize, 1.0 - st.y); - float right = step(roundSize, 1.0 - st.x); - - return (left*bottom*right*top)*fill; + finalColor = mix(fogColor, finalColor, fogFactor); } +#version 330 -void main() -{ - vec2 fragPos = fragTexCoord; - fragPos.xy += uTime/9.0; - - fragPos *= divisions; - vec2 ipos = floor(fragPos); // Get the integer coords - vec2 fpos = fract(fragPos); // Get the fractional coords - - fpos = VectorRotateTime(fpos, 0.2); - - float alpha = Rectangle(fpos, 0.216, 1.0); - vec3 color = vec3(0.3, 0.3, 0.3); - - gl_FragColor = vec4(color, alpha); -}#version 100 - -precision mediump float; - -// Input vertex attributes (from vertex shader) -varying vec2 fragTexCoord; -varying vec4 fragColor; +// Input vertex attributes +in vec3 vertexPosition; +in vec2 vertexTexCoord; +in vec3 vertexNormal; +in vec4 vertexColor; // Input uniform values -uniform sampler2D texture0; // Depth texture -uniform vec4 colDiffuse; - -// NOTE: Add here your custom variables - -void main() -{ - float zNear = 0.01; // camera z near - float zFar = 10.0; // camera z far - float z = texture2D(texture0, fragTexCoord).x; - - // Linearize depth value - float depth = (2.0*zNear)/(zFar + zNear - z*(zFar - zNear)); - - // Calculate final fragment color - gl_FragColor = vec4(depth, depth, depth, 1.0f); -}#version 100 - -precision mediump float; - -/************************************************************************************* - - The Sieve of Eratosthenes -- a simple shader by ProfJski - An early prime number sieve: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes +uniform mat4 mvp; +uniform mat4 matModel; - The screen is divided into a square grid of boxes, each representing an integer value. - Each integer is tested to see if it is a prime number. Primes are colored white. - Non-primes are colored with a color that indicates the smallest factor which evenly divdes our integer. +// Output vertex attributes (to fragment shader) +out vec2 fragTexCoord; +out vec4 fragColor; +out vec3 fragPosition; +out vec3 fragNormal; - You can change the scale variable to make a larger or smaller grid. - Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers. +// NOTE: Add here your custom variables - WARNING: If you make scale too large, your GPU may bog down! +void main() +{ + // Send vertex attributes to fragment shader + fragTexCoord = vertexTexCoord; + fragColor = vertexColor; + fragPosition = vec3(matModel*vec4(vertexPosition, 1.0f)); + mat3 normalMatrix = transpose(inverse(mat3(matModel))); + fragNormal = normalize(normalMatrix*vertexNormal); -***************************************************************************************/ + // Calculate final vertex position + gl_Position = mvp*vec4(vertexPosition, 1.0); +} +#version 100 + +precision mediump float; // Input vertex attributes (from vertex shader) varying vec2 fragTexCoord; varying vec4 fragColor; -// Make a nice spectrum of colors based on counter and maxSize -vec4 Colorizer(float counter, float maxSize) -{ - float red = 0.0, green = 0.0, blue = 0.0; - float normsize = counter/maxSize; - - red = smoothstep(0.3, 0.7, normsize); - green = sin(3.14159*normsize); - blue = 1.0 - smoothstep(0.0, 0.4, normsize); - - return vec4(0.8*red, 0.8*green, 0.8*blue, 1.0); -} +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables void main() { - vec4 color = vec4(1.0); - float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid. - int value = int(scale*floor(fragTexCoord.y*scale) + floor(fragTexCoord.x*scale)); // Group pixels into boxes representing integer values - - if ((value == 0) || (value == 1) || (value == 2)) gl_FragColor = vec4(1.0); - else - { - for (int i = 2; (i < max(2, sqrt(value) + 1)); i++) - { - if ((value - i*floor(value/i)) == 0) - { - color = Colorizer(float(i), scale); - //break; // Uncomment to color by the largest factor instead - } - } - - gl_FragColor = color; - } -} -#version 100 + // Texel color fetching from texture sampler + vec4 texelColor = texture2D(texture0, fragTexCoord)*colDiffuse*fragColor; + + // Convert texel color to grayscale using NTSC conversion weights + float gray = dot(texelColor.rgb, vec3(0.299, 0.587, 0.114)); + + // Calculate final fragment color + gl_FragColor = vec4(gray, gray, gray, texelColor.a); +}#version 100 precision mediump float; @@ -7534,7 +7611,9 @@ uniform vec2 c; // c.x = real, c.y = imaginary component. Equati uniform vec2 offset; // Offset of the scale. uniform float zoom; // Zoom of the scale. -const int MAX_ITERATIONS = 255; // Max iterations to do. +// NOTE: Maximum number of shader for-loop iterations depend on GPU, +// for example, on RasperryPi for this examply only supports up to 60 +const int MAX_ITERATIONS = 48; // Max iterations to do // Square a complex number vec2 ComplexSquare(vec2 z) @@ -7553,7 +7632,6 @@ vec3 Hsv2rgb(vec3 c) return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); } - void main() { /********************************************************************************************** @@ -7579,21 +7657,22 @@ void main() // NOTE: fragTexCoord already comes as normalized screen coordinates but offset must be normalized before scaling and zoom vec2 z = vec2((fragTexCoord.x + offset.x/screenDims.x)*2.5/zoom, (fragTexCoord.y + offset.y/screenDims.y)*1.5/zoom); - int iterations = 0; - for (iterations = 0; iterations < MAX_ITERATIONS; iterations++) + int iter = 0; + for (int iterations = 0; iterations < 60; iterations++) { z = ComplexSquare(z) + c; // Iterate function - if (dot(z, z) > 4.0) break; + + iter = iterations; } - + // Another few iterations decreases errors in the smoothing calculation. // See http://linas.org/art-gallery/escape/escape.html for more information. z = ComplexSquare(z) + c; z = ComplexSquare(z) + c; // This last part smooths the color (again see link above). - float smoothVal = float(iterations) + 1.0 - (log(log(length(z)))/log(2.0)); + float smoothVal = float(iter) + 1.0 - (log(log(length(z)))/log(2.0)); // Normalize the value so it is between 0 and 1. float norm = smoothVal/float(MAX_ITERATIONS); @@ -7602,6 +7681,48 @@ void main() if (norm > 0.999) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); else gl_FragColor = vec4(Hsv2rgb(vec3(norm, 1.0, 1.0)), 1.0); } +#version 330 + +// Input vertex attributes (from vertex shader) +in vec2 fragTexCoord; + +// Input uniform values +uniform sampler2D texture0; +uniform sampler2D mask; +uniform int frame; + +// Output fragment color +out vec4 finalColor; + +void main() +{ + vec4 maskColour = texture(mask, fragTexCoord+vec2(sin(-frame/150.0)/10.0,cos(-frame/170.0)/10.0)); + if (maskColour.r < 0.25) discard; + vec4 texelColor = texture(texture0, fragTexCoord+vec2(sin(frame/90.0)/8.0,cos(frame/60.0)/8.0)); + + finalColor = texelColor * maskColour; +} +#version 330 + +// Input vertex attributes +in vec3 vertexPosition; +in vec2 vertexTexCoord; + +// Input uniform values +uniform mat4 mvp; +uniform mat4 matModel; + +// Output vertex attributes (to fragment shader) +out vec2 fragTexCoord; + +void main() +{ + // Send vertex attributes to fragment shader + fragTexCoord = vertexTexCoord; + + // Calculate final vertex position + gl_Position = mvp*vec4(vertexPosition, 1.0); +} #version 100 precision mediump float; @@ -7619,17 +7740,29 @@ uniform ivec3 palette[colors]; void main() { // Texel color fetching from texture sampler - vec4 texelColor = texture2D(texture0, fragTexCoord) * fragColor; + vec4 texelColor = texture2D(texture0, fragTexCoord)*fragColor; // Convert the (normalized) texel color RED component (GB would work, too) // to the palette index by scaling up from [0, 1] to [0, 255]. - int index = int(texelColor.r * 255.0); - ivec3 color = palette[index]; + int index = int(texelColor.r*255.0); + + ivec3 color = ivec3(0); + + // NOTE: On GLSL 100 we are not allowed to index a uniform array by a variable value, + // a constantmust be used, so this logic... + if (index == 0) color = palette[0]; + else if (index == 1) color = palette[1]; + else if (index == 2) color = palette[2]; + else if (index == 3) color = palette[3]; + else if (index == 4) color = palette[4]; + else if (index == 5) color = palette[5]; + else if (index == 6) color = palette[6]; + else if (index == 7) color = palette[7]; // Calculate final fragment color. Note that the palette color components // are defined in the range [0, 255] and need to be normalized to [0, 1] // for OpenGL to work. - gl_FragColor = vec4(color / 255.0, texelColor.a); + gl_FragColor = vec4(float(color.x)/255.0, float(color.y)/255.0, float(color.z)/255.0, texelColor.a); } #version 100 @@ -7639,6 +7772,95 @@ precision mediump float; varying vec2 fragTexCoord; varying vec4 fragColor; +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +// NOTE: Render size values must be passed from code +const float renderWidth = 800.0; +const float renderHeight = 450.0; + +float pixelWidth = 5.0; +float pixelHeight = 5.0; + +void main() +{ + float dx = pixelWidth*(1.0/renderWidth); + float dy = pixelHeight*(1.0/renderHeight); + + vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy)); + + vec3 tc = texture2D(texture0, coord).rgb; + + gl_FragColor = vec4(tc, 1.0); +}#version 100 + +precision mediump float; + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +float gamma = 0.6; +float numColors = 8.0; + +void main() +{ + vec3 color = texture2D(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)); + + gl_FragColor = vec4(color, 1.0); +}#version 100 + +precision mediump float; + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + +void main() +{ + vec3 color = texture2D(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; + + vec3 tc = vec3(0.0, 0.0, 0.0); + + if (lum < 0.5) tc = mix(colors[0], colors[1], lum/0.5); + else tc = mix(colors[1], colors[2], (lum - 0.5)/0.5); + + gl_FragColor = vec4(tc, 1.0); +}#version 100 + +precision mediump float; + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + uniform vec3 viewEye; uniform vec3 viewCenter; uniform vec3 viewUp; @@ -8075,6 +8297,88 @@ uniform vec4 colDiffuse; // NOTE: Add here your custom variables +float offset = 0.0; +float frequency = 450.0/3.0; + +uniform float time; + +void main() +{ +/* + // Scanlines method 1 + float tval = 0; //time + vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval)); + + vec4 color = texture2D(texture0, fragTexCoord); + + color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0); + color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y); + color *= vec4(0.8, 1.0, 0.7, 1); + color *= 0.9 + 0.1*sin(10.0*tval + uv.y*1000.0); + color *= 0.97 + 0.03*sin(110.0*tval); + + fragColor = color; +*/ + // Scanlines method 2 + float globalPos = (fragTexCoord.y + offset) * frequency; + float wavePos = cos((fract(globalPos) - 0.5)*3.14); + + vec4 color = texture2D(texture0, fragTexCoord); + + gl_FragColor = mix(vec4(0.0, 0.3, 0.0, 0.0), color, wavePos); +}#version 100 + +precision mediump float; + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables +vec2 resolution = vec2(800.0, 450.0); + +void main() +{ + float x = 1.0/resolution.x; + float y = 1.0/resolution.y; + + vec4 horizEdge = vec4(0.0); + horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; + horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y ))*2.0; + horizEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; + horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; + horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y ))*2.0; + horizEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; + + vec4 vertEdge = vec4(0.0); + vertEdge -= texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y - y))*1.0; + vertEdge -= texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y - y))*2.0; + vertEdge -= texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y - y))*1.0; + vertEdge += texture2D(texture0, vec2(fragTexCoord.x - x, fragTexCoord.y + y))*1.0; + vertEdge += texture2D(texture0, vec2(fragTexCoord.x , fragTexCoord.y + y))*2.0; + vertEdge += texture2D(texture0, vec2(fragTexCoord.x + x, fragTexCoord.y + y))*1.0; + + vec3 edge = sqrt((horizEdge.rgb*horizEdge.rgb) + (vertEdge.rgb*vertEdge.rgb)); + + gl_FragColor = vec4(edge, texture2D(texture0, fragTexCoord).a); +}#version 100 + +precision mediump float; + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +// NOTE: Add here your custom variables + // NOTE: Render size values should be passed from code const float renderWidth = 800.0; const float renderHeight = 450.0; -- cgit v1.2.3