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 need_update_attributes;
63 /* information about shader after compiling */
65 bool has_surface_emission;
67 bool has_displacement;
69 /* requested mesh attributes */
70 AttributeRequestSet attributes;
75 void set_graph(ShaderGraph *graph);
76 void tag_update(Scene *scene);
79 /* Shader Manager virtual base class
81 * From this the SVM and OSL shader managers are derived, that do the actual
82 * shader compiling and device updating. */
88 static ShaderManager *create(Scene *scene);
89 virtual ~ShaderManager();
92 virtual void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) = 0;
93 virtual void device_free(Device *device, DeviceScene *dscene) = 0;
95 /* get globally unique id for a type of attribute */
96 uint get_attribute_id(ustring name);
97 uint get_attribute_id(Attribute::Standard std);
99 /* get shader id for mesh faces */
100 int get_shader_id(uint shader, Mesh *mesh = NULL, bool smooth = false);
102 /* add default shaders to scene, to use as default for things that don't
103 have any shader assigned explicitly */
104 static void add_default(Scene *scene);
109 typedef unordered_map<ustring, uint, ustringHash> AttributeIDMap;
110 AttributeIDMap unique_attribute_id;
115 #endif /* __SHADER_H__ */