diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-08-18 19:37:05 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-11-08 00:35:12 +0300 |
commit | 26f39e6359d1db85509a0ee1077b6d0af122a456 (patch) | |
tree | 1919525e00082a698f997dac61c7c8ee9b7f7451 /intern/cycles/kernel/osl/osl_services.cpp | |
parent | f79f38673145c716f9a693084b0bc4c4873e66c1 (diff) |
Cycles: add bevel shader, for raytrace based rounded edges.
The algorithm averages normals from nearby surfaces. It uses the same
sampling strategy as BSSRDFs, casting rays along the normal and two
orthogonal axes, and combining the samples with MIS.
The main concern here is that we are introducing raytracing inside
shader evaluation, which could be quite bad for GPU performance and
stack memory usage. In practice it doesn't seem so bad though.
Note that using this feature can easily slow down renders 20%, and
that if you care about performance then it's better to use a bevel
modifier. Mainly this is useful for baking, and for cases where the
mesh topology makes it difficult for the bevel modifier to work well.
Differential Revision: https://developer.blender.org/D2803
Diffstat (limited to 'intern/cycles/kernel/osl/osl_services.cpp')
-rw-r--r-- | intern/cycles/kernel/osl/osl_services.cpp | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/intern/cycles/kernel/osl/osl_services.cpp b/intern/cycles/kernel/osl/osl_services.cpp index 8ae004031e1..3789073f344 100644 --- a/intern/cycles/kernel/osl/osl_services.cpp +++ b/intern/cycles/kernel/osl/osl_services.cpp @@ -117,6 +117,7 @@ ustring OSLRenderServices::u_I("I"); ustring OSLRenderServices::u_u("u"); ustring OSLRenderServices::u_v("v"); ustring OSLRenderServices::u_empty; +ustring OSLRenderServices::u_at_bevel("@bevel"); OSLRenderServices::OSLRenderServices() { @@ -958,20 +959,36 @@ bool OSLRenderServices::texture(ustring filename, return true; } #endif - bool status; + bool status = false; if(filename.length() && filename[0] == '@') { - int slot = atoi(filename.c_str() + 1); - float4 rgba = kernel_tex_image_interp(kg, slot, s, 1.0f - t); - - result[0] = rgba[0]; - if(nchannels > 1) - result[1] = rgba[1]; - if(nchannels > 2) - result[2] = rgba[2]; - if(nchannels > 3) - result[3] = rgba[3]; - status = true; + if(filename == u_at_bevel) { + /* Bevel shader hack. */ + if(nchannels >= 3) { + PathState *state = sd->osl_path_state; + int num_samples = (int)s; + float radius = t; + float3 N = svm_bevel(kg, sd, state, radius, num_samples); + result[0] = N.x; + result[1] = N.y; + result[2] = N.z; + status = true; + } + } + else { + /* Packed texture. */ + int slot = atoi(filename.c_str() + 1); + float4 rgba = kernel_tex_image_interp(kg, slot, s, 1.0f - t); + + result[0] = rgba[0]; + if(nchannels > 1) + result[1] = rgba[1]; + if(nchannels > 2) + result[2] = rgba[2]; + if(nchannels > 3) + result[3] = rgba[3]; + status = true; + } } else { if(texture_handle != NULL) { |