diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2014-03-29 16:03:46 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2014-03-29 16:03:46 +0400 |
commit | 934767cf7f51ae82224138de2ffcafe7bae2b8fa (patch) | |
tree | 2b59a0b23431be2acc84d1e20d22b964e459a087 /intern/cycles/render | |
parent | 0509553b5eb240b3970848a4432e0bbfcbba8690 (diff) |
Cycles code refactor: change curve key to float4 for easier storage as attribute.
Diffstat (limited to 'intern/cycles/render')
-rw-r--r-- | intern/cycles/render/mesh.cpp | 53 | ||||
-rw-r--r-- | intern/cycles/render/mesh.h | 9 | ||||
-rw-r--r-- | intern/cycles/render/object.cpp | 11 |
3 files changed, 53 insertions, 20 deletions
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp index 717ebb42f5c..c6ddb00e76b 100644 --- a/intern/cycles/render/mesh.cpp +++ b/intern/cycles/render/mesh.cpp @@ -18,6 +18,7 @@ #include "bvh_build.h" #include "camera.h" +#include "curves.h" #include "device.h" #include "shader.h" #include "light.h" @@ -34,6 +35,39 @@ CCL_NAMESPACE_BEGIN +/* Triangle */ + +void Mesh::Triangle::bounds_grow(const float3 *verts, BoundBox& bounds) const +{ + bounds.grow(verts[v[0]]); + bounds.grow(verts[v[1]]); + bounds.grow(verts[v[2]]); +} + +/* Curve */ + +void Mesh::Curve::bounds_grow(const int k, const float4 *curve_keys, BoundBox& bounds) const +{ + float3 P[4]; + + P[0] = float4_to_float3(curve_keys[max(first_key + k - 1,first_key)]); + P[1] = float4_to_float3(curve_keys[first_key + k]); + P[2] = float4_to_float3(curve_keys[first_key + k + 1]); + P[3] = float4_to_float3(curve_keys[min(first_key + k + 2, first_key + num_keys - 1)]); + + float3 lower; + float3 upper; + + curvebounds(&lower.x, &upper.x, P, 0); + curvebounds(&lower.y, &upper.y, P, 1); + curvebounds(&lower.z, &upper.z, P, 2); + + float mr = max(curve_keys[first_key + k].w, curve_keys[first_key + k + 1].w); + + bounds.grow(lower, mr); + bounds.grow(upper, mr); +} + /* Mesh */ Mesh::Mesh() @@ -125,9 +159,8 @@ void Mesh::add_triangle(int v0, int v1, int v2, int shader_, bool smooth_) void Mesh::add_curve_key(float3 co, float radius) { - CurveKey key; - key.co = co; - key.radius = radius; + float4 key = float3_to_float4(co); + key.w = radius; curve_keys.push_back(key); } @@ -153,7 +186,7 @@ void Mesh::compute_bounds() bnds.grow(verts[i]); for(size_t i = 0; i < curve_keys_size; i++) - bnds.grow(curve_keys[i].co, curve_keys[i].radius); + bnds.grow(float4_to_float3(curve_keys[i]), curve_keys[i].w); if(!bnds.valid()) { bnds = BoundBox::empty; @@ -163,7 +196,7 @@ void Mesh::compute_bounds() bnds.grow_safe(verts[i]); for(size_t i = 0; i < curve_keys_size; i++) - bnds.grow_safe(curve_keys[i].co, curve_keys[i].radius); + bnds.grow_safe(float4_to_float3(curve_keys[i]), curve_keys[i].w); } } @@ -337,18 +370,14 @@ void Mesh::pack_verts(float4 *tri_verts, float4 *tri_vindex, size_t vert_offset) void Mesh::pack_curves(Scene *scene, float4 *curve_key_co, float4 *curve_data, size_t curvekey_offset) { size_t curve_keys_size = curve_keys.size(); - CurveKey *keys_ptr = NULL; + float4 *keys_ptr = NULL; /* pack curve keys */ if(curve_keys_size) { keys_ptr = &curve_keys[0]; - for(size_t i = 0; i < curve_keys_size; i++) { - float3 p = keys_ptr[i].co; - float radius = keys_ptr[i].radius; - - curve_key_co[i] = make_float4(p.x, p.y, p.z, radius); - } + for(size_t i = 0; i < curve_keys_size; i++) + curve_key_co[i] = keys_ptr[i]; } /* pack curve segments */ diff --git a/intern/cycles/render/mesh.h b/intern/cycles/render/mesh.h index 9c59aca4c72..5ae8f1f6033 100644 --- a/intern/cycles/render/mesh.h +++ b/intern/cycles/render/mesh.h @@ -46,6 +46,8 @@ public: /* Mesh Triangle */ struct Triangle { int v[3]; + + void bounds_grow(const float3 *verts, BoundBox& bounds) const; }; /* Mesh Curve */ @@ -55,11 +57,8 @@ public: uint shader; int num_segments() { return num_keys - 1; } - }; - struct CurveKey { - float3 co; - float radius; + void bounds_grow(const int k, const float4 *curve_keys, BoundBox& bounds) const; }; /* Displacement */ @@ -77,7 +76,7 @@ public: vector<uint> shader; vector<bool> smooth; - vector<CurveKey> curve_keys; + vector<float4> curve_keys; /* co + radius */ vector<Curve> curves; vector<uint> used_shaders; diff --git a/intern/cycles/render/object.cpp b/intern/cycles/render/object.cpp index 0a89642fc4a..362b4762b74 100644 --- a/intern/cycles/render/object.cpp +++ b/intern/cycles/render/object.cpp @@ -86,19 +86,24 @@ void Object::apply_transform() { if(!mesh || tfm == transform_identity()) return; - + float3 c0 = transform_get_column(&tfm, 0); float3 c1 = transform_get_column(&tfm, 1); float3 c2 = transform_get_column(&tfm, 2); float scalar = pow(fabsf(dot(cross(c0, c1), c2)), 1.0f/3.0f); + /* apply to mesh vertices */ for(size_t i = 0; i < mesh->verts.size(); i++) mesh->verts[i] = transform_point(&tfm, mesh->verts[i]); + /* apply to curve keys */ for(size_t i = 0; i < mesh->curve_keys.size(); i++) { - mesh->curve_keys[i].co = transform_point(&tfm, mesh->curve_keys[i].co); + float3 co = transform_point(&tfm, float4_to_float3(mesh->curve_keys[i])); + float radius = mesh->curve_keys[i].w * scalar; + + mesh->curve_keys[i] = float3_to_float4(co); /* scale for strand radius - only correct for uniform transforms*/ - mesh->curve_keys[i].radius *= scalar; + mesh->curve_keys[i].w *= radius; } /* store matrix to transform later. when accessing these as attributes we |