diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2022-07-07 23:01:36 +0200 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2022-07-07 23:01:36 +0200 |
| commit | 928b1b0503d2ecab09cc275e9775593a41e417cb (patch) | |
| tree | 3d90f2994c504544eb62a1e1363ee8ac17cbf5f0 /shaders/include | |
| parent | 5692f616c6201b39184e4353b6a4cb850a84a450 (diff) | |
Interpolation function & no more triangle structure in shader
Diffstat (limited to 'shaders/include')
| -rw-r--r-- | shaders/include/math.h | 8 | ||||
| -rw-r--r-- | shaders/include/ray.h | 11 |
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]
);
}
|
