GPUShaderCreateInfo: Add optionnal check for optimized out resources
[blender.git] / source / blender / render / RE_bake.h
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) 2010 Blender Foundation.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup render
22  */
23
24 #pragma once
25
26 struct Depsgraph;
27 struct ImBuf;
28 struct MLoopUV;
29 struct Mesh;
30 struct Render;
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 typedef struct BakeImage {
37   struct Image *image;
38   int width;
39   int height;
40   size_t offset;
41 } BakeImage;
42
43 typedef struct BakeTargets {
44   /* All images of the object. */
45   BakeImage *images;
46   int num_images;
47
48   /* Lookup table from Material number to BakeImage. */
49   int *material_to_image;
50   int num_materials;
51
52   /* Pixel buffer to bake to. */
53   float *result;
54   int num_pixels;
55   int num_channels;
56
57   /* Baking to non-color data image. */
58   bool is_noncolor;
59 } BakeTargets;
60
61 typedef struct BakePixel {
62   int primitive_id, object_id;
63   int seed;
64   float uv[2];
65   float du_dx, du_dy;
66   float dv_dx, dv_dy;
67 } BakePixel;
68
69 typedef struct BakeHighPolyData {
70   struct Object *ob;
71   struct Object *ob_eval;
72   struct Mesh *me;
73   bool is_flip_object;
74
75   float obmat[4][4];
76   float imat[4][4];
77 } BakeHighPolyData;
78
79 /* external_engine.c */
80 bool RE_bake_has_engine(const struct Render *re);
81
82 bool RE_bake_engine(struct Render *re,
83                     struct Depsgraph *depsgraph,
84                     struct Object *object,
85                     int object_id,
86                     const BakePixel pixel_array[],
87                     const BakeTargets *targets,
88                     eScenePassType pass_type,
89                     int pass_filter,
90                     float result[]);
91
92 /* bake.c */
93 int RE_pass_depth(eScenePassType pass_type);
94
95 bool RE_bake_pixels_populate_from_objects(struct Mesh *me_low,
96                                           BakePixel pixel_array_from[],
97                                           BakePixel pixel_array_to[],
98                                           BakeHighPolyData highpoly[],
99                                           int tot_highpoly,
100                                           size_t num_pixels,
101                                           bool is_custom_cage,
102                                           float cage_extrusion,
103                                           float max_ray_distance,
104                                           float mat_low[4][4],
105                                           float mat_cage[4][4],
106                                           struct Mesh *me_cage);
107
108 void RE_bake_pixels_populate(struct Mesh *me,
109                              struct BakePixel *pixel_array,
110                              size_t num_pixels,
111                              const struct BakeTargets *targets,
112                              const char *uv_layer);
113
114 void RE_bake_mask_fill(const BakePixel pixel_array[], size_t num_pixels, char *mask);
115
116 void RE_bake_margin(struct ImBuf *ibuf,
117                     char *mask,
118                     int margin,
119                     char margin_type,
120                     struct Mesh const *me,
121                     char const *uv_layer);
122
123 void RE_bake_normal_world_to_object(const BakePixel pixel_array[],
124                                     size_t num_pixels,
125                                     int depth,
126                                     float result[],
127                                     struct Object *ob,
128                                     const eBakeNormalSwizzle normal_swizzle[3]);
129 /**
130  * This function converts an object space normal map
131  * to a tangent space normal map for a given low poly mesh.
132  */
133 void RE_bake_normal_world_to_tangent(const BakePixel pixel_array[],
134                                      size_t num_pixels,
135                                      int depth,
136                                      float result[],
137                                      struct Mesh *me,
138                                      const eBakeNormalSwizzle normal_swizzle[3],
139                                      float mat[4][4]);
140 void RE_bake_normal_world_to_world(const BakePixel pixel_array[],
141                                    size_t num_pixels,
142                                    int depth,
143                                    float result[],
144                                    const eBakeNormalSwizzle normal_swizzle[3]);
145
146 void RE_bake_ibuf_clear(struct Image *image, bool is_tangent);
147
148 #ifdef __cplusplus
149 }
150 #endif