From db7f9a70b0addd17a2f8a8d87c0b4d77d78b536e Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 5 Mar 2019 14:54:54 +0100 Subject: 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 --- intern/cycles/kernel/osl/osl_services.cpp | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'intern/cycles/kernel/osl') 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, -- cgit v1.2.3