aboutsummaryrefslogtreecommitdiffstats
path: root/shaders/include
diff options
context:
space:
mode:
Diffstat (limited to 'shaders/include')
-rw-r--r--shaders/include/math.h8
-rw-r--r--shaders/include/ray.h11
2 files changed, 11 insertions, 8 deletions
diff --git a/shaders/include/math.h b/shaders/include/math.h
index cc4e2f4..c95b065 100644
--- a/shaders/include/math.h
+++ b/shaders/include/math.h
@@ -43,3 +43,11 @@ vec3 rotate_point(vec4 q, vec3 v) {
const vec3 q_axis = q.xyz;
return 2.0f * dot(q_axis, v) * q_axis + (q.w * q.w - dot(q_axis, q_axis)) * v + 2.0f * q.w * cross(q_axis, v);
}
+
+vec3 interpolate_attribute(vec3 values[3], vec3 weights) {
+ return values[0] * weights.x + values[1] * weights.y + values[2] * weights.z;
+}
+
+vec2 interpolate_attribute(vec2 values[3], vec3 weights) {
+ return values[0] * weights.x + values[1] * weights.y + values[2] * weights.z;
+}
diff --git a/shaders/include/ray.h b/shaders/include/ray.h
index 3732c42..221202f 100644
--- a/shaders/include/ray.h
+++ b/shaders/include/ray.h
@@ -55,15 +55,10 @@ vec2[3] get_triangle_uvs(uvec3 indices) {
triangle get_triangle(uint triangle_id) {
uvec4 indices = decode_triangle_indices(triangle_id);
- vec3 positions[3] = get_triangle_positions(indices.xyz);
- vec3 normals[3] = get_triangle_normals(indices.xyz);
- vec2 uvs[3] = get_triangle_uvs(indices.xyz);
-
- vertex v1 = vertex(positions[0], normals[0], uvs[0]);
- vertex v2 = vertex(positions[1], normals[1], uvs[1]);
- vertex v3 = vertex(positions[2], normals[2], uvs[2]);
return triangle(
- v1, v2, v3,
+ get_triangle_positions(indices.xyz),
+ get_triangle_normals(indices.xyz),
+ get_triangle_uvs(indices.xyz),
bufs.materials_arr.materials[indices.w]
);
}