Merge branch 'master' of github.com:patriciogonzalezvivo/thebookofshaders
commit
f6c6bd75c0
@ -0,0 +1,260 @@
|
||||
/*
|
||||
** Copyright (c) 2012, Romain Dura romain@shazbits.com
|
||||
**
|
||||
** Permission to use, copy, modify, and/or distribute this software for any
|
||||
** purpose with or without fee is hereby granted, provided that the above
|
||||
** copyright notice and this permission notice appear in all copies.
|
||||
**
|
||||
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
** WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
** SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
** WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
** ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
** IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
** Photoshop & misc math
|
||||
** Blending modes, RGB/HSL/Contrast/Desaturate, levels control
|
||||
**
|
||||
** Romain Dura | Romz
|
||||
** Blog: http://mouaif.wordpress.com
|
||||
** Post: http://mouaif.wordpress.com/?p=94
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Desaturation
|
||||
*/
|
||||
|
||||
vec4 Desaturate(vec3 color, float Desaturation)
|
||||
{
|
||||
vec3 grayXfer = vec3(0.3, 0.59, 0.11);
|
||||
vec3 gray = vec3(dot(grayXfer, color));
|
||||
return vec4(mix(color, gray, Desaturation), 1.0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Hue, saturation, luminance
|
||||
*/
|
||||
|
||||
vec3 RGBToHSL(vec3 color)
|
||||
{
|
||||
vec3 hsl; // init to 0 to avoid warnings ? (and reverse if + remove first part)
|
||||
|
||||
float fmin = min(min(color.r, color.g), color.b); //Min. value of RGB
|
||||
float fmax = max(max(color.r, color.g), color.b); //Max. value of RGB
|
||||
float delta = fmax - fmin; //Delta RGB value
|
||||
|
||||
hsl.z = (fmax + fmin) / 2.0; // Luminance
|
||||
|
||||
if (delta == 0.0) //This is a gray, no chroma...
|
||||
{
|
||||
hsl.x = 0.0; // Hue
|
||||
hsl.y = 0.0; // Saturation
|
||||
}
|
||||
else //Chromatic data...
|
||||
{
|
||||
if (hsl.z < 0.5)
|
||||
hsl.y = delta / (fmax + fmin); // Saturation
|
||||
else
|
||||
hsl.y = delta / (2.0 - fmax - fmin); // Saturation
|
||||
|
||||
float deltaR = (((fmax - color.r) / 6.0) + (delta / 2.0)) / delta;
|
||||
float deltaG = (((fmax - color.g) / 6.0) + (delta / 2.0)) / delta;
|
||||
float deltaB = (((fmax - color.b) / 6.0) + (delta / 2.0)) / delta;
|
||||
|
||||
if (color.r == fmax )
|
||||
hsl.x = deltaB - deltaG; // Hue
|
||||
else if (color.g == fmax)
|
||||
hsl.x = (1.0 / 3.0) + deltaR - deltaB; // Hue
|
||||
else if (color.b == fmax)
|
||||
hsl.x = (2.0 / 3.0) + deltaG - deltaR; // Hue
|
||||
|
||||
if (hsl.x < 0.0)
|
||||
hsl.x += 1.0; // Hue
|
||||
else if (hsl.x > 1.0)
|
||||
hsl.x -= 1.0; // Hue
|
||||
}
|
||||
|
||||
return hsl;
|
||||
}
|
||||
|
||||
float HueToRGB(float f1, float f2, float hue)
|
||||
{
|
||||
if (hue < 0.0)
|
||||
hue += 1.0;
|
||||
else if (hue > 1.0)
|
||||
hue -= 1.0;
|
||||
float res;
|
||||
if ((6.0 * hue) < 1.0)
|
||||
res = f1 + (f2 - f1) * 6.0 * hue;
|
||||
else if ((2.0 * hue) < 1.0)
|
||||
res = f2;
|
||||
else if ((3.0 * hue) < 2.0)
|
||||
res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0;
|
||||
else
|
||||
res = f1;
|
||||
return res;
|
||||
}
|
||||
|
||||
vec3 HSLToRGB(vec3 hsl)
|
||||
{
|
||||
vec3 rgb;
|
||||
|
||||
if (hsl.y == 0.0)
|
||||
rgb = vec3(hsl.z); // Luminance
|
||||
else
|
||||
{
|
||||
float f2;
|
||||
|
||||
if (hsl.z < 0.5)
|
||||
f2 = hsl.z * (1.0 + hsl.y);
|
||||
else
|
||||
f2 = (hsl.z + hsl.y) - (hsl.y * hsl.z);
|
||||
|
||||
float f1 = 2.0 * hsl.z - f2;
|
||||
|
||||
rgb.r = HueToRGB(f1, f2, hsl.x + (1.0/3.0));
|
||||
rgb.g = HueToRGB(f1, f2, hsl.x);
|
||||
rgb.b= HueToRGB(f1, f2, hsl.x - (1.0/3.0));
|
||||
}
|
||||
|
||||
return rgb;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Contrast, saturation, brightness
|
||||
** Code of this function is from TGM's shader pack
|
||||
** http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=21057
|
||||
*/
|
||||
|
||||
// For all settings: 1.0 = 100% 0.5=50% 1.5 = 150%
|
||||
vec3 ContrastSaturationBrightness(vec3 color, float brt, float sat, float con)
|
||||
{
|
||||
// Increase or decrease theese values to adjust r, g and b color channels seperately
|
||||
const float AvgLumR = 0.5;
|
||||
const float AvgLumG = 0.5;
|
||||
const float AvgLumB = 0.5;
|
||||
|
||||
const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);
|
||||
|
||||
vec3 AvgLumin = vec3(AvgLumR, AvgLumG, AvgLumB);
|
||||
vec3 brtColor = color * brt;
|
||||
vec3 intensity = vec3(dot(brtColor, LumCoeff));
|
||||
vec3 satColor = mix(intensity, brtColor, sat);
|
||||
vec3 conColor = mix(AvgLumin, satColor, con);
|
||||
return conColor;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Float blending modes
|
||||
** Adapted from here: http://www.nathanm.com/photoshop-blending-math/
|
||||
** But I modified the HardMix (wrong condition), Overlay, SoftLight, ColorDodge, ColorBurn, VividLight, PinLight (inverted layers) ones to have correct results
|
||||
*/
|
||||
|
||||
#define BlendLinearDodgef BlendAddf
|
||||
#define BlendLinearBurnf BlendSubstractf
|
||||
#define BlendAddf(base, blend) min(base + blend, 1.0)
|
||||
#define BlendSubstractf(base, blend) max(base + blend - 1.0, 0.0)
|
||||
#define BlendLightenf(base, blend) max(blend, base)
|
||||
#define BlendDarkenf(base, blend) min(blend, base)
|
||||
#define BlendLinearLightf(base, blend) (blend < 0.5 ? BlendLinearBurnf(base, (2.0 * blend)) : BlendLinearDodgef(base, (2.0 * (blend - 0.5))))
|
||||
#define BlendScreenf(base, blend) (1.0 - ((1.0 - base) * (1.0 - blend)))
|
||||
#define BlendOverlayf(base, blend) (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))
|
||||
#define BlendSoftLightf(base, blend) ((blend < 0.5) ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend)))
|
||||
#define BlendColorDodgef(base, blend) ((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0))
|
||||
#define BlendColorBurnf(base, blend) ((blend == 0.0) ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0))
|
||||
#define BlendVividLightf(base, blend) ((blend < 0.5) ? BlendColorBurnf(base, (2.0 * blend)) : BlendColorDodgef(base, (2.0 * (blend - 0.5))))
|
||||
#define BlendPinLightf(base, blend) ((blend < 0.5) ? BlendDarkenf(base, (2.0 * blend)) : BlendLightenf(base, (2.0 *(blend - 0.5))))
|
||||
#define BlendHardMixf(base, blend) ((BlendVividLightf(base, blend) < 0.5) ? 0.0 : 1.0)
|
||||
#define BlendReflectf(base, blend) ((blend == 1.0) ? blend : min(base * base / (1.0 - blend), 1.0))
|
||||
|
||||
|
||||
/*
|
||||
** Vector3 blending modes
|
||||
*/
|
||||
|
||||
// Component wise blending
|
||||
#define Blend(base, blend, funcf) vec3(funcf(base.r, blend.r), funcf(base.g, blend.g), funcf(base.b, blend.b))
|
||||
|
||||
#define BlendNormal(base, blend) (blend)
|
||||
#define BlendLighten BlendLightenf
|
||||
#define BlendDarken BlendDarkenf
|
||||
#define BlendMultiply(base, blend) (base * blend)
|
||||
#define BlendAverage(base, blend) ((base + blend) / 2.0)
|
||||
#define BlendAdd(base, blend) min(base + blend, vec3(1.0))
|
||||
#define BlendSubstract(base, blend) max(base + blend - vec3(1.0), vec3(0.0))
|
||||
#define BlendDifference(base, blend) abs(base - blend)
|
||||
#define BlendNegation(base, blend) (vec3(1.0) - abs(vec3(1.0) - base - blend))
|
||||
#define BlendExclusion(base, blend) (base + blend - 2.0 * base * blend)
|
||||
#define BlendScreen(base, blend) Blend(base, blend, BlendScreenf)
|
||||
#define BlendOverlay(base, blend) Blend(base, blend, BlendOverlayf)
|
||||
#define BlendSoftLight(base, blend) Blend(base, blend, BlendSoftLightf)
|
||||
#define BlendHardLight(base, blend) BlendOverlay(blend, base)
|
||||
#define BlendColorDodge(base, blend) Blend(base, blend, BlendColorDodgef)
|
||||
#define BlendColorBurn(base, blend) Blend(base, blend, BlendColorBurnf)
|
||||
#define BlendLinearDodge BlendAdd
|
||||
#define BlendLinearBurn BlendSubstract
|
||||
// Linear Light is another contrast-increasing mode
|
||||
// If the blend color is darker than midgray, Linear Light darkens the image by decreasing the brightness. If the blend color is lighter than midgray, the result is a brighter image due to increased brightness.
|
||||
#define BlendLinearLight(base, blend) Blend(base, blend, BlendLinearLightf)
|
||||
#define BlendVividLight(base, blend) Blend(base, blend, BlendVividLightf)
|
||||
#define BlendPinLight(base, blend) Blend(base, blend, BlendPinLightf)
|
||||
#define BlendHardMix(base, blend) Blend(base, blend, BlendHardMixf)
|
||||
#define BlendReflect(base, blend) Blend(base, blend, BlendReflectf)
|
||||
#define BlendGlow(base, blend) BlendReflect(blend, base)
|
||||
#define BlendPhoenix(base, blend) (min(base, blend) - max(base, blend) + vec3(1.0))
|
||||
#define BlendOpacity(base, blend, F, O) (F(base, blend) * O + blend * (1.0 - O))
|
||||
|
||||
|
||||
// Hue Blend mode creates the result color by combining the luminance and saturation of the base color with the hue of the blend color.
|
||||
vec3 BlendHue(vec3 base, vec3 blend)
|
||||
{
|
||||
vec3 baseHSL = RGBToHSL(base);
|
||||
return HSLToRGB(vec3(RGBToHSL(blend).r, baseHSL.g, baseHSL.b));
|
||||
}
|
||||
|
||||
// Saturation Blend mode creates the result color by combining the luminance and hue of the base color with the saturation of the blend color.
|
||||
vec3 BlendSaturation(vec3 base, vec3 blend)
|
||||
{
|
||||
vec3 baseHSL = RGBToHSL(base);
|
||||
return HSLToRGB(vec3(baseHSL.r, RGBToHSL(blend).g, baseHSL.b));
|
||||
}
|
||||
|
||||
// Color Mode keeps the brightness of the base color and applies both the hue and saturation of the blend color.
|
||||
vec3 BlendColor(vec3 base, vec3 blend)
|
||||
{
|
||||
vec3 blendHSL = RGBToHSL(blend);
|
||||
return HSLToRGB(vec3(blendHSL.r, blendHSL.g, RGBToHSL(base).b));
|
||||
}
|
||||
|
||||
// Luminosity Blend mode creates the result color by combining the hue and saturation of the base color with the luminance of the blend color.
|
||||
vec3 BlendLuminosity(vec3 base, vec3 blend)
|
||||
{
|
||||
vec3 baseHSL = RGBToHSL(base);
|
||||
return HSLToRGB(vec3(baseHSL.r, baseHSL.g, RGBToHSL(blend).b));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Gamma correction
|
||||
** Details: http://blog.mouaif.org/2009/01/22/photoshop-gamma-correction-shader/
|
||||
*/
|
||||
|
||||
#define GammaCorrection(color, gamma) pow(color, 1.0 / gamma)
|
||||
|
||||
/*
|
||||
** Levels control (input (+gamma), output)
|
||||
** Details: http://blog.mouaif.org/2009/01/28/levels-control-shader/
|
||||
*/
|
||||
|
||||
#define LevelsControlInputRange(color, minInput, maxInput) min(max(color - vec3(minInput), vec3(0.0)) / (vec3(maxInput) - vec3(minInput)), vec3(1.0))
|
||||
#define LevelsControlInput(color, minInput, gamma, maxInput) GammaCorrection(LevelsControlInputRange(color, minInput, maxInput), gamma)
|
||||
#define LevelsControlOutputRange(color, minOutput, maxOutput) mix(vec3(minOutput), vec3(maxOutput), color)
|
||||
#define LevelsControl(color, minInput, gamma, maxInput, minOutput, maxOutput) LevelsControlOutputRange(LevelsControlInput(color, minInput, gamma, maxInput), minOutput, maxOutput)
|
Binary file not shown.
After Width: | Height: | Size: 78 KiB |
@ -0,0 +1,189 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
#define PI 3.141592653589793
|
||||
#define HALF_PI 1.5707963267948966
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
// Robert Penner's easing functions in GLSL
|
||||
// https://github.com/stackgl/glsl-easings
|
||||
float linear(float t) {
|
||||
return t;
|
||||
}
|
||||
|
||||
float exponentialIn(float t) {
|
||||
return t == 0.0 ? t : pow(2.0, 10.0 * (t - 1.0));
|
||||
}
|
||||
|
||||
float exponentialOut(float t) {
|
||||
return t == 1.0 ? t : 1.0 - pow(2.0, -10.0 * t);
|
||||
}
|
||||
|
||||
float exponentialInOut(float t) {
|
||||
return t == 0.0 || t == 1.0
|
||||
? t
|
||||
: t < 0.5
|
||||
? +0.5 * pow(2.0, (20.0 * t) - 10.0)
|
||||
: -0.5 * pow(2.0, 10.0 - (t * 20.0)) + 1.0;
|
||||
}
|
||||
|
||||
float sineIn(float t) {
|
||||
return sin((t - 1.0) * HALF_PI) + 1.0;
|
||||
}
|
||||
|
||||
float sineOut(float t) {
|
||||
return sin(t * HALF_PI);
|
||||
}
|
||||
|
||||
float sineInOut(float t) {
|
||||
return -0.5 * (cos(PI * t) - 1.0);
|
||||
}
|
||||
|
||||
float qinticIn(float t) {
|
||||
return pow(t, 5.0);
|
||||
}
|
||||
|
||||
float qinticOut(float t) {
|
||||
return 1.0 - (pow(t - 1.0, 5.0));
|
||||
}
|
||||
|
||||
float qinticInOut(float t) {
|
||||
return t < 0.5
|
||||
? +16.0 * pow(t, 5.0)
|
||||
: -0.5 * pow(2.0 * t - 2.0, 5.0) + 1.0;
|
||||
}
|
||||
|
||||
float quarticIn(float t) {
|
||||
return pow(t, 4.0);
|
||||
}
|
||||
|
||||
float quarticOut(float t) {
|
||||
return pow(t - 1.0, 3.0) * (1.0 - t) + 1.0;
|
||||
}
|
||||
|
||||
float quarticInOut(float t) {
|
||||
return t < 0.5
|
||||
? +8.0 * pow(t, 4.0)
|
||||
: -8.0 * pow(t - 1.0, 4.0) + 1.0;
|
||||
}
|
||||
|
||||
float quadraticInOut(float t) {
|
||||
float p = 2.0 * t * t;
|
||||
return t < 0.5 ? p : -p + (4.0 * t) - 1.0;
|
||||
}
|
||||
|
||||
float quadraticIn(float t) {
|
||||
return t * t;
|
||||
}
|
||||
|
||||
float quadraticOut(float t) {
|
||||
return -t * (t - 2.0);
|
||||
}
|
||||
|
||||
float cubicIn(float t) {
|
||||
return t * t * t;
|
||||
}
|
||||
|
||||
float cubicOut(float t) {
|
||||
float f = t - 1.0;
|
||||
return f * f * f + 1.0;
|
||||
}
|
||||
|
||||
float cubicInOut(float t) {
|
||||
return t < 0.5
|
||||
? 4.0 * t * t * t
|
||||
: 0.5 * pow(2.0 * t - 2.0, 3.0) + 1.0;
|
||||
}
|
||||
|
||||
float elasticIn(float t) {
|
||||
return sin(13.0 * t * HALF_PI) * pow(2.0, 10.0 * (t - 1.0));
|
||||
}
|
||||
|
||||
float elasticOut(float t) {
|
||||
return sin(-13.0 * (t + 1.0) * HALF_PI) * pow(2.0, -10.0 * t) + 1.0;
|
||||
}
|
||||
|
||||
float elasticInOut(float t) {
|
||||
return t < 0.5
|
||||
? 0.5 * sin(+13.0 * HALF_PI * 2.0 * t) * pow(2.0, 10.0 * (2.0 * t - 1.0))
|
||||
: 0.5 * sin(-13.0 * HALF_PI * ((2.0 * t - 1.0) + 1.0)) * pow(2.0, -10.0 * (2.0 * t - 1.0)) + 1.0;
|
||||
}
|
||||
|
||||
float circularIn(float t) {
|
||||
return 1.0 - sqrt(1.0 - t * t);
|
||||
}
|
||||
|
||||
float circularOut(float t) {
|
||||
return sqrt((2.0 - t) * t);
|
||||
}
|
||||
|
||||
float circularInOut(float t) {
|
||||
return t < 0.5
|
||||
? 0.5 * (1.0 - sqrt(1.0 - 4.0 * t * t))
|
||||
: 0.5 * (sqrt((3.0 - 2.0 * t) * (2.0 * t - 1.0)) + 1.0);
|
||||
}
|
||||
|
||||
float bounceOut(float t) {
|
||||
const float a = 4.0 / 11.0;
|
||||
const float b = 8.0 / 11.0;
|
||||
const float c = 9.0 / 10.0;
|
||||
|
||||
const float ca = 4356.0 / 361.0;
|
||||
const float cb = 35442.0 / 1805.0;
|
||||
const float cc = 16061.0 / 1805.0;
|
||||
|
||||
float t2 = t * t;
|
||||
|
||||
return t < a
|
||||
? 7.5625 * t2
|
||||
: t < b
|
||||
? 9.075 * t2 - 9.9 * t + 3.4
|
||||
: t < c
|
||||
? ca * t2 - cb * t + cc
|
||||
: 10.8 * t * t - 20.52 * t + 10.72;
|
||||
}
|
||||
|
||||
float bounceIn(float t) {
|
||||
return 1.0 - bounceOut(1.0 - t);
|
||||
}
|
||||
|
||||
float bounceInOut(float t) {
|
||||
return t < 0.5
|
||||
? 0.5 * (1.0 - bounceOut(1.0 - t * 2.0))
|
||||
: 0.5 * bounceOut(t * 2.0 - 1.0) + 0.5;
|
||||
}
|
||||
|
||||
float backIn(float t) {
|
||||
return pow(t, 3.0) - t * sin(t * PI);
|
||||
}
|
||||
|
||||
float backOut(float t) {
|
||||
float f = 1.0 - t;
|
||||
return 1.0 - (pow(f, 3.0) - f * sin(f * PI));
|
||||
}
|
||||
|
||||
float backInOut(float t) {
|
||||
float f = t < 0.5
|
||||
? 2.0 * t
|
||||
: 1.0 - (2.0 * t - 1.0);
|
||||
|
||||
float g = pow(f, 3.0) - f * sin(f * PI);
|
||||
|
||||
return t < 0.5
|
||||
? 0.5 * g
|
||||
: 0.5 * (1.0 - g) + 0.5;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec3 colorA = vec3(0.149,0.141,0.912);
|
||||
vec3 colorB = vec3(1.000,0.833,0.224);
|
||||
|
||||
float t = u_time*0.5;
|
||||
float pct = cubicInOut( abs(fract(t)*2.0-1.) );
|
||||
|
||||
gl_FragColor = vec4(vec3(mix(colorA, colorB, pct)),1.0);
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
#define PI 3.14159265359
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
vec3 colorA = vec3(0.149,0.141,0.912);
|
||||
vec3 colorB = vec3(1.000,0.833,0.224);
|
||||
|
||||
float plot (vec2 _st, float _pct){
|
||||
return smoothstep( _pct-0.01, _pct, _st.y) -
|
||||
smoothstep( _pct, _pct+0.01, _st.y);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
vec3 pct = vec3(st.x);
|
||||
|
||||
// pct.r = smoothstep(0.0,1.0, st.x);
|
||||
// pct.g = sin(st.x*PI);
|
||||
// pct.b = pow(st.x,0.5);
|
||||
|
||||
color = mix(colorA, colorB, pct);
|
||||
|
||||
// Plot transition lines for each channel
|
||||
color = mix(color,vec3(1.0,0.0,0.0),plot(st,pct.r));
|
||||
color = mix(color,vec3(0.0,1.0,0.0),plot(st,pct.g));
|
||||
color = mix(color,vec3(0.0,0.0,1.0),plot(st,pct.b));
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
#define TWO_PI 6.28318530718
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform float u_time;
|
||||
|
||||
// Function from Iñigo Quiles
|
||||
// https://www.shadertoy.com/view/MsS3Wc
|
||||
vec3 hsb2rgb( in vec3 c ){
|
||||
vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),
|
||||
6.0)-3.0)-1.0,
|
||||
0.0,
|
||||
1.0 );
|
||||
rgb = rgb*rgb*(3.0-2.0*rgb);
|
||||
return c.z * mix( vec3(1.0), rgb, c.y);
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution;
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
// Use polar coordinates instead of cartesian
|
||||
vec2 toCenter = vec2(0.5)-st;
|
||||
float angle = atan(toCenter.y,toCenter.x);
|
||||
float radius = length(toCenter)*2.0;
|
||||
|
||||
// Map the angle (-PI to PI) to the Hue (from 0 to 1)
|
||||
// and the Saturation to the radius
|
||||
color = hsb2rgb(vec3((angle/TWO_PI)+0.5,radius,1.0));
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform float u_time;
|
||||
|
||||
vec3 rgb2hsb( in vec3 c ){
|
||||
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
vec4 p = mix(vec4(c.bg, K.wz),
|
||||
vec4(c.gb, K.xy),
|
||||
step(c.b, c.g));
|
||||
vec4 q = mix(vec4(p.xyw, c.r),
|
||||
vec4(c.r, p.yzx),
|
||||
step(p.x, c.r));
|
||||
float d = q.x - min(q.w, q.y);
|
||||
float e = 1.0e-10;
|
||||
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)),
|
||||
d / (q.x + e),
|
||||
q.x);
|
||||
}
|
||||
|
||||
// Function from Iñigo Quiles
|
||||
// https://www.shadertoy.com/view/MsS3Wc
|
||||
vec3 hsb2rgb( in vec3 c ){
|
||||
vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),
|
||||
6.0)-3.0)-1.0,
|
||||
0.0,
|
||||
1.0 );
|
||||
rgb = rgb*rgb*(3.0-2.0*rgb);
|
||||
return c.z * mix(vec3(1.0), rgb, c.y);
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution;
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
// We map x (0.0 - 1.0) to the hue (0.0 - 1.0)
|
||||
// And the y (0.0 - 1.0) to the brightness
|
||||
color = hsb2rgb(vec3(st.x,1.0,st.y));
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Color</title>
|
||||
<meta name="keywords" content="glsl,color,hsb,rgb,hue,shader" />
|
||||
<meta name="description" content="This is a gentle step-by-step guide through the abstract and complex universe of Fragment Shaders."/>
|
||||
|
||||
<!-- CodeMirror -->
|
||||
<link type='text/css' rel='stylesheet' href="../src/codemirror/css/codemirror.css">
|
||||
<link type='text/css' rel="stylesheet" href="../src/codemirror/addon/fold/foldgutter.css">
|
||||
<link type='text/css' rel="stylesheet" href="../src/codemirror/addon/dialog/dialog.css">
|
||||
<link type='text/css' rel="stylesheet" href="../src/codemirror/addon/hint/show-hint.css">
|
||||
<link type='text/css' rel="stylesheet" href="../src/codemirror/theme/neo.css">
|
||||
<script type="text/javascript" src="../src/codemirror.js"></script>
|
||||
<script type="text/javascript" src="../src/codemirror/addon/search/searchcursor.js"></script>
|
||||
<script type="text/javascript" src="../src/codemirror/addon/search/search.js"></script>
|
||||
<script type="text/javascript" src="../src/codemirror/addon/dialog/dialog.js"></script>
|
||||
<script type="text/javascript" src="../src/codemirror/addon/edit/matchbrackets.js"></script>
|
||||
<script type="text/javascript" src="../src/codemirror/addon/edit/closebrackets.js"></script>
|
||||
<script type="text/javascript" src="../src/codemirror/addon/comment/comment.js"></script>
|
||||
<script type="text/javascript" src="../src/codemirror/addon/wrap/hardwrap.js"></script>
|
||||
<script type="text/javascript" src="../src/codemirror/addon/fold/foldcode.js"></script>
|
||||
<script type="text/javascript" src="../src/codemirror/addon/fold/brace-fold.js"></script>
|
||||
<script type="text/javascript" src="../src/codemirror/keymap/sublime.js"></script>
|
||||
<script type="text/javascript" src="../src/codemirror/addon/hint/show-hint.js"></script>
|
||||
<script type="text/javascript" src="../src/codemirror/mode/clike.js"></script>
|
||||
|
||||
<!-- Highlight -->
|
||||
<link type='text/css' rel='stylesheet' href="../css/github.css">
|
||||
<script type="text/javascript" src="../src/highlight.min.js"></script>
|
||||
|
||||
<!-- Marked -->
|
||||
<script type="text/javascript" src="../src/marked.js"></script>
|
||||
|
||||
<!-- My stuff -->
|
||||
<link type='text/css' rel='stylesheet' href="../css/style.css">
|
||||
<script type="text/javascript" src="../src/glslCanvas.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div class="header"><p><a href="http://patriciogonzalezvivo.com/2015/thebookofshaders/">The Book of Shaders</a> by <a href="http://patriciogonzalezvivo.com">Patricio Gonzalez Vivo</a></p></div>
|
||||
<hr>
|
||||
<div id="content"> </div>
|
||||
<hr>
|
||||
<ul class="navigationBar" >
|
||||
<li class="navigationBar" onclick="previusPage()">< < Previous</li>
|
||||
<li class="navigationBar" onclick="homePage()"> Home </li>
|
||||
<!-- <li class="navigationBar" onclick="nextPage()">Next > ></li>
|
||||
--> </ul>
|
||||
|
||||
<footer>
|
||||
<p> Copyright 2015 <a href="http://www.patriciogonzalezvivo.com" target="_blank">Patricio Gonzalez Vivo</a> </p>
|
||||
</footer>
|
||||
|
||||
<script type="text/javascript" src="../src/main.js" defer></script>
|
||||
<script>
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||
|
||||
ga('create', 'UA-18824436-2', 'auto');
|
||||
ga('send', 'pageview');
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
Binary file not shown.
After Width: | Height: | Size: 172 KiB |
Binary file not shown.
After Width: | Height: | Size: 217 KiB |
@ -0,0 +1,21 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform float u_time;
|
||||
|
||||
vec3 colorA = vec3(0.149,0.141,0.912);
|
||||
vec3 colorB = vec3(1.000,0.833,0.224);
|
||||
|
||||
void main() {
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
float pct = abs(sin(u_time));
|
||||
|
||||
// Mix uses pct (a value from 0-1) to
|
||||
// mix the two colors
|
||||
color = mix(colorA, colorB, pct);
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 45 KiB |
Binary file not shown.
After Width: | Height: | Size: 140 KiB |
@ -1,25 +1,34 @@
|
||||
# List of Examples
|
||||
|
||||
The following is a list of examples present in this book.
|
||||
|
||||
### Chapters examples
|
||||
|
||||
* Getting started
|
||||
* Hello World
|
||||
- ["Hello World!"](http://thebookofshaders.com/edit.html#02/hello_world.frag)
|
||||
- ["Hello World!"](../edit.html#02/hello_world.frag)
|
||||
* Uniforms
|
||||
- [u_time](http://thebookofshaders.com/edit.html#03/time.frag)
|
||||
- [gl_FragCoord](http://thebookofshaders.com/edit.html#03/space.frag)
|
||||
- [u_time](../edit.html#03/time.frag)
|
||||
- [gl_FragCoord](../edit.html#03/space.frag)
|
||||
* Algorithmic drawing
|
||||
* Shaping functions
|
||||
- [Linear Interpolation](http://thebookofshaders.com/edit.html#05/linear.frag)
|
||||
- [Exponential Interpolation](http://thebookofshaders.com/edit.html#05/expo.frag)
|
||||
- [Step function](http://thebookofshaders.com/edit.html#05/step.frag)
|
||||
- [Smoothstep function](http://thebookofshaders.com/edit.html#05/smoothstep.frag)
|
||||
- [Iñigo Quiles's impulse](http://thebookofshaders.com/edit.html#05/impulse.frag)
|
||||
- [Iñigo Quiles's Cubic Pulse](http://thebookofshaders.com/edit.html#05/cubicpulse.frag)
|
||||
- [Iñigo Quiles's Exponential Step](http://thebookofshaders.com/edit.html#05/expstep.frag)
|
||||
- [Iñigo Quiles's Parabola](http://thebookofshaders.com/edit.html#05/parabola.frag)
|
||||
- [Iñigo Quiles's Power Curve](http://thebookofshaders.com/edit.html#05/pcurve.frag)
|
||||
- [Linear Interpolation](../edit.html#05/linear.frag)
|
||||
- [Exponential Interpolation](../edit.html#05/expo.frag)
|
||||
- [Step function](../edit.html#05/step.frag)
|
||||
- [Smoothstep function](../edit.html#05/smoothstep.frag)
|
||||
- [Iñigo Quiles's Impulse](../edit.html#05/impulse.frag)
|
||||
- [Iñigo Quiles's Cubic Pulse](../edit.html#05/cubicpulse.frag)
|
||||
- [Iñigo Quiles's Exponential Step](../edit.html#05/expstep.frag)
|
||||
- [Iñigo Quiles's Parabola](../edit.html#05/parabola.frag)
|
||||
- [Iñigo Quiles's Power Curve](../edit.html#05/pcurve.frag)
|
||||
|
||||
* Color
|
||||
- [Mix](../edit.html#06/mix.frag)
|
||||
- [Easing functions](../edit.html#06/easing.frag)
|
||||
- [Gradient](../edit.html#06/gradient.frag)
|
||||
- [HSB](../edit.html#06/hsb.frag)
|
||||
- [HSB - Color Wheel](../edit.html#06/hsb-colorwheel.frag)
|
||||
|
||||
### Advance
|
||||
|
||||
* [Moon](http://thebookofshaders.com/edit.html#examples/moon.frag&examples/images/moon-texture.jpg)
|
||||
* [Moon](../edit.html#examples/moon.frag&examples/images/moon-texture.jpg)
|
||||
|
Loading…
Reference in New Issue