Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 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 * The Original Code is Copyright (C) 2005 Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): Brecht Van Lommel. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00032 #ifndef __GPU_MATERIAL__ 00033 #define __GPU_MATERIAL__ 00034 00035 #include "DNA_listBase.h" 00036 00037 #ifdef __cplusplus 00038 extern "C" { 00039 #endif 00040 00041 struct Image; 00042 struct ImageUser; 00043 struct Material; 00044 struct Object; 00045 struct Lamp; 00046 struct Image; 00047 struct bNode; 00048 struct LinkNode; 00049 struct LinkInOutsMuteNode; 00050 struct Scene; 00051 struct GPUVertexAttribs; 00052 struct GPUNode; 00053 struct GPUNodeLink; 00054 struct GPUNodeStack; 00055 struct GPUMaterial; 00056 struct GPUTexture; 00057 struct GPULamp; 00058 00059 typedef struct GPUNode GPUNode; 00060 typedef struct GPUNodeLink GPUNodeLink; 00061 typedef struct GPUMaterial GPUMaterial; 00062 typedef struct GPULamp GPULamp; 00063 00064 /* Functions to create GPU Materials nodes */ 00065 00066 typedef enum GPUType { 00067 GPU_NONE = 0, 00068 GPU_FLOAT = 1, 00069 GPU_VEC2 = 2, 00070 GPU_VEC3 = 3, 00071 GPU_VEC4 = 4, 00072 GPU_MAT3 = 9, 00073 GPU_MAT4 = 16, 00074 GPU_TEX2D = 1002, 00075 GPU_SHADOW2D = 1003, 00076 GPU_ATTRIB = 3001 00077 } GPUType; 00078 00079 typedef enum GPUBuiltin { 00080 GPU_VIEW_MATRIX = 1, 00081 GPU_OBJECT_MATRIX = 2, 00082 GPU_INVERSE_VIEW_MATRIX = 4, 00083 GPU_INVERSE_OBJECT_MATRIX = 8, 00084 GPU_VIEW_POSITION = 16, 00085 GPU_VIEW_NORMAL = 32, 00086 GPU_OBCOLOR = 64, 00087 GPU_AUTO_BUMPSCALE = 128 00088 } GPUBuiltin; 00089 00090 typedef enum GPUBlendMode { 00091 GPU_BLEND_SOLID = 0, 00092 GPU_BLEND_ADD = 1, 00093 GPU_BLEND_ALPHA = 2, 00094 GPU_BLEND_CLIP = 4, 00095 GPU_BLEND_ALPHA_SORT = 8 00096 } GPUBlendMode; 00097 00098 typedef struct GPUNodeStack { 00099 GPUType type; 00100 const char *name; 00101 float vec[4]; 00102 struct GPUNodeLink *link; 00103 short hasinput; 00104 short hasoutput; 00105 short sockettype; 00106 } GPUNodeStack; 00107 00108 GPUNodeLink *GPU_attribute(int type, const char *name); 00109 GPUNodeLink *GPU_uniform(float *num); 00110 GPUNodeLink *GPU_dynamic_uniform(float *num, int dynamictype, void *data); 00111 GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser); 00112 GPUNodeLink *GPU_texture(int size, float *pixels); 00113 GPUNodeLink *GPU_dynamic_texture(struct GPUTexture *tex, int dynamictype, void *data); 00114 GPUNodeLink *GPU_socket(GPUNodeStack *sock); 00115 GPUNodeLink *GPU_builtin(GPUBuiltin builtin); 00116 00117 int GPU_link(GPUMaterial *mat, const char *name, ...); 00118 int GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNodeStack *out, ...); 00119 int GPU_stack_link_mute(GPUMaterial *mat, const char *name, struct LinkInOutsMuteNode *mlnk); 00120 00121 void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link); 00122 void GPU_material_enable_alpha(GPUMaterial *material); 00123 GPUBlendMode GPU_material_alpha_blend(GPUMaterial *material, float obcol[4]); 00124 00125 /* High level functions to create and use GPU materials */ 00126 00127 GPUMaterial *GPU_material_from_blender(struct Scene *scene, struct Material *ma); 00128 void GPU_material_free(struct Material *ma); 00129 00130 void GPU_materials_free(void); 00131 00132 void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double time, int mipmap); 00133 void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[][4], float viewmat[][4], float viewinv[][4], float obcol[4], float autobumpscale); 00134 void GPU_material_unbind(GPUMaterial *material); 00135 int GPU_material_bound(GPUMaterial *material); 00136 00137 void GPU_material_vertex_attributes(GPUMaterial *material, 00138 struct GPUVertexAttribs *attrib); 00139 00140 /* Exported shading */ 00141 00142 typedef struct GPUShadeInput { 00143 GPUMaterial *gpumat; 00144 struct Material *mat; 00145 00146 GPUNodeLink *rgb, *specrgb, *vn, *view, *vcol, *ref; 00147 GPUNodeLink *alpha, *refl, *spec, *emit, *har, *amb; 00148 } GPUShadeInput; 00149 00150 typedef struct GPUShadeResult { 00151 GPUNodeLink *diff, *spec, *combined, *alpha; 00152 } GPUShadeResult; 00153 00154 void GPU_shadeinput_set(GPUMaterial *mat, struct Material *ma, GPUShadeInput *shi); 00155 void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr); 00156 00157 /* Export GLSL shader */ 00158 00159 typedef enum GPUDynamicType { 00160 GPU_DYNAMIC_NONE = 0, 00161 GPU_DYNAMIC_OBJECT_VIEWMAT = 1, 00162 GPU_DYNAMIC_OBJECT_MAT = 2, 00163 GPU_DYNAMIC_OBJECT_VIEWIMAT = 3, 00164 GPU_DYNAMIC_OBJECT_IMAT = 4, 00165 GPU_DYNAMIC_OBJECT_COLOR = 5, 00166 GPU_DYNAMIC_OBJECT_AUTOBUMPSCALE = 15, 00167 GPU_DYNAMIC_LAMP_FIRST = 6, 00168 GPU_DYNAMIC_LAMP_DYNVEC = 6, 00169 GPU_DYNAMIC_LAMP_DYNCO = 7, 00170 GPU_DYNAMIC_LAMP_DYNIMAT = 8, 00171 GPU_DYNAMIC_LAMP_DYNPERSMAT = 9, 00172 GPU_DYNAMIC_LAMP_DYNENERGY = 10, 00173 GPU_DYNAMIC_LAMP_DYNCOL = 11, 00174 GPU_DYNAMIC_LAMP_LAST = 11, 00175 GPU_DYNAMIC_SAMPLER_2DBUFFER = 12, 00176 GPU_DYNAMIC_SAMPLER_2DIMAGE = 13, 00177 GPU_DYNAMIC_SAMPLER_2DSHADOW = 14, 00178 } GPUDynamicType; 00179 00180 typedef enum GPUDataType { 00181 GPU_DATA_NONE = 0, 00182 GPU_DATA_1I = 1, // 1 integer 00183 GPU_DATA_1F = 2, 00184 GPU_DATA_2F = 3, 00185 GPU_DATA_3F = 4, 00186 GPU_DATA_4F = 5, 00187 GPU_DATA_9F = 6, 00188 GPU_DATA_16F = 7, 00189 GPU_DATA_4UB = 8, 00190 } GPUDataType; 00191 00192 /* this structure gives information of each uniform found in the shader */ 00193 typedef struct GPUInputUniform { 00194 struct GPUInputUniform *next, *prev; 00195 char varname[32]; /* name of uniform in shader */ 00196 GPUDynamicType type; /* type of uniform, data format and calculation derive from it */ 00197 GPUDataType datatype; /* type of uniform data */ 00198 struct Object *lamp; /* when type=GPU_DYNAMIC_LAMP_... or GPU_DYNAMIC_SAMPLER_2DSHADOW */ 00199 struct Image *image; /* when type=GPU_DYNAMIC_SAMPLER_2DIMAGE */ 00200 int texnumber; /* when type=GPU_DYNAMIC_SAMPLER, texture number: 0.. */ 00201 unsigned char *texpixels; /* for internally generated texture, pixel data in RGBA format */ 00202 int texsize; /* size in pixel of the texture in texpixels buffer: for 2D textures, this is S and T size (square texture) */ 00203 } GPUInputUniform; 00204 00205 typedef struct GPUInputAttribute { 00206 struct GPUInputAttribute *next, *prev; 00207 char varname[32]; /* name of attribute in shader */ 00208 int type; /* from CustomData.type, data type derives from it */ 00209 GPUDataType datatype; /* type of attribute data */ 00210 const char *name; /* layer name */ 00211 int number; /* generic attribute number */ 00212 } GPUInputAttribute; 00213 00214 typedef struct GPUShaderExport { 00215 ListBase uniforms; 00216 ListBase attributes; 00217 char *vertex; 00218 char *fragment; 00219 } GPUShaderExport; 00220 00221 GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma); 00222 void GPU_free_shader_export(GPUShaderExport *shader); 00223 00224 /* Lamps */ 00225 00226 GPULamp *GPU_lamp_from_blender(struct Scene *scene, struct Object *ob, struct Object *par); 00227 void GPU_lamp_free(struct Object *ob); 00228 00229 int GPU_lamp_has_shadow_buffer(GPULamp *lamp); 00230 void GPU_lamp_shadow_buffer_bind(GPULamp *lamp, float viewmat[][4], int *winsize, float winmat[][4]); 00231 void GPU_lamp_shadow_buffer_unbind(GPULamp *lamp); 00232 00233 void GPU_lamp_update(GPULamp *lamp, int lay, int hide, float obmat[][4]); 00234 void GPU_lamp_update_colors(GPULamp *lamp, float r, float g, float b, float energy); 00235 int GPU_lamp_shadow_layer(GPULamp *lamp); 00236 00237 #ifdef __cplusplus 00238 } 00239 #endif 00240 00241 #endif /*__GPU_MATERIAL__*/ 00242