Blender  V2.93
GPU_material.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2005 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #pragma once
25 
26 #include "DNA_customdata_types.h" /* for CustomDataType */
27 #include "DNA_listBase.h"
28 
29 #include "BLI_sys_types.h" /* for bool */
30 
31 #include "GPU_texture.h" /* for eGPUSamplerState */
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 struct GHash;
38 struct GPUMaterial;
39 struct GPUNode;
40 struct GPUNodeLink;
41 struct GPUNodeStack;
42 struct GPUTexture;
43 struct GPUUniformBuf;
44 struct Image;
45 struct ImageUser;
46 struct ListBase;
47 struct Main;
48 struct Material;
49 struct Scene;
50 struct bNode;
51 struct bNodeTree;
52 
53 typedef struct GPUMaterial GPUMaterial;
54 typedef struct GPUNode GPUNode;
55 typedef struct GPUNodeLink GPUNodeLink;
56 
57 /* Functions to create GPU Materials nodes */
58 
59 typedef enum eGPUType {
60  /* Keep in sync with GPU_DATATYPE_STR */
61  /* The value indicates the number of elements in each type */
62  GPU_NONE = 0,
63  GPU_FLOAT = 1,
64  GPU_VEC2 = 2,
65  GPU_VEC3 = 3,
66  GPU_VEC4 = 4,
67  GPU_MAT3 = 9,
68  GPU_MAT4 = 16,
70 
71  /* Values not in GPU_DATATYPE_STR */
73  GPU_TEX2D = 1002,
75  GPU_TEX3D = 1004,
76  GPU_SHADOW2D = 1005,
77  GPU_TEXCUBE = 1006,
78 
79  /* GLSL Struct types */
80  GPU_CLOSURE = 1007,
81 
82  /* Opengl Attributes */
83  GPU_ATTR = 3001,
85 
86 typedef enum eGPUBuiltin {
87  GPU_VIEW_MATRIX = (1 << 0),
88  GPU_OBJECT_MATRIX = (1 << 1),
91  GPU_VIEW_POSITION = (1 << 4),
92  GPU_VIEW_NORMAL = (1 << 5),
93  GPU_OBJECT_COLOR = (1 << 6),
94  GPU_AUTO_BUMPSCALE = (1 << 7),
97  GPU_PARTICLE_LOCATION = (1 << 10),
98  GPU_PARTICLE_VELOCITY = (1 << 11),
102  GPU_OBJECT_INFO = (1 << 15),
104  GPU_BARYCENTRIC_DIST = (1 << 17),
105  GPU_WORLD_NORMAL = (1 << 18),
107 
108 typedef enum eGPUMatFlag {
110  GPU_MATFLAG_GLOSSY = (1 << 1),
112  GPU_MATFLAG_SSS = (1 << 3),
115 
116 typedef struct GPUNodeStack {
118  float vec[4];
119  struct GPUNodeLink *link;
120  bool hasinput;
121  bool hasoutput;
122  short sockettype;
123  bool end;
125 
126 typedef enum eGPUMaterialStatus {
131 
136 
138  int options,
139  const char **vert_code,
140  const char **geom_code,
141  const char **frag_lib,
142  const char **defines);
143 
144 GPUNodeLink *GPU_constant(const float *num);
145 GPUNodeLink *GPU_uniform(const float *num);
146 GPUNodeLink *GPU_attribute(GPUMaterial *mat, CustomDataType type, const char *name);
147 GPUNodeLink *GPU_uniform_attribute(GPUMaterial *mat, const char *name, bool use_dupli);
149  struct Image *ima,
150  struct ImageUser *iuser,
151  eGPUSamplerState sampler_state);
153  struct Image *ima,
154  struct ImageUser *iuser,
155  eGPUSamplerState sampler_state);
156 GPUNodeLink *GPU_image_tiled_mapping(GPUMaterial *mat, struct Image *ima, struct ImageUser *iuser);
157 GPUNodeLink *GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *row);
159  const char *name,
160  eGPUVolumeDefaultValue default_value);
162 
163 bool GPU_link(GPUMaterial *mat, const char *name, ...);
164 bool GPU_stack_link(GPUMaterial *mat,
165  struct bNode *node,
166  const char *name,
167  GPUNodeStack *in,
168  GPUNodeStack *out,
169  ...);
171  struct bNode *node,
172  struct GPUNodeStack *stack,
173  const int index);
174 
177 
179  float radii[3],
180  const short *falloff_type,
181  const float *sharpness);
183  int sample_len,
184  struct GPUTexture **tex_profile);
185 
186 /* High level functions to create and use GPU materials */
188  const void *engine_type,
189  int options);
191  struct Material *ma,
192  struct bNodeTree *ntree,
193  struct ListBase *gpumaterials,
194  const void *engine_type,
195  const int options,
196  const bool is_volume_shader,
197  const char *vert_code,
198  const char *geom_code,
199  const char *frag_lib,
200  const char *defines,
201  const char *name,
204 void GPU_material_free(struct ListBase *gpumaterial);
205 
206 void GPU_materials_free(struct Main *bmain);
207 
213 
217 
220 
222 
225 
226 void GPU_pass_cache_init(void);
228 void GPU_pass_cache_free(void);
229 
230 /* Requested Material Attributes and Textures */
231 
232 typedef struct GPUMaterialAttribute {
234  int type; /* CustomDataType */
235  char name[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
237  int id;
238  int users;
240 
241 typedef struct GPUMaterialTexture {
243  struct Image *ima;
244  struct ImageUser *iuser;
246  char sampler_name[32]; /* Name of sampler in GLSL. */
247  char tiled_mapping_name[32]; /* Name of tile mapping sampler in GLSL. */
248  int users;
249  int sampler_state; /* eGPUSamplerState */
251 
252 typedef struct GPUMaterialVolumeGrid {
254  char *name;
256  char sampler_name[32]; /* Name of sampler in GLSL. */
257  char transform_name[32]; /* Name of 4x4 matrix in GLSL. */
258  int users;
260 
264 
265 typedef struct GPUUniformAttr {
267 
268  /* Meaningful part of the attribute set key. */
269  char name[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
270  bool use_dupli;
271 
272  /* Helper fields used by code generation. */
273  short id;
274  int users;
276 
277 typedef struct GPUUniformAttrList {
278  ListBase list; /* GPUUniformAttr */
279 
280  /* List length and hash code precomputed for fast lookup and comparison. */
281  unsigned int count, hash_code;
283 
285 
286 struct GHash *GPU_uniform_attr_list_hash_new(const char *info);
289 
290 #ifdef __cplusplus
291 }
292 #endif
CustomDataType
These structs are the foundation for all linked lists in the library system.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
struct GPUUniformAttrList GPUUniformAttrList
GPUNodeLink * GPU_builtin(eGPUBuiltin builtin)
void GPU_material_free(struct ListBase *gpumaterial)
Definition: gpu_material.c:192
GPUUniformAttrList * GPU_material_uniform_attributes(GPUMaterial *material)
Definition: gpu_material.c:587
void GPU_material_compile(GPUMaterial *mat)
Definition: gpu_material.c:775
void GPU_uniform_attr_list_copy(GPUUniformAttrList *dest, GPUUniformAttrList *src)
struct GPUShader * GPU_material_get_shader(GPUMaterial *material)
Definition: gpu_material.c:212
void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link)
Definition: gpu_material.c:593
struct GHash * GPU_uniform_attr_list_hash_new(const char *info)
bool GPU_material_has_surface_output(GPUMaterial *mat)
Definition: gpu_material.c:626
GPUNodeLink * GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *row)
struct GPUMaterialAttribute GPUMaterialAttribute
GPUNodeLink * GPU_image(GPUMaterial *mat, struct Image *ima, struct ImageUser *iuser, eGPUSamplerState sampler_state)
void GPU_materials_free(struct Main *bmain)
Definition: gpu_material.c:805
void(* GPUMaterialEvalCallbackFn)(GPUMaterial *mat, int options, const char **vert_code, const char **geom_code, const char **frag_lib, const char **defines)
Definition: GPU_material.h:137
GPUNodeLink * GPU_image_tiled_mapping(GPUMaterial *mat, struct Image *ima, struct ImageUser *iuser)
void GPU_material_add_output_link_aov(GPUMaterial *material, GPUNodeLink *link, int hash)
Definition: gpu_material.c:600
GPUNodeLink * GPU_attribute(GPUMaterial *mat, CustomDataType type, const char *name)
GPUNodeLink * GPU_uniform_attribute(GPUMaterial *mat, const char *name, bool use_dupli)
void GPU_pass_cache_free(void)
Definition: gpu_codegen.c:1101
eGPUMatFlag
Definition: GPU_material.h:108
@ GPU_MATFLAG_GLOSSY
Definition: GPU_material.h:110
@ GPU_MATFLAG_REFRACT
Definition: GPU_material.h:111
@ GPU_MATFLAG_BARYCENTRIC
Definition: GPU_material.h:113
@ GPU_MATFLAG_SSS
Definition: GPU_material.h:112
@ GPU_MATFLAG_DIFFUSE
Definition: GPU_material.h:109
ListBase GPU_material_textures(GPUMaterial *material)
Definition: gpu_material.c:577
GPUMaterial * GPU_material_from_nodetree(struct Scene *scene, struct Material *ma, struct bNodeTree *ntree, struct ListBase *gpumaterials, const void *engine_type, const int options, const bool is_volume_shader, const char *vert_code, const char *geom_code, const char *frag_lib, const char *defines, const char *name, GPUMaterialEvalCallbackFn callback)
Definition: gpu_material.c:670
struct Scene * GPU_material_scene(GPUMaterial *material)
Definition: gpu_material.c:202
struct GPUMaterialVolumeGrid GPUMaterialVolumeGrid
GPUNodeLink * GPU_constant(const float *num)
eGPUMaterialStatus GPU_material_status(GPUMaterial *mat)
Definition: gpu_material.c:619
bool GPU_material_is_volume_shader(GPUMaterial *mat)
Definition: gpu_material.c:636
eGPUBuiltin
Definition: GPU_material.h:86
@ GPU_WORLD_NORMAL
Definition: GPU_material.h:105
@ GPU_PARTICLE_ANG_VELOCITY
Definition: GPU_material.h:99
@ GPU_OBJECT_COLOR
Definition: GPU_material.h:93
@ GPU_VIEW_POSITION
Definition: GPU_material.h:91
@ GPU_BARYCENTRIC_TEXCO
Definition: GPU_material.h:103
@ GPU_INVERSE_OBJECT_MATRIX
Definition: GPU_material.h:90
@ GPU_OBJECT_MATRIX
Definition: GPU_material.h:88
@ GPU_INVERSE_VIEW_MATRIX
Definition: GPU_material.h:89
@ GPU_PARTICLE_SCALAR_PROPS
Definition: GPU_material.h:96
@ GPU_PARTICLE_VELOCITY
Definition: GPU_material.h:98
@ GPU_PARTICLE_LOCATION
Definition: GPU_material.h:97
@ GPU_CAMERA_TEXCO_FACTORS
Definition: GPU_material.h:95
@ GPU_AUTO_BUMPSCALE
Definition: GPU_material.h:94
@ GPU_OBJECT_INFO
Definition: GPU_material.h:102
@ GPU_INVERSE_LOC_TO_VIEW_MATRIX
Definition: GPU_material.h:101
@ GPU_LOC_TO_VIEW_MATRIX
Definition: GPU_material.h:100
@ GPU_VIEW_NORMAL
Definition: GPU_material.h:92
@ GPU_VIEW_MATRIX
Definition: GPU_material.h:87
@ GPU_BARYCENTRIC_DIST
Definition: GPU_material.h:104
GPUNodeLink * GPU_uniform(const float *num)
GPUNodeLink * GPU_image_tiled(GPUMaterial *mat, struct Image *ima, struct ImageUser *iuser, eGPUSamplerState sampler_state)
eGPUMaterialStatus
Definition: GPU_material.h:126
@ GPU_MAT_QUEUED
Definition: GPU_material.h:128
@ GPU_MAT_FAILED
Definition: GPU_material.h:127
@ GPU_MAT_SUCCESS
Definition: GPU_material.h:129
struct GPUUniformBuf * GPU_material_create_sss_profile_ubo(void)
Definition: gpu_material.c:564
GPUNodeLink * GPU_volume_grid(GPUMaterial *mat, const char *name, eGPUVolumeDefaultValue default_value)
struct GPUPass * GPU_material_get_pass(GPUMaterial *material)
Definition: gpu_material.c:207
void GPU_material_flag_set(GPUMaterial *mat, eGPUMatFlag flag)
Definition: gpu_material.c:641
void GPU_uniform_attr_list_free(GPUUniformAttrList *set)
struct Material * GPU_material_get_material(GPUMaterial *material)
Definition: gpu_material.c:218
ListBase GPU_material_volume_grids(GPUMaterial *material)
Definition: gpu_material.c:582
struct GPUUniformBuf * GPU_material_uniform_buffer_get(GPUMaterial *material)
Definition: gpu_material.c:223
struct GPUMaterialTexture GPUMaterialTexture
ListBase GPU_material_attributes(GPUMaterial *material)
Definition: gpu_material.c:572
eGPUType
Definition: GPU_material.h:59
@ GPU_ATTR
Definition: GPU_material.h:83
@ GPU_VEC2
Definition: GPU_material.h:64
@ GPU_MAT4
Definition: GPU_material.h:68
@ GPU_SHADOW2D
Definition: GPU_material.h:76
@ GPU_TEX1D_ARRAY
Definition: GPU_material.h:72
@ GPU_TEXCUBE
Definition: GPU_material.h:77
@ GPU_MAX_CONSTANT_DATA
Definition: GPU_material.h:69
@ GPU_TEX2D_ARRAY
Definition: GPU_material.h:74
@ GPU_TEX2D
Definition: GPU_material.h:73
@ GPU_VEC4
Definition: GPU_material.h:66
@ GPU_NONE
Definition: GPU_material.h:62
@ GPU_CLOSURE
Definition: GPU_material.h:80
@ GPU_VEC3
Definition: GPU_material.h:65
@ GPU_MAT3
Definition: GPU_material.h:67
@ GPU_TEX3D
Definition: GPU_material.h:75
@ GPU_FLOAT
Definition: GPU_material.h:63
void GPU_pass_cache_garbage_collect(void)
Definition: gpu_codegen.c:1068
GPUMaterial * GPU_material_from_nodetree_find(struct ListBase *gpumaterials, const void *engine_type, int options)
Definition: gpu_material.c:651
struct GPUUniformAttr GPUUniformAttr
struct GPUUniformBuf * GPU_material_sss_profile_get(GPUMaterial *material, int sample_len, struct GPUTexture **tex_profile)
Definition: gpu_material.c:519
void GPU_pass_cache_init(void)
Definition: gpu_codegen.c:1096
void GPU_material_sss_profile_create(GPUMaterial *material, float radii[3], const short *falloff_type, const float *sharpness)
Definition: gpu_material.c:502
eGPUVolumeDefaultValue
Definition: GPU_material.h:132
@ GPU_VOLUME_DEFAULT_0
Definition: GPU_material.h:133
@ GPU_VOLUME_DEFAULT_1
Definition: GPU_material.h:134
void GPU_material_uniform_buffer_create(GPUMaterial *material, ListBase *inputs)
Definition: gpu_material.c:233
bool GPU_link(GPUMaterial *mat, const char *name,...)
bool GPU_material_has_volume_output(GPUMaterial *mat)
Definition: gpu_material.c:631
bool GPU_material_flag_get(GPUMaterial *mat, eGPUMatFlag flag)
Definition: gpu_material.c:646
struct GPUNodeStack GPUNodeStack
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_uniformbuf_link_out(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *stack, const int index)
struct GPUShader GPUShader
Definition: GPU_shader.h:33
eGPUSamplerState
Definition: GPU_texture.h:40
struct GPUTexture GPUTexture
Definition: GPU_texture.h:33
struct GPUUniformBuf GPUUniformBuf
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
CCL_NAMESPACE_BEGIN struct Options options
OperationNode * node
Scene scene
Material material
DEGForeachIDComponentCallback callback
bNodeTree * ntree
static bNodeSocketTemplate inputs[]
#define hash
Definition: noise.c:169
struct GPUMaterialAttribute * prev
Definition: GPU_material.h:233
struct GPUMaterialAttribute * next
Definition: GPU_material.h:233
struct GPUMaterialTexture * prev
Definition: GPU_material.h:242
struct GPUMaterialTexture * next
Definition: GPU_material.h:242
struct ImageUser * iuser
Definition: GPU_material.h:244
struct Image * ima
Definition: GPU_material.h:243
char tiled_mapping_name[32]
Definition: GPU_material.h:247
struct GPUTexture ** colorband
Definition: GPU_material.h:245
struct GPUMaterialVolumeGrid * prev
Definition: GPU_material.h:253
struct GPUMaterialVolumeGrid * next
Definition: GPU_material.h:253
eGPUVolumeDefaultValue default_value
Definition: GPU_material.h:255
struct GPUNodeLink * link
Definition: GPU_material.h:119
eGPUType type
Definition: GPU_material.h:117
float vec[4]
Definition: GPU_material.h:118
short sockettype
Definition: GPU_material.h:122
unsigned int count
Definition: GPU_material.h:281
unsigned int hash_code
Definition: GPU_material.h:281
struct GPUUniformAttr * next
Definition: GPU_material.h:266
struct GPUUniformAttr * prev
Definition: GPU_material.h:266
Definition: BKE_main.h:116