Skip to content

Instantly share code, notes, and snippets.

@behreajj
behreajj / labxyz.c
Last active May 22, 2021 16:29
CIE XYZ CIE LAB Conversion
vector xyzToLab(vector xyz) {
float vx = xyz[0] / 0.95047;
float vy = xyz[1];
float vz = xyz[2] / 1.08883;
vx = select(7.787 * vx + 16.0 / 116.0, pow(vx, 1.0 / 3.0), vx > 0.008856);
vy = select(7.787 * vy + 16.0 / 116.0, pow(vy, 1.0 / 3.0), vy > 0.008856);
vz = select(7.787 * vz + 16.0 / 116.0, pow(vz, 1.0 / 3.0), vz > 0.008856);
return vector(
@behreajj
behreajj / linearciexyz.c
Last active May 22, 2021 12:31
Linear-CIE XYZ Conversion
vector lRgbToXyz(color linear) {
return transform(matrix(
0.41241086, 0.21264935, 0.019331759, 0.0,
0.35758457, 0.71516913, 0.11919486 , 0.0,
0.1804538 , 0.07218152, 0.95039004 , 0.0,
0.0 , 0.0 , 0.0 , 1.0),
linear);
}
color xyzTolRgb(vector xyz) {
@behreajj
behreajj / linearStandardRevised.c
Last active May 22, 2021 12:30
Linear Standard Revised
vector le(vector a, float b) {
return vector(a[0] <= b, a[1] <= b, a[2] <= b);
}
vector gt(vector a, float b) {
return vector(a[0] > b, a[1] > b, a[2] > b);
}
color sRgbTolRgb(color standard) {
return select(pow((standard + 0.055) / 1.055, 2.4),
@behreajj
behreajj / linearGradient.c
Last active May 22, 2021 12:29
linearGradient.osl
float scalarProj(vector a, vector b) {
return dot(a, b) / dot(b, b);
}
float uquantize(float x, int levels) {
return select(
max(0.0, (ceil(x * levels) - 1.0) / (levels - 1.0)),
x, levels < 2);
}
@behreajj
behreajj / circle1.c
Last active May 22, 2021 12:29
Circle Mixed With Noise
float quantize(float x, int levels) {
return select(
floor(0.5 + x * levels) / levels,
x, levels < 2);
}
shader circle1(
point Point = P,
point Center = 0.0,
float Radius = 1.5,
@behreajj
behreajj / linearStandard.c
Last active May 22, 2021 12:29
Linear Standard RGB Conversions
color sRgbTolRgb(color standard) {
float sr = standard[0];
float sg = standard[1];
float sb = standard[2];
return color(
select(pow((sr + 0.055) / 1.055, 2.4), sr / 12.92, sr <= 0.04045),
select(pow((sg + 0.055) / 1.055, 2.4), sg / 12.92, sg <= 0.04045),
select(pow((sb + 0.055) / 1.055, 2.4), sb / 12.92, sb <= 0.04045));
}
@behreajj
behreajj / circle0.c
Last active May 22, 2021 12:29
Circle 0
shader circle0(
vector UV = vector(0.5, 0.5, 0.0),
vector Center = vector(0.5, 0.5, 0.0),
float Radius = 1.0,
float Blur = 0.0,
color Outside = color(1.0, 0.0, 0.0),
color Inside = 1.0,
output color Color = 0.8,
output float Fac = 0.5) {
@behreajj
behreajj / distorted_suzie_03.py
Created May 20, 2021 19:50
Distorted Suzanne with Shape Keys
import bpy
import bmesh
import math
from mathutils import noise, Quaternion, Vector
# Create a Suzanne (monkey head); subdivide.
bm = bmesh.new()
bmesh.ops.create_monkey(bm)
bmesh.ops.subdivide_edges(
bm,
@behreajj
behreajj / scale_anim_02.py
Created May 19, 2021 16:26
Easing Function Definitions
import bpy
import bmesh
import math
from mathutils import Vector
def lerp_vec_array(arr, step=0.5, easing_func=None):
len_arr = len(arr)
if len_arr == 0:
return Vector((0.0, 0.0, 0.0))
@behreajj
behreajj / scale_anim_01.py
Last active May 19, 2021 16:26
Cube Scale Animation
# Use Vector.Fill to create uniform scales.
scales = [
Vector.Fill(3, 1.0),
Vector((0.25, 0.75, 0.5)),
Vector.Fill(3, 2 ** 0.5),
Vector((0.75, 0.5, 0.25)),
Vector.Fill(3, 2 ** -0.5),
Vector((0.5, 0.25, 0.75)),
Vector.Fill(3, 1.0)
]