|
Blender
V2.59
|
00001 /* 00002 * $Id: GPU_material.h 35014 2011-02-21 06:58:46Z jesterking $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This shader is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. The Blender 00010 * Foundation also sells licenses for use in proprietary software under 00011 * the Blender License. See http://www.blender.org/BL/ for information 00012 * about this. 00013 * 00014 * This shader is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this shader; if not, write to the Free Software Foundation, 00021 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00022 * 00023 * The Original Code is Copyright (C) 2005 Blender Foundation. 00024 * All rights reserved. 00025 * 00026 * The Original Code is: all of this file. 00027 * 00028 * Contributor(s): Brecht Van Lommel. 00029 * 00030 * ***** END GPL LICENSE BLOCK ***** 00031 */ 00032 00037 #ifndef __GPU_MATERIAL__ 00038 #define __GPU_MATERIAL__ 00039 00040 #ifdef __cplusplus 00041 extern "C" { 00042 #endif 00043 00044 struct Image; 00045 struct ImageUser; 00046 struct Material; 00047 struct Object; 00048 struct Lamp; 00049 struct bNode; 00050 struct LinkNode; 00051 struct Scene; 00052 struct GPUVertexAttribs; 00053 struct GPUNode; 00054 struct GPUNodeLink; 00055 struct GPUNodeStack; 00056 struct GPUMaterial; 00057 struct GPUTexture; 00058 struct GPULamp; 00059 00060 typedef struct GPUNode GPUNode; 00061 typedef struct GPUNodeLink GPUNodeLink; 00062 typedef struct GPUMaterial GPUMaterial; 00063 typedef struct GPULamp GPULamp; 00064 00065 /* Functions to create GPU Materials nodes */ 00066 00067 typedef enum GPUType { 00068 GPU_NONE = 0, 00069 GPU_FLOAT = 1, 00070 GPU_VEC2 = 2, 00071 GPU_VEC3 = 3, 00072 GPU_VEC4 = 4, 00073 GPU_MAT3 = 9, 00074 GPU_MAT4 = 16, 00075 GPU_TEX1D = 1001, 00076 GPU_TEX2D = 1002, 00077 GPU_SHADOW2D = 1003, 00078 GPU_ATTRIB = 3001 00079 } GPUType; 00080 00081 typedef enum GPUBuiltin { 00082 GPU_VIEW_MATRIX = 1, 00083 GPU_OBJECT_MATRIX = 2, 00084 GPU_INVERSE_VIEW_MATRIX = 4, 00085 GPU_INVERSE_OBJECT_MATRIX = 8, 00086 GPU_VIEW_POSITION = 16, 00087 GPU_VIEW_NORMAL = 32, 00088 GPU_OBCOLOR = 64 00089 } GPUBuiltin; 00090 00091 typedef enum GPUBlendMode { 00092 GPU_BLEND_SOLID = 0, 00093 GPU_BLEND_ADD = 1, 00094 GPU_BLEND_ALPHA = 2, 00095 GPU_BLEND_CLIP = 4 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); 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); 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 00120 void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link); 00121 void GPU_material_enable_alpha(GPUMaterial *material); 00122 GPUBlendMode GPU_material_blend_mode(GPUMaterial *material, float obcol[4]); 00123 00124 /* High level functions to create and use GPU materials */ 00125 00126 GPUMaterial *GPU_material_from_blender(struct Scene *scene, struct Material *ma); 00127 void GPU_material_free(struct Material *ma); 00128 00129 void GPU_materials_free(void); 00130 00131 void GPU_material_bind(GPUMaterial *material, int oblay, int viewlay, double time, int mipmap); 00132 void GPU_material_bind_uniforms(GPUMaterial *material, float obmat[][4], float viewmat[][4], float viewinv[][4], float obcol[4]); 00133 void GPU_material_unbind(GPUMaterial *material); 00134 int GPU_material_bound(GPUMaterial *material); 00135 00136 void GPU_material_vertex_attributes(GPUMaterial *material, 00137 struct GPUVertexAttribs *attrib); 00138 00139 /* Exported shading */ 00140 00141 typedef struct GPUShadeInput { 00142 GPUMaterial *gpumat; 00143 struct Material *mat; 00144 00145 GPUNodeLink *rgb, *specrgb, *vn, *view, *vcol, *ref; 00146 GPUNodeLink *alpha, *refl, *spec, *emit, *har, *amb; 00147 } GPUShadeInput; 00148 00149 typedef struct GPUShadeResult { 00150 GPUNodeLink *diff, *spec, *combined, *alpha; 00151 } GPUShadeResult; 00152 00153 void GPU_shadeinput_set(GPUMaterial *mat, struct Material *ma, GPUShadeInput *shi); 00154 void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr); 00155 00156 /* Lamps */ 00157 00158 GPULamp *GPU_lamp_from_blender(struct Scene *scene, struct Object *ob, struct Object *par); 00159 void GPU_lamp_free(struct Object *ob); 00160 00161 int GPU_lamp_has_shadow_buffer(GPULamp *lamp); 00162 void GPU_lamp_shadow_buffer_bind(GPULamp *lamp, float viewmat[][4], int *winsize, float winmat[][4]); 00163 void GPU_lamp_shadow_buffer_unbind(GPULamp *lamp); 00164 00165 void GPU_lamp_update(GPULamp *lamp, int lay, int hide, float obmat[][4]); 00166 void GPU_lamp_update_colors(GPULamp *lamp, float r, float g, float b, float energy); 00167 int GPU_lamp_shadow_layer(GPULamp *lamp); 00168 00169 #ifdef __cplusplus 00170 } 00171 #endif 00172 00173 #endif /*__GPU_MATERIAL__*/ 00174