2 * Copyright 2011, Blender Foundation.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "attribute.h"
23 #include "kernel_types.h"
26 #include "util_param.h"
27 #include "util_string.h"
28 #include "util_types.h"
40 /* Shader describing the appearance of a Mesh, Light or Background.
42 * While there is only a single shader graph, it has three outputs: surface,
43 * volume and displacement, that the shader manager will compile and execute
54 /* shader graph with auto bump mapping included, we compile two shaders,
55 with and without bump, because the displacement method is a mesh
56 level setting, so we need to handle both */
57 ShaderGraph *graph_bump;
61 bool homogeneous_volume;
65 bool need_update_attributes;
67 /* information about shader after compiling */
69 bool has_surface_emission;
70 bool has_surface_transparent;
72 bool has_displacement;
74 /* requested mesh attributes */
75 AttributeRequestSet attributes;
80 void set_graph(ShaderGraph *graph);
81 void tag_update(Scene *scene);
84 /* Shader Manager virtual base class
86 * From this the SVM and OSL shader managers are derived, that do the actual
87 * shader compiling and device updating. */
93 static ShaderManager *create(Scene *scene);
94 virtual ~ShaderManager();
97 virtual void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) = 0;
98 virtual void device_free(Device *device, DeviceScene *dscene) = 0;
100 void device_update_common(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress);
101 void device_free_common(Device *device, DeviceScene *dscene);
103 /* get globally unique id for a type of attribute */
104 uint get_attribute_id(ustring name);
105 uint get_attribute_id(Attribute::Standard std);
107 /* get shader id for mesh faces */
108 int get_shader_id(uint shader, Mesh *mesh = NULL, bool smooth = false);
110 /* add default shaders to scene, to use as default for things that don't
111 have any shader assigned explicitly */
112 static void add_default(Scene *scene);
117 typedef unordered_map<ustring, uint, ustringHash> AttributeIDMap;
118 AttributeIDMap unique_attribute_id;
123 #endif /* __SHADER_H__ */