diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-03-05 16:54:54 +0300 |
---|---|---|
committer | Stefan Werner <stefan.werner@tangent-animation.com> | 2019-03-05 16:55:21 +0300 |
commit | db7f9a70b0addd17a2f8a8d87c0b4d77d78b536e (patch) | |
tree | 46a8b0a62f146a17a2e764159b58a6f0c66e01f6 /intern/cycles/kernel/osl | |
parent | a325bc6bf3e6dace5d1e15330650ea532052c9fc (diff) |
Cycles: Added Float2 attribute type.
Float2 are now a new type for attributes in Cycles. Before, the choices
for attribute storage were float and float3, the latter padded to
float4. This meant that UV maps were inflated to twice the size
necessary.
Reviewers: brecht, sergey
Reviewed By: brecht
Subscribers: #cycles
Tags: #cycles
Differential Revision: https://developer.blender.org/D4409
Diffstat (limited to 'intern/cycles/kernel/osl')
-rw-r--r-- | intern/cycles/kernel/osl/osl_services.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/intern/cycles/kernel/osl/osl_services.cpp b/intern/cycles/kernel/osl/osl_services.cpp index 5436a66c9d4..6464d382634 100644 --- a/intern/cycles/kernel/osl/osl_services.cpp +++ b/intern/cycles/kernel/osl/osl_services.cpp @@ -392,6 +392,44 @@ bool OSLRenderServices::get_array_attribute(OSL::ShaderGlobals *sg, bool derivat return false; } +static bool set_attribute_float2(float2 f[3], TypeDesc type, bool derivatives, void *val) +{ + if(type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || + type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor) + { + float *fval = (float *)val; + + fval[0] = f[0].x; + fval[1] = f[0].y; + fval[2] = 0.0f; + + if(derivatives) { + fval[3] = f[1].x; + fval[4] = f[1].y; + fval[5] = 0.0f; + + fval[6] = f[2].x; + fval[7] = f[2].y; + fval[8] = 0.0f; + } + + return true; + } + else if(type == TypeDesc::TypeFloat) { + float *fval = (float *)val; + fval[0] = average(f[0]); + + if(derivatives) { + fval[1] = average(f[1]); + fval[2] = average(f[2]); + } + + return true; + } + + return false; +} + static bool set_attribute_float3(float3 f[3], TypeDesc type, bool derivatives, void *val) { if(type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || @@ -572,6 +610,12 @@ static bool get_primitive_attribute(KernelGlobals *kg, const ShaderData *sd, con (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL); return set_attribute_float3(fval, type, derivatives, val); } + else if(attr.type == TypeFloat2) { + float2 fval[2]; + fval[0] = primitive_attribute_float2(kg, sd, attr.desc, + (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL); + return set_attribute_float2(fval, type, derivatives, val); + } else if(attr.type == TypeDesc::TypeFloat) { float fval[3]; fval[0] = primitive_attribute_float(kg, sd, attr.desc, |