2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 02:50:24 +01:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
2014-10-06 13:39:19 +06:00
|
|
|
#include <OSL/oslexec.h>
|
|
|
|
|
2020-03-06 14:15:21 +01:00
|
|
|
// clang-format off
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
#include "kernel/device/cpu/compat.h"
|
|
|
|
#include "kernel/device/cpu/globals.h"
|
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "kernel/types.h"
|
2014-03-29 13:03:45 +01:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "kernel/geom/object.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "kernel/integrator/state.h"
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "kernel/osl/closures.h"
|
|
|
|
#include "kernel/osl/globals.h"
|
|
|
|
#include "kernel/osl/services.h"
|
|
|
|
#include "kernel/osl/shader.h"
|
2020-03-06 14:15:21 +01:00
|
|
|
// clang-format on
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/attribute.h"
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Threads */
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
void OSLShader::thread_init(KernelGlobalsCPU *kg, OSLGlobals *osl_globals)
|
2012-11-09 03:10:22 +00:00
|
|
|
{
|
2012-12-01 19:15:05 +00:00
|
|
|
/* no osl used? */
|
|
|
|
if (!osl_globals->use) {
|
|
|
|
kg->osl = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2012-11-09 03:10:22 +00:00
|
|
|
|
2021-06-26 21:35:18 +10:00
|
|
|
/* Per thread kernel data init. */
|
2012-12-01 19:15:05 +00:00
|
|
|
kg->osl = osl_globals;
|
2012-11-09 03:10:22 +00:00
|
|
|
|
2012-12-01 19:15:05 +00:00
|
|
|
OSL::ShadingSystem *ss = kg->osl->ss;
|
|
|
|
OSLThreadData *tdata = new OSLThreadData();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2018-06-11 12:54:17 +02:00
|
|
|
memset((void *)&tdata->globals, 0, sizeof(OSL::ShaderGlobals));
|
2012-12-15 10:18:42 +00:00
|
|
|
tdata->globals.tracedata = &tdata->tracedata;
|
|
|
|
tdata->globals.flipHandedness = false;
|
2013-08-05 12:49:15 +00:00
|
|
|
tdata->osl_thread_info = ss->create_thread_info();
|
2017-08-22 15:00:52 +02:00
|
|
|
tdata->context = ss->get_context(tdata->osl_thread_info);
|
2013-08-05 12:49:15 +00:00
|
|
|
|
|
|
|
tdata->oiio_thread_info = osl_globals->ts->get_perthread_info();
|
2012-12-15 10:18:42 +00:00
|
|
|
|
2012-12-01 19:15:05 +00:00
|
|
|
kg->osl_ss = (OSLShadingSystem *)ss;
|
|
|
|
kg->osl_tdata = tdata;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
void OSLShader::thread_free(KernelGlobalsCPU *kg)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-12-01 19:15:05 +00:00
|
|
|
if (!kg->osl)
|
|
|
|
return;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-12-01 19:15:05 +00:00
|
|
|
OSL::ShadingSystem *ss = (OSL::ShadingSystem *)kg->osl_ss;
|
|
|
|
OSLThreadData *tdata = kg->osl_tdata;
|
2017-08-22 15:00:52 +02:00
|
|
|
ss->release_context(tdata->context);
|
2012-12-15 10:18:42 +00:00
|
|
|
|
2013-08-05 12:49:15 +00:00
|
|
|
ss->destroy_thread_info(tdata->osl_thread_info);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
delete tdata;
|
2012-12-01 19:15:05 +00:00
|
|
|
|
|
|
|
kg->osl = NULL;
|
|
|
|
kg->osl_ss = NULL;
|
|
|
|
kg->osl_tdata = NULL;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Globals */
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
static void shaderdata_to_shaderglobals(const KernelGlobalsCPU *kg,
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
ShaderData *sd,
|
2021-10-17 16:22:20 +02:00
|
|
|
const void *state,
|
2021-10-17 20:09:45 +02:00
|
|
|
uint32_t path_flag,
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
OSLThreadData *tdata)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-12-15 10:18:42 +00:00
|
|
|
OSL::ShaderGlobals *globals = &tdata->globals;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* copy from shader data to shader globals */
|
|
|
|
globals->P = TO_VEC3(sd->P);
|
|
|
|
globals->dPdx = TO_VEC3(sd->dP.dx);
|
|
|
|
globals->dPdy = TO_VEC3(sd->dP.dy);
|
|
|
|
globals->I = TO_VEC3(sd->I);
|
|
|
|
globals->dIdx = TO_VEC3(sd->dI.dx);
|
|
|
|
globals->dIdy = TO_VEC3(sd->dI.dy);
|
|
|
|
globals->N = TO_VEC3(sd->N);
|
|
|
|
globals->Ng = TO_VEC3(sd->Ng);
|
|
|
|
globals->u = sd->u;
|
|
|
|
globals->dudx = sd->du.dx;
|
|
|
|
globals->dudy = sd->du.dy;
|
|
|
|
globals->v = sd->v;
|
|
|
|
globals->dvdx = sd->dv.dx;
|
|
|
|
globals->dvdy = sd->dv.dy;
|
|
|
|
globals->dPdu = TO_VEC3(sd->dPdu);
|
|
|
|
globals->dPdv = TO_VEC3(sd->dPdv);
|
2020-12-24 13:45:04 +01:00
|
|
|
globals->surfacearea = 1.0f;
|
2012-11-29 16:11:37 +00:00
|
|
|
globals->time = sd->time;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* booleans */
|
2012-12-15 10:18:42 +00:00
|
|
|
globals->raytype = path_flag;
|
2011-04-27 11:58:34 +00:00
|
|
|
globals->backfacing = (sd->flag & SD_BACKFACING);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* shader data to be used in services callbacks */
|
2018-07-06 10:17:58 +02:00
|
|
|
globals->renderstate = sd;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* hacky, we leave it to services to fetch actual object matrix */
|
|
|
|
globals->shader2common = sd;
|
|
|
|
globals->object2common = sd;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* must be set to NULL before execute */
|
|
|
|
globals->Ci = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-15 10:18:42 +00:00
|
|
|
/* clear trace data */
|
|
|
|
tdata->tracedata.init = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-05 16:23:34 +11:00
|
|
|
/* Used by render-services. */
|
2019-05-14 12:13:43 +02:00
|
|
|
sd->osl_globals = kg;
|
2021-10-17 16:22:20 +02:00
|
|
|
if (path_flag & PATH_RAY_SHADOW) {
|
2021-11-09 14:56:22 +01:00
|
|
|
sd->osl_path_state = nullptr;
|
2021-10-17 16:22:20 +02:00
|
|
|
sd->osl_shadow_path_state = (const IntegratorShadowStateCPU *)state;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sd->osl_path_state = (const IntegratorStateCPU *)state;
|
2021-11-09 14:56:22 +01:00
|
|
|
sd->osl_shadow_path_state = nullptr;
|
2021-10-17 16:22:20 +02:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Surface */
|
|
|
|
|
2019-05-14 12:13:43 +02:00
|
|
|
static void flatten_surface_closure_tree(ShaderData *sd,
|
2021-10-17 20:09:45 +02:00
|
|
|
uint32_t path_flag,
|
2016-07-25 03:03:23 +02:00
|
|
|
const OSL::ClosureColor *closure,
|
|
|
|
float3 weight = make_float3(1.0f, 1.0f, 1.0f))
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-06-05 09:29:47 +00:00
|
|
|
/* OSL gives us a closure tree, we flatten it into arrays per
|
2011-04-27 11:58:34 +00:00
|
|
|
* closure type, for evaluation, sampling, etc later on. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-09-23 12:23:37 +05:00
|
|
|
switch (closure->id) {
|
|
|
|
case OSL::ClosureColor::MUL: {
|
|
|
|
OSL::ClosureMul *mul = (OSL::ClosureMul *)closure;
|
2019-05-14 12:13:43 +02:00
|
|
|
flatten_surface_closure_tree(sd, path_flag, mul->closure, TO_FLOAT3(mul->weight) * weight);
|
2015-09-23 12:23:37 +05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OSL::ClosureColor::ADD: {
|
|
|
|
OSL::ClosureAdd *add = (OSL::ClosureAdd *)closure;
|
2019-05-14 12:13:43 +02:00
|
|
|
flatten_surface_closure_tree(sd, path_flag, add->closureA, weight);
|
|
|
|
flatten_surface_closure_tree(sd, path_flag, add->closureB, weight);
|
2015-09-23 12:23:37 +05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
OSL::ClosureComponent *comp = (OSL::ClosureComponent *)closure;
|
|
|
|
CClosurePrimitive *prim = (CClosurePrimitive *)comp->data();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-09-23 12:23:37 +05:00
|
|
|
if (prim) {
|
2013-09-09 21:52:26 +00:00
|
|
|
#ifdef OSL_SUPPORTS_WEIGHTED_CLOSURE_COMPONENTS
|
2015-09-23 12:23:37 +05:00
|
|
|
weight = weight * TO_FLOAT3(comp->w);
|
2013-09-09 21:52:26 +00:00
|
|
|
#endif
|
2019-05-14 12:13:43 +02:00
|
|
|
prim->setup(sd, path_flag, weight);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2015-09-23 12:23:37 +05:00
|
|
|
break;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
void OSLShader::eval_surface(const KernelGlobalsCPU *kg,
|
2021-10-17 16:22:20 +02:00
|
|
|
const void *state,
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
ShaderData *sd,
|
2021-10-17 20:09:45 +02:00
|
|
|
uint32_t path_flag)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* setup shader globals from shader data */
|
2012-12-15 10:18:42 +00:00
|
|
|
OSLThreadData *tdata = kg->osl_tdata;
|
2016-01-06 23:38:13 +01:00
|
|
|
shaderdata_to_shaderglobals(kg, sd, state, path_flag, tdata);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* execute shader for this point */
|
2012-12-15 10:18:42 +00:00
|
|
|
OSL::ShadingSystem *ss = (OSL::ShadingSystem *)kg->osl_ss;
|
|
|
|
OSL::ShaderGlobals *globals = &tdata->globals;
|
2017-08-22 15:00:52 +02:00
|
|
|
OSL::ShadingContext *octx = tdata->context;
|
2011-09-27 20:37:24 +00:00
|
|
|
int shader = sd->shader & SHADER_MASK;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-14 11:44:25 -04:00
|
|
|
/* automatic bump shader */
|
|
|
|
if (kg->osl->bump_state[shader]) {
|
|
|
|
/* save state */
|
|
|
|
float3 P = sd->P;
|
|
|
|
float3 dPdx = sd->dP.dx;
|
|
|
|
float3 dPdy = sd->dP.dy;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-14 11:44:25 -04:00
|
|
|
/* set state as if undisplaced */
|
|
|
|
if (sd->flag & SD_HAS_DISPLACEMENT) {
|
|
|
|
float data[9];
|
|
|
|
bool found = kg->osl->services->get_attribute(sd,
|
|
|
|
true,
|
|
|
|
OSLRenderServices::u_empty,
|
|
|
|
TypeDesc::TypeVector,
|
|
|
|
OSLRenderServices::u_geom_undisplaced,
|
|
|
|
data);
|
2018-11-09 12:08:51 +01:00
|
|
|
(void)found;
|
2016-08-14 11:44:25 -04:00
|
|
|
assert(found);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-14 11:44:25 -04:00
|
|
|
memcpy(&sd->P, data, sizeof(float) * 3);
|
|
|
|
memcpy(&sd->dP.dx, data + 3, sizeof(float) * 3);
|
|
|
|
memcpy(&sd->dP.dy, data + 6, sizeof(float) * 3);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-14 11:44:25 -04:00
|
|
|
object_position_transform(kg, sd, &sd->P);
|
|
|
|
object_dir_transform(kg, sd, &sd->dP.dx);
|
|
|
|
object_dir_transform(kg, sd, &sd->dP.dy);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-14 11:44:25 -04:00
|
|
|
globals->P = TO_VEC3(sd->P);
|
|
|
|
globals->dPdx = TO_VEC3(sd->dP.dx);
|
|
|
|
globals->dPdy = TO_VEC3(sd->dP.dy);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-14 11:44:25 -04:00
|
|
|
/* execute bump shader */
|
|
|
|
ss->execute(octx, *(kg->osl->bump_state[shader]), *globals);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-14 11:44:25 -04:00
|
|
|
/* reset state */
|
|
|
|
sd->P = P;
|
|
|
|
sd->dP.dx = dPdx;
|
|
|
|
sd->dP.dy = dPdy;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-14 11:44:25 -04:00
|
|
|
globals->P = TO_VEC3(P);
|
|
|
|
globals->dPdx = TO_VEC3(dPdx);
|
|
|
|
globals->dPdy = TO_VEC3(dPdy);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-14 11:44:25 -04:00
|
|
|
/* surface shader */
|
2016-01-07 14:04:12 +05:00
|
|
|
if (kg->osl->surface_state[shader]) {
|
|
|
|
ss->execute(octx, *(kg->osl->surface_state[shader]), *globals);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* flatten closure tree */
|
2015-03-28 00:15:15 +05:00
|
|
|
if (globals->Ci)
|
2019-05-14 12:13:43 +02:00
|
|
|
flatten_surface_closure_tree(sd, path_flag, globals->Ci);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Background */
|
|
|
|
|
2019-05-14 12:13:43 +02:00
|
|
|
static void flatten_background_closure_tree(ShaderData *sd,
|
2016-07-25 03:03:23 +02:00
|
|
|
const OSL::ClosureColor *closure,
|
|
|
|
float3 weight = make_float3(1.0f, 1.0f, 1.0f))
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-06-05 09:29:47 +00:00
|
|
|
/* OSL gives us a closure tree, if we are shading for background there
|
2011-04-27 11:58:34 +00:00
|
|
|
* is only one supported closure type at the moment, which has no evaluation
|
|
|
|
* functions, so we just sum the weights */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-09-23 12:23:37 +05:00
|
|
|
switch (closure->id) {
|
|
|
|
case OSL::ClosureColor::MUL: {
|
|
|
|
OSL::ClosureMul *mul = (OSL::ClosureMul *)closure;
|
2019-05-14 12:13:43 +02:00
|
|
|
flatten_background_closure_tree(sd, mul->closure, weight * TO_FLOAT3(mul->weight));
|
2016-07-25 03:03:23 +02:00
|
|
|
break;
|
2015-09-23 12:23:37 +05:00
|
|
|
}
|
|
|
|
case OSL::ClosureColor::ADD: {
|
|
|
|
OSL::ClosureAdd *add = (OSL::ClosureAdd *)closure;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-14 12:13:43 +02:00
|
|
|
flatten_background_closure_tree(sd, add->closureA, weight);
|
|
|
|
flatten_background_closure_tree(sd, add->closureB, weight);
|
2016-07-25 03:03:23 +02:00
|
|
|
break;
|
2015-09-23 12:23:37 +05:00
|
|
|
}
|
|
|
|
default: {
|
|
|
|
OSL::ClosureComponent *comp = (OSL::ClosureComponent *)closure;
|
|
|
|
CClosurePrimitive *prim = (CClosurePrimitive *)comp->data();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
if (prim) {
|
2015-09-23 12:23:37 +05:00
|
|
|
#ifdef OSL_SUPPORTS_WEIGHTED_CLOSURE_COMPONENTS
|
2016-07-25 03:03:23 +02:00
|
|
|
weight = weight * TO_FLOAT3(comp->w);
|
2015-09-23 12:23:37 +05:00
|
|
|
#endif
|
2019-05-14 12:13:43 +02:00
|
|
|
prim->setup(sd, 0, weight);
|
2016-07-25 03:03:23 +02:00
|
|
|
}
|
|
|
|
break;
|
2015-09-23 12:23:37 +05:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
void OSLShader::eval_background(const KernelGlobalsCPU *kg,
|
2021-10-17 16:22:20 +02:00
|
|
|
const void *state,
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
ShaderData *sd,
|
2021-10-17 20:09:45 +02:00
|
|
|
uint32_t path_flag)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* setup shader globals from shader data */
|
2012-12-15 10:18:42 +00:00
|
|
|
OSLThreadData *tdata = kg->osl_tdata;
|
2016-01-06 23:38:13 +01:00
|
|
|
shaderdata_to_shaderglobals(kg, sd, state, path_flag, tdata);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* execute shader for this point */
|
2012-12-15 10:18:42 +00:00
|
|
|
OSL::ShadingSystem *ss = (OSL::ShadingSystem *)kg->osl_ss;
|
|
|
|
OSL::ShaderGlobals *globals = &tdata->globals;
|
2017-08-22 15:00:52 +02:00
|
|
|
OSL::ShadingContext *octx = tdata->context;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-01-07 14:04:12 +05:00
|
|
|
if (kg->osl->background_state) {
|
|
|
|
ss->execute(octx, *(kg->osl->background_state), *globals);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* return background color immediately */
|
2015-03-28 00:15:15 +05:00
|
|
|
if (globals->Ci)
|
2019-05-14 12:13:43 +02:00
|
|
|
flatten_background_closure_tree(sd, globals->Ci);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Volume */
|
|
|
|
|
2019-05-14 12:13:43 +02:00
|
|
|
static void flatten_volume_closure_tree(ShaderData *sd,
|
2016-07-25 03:03:23 +02:00
|
|
|
const OSL::ClosureColor *closure,
|
|
|
|
float3 weight = make_float3(1.0f, 1.0f, 1.0f))
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-06-05 09:29:47 +00:00
|
|
|
/* OSL gives us a closure tree, we flatten it into arrays per
|
2011-04-27 11:58:34 +00:00
|
|
|
* closure type, for evaluation, sampling, etc later on. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-09-23 12:23:37 +05:00
|
|
|
switch (closure->id) {
|
|
|
|
case OSL::ClosureColor::MUL: {
|
|
|
|
OSL::ClosureMul *mul = (OSL::ClosureMul *)closure;
|
2019-05-14 12:13:43 +02:00
|
|
|
flatten_volume_closure_tree(sd, mul->closure, TO_FLOAT3(mul->weight) * weight);
|
2015-09-23 12:23:37 +05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OSL::ClosureColor::ADD: {
|
|
|
|
OSL::ClosureAdd *add = (OSL::ClosureAdd *)closure;
|
2019-05-14 12:13:43 +02:00
|
|
|
flatten_volume_closure_tree(sd, add->closureA, weight);
|
|
|
|
flatten_volume_closure_tree(sd, add->closureB, weight);
|
2015-09-23 12:23:37 +05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
OSL::ClosureComponent *comp = (OSL::ClosureComponent *)closure;
|
|
|
|
CClosurePrimitive *prim = (CClosurePrimitive *)comp->data();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-09-23 12:23:37 +05:00
|
|
|
if (prim) {
|
2013-09-09 21:52:26 +00:00
|
|
|
#ifdef OSL_SUPPORTS_WEIGHTED_CLOSURE_COMPONENTS
|
2015-09-23 12:23:37 +05:00
|
|
|
weight = weight * TO_FLOAT3(comp->w);
|
2013-09-09 21:52:26 +00:00
|
|
|
#endif
|
2019-05-14 12:13:43 +02:00
|
|
|
prim->setup(sd, 0, weight);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
void OSLShader::eval_volume(const KernelGlobalsCPU *kg,
|
2021-10-17 16:22:20 +02:00
|
|
|
const void *state,
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
ShaderData *sd,
|
2021-10-17 20:09:45 +02:00
|
|
|
uint32_t path_flag)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* setup shader globals from shader data */
|
2012-12-15 10:18:42 +00:00
|
|
|
OSLThreadData *tdata = kg->osl_tdata;
|
2016-01-06 23:38:13 +01:00
|
|
|
shaderdata_to_shaderglobals(kg, sd, state, path_flag, tdata);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* execute shader */
|
2012-12-15 10:18:42 +00:00
|
|
|
OSL::ShadingSystem *ss = (OSL::ShadingSystem *)kg->osl_ss;
|
|
|
|
OSL::ShaderGlobals *globals = &tdata->globals;
|
2017-08-22 15:00:52 +02:00
|
|
|
OSL::ShadingContext *octx = tdata->context;
|
2011-09-27 20:37:24 +00:00
|
|
|
int shader = sd->shader & SHADER_MASK;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-01-07 14:04:12 +05:00
|
|
|
if (kg->osl->volume_state[shader]) {
|
|
|
|
ss->execute(octx, *(kg->osl->volume_state[shader]), *globals);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-28 01:54:44 +01:00
|
|
|
/* flatten closure tree */
|
2015-03-28 00:15:15 +05:00
|
|
|
if (globals->Ci)
|
2019-05-14 12:13:43 +02:00
|
|
|
flatten_volume_closure_tree(sd, globals->Ci);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Displacement */
|
|
|
|
|
2021-10-17 16:22:20 +02:00
|
|
|
void OSLShader::eval_displacement(const KernelGlobalsCPU *kg, const void *state, ShaderData *sd)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* setup shader globals from shader data */
|
2012-12-15 10:18:42 +00:00
|
|
|
OSLThreadData *tdata = kg->osl_tdata;
|
2016-01-06 23:38:13 +01:00
|
|
|
|
2017-10-05 15:17:09 +02:00
|
|
|
shaderdata_to_shaderglobals(kg, sd, state, 0, tdata);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* execute shader */
|
2012-12-15 10:18:42 +00:00
|
|
|
OSL::ShadingSystem *ss = (OSL::ShadingSystem *)kg->osl_ss;
|
|
|
|
OSL::ShaderGlobals *globals = &tdata->globals;
|
2017-08-22 15:00:52 +02:00
|
|
|
OSL::ShadingContext *octx = tdata->context;
|
2011-09-27 20:37:24 +00:00
|
|
|
int shader = sd->shader & SHADER_MASK;
|
|
|
|
|
2016-01-07 14:04:12 +05:00
|
|
|
if (kg->osl->displacement_state[shader]) {
|
|
|
|
ss->execute(octx, *(kg->osl->displacement_state[shader]), *globals);
|
|
|
|
}
|
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
2012-11-06 19:59:10 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* get back position */
|
|
|
|
sd->P = TO_FLOAT3(globals->P);
|
|
|
|
}
|
|
|
|
|
2012-12-01 19:15:05 +00:00
|
|
|
/* Attributes */
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
int OSLShader::find_attribute(const KernelGlobalsCPU *kg,
|
2016-07-01 17:36:27 -04:00
|
|
|
const ShaderData *sd,
|
|
|
|
uint id,
|
|
|
|
AttributeDescriptor *desc)
|
2012-12-01 19:15:05 +00:00
|
|
|
{
|
|
|
|
/* for OSL, a hash map is used to lookup the attribute by name. */
|
2013-01-09 21:09:20 +00:00
|
|
|
int object = sd->object * ATTR_PRIM_TYPES;
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
OSLGlobals::AttributeMap &attr_map = kg->osl->attribute_map[object];
|
|
|
|
ustring stdname(std::string("geom:") +
|
|
|
|
std::string(Attribute::standard_name((AttributeStandard)id)));
|
2012-12-01 19:15:05 +00:00
|
|
|
OSLGlobals::AttributeMap::const_iterator it = attr_map.find(stdname);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (it != attr_map.end()) {
|
2012-12-01 19:15:05 +00:00
|
|
|
const OSLGlobals::Attribute &osl_attr = it->second;
|
2016-07-01 17:36:27 -04:00
|
|
|
*desc = osl_attr.desc;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-01 17:36:27 -04:00
|
|
|
if (sd->prim == PRIM_NONE && (AttributeElement)osl_attr.desc.element != ATTR_ELEMENT_MESH) {
|
|
|
|
desc->offset = ATTR_STD_NOT_FOUND;
|
2013-12-31 17:33:55 +01:00
|
|
|
return ATTR_STD_NOT_FOUND;
|
2016-07-01 17:36:27 -04:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-01 19:15:05 +00:00
|
|
|
/* return result */
|
2016-07-01 17:36:27 -04:00
|
|
|
if (osl_attr.desc.element == ATTR_ELEMENT_NONE) {
|
|
|
|
desc->offset = ATTR_STD_NOT_FOUND;
|
|
|
|
}
|
|
|
|
return desc->offset;
|
2012-12-01 19:15:05 +00:00
|
|
|
}
|
2016-07-01 17:36:27 -04:00
|
|
|
else {
|
|
|
|
desc->offset = ATTR_STD_NOT_FOUND;
|
2012-12-01 19:15:05 +00:00
|
|
|
return (int)ATTR_STD_NOT_FOUND;
|
2016-07-01 17:36:27 -04:00
|
|
|
}
|
2012-12-01 19:15:05 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|