@ -39,8 +39,8 @@ The examples of this book and the [companion editor](http://editor.thebookofshad
They'll tell you where and why your program failed to compile, then you'll have to fix things and whenever the shader is ready to compile, it will be displayed instantly.
That's a great way of learning as it's very visual and you can't really break anything.
Last note, a **shader** is made of 2 programs, the **vertex shaderr** and the **fragment shader**.
In a nutshell, the **vertex shader**, the first program, recieves a *geometry* as an input and turns it into series of **pixels** (or *fragments*) then hands them over to the
Last note, a **shader** is made of 2 programs, the **vertex shader** and the **fragment shader**.
In a nutshell, the **vertex shader**, the first program, receives a *geometry* as an input and turns it into series of **pixels** (or *fragments*) then hands them over to the
**fragment shader**, the second program, that will decide which color to paint the pixels.
This book is mostly focused on the latter, in all the examples, the geometry is a simple quadrilateral that covers the whole screen.
@ -80,7 +80,7 @@ Not that hard right? as mentioned above, it even makes things easier when it com
When in doubt, remember that you're doing this for your program to run immensely faster than in JS.
#### void
There is a `void` type that roughly cooresponds to `null`, it is used as the return type of a method that doesn't return anything.
There is a `void` type that roughly corresponds to `null`, it is used as the return type of a method that doesn't return anything.
you can't assign it to a variable.
#### boolean
@ -122,7 +122,7 @@ int i = int( 1 );
int i = int( 1.9995 );
int i = int( true );
```
This may not sound like much for `scalar` types, it's not very different from **casting**, but it will make sense when adressing the *overload* section.
This may not sound like much for `scalar` types, it's not very different from **casting**, but it will make sense when addressing the *overload* section.
Ok, so these three are the `primitive types`, things you can't live without but of course, GLSL has more to offer.
@ -142,7 +142,7 @@ var Point = function( x, y ){
var p = new Point( 100,100 );
```
As we've just seen, this is SO wrong at SO many levels! That **`var`** keyword for one, then the horendous **`this`**, then again **untyped**`x` and `y` values...
As we've just seen, this is SO wrong at SO many levels! That **`var`** keyword for one, then the horrendous **`this`**, then again **untyped**`x` and `y` values...
No, this is not going to work in shaderland.
Instead, GLSL exposes built-in data structures to hold data together, namely:
@ -200,8 +200,8 @@ And the clever bunny you are already noticed three things:
* `R`, `G`, `B`&`A` are used to encode colors and alpha
* `[0]`, `[1]`, `[2]`&`[3]` mean that we have a random access array of values
So depending on wether you're manipulating 2D or 3D coordinates, a color with or without an alpha value or simply some random variables, you can pick the most suited **vector** type and size.
Typically 2D coordinates and vectors (in the geometric sense) are stored as a `vec2`, `vec3` or `vec4`, colors as `vec3` or `vec4` if you need opacity but htere is no restriction on how to use the vectors.
So depending on whether you're manipulating 2D or 3D coordinates, a color with or without an alpha value or simply some random variables, you can pick the most suited **vector** type and size.
Typically 2D coordinates and vectors (in the geometric sense) are stored as a `vec2`, `vec3` or `vec4`, colors as `vec3` or `vec4` if you need opacity but there is no restriction on how to use the vectors.
For instance, if you want to store only one boolean value in a `bvce4`, it's possible, it's just a waste of memory.
**note**: in a shader, color values (`R`, `G`, `B`&`A`) are normalised, they range from 0 to 1 and not from 0 to 0xFF, so you'd rather use a Float `vec4` than an Integer `ivec4` to store them.
@ -240,7 +240,7 @@ So not only can you retrieve a subset of your data, but you can also specify the
vec4 color = vec4( 0.2, 0.8, 0.0, 1.0 );
//and retrieve the color components in the A,B,G,R order
And of course, you can ask the same component multiple times:
```glsl
@ -282,7 +282,7 @@ We built a `vec4` out of two `vec2`, by doing so, the new `vec4` used the `a.x`
Then it took `b.x` and `b.y` and used them as the `Z` and `W` components of `c`.
This is what happens when a **function** is overloaded to accept different arguments, in this case, the `vec4`**constructor**.
It means that many **vesrions** of the same method with a different signature can coexist in the same program, for instance the following declarations are all valid:
It means that many **versions** of the same method with a different signature can coexist in the same program, for instance the following declarations are all valid:
```glsl
vec4 a = vec4(1.0, 1.0, 1.0, 1.0);
vec4 a = vec4(1.0);// x, y, z, w all equal 1.0
@ -294,7 +294,7 @@ the only thing you should make sure of is to provide enough arguments to feed yo
Last thing, you are allowed to overload the built-in functions in your program so they can take arguments they were not designed for (this shouldn't happen too often though).
### more types
#### more types
Vectors are fun, they're the meat of your shader.
There are other primitives such as Matrices and Texture samplers which will be covered later in the book.