Blender V2.61 - r43446

osl_shader.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2011, Blender Foundation.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #ifndef __OSL_SHADER_H__
00020 #define __OSL_SHADER_H__
00021 
00022 #ifdef WITH_OSL
00023 
00024 /* OSL Shader Engine
00025  *
00026  * Holds all variables to execute and use OSL shaders from the kernel. These
00027  * are initialized externally by OSLShaderManager before rendering starts.
00028  *
00029  * Before/after a thread starts rendering, thread_init/thread_free must be
00030  * called, which will store any per thread OSL state in thread local storage.
00031  * This means no thread state must be passed along in the kernel itself.
00032  */
00033 
00034 #include <OSL/oslexec.h>
00035 #include <OSL/oslclosure.h>
00036 
00037 #include "kernel_types.h"
00038 
00039 #include "util_map.h"
00040 #include "util_param.h"
00041 #include "util_vector.h"
00042 
00043 CCL_NAMESPACE_BEGIN
00044 
00045 namespace OSL = ::OSL;
00046 
00047 class OSLRenderServices;
00048 class Scene;
00049 class ShaderClosure;
00050 class ShaderData;
00051 class differential3;
00052 class KernelGlobals;
00053 
00054 class OSLShader {
00055 public:
00056     /* init */
00057     static void register_closures(OSL::ShadingSystem *ss);
00058 
00059     /* per thread data */
00060     static void thread_init(KernelGlobals *kg);
00061     static void thread_free(KernelGlobals *kg);
00062 
00063     /* eval */
00064     static void eval_surface(KernelGlobals *kg, ShaderData *sd, float randb, int path_flag);
00065     static float3 eval_background(KernelGlobals *kg, ShaderData *sd, int path_flag);
00066     static void eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int path_flag);
00067     static void eval_displacement(KernelGlobals *kg, ShaderData *sd);
00068 
00069     /* sample & eval */
00070     static int bsdf_sample(const ShaderData *sd, const ShaderClosure *sc,
00071         float randu, float randv,
00072         float3& eval, float3& omega_in, differential3& domega_in, float& pdf);
00073     static float3 bsdf_eval(const ShaderData *sd, const ShaderClosure *sc,
00074         const float3& omega_in, float& pdf);
00075 
00076     static float3 emissive_eval(const ShaderData *sd, const ShaderClosure *sc);
00077 
00078     static float3 volume_eval_phase(const ShaderData *sd, const ShaderClosure *sc,
00079         const float3 omega_in, const float3 omega_out);
00080 
00081     /* release */
00082     static void release(KernelGlobals *kg, const ShaderData *sd);
00083 };
00084 
00085 CCL_NAMESPACE_END
00086 
00087 #endif
00088 
00089 #endif /* __OSL_SHADER_H__ */
00090