diff options
Diffstat (limited to 'intern/cycles/kernel/osl')
5 files changed, 89 insertions, 66 deletions
diff --git a/intern/cycles/kernel/osl/services_gpu.h b/intern/cycles/kernel/osl/services_gpu.h index e6e19b8c484..75cf39919a0 100644 --- a/intern/cycles/kernel/osl/services_gpu.h +++ b/intern/cycles/kernel/osl/services_gpu.h @@ -15,6 +15,14 @@ namespace DeviceStrings { /* "" */ ccl_device_constant DeviceString _emptystring_ = {0ull}; +/* "common" */ +ccl_device_constant DeviceString u_common = {14645198576927606093ull}; +/* "world" */ +ccl_device_constant DeviceString u_world = {16436542438370751598ull}; +/* "shader" */ +ccl_device_constant DeviceString u_shader = {4279676006089868ull}; +/* "object" */ +ccl_device_constant DeviceString u_object = {973692718279674627ull}; /* "NDC" */ ccl_device_constant DeviceString u_ndc = {5148305047403260775ull}; /* "screen" */ @@ -23,10 +31,6 @@ ccl_device_constant DeviceString u_screen = {14159088609039777114ull}; ccl_device_constant DeviceString u_camera = {2159505832145726196ull}; /* "raster" */ ccl_device_constant DeviceString u_raster = {7759263238610201778ull}; -/* "world" */ -ccl_device_constant DeviceString u_world = {16436542438370751598ull}; -/* "common" */ -ccl_device_constant DeviceString u_common = {14645198576927606093ull}; /* "hsv" */ ccl_device_constant DeviceString u_hsv = {2177035556331879497ull}; /* "hsl" */ @@ -419,10 +423,13 @@ ccl_device_extern bool osl_transformc(ccl_private ShaderGlobals *sg, c_out[i] = rgb; } } + + return true; } /* Matrix Utilities */ +#include "kernel/geom/object.h" #include "util/transform.h" ccl_device_forceinline void copy_matrix(ccl_private float *res, const Transform &tfm) @@ -463,24 +470,24 @@ ccl_device_forceinline void copy_matrix(ccl_private float *res, const Projection res[14] = tfm.z.w; res[15] = tfm.w.w; } -ccl_device_forceinline void copy_identity_matrix(ccl_private float *res) +ccl_device_forceinline void copy_identity_matrix(ccl_private float *res, float value = 1.0f) { - res[0] = 1.0f; + res[0] = value; res[1] = 0.0f; res[2] = 0.0f; res[3] = 0.0f; res[4] = 0.0f; - res[5] = 1.0f; + res[5] = value; res[6] = 0.0f; res[7] = 0.0f; res[8] = 0.0f; res[9] = 0.0f; - res[10] = 1.0f; + res[10] = value; res[11] = 0.0f; res[12] = 0.0f; res[13] = 0.0f; res[14] = 0.0f; - res[15] = 1.0f; + res[15] = value; } ccl_device_forceinline Transform convert_transform(ccl_private const float *m) { @@ -532,22 +539,7 @@ ccl_device_extern void osl_div_mfm(ccl_private float *res, float a, ccl_private ccl_device_extern void osl_div_m_ff(ccl_private float *res, float a, float b) { float f = (b == 0) ? 0.0f : (a / b); - res[0] = f; - res[1] = 0.0f; - res[2] = 0.0f; - res[3] = 0.0f; - res[4] = 0.0f; - res[5] = f; - res[6] = 0.0f; - res[7] = 0.0f; - res[8] = 0.0f; - res[9] = 0.0f; - res[10] = f; - res[11] = 0.0f; - res[12] = 0.0f; - res[13] = 0.0f; - res[14] = 0.0f; - res[15] = f; + copy_identity_matrix(res, f); } ccl_device_extern void osl_transform_vmv(ccl_private float3 *res, @@ -605,27 +597,43 @@ ccl_device_extern void osl_transformn_dvmdv(ccl_private float3 *res, } ccl_device_extern bool osl_get_matrix(ccl_private ShaderGlobals *sg, - ccl_private float *result, + ccl_private float *res, DeviceString from) { - if (from == DeviceStrings::u_ndc) { - copy_matrix(result, kernel_data.cam.ndctoworld); + if (from == DeviceStrings::u_common || from == DeviceStrings::u_world) { + copy_identity_matrix(res); return true; } - if (from == DeviceStrings::u_raster) { - copy_matrix(result, kernel_data.cam.rastertoworld); + if (from == DeviceStrings::u_shader || from == DeviceStrings::u_object) { + KernelGlobals kg = nullptr; + ccl_private ShaderData *const sd = static_cast<ccl_private ShaderData *>(sg->renderstate); + int object = sd->object; + + if (object != OBJECT_NONE) { + const Transform tfm = object_get_transform(kg, sd); + copy_matrix(res, tfm); + return true; + } + else if (sd->type == PRIMITIVE_LAMP) { + const Transform tfm = lamp_fetch_transform(kg, sd->lamp, false); + copy_matrix(res, tfm); + return true; + } + } + else if (from == DeviceStrings::u_ndc) { + copy_matrix(res, kernel_data.cam.ndctoworld); return true; } - if (from == DeviceStrings::u_screen) { - copy_matrix(result, kernel_data.cam.screentoworld); + else if (from == DeviceStrings::u_raster) { + copy_matrix(res, kernel_data.cam.rastertoworld); return true; } - if (from == DeviceStrings::u_camera) { - copy_matrix(result, kernel_data.cam.cameratoworld); + else if (from == DeviceStrings::u_screen) { + copy_matrix(res, kernel_data.cam.screentoworld); return true; } - if (from == DeviceStrings::u_world) { - copy_identity_matrix(result); + else if (from == DeviceStrings::u_camera) { + copy_matrix(res, kernel_data.cam.cameratoworld); return true; } @@ -636,24 +644,53 @@ ccl_device_extern bool osl_get_inverse_matrix(ccl_private ShaderGlobals *sg, ccl_private float *res, DeviceString to) { - if (to == DeviceStrings::u_ndc) { + if (to == DeviceStrings::u_common || to == DeviceStrings::u_world) { + copy_identity_matrix(res); + return true; + } + if (to == DeviceStrings::u_shader || to == DeviceStrings::u_object) { + KernelGlobals kg = nullptr; + ccl_private ShaderData *const sd = static_cast<ccl_private ShaderData *>(sg->renderstate); + int object = sd->object; + + if (object != OBJECT_NONE) { + const Transform itfm = object_get_inverse_transform(kg, sd); + copy_matrix(res, itfm); + return true; + } + else if (sd->type == PRIMITIVE_LAMP) { + const Transform itfm = lamp_fetch_transform(kg, sd->lamp, true); + copy_matrix(res, itfm); + return true; + } + } + else if (to == DeviceStrings::u_ndc) { copy_matrix(res, kernel_data.cam.worldtondc); return true; } - if (to == DeviceStrings::u_raster) { + else if (to == DeviceStrings::u_raster) { copy_matrix(res, kernel_data.cam.worldtoraster); return true; } - if (to == DeviceStrings::u_screen) { + else if (to == DeviceStrings::u_screen) { copy_matrix(res, kernel_data.cam.worldtoscreen); return true; } - if (to == DeviceStrings::u_camera) { + else if (to == DeviceStrings::u_camera) { copy_matrix(res, kernel_data.cam.worldtocamera); return true; } - if (to == DeviceStrings::u_world) { - copy_identity_matrix(res); + + return false; +} + +ccl_device_extern bool osl_prepend_matrix_from(ccl_private ShaderGlobals *sg, + ccl_private float *res, + DeviceString from) +{ + float m_from[16]; + if (osl_get_matrix(sg, m_from, from)) { + osl_mul_mmm(res, m_from, res); return true; } @@ -674,16 +711,6 @@ ccl_device_extern bool osl_get_from_to_matrix(ccl_private ShaderGlobals *sg, return false; } -ccl_device_extern void osl_prepend_matrix_from(ccl_private ShaderGlobals *sg, - ccl_private float *res, - DeviceString from) -{ - float m[16]; - if (osl_get_matrix(sg, m, from)) { - osl_mul_mmm(res, m, res); - } -} - ccl_device_extern bool osl_transform_triple(ccl_private ShaderGlobals *sg, ccl_private float3 *p_in, int p_in_derivs, diff --git a/intern/cycles/kernel/osl/shaders/node_geometry.osl b/intern/cycles/kernel/osl/shaders/node_geometry.osl index cc891abd6e3..5d9284deac2 100644 --- a/intern/cycles/kernel/osl/shaders/node_geometry.osl +++ b/intern/cycles/kernel/osl/shaders/node_geometry.osl @@ -3,8 +3,7 @@ #include "stdcycles.h" -shader node_geometry(normal NormalIn = N, - string bump_offset = "center", +shader node_geometry(string bump_offset = "center", output point Position = point(0.0, 0.0, 0.0), output normal Normal = normal(0.0, 0.0, 0.0), @@ -17,7 +16,7 @@ shader node_geometry(normal NormalIn = N, output float RandomPerIsland = 0.0) { Position = P; - Normal = NormalIn; + Normal = N; TrueNormal = Ng; Incoming = I; Parametric = point(1.0 - u - v, u, 0.0); diff --git a/intern/cycles/kernel/osl/shaders/node_normal_map.osl b/intern/cycles/kernel/osl/shaders/node_normal_map.osl index 3cda485c686..7e41bbf1720 100644 --- a/intern/cycles/kernel/osl/shaders/node_normal_map.osl +++ b/intern/cycles/kernel/osl/shaders/node_normal_map.osl @@ -3,13 +3,12 @@ #include "stdcycles.h" -shader node_normal_map(normal NormalIn = N, - float Strength = 1.0, +shader node_normal_map(float Strength = 1.0, color Color = color(0.5, 0.5, 1.0), string space = "tangent", string attr_name = "geom:tangent", string attr_sign_name = "geom:tangent_sign", - output normal Normal = NormalIn) + output normal Normal = N) { color mcolor = 2.0 * color(Color[0] - 0.5, Color[1] - 0.5, Color[2] - 0.5); int is_backfacing = backfacing(); @@ -71,5 +70,5 @@ shader node_normal_map(normal NormalIn = N, } if (Strength != 1.0) - Normal = normalize(NormalIn + (Normal - NormalIn) * max(Strength, 0.0)); + Normal = normalize(N + (Normal - N) * max(Strength, 0.0)); } diff --git a/intern/cycles/kernel/osl/shaders/node_tangent.osl b/intern/cycles/kernel/osl/shaders/node_tangent.osl index a302c001f08..b3808778b2f 100644 --- a/intern/cycles/kernel/osl/shaders/node_tangent.osl +++ b/intern/cycles/kernel/osl/shaders/node_tangent.osl @@ -3,8 +3,7 @@ #include "stdcycles.h" -shader node_tangent(normal NormalIn = N, - string attr_name = "geom:tangent", +shader node_tangent(string attr_name = "geom:tangent", string direction_type = "radial", string axis = "z", output normal Tangent = normalize(dPdu)) @@ -29,5 +28,5 @@ shader node_tangent(normal NormalIn = N, } T = transform("object", "world", T); - Tangent = cross(NormalIn, normalize(cross(T, NormalIn))); + Tangent = cross(N, normalize(cross(T, N))); } diff --git a/intern/cycles/kernel/osl/shaders/node_texture_coordinate.osl b/intern/cycles/kernel/osl/shaders/node_texture_coordinate.osl index 24875ce140a..cd2fdae3cb3 100644 --- a/intern/cycles/kernel/osl/shaders/node_texture_coordinate.osl +++ b/intern/cycles/kernel/osl/shaders/node_texture_coordinate.osl @@ -4,7 +4,6 @@ #include "stdcycles.h" shader node_texture_coordinate( - normal NormalIn = N, int is_background = 0, int is_volume = 0, int from_dupli = 0, @@ -27,7 +26,7 @@ shader node_texture_coordinate( point Pcam = transform("camera", "world", point(0, 0, 0)); Camera = transform("camera", P + Pcam); getattribute("NDC", Window); - Normal = NormalIn; + Normal = N; Reflection = I; } else { @@ -59,8 +58,8 @@ shader node_texture_coordinate( } Camera = transform("camera", P); Window = transform("NDC", P); - Normal = transform("world", "object", NormalIn); - Reflection = -reflect(I, NormalIn); + Normal = transform("world", "object", N); + Reflection = -reflect(I, N); } if (bump_offset == "dx") { |