diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-11-06 23:59:10 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-11-06 23:59:10 +0400 |
commit | 3e9f2938f07feb7808186834f5975f7c2c211b15 (patch) | |
tree | d8aa84852f05b64a1c76e09f29f8b6916f6beb26 /intern/cycles/kernel/osl/osl_shader.cpp | |
parent | 209cd2574588d79edc8747bc94e329f6c81a3f99 (diff) |
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
Diffstat (limited to 'intern/cycles/kernel/osl/osl_shader.cpp')
-rw-r--r-- | intern/cycles/kernel/osl/osl_shader.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/intern/cycles/kernel/osl/osl_shader.cpp b/intern/cycles/kernel/osl/osl_shader.cpp index 5d26f543efc..0c8de058b5b 100644 --- a/intern/cycles/kernel/osl/osl_shader.cpp +++ b/intern/cycles/kernel/osl/osl_shader.cpp @@ -93,6 +93,7 @@ static void shaderdata_to_shaderglobals(KernelGlobals *kg, ShaderData *sd, /* shader data to be used in services callbacks */ globals->renderstate = sd; + globals->tracedata = NULL; /* hacky, we leave it to services to fetch actual object matrix */ globals->shader2common = sd; @@ -219,6 +220,10 @@ void OSLShader::eval_surface(KernelGlobals *kg, ShaderData *sd, float randb, int if (kg->osl.surface_state[shader]) ss->execute(*ctx, *(kg->osl.surface_state[shader]), *globals); + /* free trace data */ + if(globals->tracedata) + delete (OSLRenderServices::TraceData*)globals->tracedata; + /* flatten closure tree */ sd->num_closure = 0; sd->randb_closure = randb; @@ -274,6 +279,10 @@ float3 OSLShader::eval_background(KernelGlobals *kg, ShaderData *sd, int path_fl if (kg->osl.background_state) ss->execute(*ctx, *(kg->osl.background_state), *globals); + /* free trace data */ + if(globals->tracedata) + delete (OSLRenderServices::TraceData*)globals->tracedata; + /* return background color immediately */ if (globals->Ci) return flatten_background_closure_tree(globals->Ci); @@ -352,6 +361,10 @@ void OSLShader::eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int if (kg->osl.volume_state[shader]) ss->execute(*ctx, *(kg->osl.volume_state[shader]), *globals); + /* free trace data */ + if(globals->tracedata) + delete (OSLRenderServices::TraceData*)globals->tracedata; + if (globals->Ci) flatten_volume_closure_tree(sd, globals->Ci); } @@ -375,6 +388,10 @@ void OSLShader::eval_displacement(KernelGlobals *kg, ShaderData *sd) if (kg->osl.displacement_state[shader]) ss->execute(*ctx, *(kg->osl.displacement_state[shader]), *globals); + /* free trace data */ + if(globals->tracedata) + delete (OSLRenderServices::TraceData*)globals->tracedata; + /* get back position */ sd->P = TO_FLOAT3(globals->P); } |