2 * ***** BEGIN GPL LICENSE BLOCK *****
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.
18 * The Original Code is Copyright (C) 2005 Blender Foundation.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): Brecht Van Lommel.
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file GPU_material.h
32 #ifndef __GPU_MATERIAL_H__
33 #define __GPU_MATERIAL_H__
35 #include "DNA_listBase.h"
49 struct LinkInOutsMuteNode;
51 struct GPUVertexAttribs;
59 typedef struct GPUNode GPUNode;
60 typedef struct GPUNodeLink GPUNodeLink;
61 typedef struct GPUMaterial GPUMaterial;
62 typedef struct GPULamp GPULamp;
64 /* Functions to create GPU Materials nodes */
66 typedef enum GPUType {
79 typedef enum GPUBuiltin {
81 GPU_OBJECT_MATRIX = 2,
82 GPU_INVERSE_VIEW_MATRIX = 4,
83 GPU_INVERSE_OBJECT_MATRIX = 8,
84 GPU_VIEW_POSITION = 16,
87 GPU_AUTO_BUMPSCALE = 128
90 typedef enum GPUBlendMode {
95 GPU_BLEND_ALPHA_SORT = 8
98 typedef struct GPUNodeStack {
102 struct GPUNodeLink *link;
108 GPUNodeLink *GPU_attribute(int type, const char *name);
109 GPUNodeLink *GPU_uniform(float *num);
110 GPUNodeLink *GPU_dynamic_uniform(float *num, int dynamictype, void *data);
111 GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser);
112 GPUNodeLink *GPU_texture(int size, float *pixels);
113 GPUNodeLink *GPU_dynamic_texture(struct GPUTexture *tex, int dynamictype, void *data);
114 GPUNodeLink *GPU_socket(GPUNodeStack *sock);
115 GPUNodeLink *GPU_builtin(GPUBuiltin builtin);
117 int GPU_link(GPUMaterial *mat, const char *name, ...);
118 int GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNodeStack *out, ...);
119 int GPU_stack_link_mute(GPUMaterial *mat, const char *name, struct LinkInOutsMuteNode *mlnk);
121 void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link);
122 void GPU_material_enable_alpha(GPUMaterial *material);
123 GPUBlendMode GPU_material_alpha_blend(GPUMaterial *material, float obcol[4]);
125 /* High level functions to create and use GPU materials */
127 GPUMaterial *GPU_material_from_blender(struct Scene *scene, struct Material *ma);
128 void GPU_material_free(struct Material *ma);
130 void GPU_materials_free(void);
132 void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double time, int mipmap);
133 void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[][4], float viewmat[][4], float viewinv[][4], float obcol[4], float autobumpscale);
134 void GPU_material_unbind(GPUMaterial *material);
135 int GPU_material_bound(GPUMaterial *material);
137 void GPU_material_vertex_attributes(GPUMaterial *material,
138 struct GPUVertexAttribs *attrib);
140 /* Exported shading */
142 typedef struct GPUShadeInput {
144 struct Material *mat;
146 GPUNodeLink *rgb, *specrgb, *vn, *view, *vcol, *ref;
147 GPUNodeLink *alpha, *refl, *spec, *emit, *har, *amb;
150 typedef struct GPUShadeResult {
151 GPUNodeLink *diff, *spec, *combined, *alpha;
154 void GPU_shadeinput_set(GPUMaterial *mat, struct Material *ma, GPUShadeInput *shi);
155 void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr);
157 /* Export GLSL shader */
159 typedef enum GPUDynamicType {
160 GPU_DYNAMIC_NONE = 0,
161 GPU_DYNAMIC_OBJECT_VIEWMAT = 1,
162 GPU_DYNAMIC_OBJECT_MAT = 2,
163 GPU_DYNAMIC_OBJECT_VIEWIMAT = 3,
164 GPU_DYNAMIC_OBJECT_IMAT = 4,
165 GPU_DYNAMIC_OBJECT_COLOR = 5,
166 GPU_DYNAMIC_OBJECT_AUTOBUMPSCALE = 15,
167 GPU_DYNAMIC_LAMP_FIRST = 6,
168 GPU_DYNAMIC_LAMP_DYNVEC = 6,
169 GPU_DYNAMIC_LAMP_DYNCO = 7,
170 GPU_DYNAMIC_LAMP_DYNIMAT = 8,
171 GPU_DYNAMIC_LAMP_DYNPERSMAT = 9,
172 GPU_DYNAMIC_LAMP_DYNENERGY = 10,
173 GPU_DYNAMIC_LAMP_DYNCOL = 11,
174 GPU_DYNAMIC_LAMP_LAST = 11,
175 GPU_DYNAMIC_SAMPLER_2DBUFFER = 12,
176 GPU_DYNAMIC_SAMPLER_2DIMAGE = 13,
177 GPU_DYNAMIC_SAMPLER_2DSHADOW = 14,
180 typedef enum GPUDataType {
182 GPU_DATA_1I = 1, // 1 integer
192 /* this structure gives information of each uniform found in the shader */
193 typedef struct GPUInputUniform {
194 struct GPUInputUniform *next, *prev;
195 char varname[32]; /* name of uniform in shader */
196 GPUDynamicType type; /* type of uniform, data format and calculation derive from it */
197 GPUDataType datatype; /* type of uniform data */
198 struct Object *lamp; /* when type=GPU_DYNAMIC_LAMP_... or GPU_DYNAMIC_SAMPLER_2DSHADOW */
199 struct Image *image; /* when type=GPU_DYNAMIC_SAMPLER_2DIMAGE */
200 int texnumber; /* when type=GPU_DYNAMIC_SAMPLER, texture number: 0.. */
201 unsigned char *texpixels; /* for internally generated texture, pixel data in RGBA format */
202 int texsize; /* size in pixel of the texture in texpixels buffer: for 2D textures, this is S and T size (square texture) */
205 typedef struct GPUInputAttribute {
206 struct GPUInputAttribute *next, *prev;
207 char varname[32]; /* name of attribute in shader */
208 int type; /* from CustomData.type, data type derives from it */
209 GPUDataType datatype; /* type of attribute data */
210 const char *name; /* layer name */
211 int number; /* generic attribute number */
214 typedef struct GPUShaderExport {
221 GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma);
222 void GPU_free_shader_export(GPUShaderExport *shader);
226 GPULamp *GPU_lamp_from_blender(struct Scene *scene, struct Object *ob, struct Object *par);
227 void GPU_lamp_free(struct Object *ob);
229 int GPU_lamp_has_shadow_buffer(GPULamp *lamp);
230 void GPU_lamp_shadow_buffer_bind(GPULamp *lamp, float viewmat[][4], int *winsize, float winmat[][4]);
231 void GPU_lamp_shadow_buffer_unbind(GPULamp *lamp);
233 void GPU_lamp_update(GPULamp *lamp, int lay, int hide, float obmat[][4]);
234 void GPU_lamp_update_colors(GPULamp *lamp, float r, float g, float b, float energy);
235 int GPU_lamp_shadow_layer(GPULamp *lamp);
241 #endif /*__GPU_MATERIAL_H__*/