Add smoothstep

This commit is contained in:
gingerBill
2021-11-04 15:57:27 +00:00
parent 57eedfc4f4
commit 84540d7aa2

View File

@@ -769,6 +769,31 @@ step_dvec2 :: proc "c" (edge, x: dvec2) -> dvec2 { return {step(edge.x, x.x), st
step_dvec3 :: proc "c" (edge, x: dvec3) -> dvec3 { return {step(edge.x, x.x), step(edge.y, x.y), step(edge.z, x.z)} }
step_dvec4 :: proc "c" (edge, x: dvec4) -> dvec4 { return {step(edge.x, x.x), step(edge.y, x.y), step(edge.z, x.z), step(edge.w, x.w)} }
smoothstep :: proc{
smoothstep_f32,
smoothstep_f64,
smoothstep_vec2,
smoothstep_vec3,
smoothstep_vec4,
smoothstep_dvec2,
smoothstep_dvec3,
smoothstep_dvec4,
}
smoothstep_f32 :: proc "c" (edge0, edge1, x: f32) -> f32 {
y := clamp(((x-edge0) / (edge1 - edge0)), 0, 1)
return y * y * (3 - 2*y)
}
smoothstep_f64 :: proc "c" (edge0, edge1, x: f64) -> f64 {
y := clamp(((x-edge0) / (edge1 - edge0)), 0, 1)
return y * y * (3 - 2*y)
}
smoothstep_vec2 :: proc "c" (edge0, edge1, x: vec2) -> vec2 { return {smoothstep(edge0.x, edge1.x, x.x), smoothstep(edge0.y, edge1.y, x.y)} }
smoothstep_vec3 :: proc "c" (edge0, edge1, x: vec3) -> vec3 { return {smoothstep(edge0.x, edge1.x, x.x), smoothstep(edge0.y, edge1.y, x.y), smoothstep(edge0.z, edge1.z, x.z)} }
smoothstep_vec4 :: proc "c" (edge0, edge1, x: vec4) -> vec4 { return {smoothstep(edge0.x, edge1.x, x.x), smoothstep(edge0.y, edge1.y, x.y), smoothstep(edge0.z, edge1.z, x.z), smoothstep(edge0.w, edge1.w, x.w)} }
smoothstep_dvec2 :: proc "c" (edge0, edge1, x: dvec2) -> dvec2 { return {smoothstep(edge0.x, edge1.x, x.x), smoothstep(edge0.y, edge1.y, x.y)} }
smoothstep_dvec3 :: proc "c" (edge0, edge1, x: dvec3) -> dvec3 { return {smoothstep(edge0.x, edge1.x, x.x), smoothstep(edge0.y, edge1.y, x.y), smoothstep(edge0.z, edge1.z, x.z)} }
smoothstep_dvec4 :: proc "c" (edge0, edge1, x: dvec4) -> dvec4 { return {smoothstep(edge0.x, edge1.x, x.x), smoothstep(edge0.y, edge1.y, x.y), smoothstep(edge0.z, edge1.z, x.z), smoothstep(edge0.w, edge1.w, x.w)} }
abs :: proc{
abs_i32,