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
|
|
|
|
* limitations under the License
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __OSL_GLOBALS_H__
|
|
|
|
#define __OSL_GLOBALS_H__
|
|
|
|
|
|
|
|
#ifdef WITH_OSL
|
|
|
|
|
|
|
|
#include <OSL/oslexec.h>
|
2012-11-14 22:45:44 +00:00
|
|
|
#include <cmath>
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
#include "util_map.h"
|
|
|
|
#include "util_param.h"
|
|
|
|
#include "util_thread.h"
|
|
|
|
#include "util_vector.h"
|
|
|
|
|
2012-11-14 22:45:44 +00:00
|
|
|
#ifndef WIN32
|
|
|
|
using std::isfinite;
|
|
|
|
#endif
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2012-09-03 18:51:02 +00:00
|
|
|
class OSLRenderServices;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
struct OSLGlobals {
|
2012-12-01 19:15:05 +00:00
|
|
|
OSLGlobals()
|
|
|
|
{
|
|
|
|
ss = NULL;
|
|
|
|
ts = NULL;
|
|
|
|
services = NULL;
|
|
|
|
use = false;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
bool use;
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
/* shading system */
|
2011-04-27 11:58:34 +00:00
|
|
|
OSL::ShadingSystem *ss;
|
2012-11-20 17:40:21 +00:00
|
|
|
OSL::TextureSystem *ts;
|
2012-09-03 18:51:02 +00:00
|
|
|
OSLRenderServices *services;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* shader states */
|
|
|
|
vector<OSL::ShadingAttribStateRef> surface_state;
|
|
|
|
vector<OSL::ShadingAttribStateRef> volume_state;
|
|
|
|
vector<OSL::ShadingAttribStateRef> displacement_state;
|
|
|
|
OSL::ShadingAttribStateRef background_state;
|
|
|
|
|
|
|
|
/* attributes */
|
|
|
|
struct Attribute {
|
|
|
|
TypeDesc type;
|
|
|
|
AttributeElement elem;
|
|
|
|
int offset;
|
|
|
|
ParamValue value;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef unordered_map<ustring, Attribute, ustringHash> AttributeMap;
|
|
|
|
typedef unordered_map<ustring, int, ustringHash> ObjectNameMap;
|
|
|
|
|
|
|
|
vector<AttributeMap> attribute_map;
|
|
|
|
ObjectNameMap object_name_map;
|
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
|
|
|
vector<ustring> object_names;
|
2012-12-01 19:15:05 +00:00
|
|
|
};
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-12-15 10:18:42 +00:00
|
|
|
/* trace() call result */
|
|
|
|
struct OSLTraceData {
|
|
|
|
Ray ray;
|
|
|
|
Intersection isect;
|
|
|
|
ShaderData sd;
|
|
|
|
bool setup;
|
|
|
|
bool init;
|
|
|
|
};
|
|
|
|
|
2012-12-01 19:15:05 +00:00
|
|
|
/* thread key for thread specific data lookup */
|
|
|
|
struct OSLThreadData {
|
|
|
|
OSL::ShaderGlobals globals;
|
2013-08-05 12:49:15 +00:00
|
|
|
OSL::PerThreadInfo *osl_thread_info;
|
2012-12-15 10:18:42 +00:00
|
|
|
OSLTraceData tracedata;
|
|
|
|
OSL::ShadingContext *context[SHADER_CONTEXT_NUM];
|
2013-08-05 12:49:15 +00:00
|
|
|
OIIO::TextureSystem::Perthread *oiio_thread_info;
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __OSL_GLOBALS_H__ */
|
|
|
|
|