diff options
Diffstat (limited to 'intern/cycles/kernel/osl')
-rw-r--r-- | intern/cycles/kernel/osl/osl_services.cpp | 137 |
1 files changed, 121 insertions, 16 deletions
diff --git a/intern/cycles/kernel/osl/osl_services.cpp b/intern/cycles/kernel/osl/osl_services.cpp index 7d1d1ae20c1..2a4a1dfe325 100644 --- a/intern/cycles/kernel/osl/osl_services.cpp +++ b/intern/cycles/kernel/osl/osl_services.cpp @@ -403,8 +403,28 @@ bool OSLRenderServices::get_array_attribute(OSL::ShaderGlobals *sg, 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) { + if (type == TypeFloatArray4) { + float *fval = (float *)val; + fval[0] = f[0].x; + fval[1] = f[0].y; + fval[2] = 0.0f; + fval[3] = 1.0f; + + if (derivatives) { + fval[4] = f[1].x; + fval[5] = f[1].y; + fval[6] = 0.0f; + fval[7] = 0.0f; + + fval[8] = f[2].x; + fval[9] = f[2].y; + fval[10] = 0.0f; + fval[11] = 0.0f; + } + return true; + } + else if (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || + type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor) { float *fval = (float *)val; fval[0] = f[0].x; @@ -438,10 +458,41 @@ static bool set_attribute_float2(float2 f[3], TypeDesc type, bool derivatives, v return false; } +static bool set_attribute_float2(float2 f, TypeDesc type, bool derivatives, void *val) +{ + float2 fv[3]; + + fv[0] = f; + fv[1] = make_float2(0.0f, 0.0f); + fv[2] = make_float2(0.0f, 0.0f); + + return set_attribute_float2(fv, type, derivatives, val); +} + static bool set_attribute_float3(float3 f[3], TypeDesc type, bool derivatives, void *val) { - if (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || - type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor) { + if (type == TypeFloatArray4) { + float *fval = (float *)val; + fval[0] = f[0].x; + fval[1] = f[0].y; + fval[2] = f[0].z; + fval[3] = 1.0f; + + if (derivatives) { + fval[4] = f[1].x; + fval[5] = f[1].y; + fval[6] = f[1].z; + fval[7] = 0.0f; + + fval[8] = f[2].x; + fval[9] = f[2].y; + fval[10] = f[2].z; + fval[11] = 0.0f; + } + return true; + } + else if (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || + type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor) { float *fval = (float *)val; fval[0] = f[0].x; @@ -545,14 +596,45 @@ static bool set_attribute_float4(float4 f[3], TypeDesc type, bool derivatives, v return false; } +static bool set_attribute_float4(float4 f, TypeDesc type, bool derivatives, void *val) +{ + float4 fv[3]; + + fv[0] = f; + fv[1] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + fv[2] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + + return set_attribute_float4(fv, type, derivatives, val); +} + static bool set_attribute_float(float f[3], TypeDesc type, bool derivatives, void *val) { - if (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || - type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor) { + if (type == TypeFloatArray4) { float *fval = (float *)val; fval[0] = f[0]; - fval[1] = f[1]; - fval[2] = f[2]; + fval[1] = f[0]; + fval[2] = f[0]; + fval[3] = 1.0f; + + if (derivatives) { + fval[4] = f[1]; + fval[5] = f[1]; + fval[6] = f[1]; + fval[7] = 0.0f; + + fval[8] = f[2]; + fval[9] = f[2]; + fval[10] = f[2]; + fval[11] = 0.0f; + } + return true; + } + else if (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || + type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor) { + float *fval = (float *)val; + fval[0] = f[0]; + fval[1] = f[0]; + fval[2] = f[0]; if (derivatives) { fval[3] = f[1]; @@ -709,7 +791,7 @@ static bool get_primitive_attribute(KernelGlobals *kg, } return set_attribute_float(fval, type, derivatives, val); } - else if (attr.type == TypeRGBA) { + else if (attr.type == TypeDesc::TypeFloat4 || attr.type == TypeRGBA) { float4 fval[3]; if (primitive_is_volume_attribute(sd, attr.desc)) { memset(fval, 0, sizeof(fval)); @@ -742,13 +824,37 @@ static bool get_mesh_attribute(KernelGlobals *kg, } } -static void get_object_attribute(const OSLGlobals::Attribute &attr, bool derivatives, void *val) +static bool get_object_attribute(const OSLGlobals::Attribute &attr, + TypeDesc type, + bool derivatives, + void *val) { - size_t datasize = attr.value.datasize(); + if (attr.type == TypeDesc::TypePoint || attr.type == TypeDesc::TypeVector || + attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor) { + return set_attribute_float3(*(float3 *)attr.value.data(), type, derivatives, val); + } + else if (attr.type == TypeFloat2) { + return set_attribute_float2(*(float2 *)attr.value.data(), type, derivatives, val); + } + else if (attr.type == TypeDesc::TypeFloat) { + return set_attribute_float(*(float *)attr.value.data(), type, derivatives, val); + } + else if (attr.type == TypeRGBA || attr.type == TypeDesc::TypeFloat4) { + return set_attribute_float4(*(float4 *)attr.value.data(), type, derivatives, val); + } + else if (attr.type == type) { + size_t datasize = attr.value.datasize(); - memcpy(val, attr.value.data(), datasize); - if (derivatives) - memset((char *)val + datasize, 0, datasize * 2); + memcpy(val, attr.value.data(), datasize); + if (derivatives) { + memset((char *)val + datasize, 0, datasize * 2); + } + + return true; + } + else { + return false; + } } bool OSLRenderServices::get_object_standard_attribute( @@ -1011,8 +1117,7 @@ bool OSLRenderServices::get_attribute( } else { /* object attribute */ - get_object_attribute(attr, derivatives, val); - return true; + return get_object_attribute(attr, type, derivatives, val); } } else { |