GLSL
# Links
# Essentials
# Pages
# Functions ^h1saewe
|
|
Some 3D functions: ^c4jjbre
|
|
- dFdx and dFdy
- sign - use this to get the sign.
# Variables
|
|
# Data types
floats, ints, etc.. Some exotic ones:
bvec(2,3,4)
- a boolean vector ^c28a06ivec(2,3,4)
- an integer vector
# Syntax neatos
- You can actually do
1.0 - vec3(1,2,3)
or some stuff like that. It’s the same asvec3(1.0) - vec3(1,2,3)
^nk0sofj
# Dealing with matrices
|
|
You can also define non-square matrices with matNxM
, e.g. mat2x3
.
If a larger matrix is constructed from a smaller matrix, the additional rows and columns are set to the values they would have in an identity matrix:
|
|
If a smaller matrix is constructed from a larger matrix, the top, left submatrix of the larger matrix is chosen, e.g. in the last line of the previous example.
See also Angles and rotation in GLSL
# Snippets
# Custom blurring function
|
|
# Pitfalls & trivia
pow(x,y)
is doingexp(y*log(x))
: costly, not valid for x<0, not perfect precision.- for x^2, do prefer
x*x
! - for 2^x use
exp2(x)
. The reverselog2
also exist.
- for x^2, do prefer
mix
function doesn’t clamp a (the last value)! So if it’s greater than 1, the second color gets multiplied. Because it’s implemented like this: $$(1-a)x+ay$$- GLSL compilation
# To process #todo
# Shaders
- Flipping tiles ( https://www.shadertoy.com/view/XtS3Dt)
- Geometric Grid Pattern ( https://www.shadertoy.com/view/Wdd3DX)
- Portal 2 Box Flip Rotation ( https://www.shadertoy.com/view/ltBcD3)
# Box formula by Shane
This renders a horizontal or vertical box-line from point a
to point b
with a line width of w
. It’s different to the the usual line formula because it doesn’t render the rounded caps on the end. Sometimes, you don’t want those. It utilizes IQ’s box formula and was put together in a hurry, so I’d imagine there are more efficient ways to do the same, but it gets the job done. I put together a more generalized angular line formula as well.
|
|