chapter 07: Shapes + glossary
@ -1,260 +0,0 @@
|
||||
/*
|
||||
** 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)
|
@ -0,0 +1,46 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_OES_standard_derivatives
|
||||
#extension GL_OES_standard_derivatives : enable
|
||||
#endif
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
#define PI 3.14159265359
|
||||
#define TWO_PI 6.28318530718
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
float shape(vec2 st, int N){
|
||||
st = st *2.-1.;
|
||||
float a = atan(st.x,st.y)+PI;
|
||||
float r = TWO_PI/float(N);
|
||||
return cos(floor(.5+a/r)*r-a)*length(st);
|
||||
}
|
||||
|
||||
// Antialiazed Step function
|
||||
// from http://webstaff.itn.liu.se/~stegu/webglshadertutorial/shadertutorial.html
|
||||
float aastep(float threshold, float value) {
|
||||
#ifdef GL_OES_standard_derivatives
|
||||
float afwidth = 0.7 * length(vec2(dFdx(value), dFdy(value)));
|
||||
return smoothstep(threshold-afwidth, threshold+afwidth, value);
|
||||
#else
|
||||
return step(threshold, value);
|
||||
#endif
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
st.x *= u_resolution.x/u_resolution.y;
|
||||
vec3 color = vec3(0.0);
|
||||
float d = 0.0;
|
||||
|
||||
d = min(shape(st,3),shape(st+vec2(0.,0.19),4));
|
||||
|
||||
gl_FragColor = vec4(vec3(1.0-aastep(.2,d)),1.0);
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
float plot (float y, float pct){
|
||||
return smoothstep( pct-0.01, pct, y) -
|
||||
smoothstep( pct, pct+0.01, y);
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution;
|
||||
st.y *= u_resolution.y/u_resolution.x;
|
||||
vec3 color = vec3(.0);
|
||||
float pct = .0;
|
||||
|
||||
float shape = 1.0-distance(st*vec2(1.,2.)-vec2(0.,.5),vec2(.5));
|
||||
|
||||
pct = shape;
|
||||
pct = min(pct, distance(st,vec2(0.5,0.76))*10.);
|
||||
pct = min(pct, distance(st,vec2(0.36,0.71))*5.);
|
||||
pct = min(pct, distance(st,vec2(0.64,0.71))*5.);
|
||||
pct = min(pct, distance(st,vec2(0.36,0.20))*4.*pow(1.-st.y,shape*1.1));
|
||||
pct = min(pct, distance(st,vec2(0.64,0.20))*4.*pow(1.-st.y,shape*1.1));
|
||||
|
||||
color = vec3(pct);
|
||||
|
||||
color += vec3(1.,1.,.0)*plot(pct,0.5+smoothstep(-1.,2.,sin(u_time))*.1);
|
||||
|
||||
|
||||
gl_FragColor = vec4( color, 1.0 );
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution;
|
||||
float pct = 0.0;
|
||||
|
||||
// a. The DISTANCE from the pixel to the center
|
||||
pct = distance(st,vec2(0.5));
|
||||
|
||||
// b. The LENGTH of the vector
|
||||
// from the pixel to the center
|
||||
// vec2 toCenter = vec2(0.5)-st;
|
||||
// pct = length(toCenter);
|
||||
|
||||
// c. The SQUARE ROOT of the vector
|
||||
// from the pixel to the center
|
||||
// vec2 tC = vec2(0.5)-st;
|
||||
// pct = sqrt(tC.x*tC.x+tC.y*tC.y);
|
||||
|
||||
vec3 color = vec3(pct);
|
||||
|
||||
gl_FragColor = vec4( color, 1.0 );
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
float circle(in vec2 _st, in float _radius){
|
||||
vec2 l = _st-vec2(0.5);
|
||||
return 1.-smoothstep(_radius-(_radius*0.01),
|
||||
_radius+(_radius*0.01),
|
||||
dot(l,l)*4.0);
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
|
||||
vec3 color = vec3(circle(st,0.9));
|
||||
|
||||
gl_FragColor = vec4( color, 1.0 );
|
||||
}
|
After Width: | Height: | Size: 112 KiB |
After Width: | Height: | Size: 271 KiB |
@ -0,0 +1,32 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
float box(in vec2 st, in vec2 size){
|
||||
size = vec2(0.5) - size*0.5;
|
||||
vec2 uv = smoothstep(size,
|
||||
size+vec2(0.001),
|
||||
st);
|
||||
uv *= smoothstep(size,
|
||||
size+vec2(0.001),
|
||||
vec2(1.0)-st);
|
||||
return uv.x*uv.y;
|
||||
}
|
||||
|
||||
float cross(in vec2 st, float size){
|
||||
return box(st, vec2(size,size/4.)) +
|
||||
box(st, vec2(size/4.,size));
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
|
||||
gl_FragColor = vec4( vec3( cross(st,0.4) ) ,1.0);
|
||||
}
|
After Width: | Height: | Size: 270 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 370 KiB |
After Width: | Height: | Size: 553 B |
@ -0,0 +1,70 @@
|
||||
<!-- Copyright 2015 Patricio Gonzalez Vivo (http://patriciogonzalezvivo.com) -->
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Shapes</title>
|
||||
<meta name="keywords" content="glsl,shader,procedural,distance field,shapes,geometry,rectangle,circle" />
|
||||
<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>
|
@ -0,0 +1,40 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
float line( vec2 _st,
|
||||
vec2 _p1, vec2 _p2,
|
||||
float _width, float _spread){
|
||||
|
||||
_width = 1.0 / _width;
|
||||
vec2 p2p1 = _p1 - _p2;
|
||||
vec2 p1p2 = -(p2p1);
|
||||
vec2 p2p = _st - _p2;
|
||||
vec2 p1p = _st - _p1;
|
||||
vec2 pp1 = -(p1p);
|
||||
vec2 pd = normalize(vec2(p2p1.y, -p2p1.x));
|
||||
float proj = dot(pd, pp1);
|
||||
float pr1 = dot(p2p1, p2p);
|
||||
float pr2 = dot(p1p2, p1p);
|
||||
|
||||
if(pr1 > 0.0 && pr2 > 0.0) {
|
||||
return pow(1.0 / abs(proj * _width), _spread);
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
|
||||
vec3 color = vec3( line(st,
|
||||
vec2(0.1),
|
||||
vec2(0.9),
|
||||
0.005, 3.0) );
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 77 KiB |
@ -0,0 +1,30 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
vec2 pos = vec2(0.5)-st;
|
||||
|
||||
float r = length(pos)*2.0;
|
||||
float a = atan(pos.y,pos.x);
|
||||
|
||||
float f = cos(a*3.);
|
||||
// f = abs(cos(a*3.));
|
||||
// f = abs(cos(a*2.5))*.5+.3;
|
||||
// f = abs(cos(a*12.)*sin(a*3.))*.8+.1;
|
||||
// f = smoothstep(-.5,1., cos(a*10.))*0.2+0.5;
|
||||
|
||||
color = vec3( 1.-smoothstep(f,f+0.02,r) );
|
||||
|
||||
gl_FragColor = vec4(color, 1.0);
|
||||
}
|
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 26 KiB |
@ -0,0 +1,30 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
st.x *= u_resolution.x/u_resolution.y;
|
||||
vec3 color = vec3(0.0);
|
||||
float d = 0.0;
|
||||
|
||||
// Remap the space to -1. to 1.
|
||||
st = st *2.-1.;
|
||||
|
||||
// Make the distance field
|
||||
d = length( abs(st)-.3 );
|
||||
// d = length( min(abs(st)-.3,0.) );
|
||||
// d = length( max(abs(st)-.3,0.) );
|
||||
|
||||
// Visualize the distance field
|
||||
gl_FragColor = vec4(vec3(fract(d*10.0)),1.0);
|
||||
|
||||
// Drawing with the distance field
|
||||
// gl_FragColor = vec4(vec3( step(.3,d) ),1.0);
|
||||
// gl_FragColor = vec4(vec3( step(.3,d) * step(d,.4)),1.0);
|
||||
// gl_FragColor = vec4(vec3( smoothstep(.3,.4,d)* smoothstep(.6,.5,d)) ,1.0);
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
// bottom-left
|
||||
vec2 bl = step(vec2(0.1),st);
|
||||
float pct = bl.x * bl.y;
|
||||
|
||||
// top-right
|
||||
// vec2 tr = step(vec2(0.1),1.0-st);
|
||||
// pct *= tr.x * tr.y;
|
||||
|
||||
color = vec3(pct);
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
float rect(in vec2 st, in vec2 size){
|
||||
size = 0.25-size*0.25;
|
||||
vec2 uv = smoothstep(size,size+size*vec2(0.002),st*(1.0-st));
|
||||
return uv.x*uv.y;
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
|
||||
vec3 color = vec3( rect(st, vec2(0.9) ) );
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
#define PI 3.14159265359
|
||||
#define TWO_PI 6.28318530718
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
// Reference to
|
||||
// http://thndl.com/square-shaped-shaders.html
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
st.x *= u_resolution.x/u_resolution.y;
|
||||
vec3 color = vec3(0.0);
|
||||
float d = 0.0;
|
||||
|
||||
// Remap the space to -1. to 1.
|
||||
st = st *2.-1.;
|
||||
|
||||
// Number of sides of your shape
|
||||
int N = 3;
|
||||
|
||||
// Angle and radius from the current pixel
|
||||
float a = atan(st.x,st.y)+PI;
|
||||
float r = TWO_PI/float(N);
|
||||
|
||||
// Shaping function that modulate the distance
|
||||
d = cos(floor(.5+a/r)*r-a)*length(st);
|
||||
|
||||
color = vec3(1.0-smoothstep(.4,.41,d));
|
||||
// color = vec3(d);
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
// Based on https://www.shadertoy.com/view/4sSSzG
|
||||
float triangleDF(vec2 st,
|
||||
vec2 p0, vec2 p1, vec2 p2){
|
||||
vec3 e0, e1, e2;
|
||||
|
||||
e0.xy = normalize(p1 - p0).yx * vec2(+1.0, -1.0);
|
||||
e1.xy = normalize(p2 - p1).yx * vec2(+1.0, -1.0);
|
||||
e2.xy = normalize(p0 - p2).yx * vec2(+1.0, -1.0);
|
||||
|
||||
e0.z = dot(e0.xy, p0);
|
||||
e1.z = dot(e1.xy, p1);
|
||||
e2.z = dot(e2.xy, p2);
|
||||
|
||||
float a = max(0.0, dot(e0.xy, st) - e0.z);
|
||||
float b = max(0.0, dot(e1.xy, st) - e1.z);
|
||||
float c = max(0.0, dot(e2.xy, st) - e2.z);
|
||||
|
||||
return length(vec3(a, b, c)*2.0);
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
// Distance Field in 3 channels
|
||||
float df = triangleDF(st,
|
||||
vec2(0.40,0.45),
|
||||
vec2(0.60,0.45),
|
||||
vec2(0.5,0.60));
|
||||
color = vec3(df);
|
||||
|
||||
// Make a shape of it
|
||||
float size = fract(u_time*0.2);
|
||||
float border = 0.025;
|
||||
color.rb += smoothstep(size+border,size+1e-7,df)-
|
||||
smoothstep(size+0.001,size+1e-7,df);
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
// Author @patriciogv - 2015
|
||||
// http://patriciogonzalezvivo.com
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform vec2 u_resolution;
|
||||
uniform vec2 u_mouse;
|
||||
uniform float u_time;
|
||||
|
||||
// Based on https://www.shadertoy.com/view/4sSSzG
|
||||
float triangle (vec2 st,
|
||||
vec2 p0, vec2 p1, vec2 p2,
|
||||
float smoothness){
|
||||
vec3 e0, e1, e2;
|
||||
|
||||
e0.xy = normalize(p1 - p0).yx * vec2(+1.0, -1.0);
|
||||
e1.xy = normalize(p2 - p1).yx * vec2(+1.0, -1.0);
|
||||
e2.xy = normalize(p0 - p2).yx * vec2(+1.0, -1.0);
|
||||
|
||||
e0.z = dot(e0.xy, p0) - smoothness;
|
||||
e1.z = dot(e1.xy, p1) - smoothness;
|
||||
e2.z = dot(e2.xy, p2) - smoothness;
|
||||
|
||||
float a = max(0.0, dot(e0.xy, st) - e0.z);
|
||||
float b = max(0.0, dot(e1.xy, st) - e1.z);
|
||||
float c = max(0.0, dot(e2.xy, st) - e2.z);
|
||||
|
||||
return smoothstep(smoothness * 2.0,
|
||||
1e-7,
|
||||
length(vec3(a, b, c)));
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec2 st = gl_FragCoord.xy/u_resolution.xy;
|
||||
|
||||
vec3 color = vec3( triangle(st,
|
||||
vec2(0.0,0.15),
|
||||
vec2(1.0,0.15),
|
||||
vec2(0.5,0.88),
|
||||
0.001) );
|
||||
|
||||
gl_FragColor = vec4(color,1.0);
|
||||
}
|
After Width: | Height: | Size: 75 KiB |
@ -1,22 +0,0 @@
|
||||
## How to use this book in a classroom with RaspberryPi?
|
||||
|
||||
A classroom can be a hard place to teach shaders because of technical limitations. A few years ago, taking for granted that all the students would have a computer with a modern graphic card was a long shot, but not today. Thanks to the [RaspberryPi project](http://www.raspberrypi.org/) a new type of small and cheap generation of computers ($35) has found its way into classrooms. Most importantly for the purposes of this book, the [RaspberryPi](http://www.raspberrypi.org/) comes with a decent Bradcom GPU card that can be accessed directly from the console. I made a [flexible GLSL live coding tool](https://github.com/patriciogonzalezvivo/glslViewer) that runs all the examples in this book while also updating automatically the changes the user makes when they save it. By making a local copy of the repository of this book (see the above section) and having the [```glslViewer``` app installed](https://github.com/patriciogonzalezvivo/glslViewer), students can read the chapters using any console text reader (like ```less```, ```nano``` or ```vim```), run the examples (with ```glslviewer```), and modify them with their favorite text editor (like ```nano```, ```pico```, ```vi```, ```vim``` or ```emacs```).
|
||||
|
||||
To install and set this all up on the RaspberryPi after installing the OS and logging in, type the following commands:
|
||||
|
||||
```bash
|
||||
sudo apt-get update
|
||||
sudo apt-get upgrade
|
||||
sudo apt-get install git-core libfreeimage
|
||||
cd ~
|
||||
git clone http://github.com/patriciogonzalezvivo/glslViewer.git
|
||||
cd glslViewer
|
||||
make
|
||||
make install
|
||||
cd ~
|
||||
git clone https://github.com/patriciogonzalezvivo/thebookofshaders.git
|
||||
cd thebookofshaders
|
||||
```
|
||||
|
||||
At the end of each section you will find code and non-code based exercises to give to your students. They are designed to help students immediately put concepts into practice, making concrete the abstract principles of parallel programming.
|
||||
|
@ -0,0 +1,162 @@
|
||||
# Glossary
|
||||
|
||||
## By theme
|
||||
|
||||
* ANGLE & TRIGONOMETRY FUNCTIONS
|
||||
|
||||
[radians()](index.html#radians.md)
|
||||
[degrees()](index.html#degrees.md)
|
||||
[sin()](index.html#sin.md)
|
||||
[cos()](index.html#cos.md)
|
||||
[tan()](index.html#tan.md)
|
||||
[asin()](index.html#asin.md)
|
||||
[acos()](index.html#acos.md)
|
||||
[atan()](index.html#atan.md)
|
||||
|
||||
* EXPONENTIAL FUNCTIONS
|
||||
|
||||
[pow()](index.html#pow.md)
|
||||
[exp()](index.html#exp.md)
|
||||
[log()](index.html#log.md)
|
||||
[exp2()](index.html#exp2.md)
|
||||
[log2()](index.html#log2.md)
|
||||
[sqrt()](index.html#sqrt.md)
|
||||
[inversesqrt()](index.html#inversesqrt.md)
|
||||
|
||||
* COMMON FUNCTIONS
|
||||
|
||||
[abs()](index.html#abs.md)
|
||||
[sign()](index.html#sign.md)
|
||||
[floor()](index.html#floor.md)
|
||||
[ceil()](index.html#ceil.md)
|
||||
[fract()](index.html#fract.md)
|
||||
[mod()](index.html#mod.md)
|
||||
[min()](index.html#min.md)
|
||||
[max()](index.html#max.md)
|
||||
[clamp()](index.html#clamp.md)
|
||||
[mix()](index.html#mix.md)
|
||||
[step()](index.html#step.md)
|
||||
[smoothstep()](index.html#smoothstep.md)
|
||||
|
||||
* GEOMETRIC FUNCTIONS
|
||||
|
||||
[length()](index.html#length.md)
|
||||
[distance()](index.html#distance.md)
|
||||
[dot()](index.html#dot.md)
|
||||
[cross()](index.html#cross.md)
|
||||
[normalize()](index.html#normalize.md)
|
||||
[facefoward()](index.html#facefoward.md)
|
||||
[reflect()](index.html#reflect.md)
|
||||
[refract()](index.html#refract.md)
|
||||
|
||||
* MATRIX FUNCTIONS
|
||||
|
||||
[matrixCompMult()](index.html#matrixCompMult.md)
|
||||
|
||||
* VECTOR RELATIONAL FUNCTIONS
|
||||
|
||||
[lessThan()](index.html#lessThan.md)
|
||||
[lessThanEqual()](index.html#lessThanEqual.md)
|
||||
[greaterThan()](index.html#greaterThan.md)
|
||||
[greaterThanEqual()](index.html#greaterThanEqual.md)
|
||||
[equal()](index.html#equal.md)
|
||||
[notEqual()](index.html#notEqual.md)
|
||||
[any()](index.html#any.md)
|
||||
[all()](index.html#all.md)
|
||||
[not()](index.html#not.md)
|
||||
|
||||
* TEXTURE LOOKUP FUNCTIONS
|
||||
|
||||
[texture2D()](index.html#texture2D.md)
|
||||
[textureCube()](index.html#textureCube.md)
|
||||
|
||||
## Alphabetical
|
||||
|
||||
* A
|
||||
|
||||
[abs()](index.html#abs.md)
|
||||
[acos()](index.html#acos.md)
|
||||
[all()](index.html#all.md)
|
||||
[any()](index.html#any.md)
|
||||
[asin()](index.html#asin.md)
|
||||
[atan()](index.html#atan.md)
|
||||
|
||||
* C
|
||||
|
||||
[ceil()](index.html#ceil.md)
|
||||
[clamp()](index.html#clamp.md)
|
||||
[cos()](index.html#cos.md)
|
||||
[cross()](index.html#cross.md)
|
||||
|
||||
* D
|
||||
|
||||
[degrees()](index.html#degrees.md)
|
||||
[distance()](index.html#distance.md)
|
||||
[dot()](index.html#dot.md)
|
||||
|
||||
* E
|
||||
|
||||
[equal()](index.html#equal.md)
|
||||
[exp()](index.html#exp.md)
|
||||
[exp2()](index.html#exp2.md)
|
||||
|
||||
* F
|
||||
|
||||
[faceforward()](index.html#faceforward.md)
|
||||
[floor()](index.html#floor.md)
|
||||
[fract()](index.html#fract.md)
|
||||
|
||||
* G
|
||||
|
||||
[greaterThan()](index.html#greaterThan.md)
|
||||
[greaterThanEqual()](index.html#greaterThanEqual.md)
|
||||
|
||||
* I
|
||||
|
||||
[inversesqrt()](index.html#inversesqrt.md)
|
||||
|
||||
* L
|
||||
|
||||
[length()](index.html#length.md)
|
||||
[lessThan()](index.html#lessThan.md)
|
||||
[lessThanEqual()](index.html#lessThanEqual.md)
|
||||
[log()](index.html#log.md)
|
||||
[log2()](index.html#log2.md)
|
||||
|
||||
* M
|
||||
|
||||
[matrixCompMult()](index.html#matrixCompMult.md)
|
||||
[max()](index.html#max.md)
|
||||
[min()](index.html#min.md)
|
||||
[mix()](index.html#mix.md)
|
||||
[mod()](index.html#mod.md)
|
||||
|
||||
* N
|
||||
|
||||
[normalize()](index.html#normalize.md)
|
||||
[not()](index.html#not.md)
|
||||
[notEqual()](index.html#notEqual.md)
|
||||
|
||||
* P
|
||||
|
||||
[pow()](index.html#pow.md)
|
||||
|
||||
* R
|
||||
|
||||
[radians()](index.html#radians.md)
|
||||
[reflect()](index.html#reflect.md)
|
||||
[refract()](index.html#refract.md)
|
||||
|
||||
* S
|
||||
|
||||
[sign()](index.html#sign.md)
|
||||
[sin()](index.html#sin.md)
|
||||
[smoothstep()](index.html#smoothstep.md)
|
||||
[sqrt()](index.html#sqrt.md)
|
||||
[step()](index.html#step.md)
|
||||
|
||||
* T
|
||||
|
||||
[tan()](index.html#tan.md)
|
||||
[texture2D()](index.html#texture2D.md)
|
||||
[textureCube()](index.html#textureCube.md)
|
@ -0,0 +1,21 @@
|
||||
## Abs
|
||||
Return the absolute value of the parameter.
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float abs(float x)
|
||||
vec2 abs(vec2 x)
|
||||
vec3 abs(vec3 x)
|
||||
vec4 abs(vec4 x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specify the value of which to return the absolute.
|
||||
|
||||
### Description
|
||||
```abs()``` returns the absolute value of ```x```.
|
||||
|
||||
<div class="simpleFunction" data="y = abs(x); "></div>
|
||||
|
||||
### See Also
|
||||
[sign()](index.html#sign.md), [min()](index.html#min.md), [max()](index.html#max.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,21 @@
|
||||
## Acos
|
||||
Return the arccosine of the parameter
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float acos(float x)
|
||||
vec2 acos(vec2 x)
|
||||
vec3 acos(vec3 x)
|
||||
vec4 acos(vec4 x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specify the value whose arccosine to return.
|
||||
|
||||
### Description
|
||||
```acos()``` returns the angle whose trigonometric cosine is ```x```.
|
||||
|
||||
<div class="simpleFunction" data="y = acos(x); "></div>
|
||||
|
||||
### See Also
|
||||
[cos()](index.html#cos.md), [sin()](index.html#sin.md), [asin()](index.html#asin.md), [tan()](index.html#tan.md), [atan()](index.html#atan.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,29 @@
|
||||
## Any
|
||||
Check whether any element of a boolean vector is true
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
bool all(bvec2 x)
|
||||
bool all(bvec3 x)
|
||||
bool all(bvec4 x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specifies the vector to be tested for truth.
|
||||
|
||||
### Description
|
||||
```any()``` returns true if any element of ```x``` is ```true``` and ```false``` otherwise. It is functionally equivalent to:
|
||||
|
||||
```glsl
|
||||
bool any(bvec x) { // bvec can be bvec2, bvec3 or bvec4
|
||||
bool result = false;
|
||||
int i;
|
||||
for (i = 0; i < x.length(); ++i) {
|
||||
result |= x[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
### See Also
|
||||
[any()](index.html#any.md), [not()](index.html#not.md)
|
@ -0,0 +1,29 @@
|
||||
## All
|
||||
Check whether all elements of a boolean vector are true
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
bool any(bvec2 x)
|
||||
bool any(bvec3 x)
|
||||
bool any(bvec4 x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specifies the vector to be tested for truth.
|
||||
|
||||
### Description
|
||||
```all()``` returns true if all elements of ```x``` are ```true``` and ```false``` otherwise. It is functionally equivalent to:
|
||||
|
||||
```glsl
|
||||
bool all(bvec x){ // bvec can be bvec2, bvec3 or bvec4
|
||||
bool result = true;
|
||||
int i;
|
||||
for (i = 0; i < x.length(); ++i)
|
||||
{
|
||||
result &= x[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
```
|
||||
### See Also
|
||||
[any()](index.html#any.md), [not()](index.html#not.md)
|
@ -0,0 +1,21 @@
|
||||
## Asin
|
||||
Return the arcsine of the parameter
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float asin(float x)
|
||||
vec2 asin(vec2 x)
|
||||
vec3 asin(vec3 x)
|
||||
vec4 asin(vec4 x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specify the value whose arcsine to return.
|
||||
|
||||
### Description
|
||||
```asin()``` returns the angle whose trigonometric sine is ```x```.
|
||||
|
||||
<div class="simpleFunction" data="y = asin(x); "></div>
|
||||
|
||||
### See Also
|
||||
[cos](index.html#cos.md), [sin](index.html#sin.md), [acos](index.html#acos.md), [tan](index.html#tan.md), [atan](index.html#atan.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,30 @@
|
||||
## Atan
|
||||
Return the arc-tangent of the parameters
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float atan(float y, float x)
|
||||
vec2 atan(vec2 y, vec2 x)
|
||||
vec3 atan(vec3 y, vec3 x)
|
||||
vec4 atan(vec4 y, vec4 x)
|
||||
|
||||
float atan(float y_over_x)
|
||||
vec2 atan(vec2 y_over_x)
|
||||
vec3 atan(vec3 y_over_x)
|
||||
vec4 atan(vec4 y_over_x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```y``` specify the numerator of the fraction whose arctangent to return.
|
||||
|
||||
```x``` specify the denominator of the fraction whose arctangent to return.
|
||||
|
||||
```y_over_x``` specify the fraction whose arctangent to return.
|
||||
|
||||
### Description
|
||||
```atan()``` returns the angle whose trigonometric arctangent is ```y,x``` or ```y_over_x```, depending on which overload is invoked. In the first overload, the signs of ```y``` and ```x``` are used to determine the quadrant that the angle lies in. The values returned by atan in this case are in the range -PI and PI. Results are undefined if ```x``` is zero.
|
||||
|
||||
For the second overload, ```atan()``` returns the angle whose tangent is ```y_over_x```. Values returned in this case are in the range -PI to PI.
|
||||
|
||||
### See Also
|
||||
[cos](index.html#cos.md), [acos](index.html#acos.md), [sin](index.html#sin.md), [asin](index.html#asin.md), [atan](index.html#atan.md), [Chapter 05: Shaping Functions](../05/), [Chapter 06: Color](../06/)
|
@ -0,0 +1,21 @@
|
||||
## Ceil
|
||||
Find the nearest integer that is greater than or equal to the parameter
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float ceil(float x)
|
||||
vec2 ceil(vec2 x)
|
||||
vec3 ceil(vec3 x)
|
||||
vec4 ceil(vec4 x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specify the value to evaluate.
|
||||
|
||||
### Description
|
||||
```ceil()``` returns a value equal to the nearest integer that is greater than or equal to ```x```.
|
||||
|
||||
<div class="simpleFunction" data="y = ceil(x); "></div>
|
||||
|
||||
### See Also
|
||||
[floor](index.html#floor.md), [fract](index.html#fract.md), [mod](index.html#mod.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,29 @@
|
||||
## Clamp
|
||||
Constrain a value to lie between two further values
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float clamp(float x, float minVal, float maxVal)
|
||||
vec2 clamp(vec2 x, vec2 minVal, vec2 maxVal)
|
||||
vec3 clamp(vec3 x, vec3 minVal, vec3 maxVal)
|
||||
vec4 clamp(vec4 x, vec4 minVal, vec4 maxVal)
|
||||
|
||||
vec2 clamp(vec2 x, float minVal, float maxVal)
|
||||
vec3 clamp(vec3 x, float minVal, float maxVal)
|
||||
vec4 clamp(vec4 x, float minVal, float maxVal)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specify the value to constrain.
|
||||
|
||||
```minVal``` specify the lower end of the range into which to constrain x.
|
||||
|
||||
```maxVal``` specify the upper end of the range into which to constrain x.
|
||||
|
||||
### Description
|
||||
```clamp()``` returns the value of ```x``` constrained to the range ```minVal``` to ```maxVal```. The returned value is computed as ```min(max(x, minVal), maxVal)```.
|
||||
|
||||
<div class="simpleFunction" data="y = clamp(x,0.,1.); "></div>
|
||||
|
||||
### See Also
|
||||
[min](index.html#min.md), [abs](index.html#abs.md), [max](index.html#max.md)
|
@ -0,0 +1,21 @@
|
||||
## Cos
|
||||
Return the cosine of the parameter
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float cos(float angle)
|
||||
vec2 cos(vec2 angle)
|
||||
vec3 cos(vec3 angle)
|
||||
vec4 cos(vec4 angle)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```angle``` specify the quantity, in radians, of which to return the cosine.
|
||||
|
||||
### Description
|
||||
```cos()``` returns the trigonometric sine of angle.
|
||||
|
||||
<div class="simpleFunction" data="y = cos(x); "></div>
|
||||
|
||||
### See Also
|
||||
[acos](index.html#acos.md), [sin](index.html#sin.md), [asin](index.html#asin.md), [tan](index.html#tan.md), [atan](index.html#atan.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,19 @@
|
||||
## Cross
|
||||
Calculate the cross product of two vectors
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
vec3 cross(vec3 x, vec3 y)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specifies the first of two vectors
|
||||
|
||||
```y``` specifies the second of two vectors
|
||||
|
||||
### Description
|
||||
```cross()``` returns the cross product of two vectors, ```x``` and ```y```. The input parameters can only be 3-component floating vectors. The cross product is equivalent to the product of the length of the vectors times the sinus of the(smaller) angle between ```x``` and ```y```.
|
||||
|
||||
### See Also
|
||||
|
||||
[dot()](index.html#dot.md)
|
@ -0,0 +1,19 @@
|
||||
## Degrees
|
||||
Convert a quantity in radians to degrees
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float degrees(float radians)
|
||||
vec2 degrees(vec2 radians)
|
||||
vec3 degrees(vec3 radians)
|
||||
vec4 degrees(vec4 radians)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```radians``` specify the quantity, in radians, to be converted to degrees.
|
||||
|
||||
### Description
|
||||
```degrees()``` converts a quantity, specified in radians into degrees. That is, the return value is ```(180.0*radians)/PI```
|
||||
|
||||
### See Also
|
||||
[radians](index.html#radians.md)
|
@ -0,0 +1,24 @@
|
||||
## Distance
|
||||
Calculate the distance between two points
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float distance(float p0, float p1)
|
||||
float distance(vec2 p0, vec2 p1)
|
||||
float distance(vec3 p0, vec3 p1)
|
||||
float distance(vec4 p0, vec4 p1)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```p0``` specifies the first of two points
|
||||
|
||||
```p1``` specifies the second of two points
|
||||
|
||||
### Description
|
||||
```distance()``` returns the distance between the two points ```p0``` and ```p1```.
|
||||
|
||||
<div class="codeAndCanvas" data="../07/circle-making.frag"></div>
|
||||
|
||||
### See Also
|
||||
|
||||
[length()](index.html#length.md), [normalize()](index.html#normalize.md), [Chapter 07: Shapes](../07/)
|
@ -0,0 +1,25 @@
|
||||
## Dot
|
||||
Calculate the dot product of two vectors
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float dot(float x, float y)
|
||||
float dot(vec2 x, vec2 y)
|
||||
float dot(vec3 x, vec3 y)
|
||||
float dot(vec4 x, vec4 y)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specifies the first of two vectors
|
||||
|
||||
```y``` specifies the second of two vectors
|
||||
|
||||
### Description
|
||||
```dot()``` returns the dot product of two vectors, ```x``` and ```y```. i.e., ```x[0]⋅y[0]+x[1]⋅y[1]+...```
|
||||
If ```x``` and ```y``` are the same the square root of the dot product is equivalent to the length of the vector. The input parameters can be floating scalars or float vectors. In case of floating scalars the dot function is trivial and returns the product of x and y.
|
||||
|
||||
<div class="codeAndCanvas" data="../07/circle.frag"></div>
|
||||
|
||||
### See Also
|
||||
|
||||
[cross()](index.html#cross.md), [Chapter 07: Shapes](../07/)
|
@ -0,0 +1,24 @@
|
||||
## Equal
|
||||
Perform a component-wise equal-to comparison of two vectors
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
bvec2 equal(vec2 x, vec2 y)
|
||||
bvec3 equal(vec3 x, vec3 y)
|
||||
bvec4 equal(vec4 x, vec4 y)
|
||||
|
||||
bvec2 equal(ivec2 x, ivec2 y)
|
||||
bvec3 equal(ivec3 x, ivec3 y)
|
||||
bvec4 equal(ivec4 x, ivec4 y)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` Specifies the first vector to be used in the comparison operation.
|
||||
|
||||
```y``` Specifies the second vector to be used in the comparison operation.
|
||||
|
||||
### Description
|
||||
```equal()``` returns a boolean vector in which each element ```i``` is computed as ```x[i] == y[i]```.
|
||||
|
||||
### See Also
|
||||
[lessThanEqual()](index.html#lessThanEqual.md), [lessThan()](index.html#lessThan.md), [greaterThanEqual()](index.html#greaterThanEqual.md), [greaterThan()](index.html#greaterThan.md), [notEqual()](index.html#notEqual.md), [any()](index.html#any.md), [all()](index.html#all.md), [not()](index.html#not.md)
|
@ -0,0 +1,22 @@
|
||||
## Exp
|
||||
Return the natural exponentiation of the parameter
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float exp(float x)
|
||||
vec2 exp(vec2 x)
|
||||
vec3 exp(vec3 x)
|
||||
vec4 exp(vec4 x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specify the value to exponentiate.
|
||||
|
||||
### Description
|
||||
```exp()``` returns the natural exponentiation of ```x```.
|
||||
|
||||
<div class="simpleFunction" data="y = exp(x); "></div>
|
||||
|
||||
### See Also
|
||||
|
||||
[log](index.html#log.md), [log2](index.html#log2.md), [exp2](index.html#exp2.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,22 @@
|
||||
## Exp2
|
||||
Return 2 raised to the power of the parameter
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float exp2(float x)
|
||||
vec2 exp2(vec2 x)
|
||||
vec3 exp2(vec3 x)
|
||||
vec4 exp2(vec4 x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specify the value of the power to which 2 will be raised.
|
||||
|
||||
### Description
|
||||
```exp2()``` returns 2 raised to the power of ```x```.
|
||||
|
||||
<div class="simpleFunction" data="y = exp2(x); "></div>
|
||||
|
||||
### See Also
|
||||
|
||||
[log](index.html#log.md), [log2](index.html#log2.md), [exp](index.html#exp.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,24 @@
|
||||
## Faceforward
|
||||
Return a vector pointing in the same direction as another
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float faceforward(float N, float I, float Nref)
|
||||
vec2 faceforward(vec2 N, vec2 I, vec2 Nref)
|
||||
vec3 faceforward(vec3 N, vec3 I, vec3 Nref)
|
||||
vec4 faceforward(vec4 N, vec4 I, vec4 Nref)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```N``` specifies the vector to orient.
|
||||
|
||||
```I``` specifies the incident vector.
|
||||
|
||||
```Nref``` specifies the reference vector.
|
||||
|
||||
### Description
|
||||
```faceforward()``` orients a vector to point away from a surface as defined by its normal. ```If dot(Nref, I) < 0``` faceforward returns ```N```, otherwise it returns ```-N```.
|
||||
|
||||
### See Also
|
||||
|
||||
[reflect()](index.html#reflect.md), [refract()](index.html#refract.md)
|
@ -0,0 +1,21 @@
|
||||
## Floor
|
||||
Find the nearest integer less than or equal to the parameter
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float floor(float x)
|
||||
vec2 floor(vec2 x)
|
||||
vec3 floor(vec3 x)
|
||||
vec4 floor(vec4 x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specify the value to evaluate.
|
||||
|
||||
### Description
|
||||
```floor()``` returns a value equal to the nearest integer that is less than or equal to ```x```.
|
||||
|
||||
<div class="simpleFunction" data="y = floor(x); "></div>
|
||||
|
||||
### See Also
|
||||
[ceil](index.html#ceil.md), [fract](index.html#fract.md), [mod](index.html#mod.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,21 @@
|
||||
## Fract
|
||||
Compute the fractional part of the argument
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float fract(float x)
|
||||
vec2 fract(vec2 x)
|
||||
vec3 fract(vec3 x)
|
||||
vec4 fract(vec4 x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specify the value to evaluate.
|
||||
|
||||
### Description
|
||||
```fract()``` returns the fractional part of ```x```. This is calculated as ```x - floor(x)```.
|
||||
|
||||
<div class="simpleFunction" data="y = fract(x); "></div>
|
||||
|
||||
### See Also
|
||||
[floor](index.html#floor.md), [ceil](index.html#ceil.md), [mod](index.html#mod.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,24 @@
|
||||
## GreaterThan
|
||||
Perform a component-wise greater-than comparison of two vectors
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
bvec2 greaterThan(vec2 x, vec2 y)
|
||||
bvec3 greaterThan(vec3 x, vec3 y)
|
||||
bvec4 greaterThan(vec4 x, vec4 y)
|
||||
|
||||
bvec2 greaterThan(ivec2 x, ivec2 y)
|
||||
bvec3 greaterThan(ivec3 x, ivec3 y)
|
||||
bvec4 greaterThan(ivec4 x, ivec4 y)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specifies the first vector to be used in the comparison operation.
|
||||
|
||||
```y``` specifies the second vector to be used in the comparison operation.
|
||||
|
||||
### Description
|
||||
```greaterThan()``` returns a boolean vector in which each element ```i``` is computed as ```x[i] > y[i]```.
|
||||
|
||||
### See Also
|
||||
[lessThanEqual()](index.html#lessThanEqual.md), [lessThan()](index.html#lessThan.md), [greaterThanEqual()](index.html#greaterThanEqual.md), [equal()](index.html#equal.md), [notEqual()](index.html#notEqual.md), [any()](index.html#any.md), [all()](index.html#all.md), [not()](index.html#not.md)
|
@ -0,0 +1,24 @@
|
||||
## GreaterThanEqual
|
||||
Perform a component-wise greater-than-or-equal comparison of two vectors
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
bvec2 greaterThanEqual(vec2 x, vec2 y)
|
||||
bvec3 greaterThanEqual(vec3 x, vec3 y)
|
||||
bvec4 greaterThanEqual(vec4 x, vec4 y)
|
||||
|
||||
bvec2 greaterThanEqual(ivec2 x, ivec2 y)
|
||||
bvec3 greaterThanEqual(ivec3 x, ivec3 y)
|
||||
bvec4 greaterThanEqual(ivec4 x, ivec4 y)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specifies the first vector to be used in the comparison operation.
|
||||
|
||||
```y``` specifies the second vector to be used in the comparison operation.
|
||||
|
||||
### Description
|
||||
```greaterThanEqual()``` returns a boolean vector in which each element ```i``` is computed as ```x[i] ≥ y[i]```.
|
||||
|
||||
### See Also
|
||||
[lessThanEqual()](index.html#lessThanEqual.md), [lessThan()](index.html#lessThan.md), [greaterThan()](index.html#greaterThan.md), [equal()](index.html#equal.md), [notEqual()](index.html#notEqual.md), [any()](index.html#any.md), [all()](index.html#all.md), [not()](index.html#not.md)
|
@ -0,0 +1,69 @@
|
||||
<!-- Copyright 2015 Patricio Gonzalez Vivo (http://patriciogonzalezvivo.com) -->
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Glossary</title>
|
||||
<meta name="keywords" content="glsl,shader,github,repository" />
|
||||
<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="homePage()"> Home </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>
|
@ -0,0 +1,22 @@
|
||||
## Inversesqrt
|
||||
Return the inverse of the square root of the parameter
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float inversesqrt(float x)
|
||||
vec2 inversesqrt(vec2 x)
|
||||
vec3 inversesqrt(vec3 x)
|
||||
vec4 inversesqrt(vec4 x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specify the value of which to take the inverse of the square root.
|
||||
|
||||
### Description
|
||||
```inversesqrt()``` returns the inverse of the square root of ```x```.
|
||||
|
||||
<div class="simpleFunction" data="y = inversesqrt(x); "></div>
|
||||
|
||||
### See Also
|
||||
|
||||
[pow](index.html#pow.md), [sqrt](index.html#sqrt.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,22 @@
|
||||
## Length
|
||||
Calculate the length of a vector
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float length(float x)
|
||||
float length(vec2 x)
|
||||
float length(vec3 x)
|
||||
float length(vec4 x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specifies a vector of which to calculate the length.
|
||||
|
||||
### Description
|
||||
```length()``` returns the length of the vector.
|
||||
|
||||
<div class="codeAndCanvas" data="../07/circle-making.frag"></div>
|
||||
|
||||
### See Also
|
||||
|
||||
[distance()](index.html#distance.md), [normalize()](index.html#normalize.md), [Chapter 07: Shapes](../07/)
|
@ -0,0 +1,24 @@
|
||||
## LessThan
|
||||
Perform a component-wise less-than comparison of two vectors
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
bvec2 lessThan(vec2 x, vec2 y)
|
||||
bvec3 lessThan(vec3 x, vec3 y)
|
||||
bvec4 lessThan(vec4 x, vec4 y)
|
||||
|
||||
bvec2 lessThan(ivec2 x, ivec2 y)
|
||||
bvec3 lessThan(ivec3 x, ivec3 y)
|
||||
bvec4 lessThan(ivec4 x, ivec4 y)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specifies the first vector to be used in the comparison operation.
|
||||
|
||||
```y``` specifies the second vector to be used in the comparison operation.
|
||||
|
||||
### Description
|
||||
```lessThan()``` returns a boolean vector in which each element ```i``` is computed as ```x[i] < y[i]```.
|
||||
|
||||
### See Also
|
||||
[lessThanEqual()](index.html#lessThanEqual.md), [greaterThan()](index.html#greaterThan.md), [greaterThanEqual()](index.html#greaterThanEqual.md), [equal()](index.html#equal.md), [notEqual()](index.html#notEqual.md), [any()](index.html#any.md), [all()](index.html#all.md), [not()](index.html#not.md)
|
@ -0,0 +1,24 @@
|
||||
## LessThanEqual
|
||||
Perform a component-wise less-than-or-equal comparison of two vectors
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
bvec2 lessThanEqual(vec2 x, vec2 y)
|
||||
bvec3 lessThanEqual(vec3 x, vec3 y)
|
||||
bvec4 lessThanEqual(vec4 x, vec4 y)
|
||||
|
||||
bvec2 lessThanEqual(ivec2 x, ivec2 y)
|
||||
bvec3 lessThanEqual(ivec3 x, ivec3 y)
|
||||
bvec4 lessThanEqual(ivec4 x, ivec4 y)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specifies the first vector to be used in the comparison operation.
|
||||
|
||||
```y``` specifies the second vector to be used in the comparison operation.
|
||||
|
||||
### Description
|
||||
```lessThanEqual()``` returns a boolean vector in which each element ```i``` is computed as ```x[i] ≤ y[i]```.
|
||||
|
||||
### See Also
|
||||
[lessThan()](index.html#lessThan.md), [greaterThan()](index.html#greaterThan.md), [greaterThanEqual()](index.html#greaterThanEqual.md), [equal()](index.html#equal.md), [notEqual()](index.html#notEqual.md), [any()](index.html#any.md), [all()](index.html#all.md), [not()](index.html#not.md)
|
@ -0,0 +1,22 @@
|
||||
## Log
|
||||
Return the natural logarithm of the parameter
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float log(float x)
|
||||
vec2 log(vec2 x)
|
||||
vec3 log(vec3 x)
|
||||
vec4 log(vec4 x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` s### Declarationpecify the value of which to take the natural logarithm.
|
||||
|
||||
### Description
|
||||
```log()``` returns the natural logarithm of ```x```.
|
||||
|
||||
<div class="simpleFunction" data="y = log(x); "></div>
|
||||
|
||||
### See Also
|
||||
|
||||
[log2](index.html#log2.md), [exp](index.html#exp.md), [exp2](index.html#exp2.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,22 @@
|
||||
## Log2
|
||||
Return the base 2 logarithm of the parameter
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float log2(float x)
|
||||
vec2 log2(vec2 x)
|
||||
vec3 log2(vec3 x)
|
||||
vec4 log2(vec4 x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specify the value of which to take the base 2 logarithm.
|
||||
|
||||
### Description
|
||||
```log2()``` returns the base 2 logarithm of ```x```.
|
||||
|
||||
<div class="simpleFunction" data="y = log2(x); "></div>
|
||||
|
||||
### See Also
|
||||
|
||||
[log](index.html#log.md), [exp](index.html#exp.md), [exp2](index.html#exp2.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,20 @@
|
||||
## MatrixCompMult
|
||||
Perform a component-wise multiplication of two matrices
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
mat2 matrixCompMult(mat2 x, mat2 y)
|
||||
mat3 matrixCompMult(mat3 x, mat3 y)
|
||||
mat4 matrixCompMult(mat4 x, mat4 y)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specifies the first matrix multiplicand.
|
||||
|
||||
```y``` specifies the second matrix multiplicand.
|
||||
|
||||
### Description
|
||||
```matrixCompMult()``` performs a component-wise multiplication of two matrices, yielding a result matrix where each component, ```result[i][j]``` is computed as the scalar product of ```x[i][j]``` and ```y[i][j]```.
|
||||
|
||||
### See Also
|
||||
[Chapter 08: Matrix](../08/)
|
@ -0,0 +1,27 @@
|
||||
## Max
|
||||
Return the greater of two values
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float max(float x, float y)
|
||||
vec2 max(vec2 x, vec2 y)
|
||||
vec3 max(vec3 x, vec3 y)
|
||||
vec4 max(vec4 x, vec4 y)
|
||||
|
||||
vec2 max(vec2 x, float y)
|
||||
vec3 max(vec3 x, float y)
|
||||
vec4 max(vec4 x, float y)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specify the first value to compare.
|
||||
|
||||
```y``` specify the second value to compare.
|
||||
|
||||
### Description
|
||||
```max()``` returns the maximum of the two parameters. It returns ```y``` if ```y``` is greater than ```x```, otherwise it returns ```x```.
|
||||
|
||||
<div class="simpleFunction" data="y = max(x,0.5); "></div>
|
||||
|
||||
### See Also
|
||||
[min](index.html#min.md), [abs](index.html#abs.md), [clamp](index.html#clamp.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,27 @@
|
||||
## Min
|
||||
Return the lesser of two values
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float min(float x, float y)
|
||||
vec2 min(vec2 x, vec2 y)
|
||||
vec3 min(vec3 x, vec3 y)
|
||||
vec4 min(vec4 x, vec4 y)
|
||||
|
||||
vec2 min(vec2 x, float y)
|
||||
vec3 min(vec3 x, float y)
|
||||
vec4 min(vec4 x, float y)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specify the first value to compare.
|
||||
|
||||
```y``` pecify the second value to compare.
|
||||
|
||||
### Description
|
||||
```min()``` returns the minimum of the two parameters. It returns ```y``` if ```y``` is less than ```x```, otherwise it returns ```x```.
|
||||
|
||||
<div class="simpleFunction" data="y = min(x,0.5); "></div>
|
||||
|
||||
### See Also
|
||||
[max](index.html#max.md), [abs](index.html#abs.md), [clamp](index.html#clamp.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,26 @@
|
||||
## Mod
|
||||
Compute value of one parameter modulo another
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float mod(float x, float y)
|
||||
vec2 mod(vec2 x, vec2 y)
|
||||
vec3 mod(vec3 x, vec3 y)
|
||||
vec4 mod(vec4 x, vec4 y)
|
||||
|
||||
vec2 mod(vec2 x, float y)
|
||||
vec3 mod(vec3 x, float y)
|
||||
vec4 mod(vec4 x, float y)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specify the value to evaluate.
|
||||
```y``` specify the value to obtain the modulo of.
|
||||
|
||||
### Description
|
||||
```mod()``` returns the value of ```x``` modulo ```y```. This is computed as ```x - y * floor(x/y)```.
|
||||
|
||||
<div class="simpleFunction" data="y = mod(x,1.5); "></div>
|
||||
|
||||
### See Also
|
||||
[floor](index.html#floor.md), [fract](index.html#fract.md), [ceil](index.html#ceil.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,20 @@
|
||||
## Normalize
|
||||
Calculate the normalize product of two vectors
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
float normalize(float x)
|
||||
vec2 normalize(vec2 x)
|
||||
vec3 normalize(vec3 x)
|
||||
vec4 normalize(vec4 x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```v``` specifies the vector to normalize.
|
||||
|
||||
### Description
|
||||
```normalize()``` returns a vector with the same direction as its parameter, v, but with length 1.
|
||||
|
||||
### See Also
|
||||
|
||||
[length()](index.html#length.md)
|
@ -0,0 +1,18 @@
|
||||
## Not
|
||||
Logically invert a boolean vector
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
bvec2 not(bvec2 x)
|
||||
bvec3 not(bvec3 x)
|
||||
bvec4 not(bvec4 x)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specifies the vector to be inverted.
|
||||
|
||||
### Description
|
||||
```not()``` logically inverts the boolean vector ```x```. It returns a new boolean vector for which each element ```i``` is computed as ```!x[i]```.
|
||||
|
||||
### See Also
|
||||
[any()](index.html#any.md), [all()](index.html#all.md)
|
@ -0,0 +1,24 @@
|
||||
## NotEqual
|
||||
Perform a component-wise not-equal-to comparison of two vectors
|
||||
|
||||
### Declaration
|
||||
```glsl
|
||||
bvec2 notEqual(vec2 x, vec2 y)
|
||||
bvec3 notEqual(vec3 x, vec3 y)
|
||||
bvec4 notEqual(vec4 x, vec4 y)
|
||||
|
||||
bvec2 notEqual(ivec2 x, ivec2 y)
|
||||
bvec3 notEqual(ivec3 x, ivec3 y)
|
||||
bvec4 notEqual(ivec4 x, ivec4 y)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
```x``` specifies the first vector to be used in the comparison operation.
|
||||
|
||||
```y``` specifies the second vector to be used in the comparison operation.
|
||||
|
||||
### Description
|
||||
```notEqual()``` returns a boolean vector in which each element ```i``` is computed as ```x[i] != y[i]```.
|
||||
|
||||
### See Also
|
||||
[lessThanEqual()](index.html#lessThanEqual.md), [lessThan()](index.html#lessThan.md), [greaterThanEqual()](index.html#greaterThanEqual.md), [greaterThan()](index.html#greaterThan.md), [equal()](index.html#equal.md), [any()](index.html#any.md), [all()](index.html#all.md), [not()](index.html#not.md)
|