1 #pragma once 2 /**************************************************************************** 3 * 4 * renderpasses.h: Render Passes functionality 5 * This is part of the yafray package 6 * Copyright (C) 2015 David Bluecame 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * 22 */ 23 24 #ifndef Y_RENDERPASSES_H 25 #define Y_RENDERPASSES_H 26 27 #include <yafray_constants.h> 28 #include <iostream> 29 #include <vector> 30 #include <string> 31 #include <map> 32 33 __BEGIN_YAFRAY 34 35 class color_t; 36 class colorA_t; 37 38 enum extPassTypes_t : int 39 { 40 PASS_EXT_DISABLED = -1, 41 PASS_EXT_COMBINED = 0, 42 PASS_EXT_Z_DEPTH, //From here, specific ext.passes for Blender Exporter 43 PASS_EXT_VECTOR, 44 PASS_EXT_NORMAL, 45 PASS_EXT_UV, 46 PASS_EXT_COLOR, 47 PASS_EXT_EMIT, 48 PASS_EXT_MIST, 49 PASS_EXT_DIFFUSE, 50 PASS_EXT_SPECULAR, 51 PASS_EXT_AO, 52 PASS_EXT_ENV, 53 PASS_EXT_INDIRECT, 54 PASS_EXT_SHADOW, 55 PASS_EXT_REFLECT, 56 PASS_EXT_REFRACT, 57 PASS_EXT_OBJ_INDEX, 58 PASS_EXT_MAT_INDEX, 59 PASS_EXT_DIFFUSE_DIRECT, 60 PASS_EXT_DIFFUSE_INDIRECT, 61 PASS_EXT_DIFFUSE_COLOR, 62 PASS_EXT_GLOSSY_DIRECT, 63 PASS_EXT_GLOSSY_INDIRECT, 64 PASS_EXT_GLOSSY_COLOR, 65 PASS_EXT_TRANS_DIRECT, 66 PASS_EXT_TRANS_INDIRECT, 67 PASS_EXT_TRANS_COLOR, 68 PASS_EXT_SUBSURFACE_DIRECT, 69 PASS_EXT_SUBSURFACE_INDIRECT, 70 PASS_EXT_SUBSURFACE_COLOR, 71 PASS_EXT_1, //From here, generic ext.passes for other exporters and plugins 72 PASS_EXT_2, 73 PASS_EXT_3, 74 PASS_EXT_4, 75 PASS_EXT_5, 76 PASS_EXT_6, 77 PASS_EXT_7, 78 PASS_EXT_8, 79 PASS_EXT_9, 80 PASS_EXT_10, 81 PASS_EXT_11, 82 PASS_EXT_12, 83 PASS_EXT_13, 84 PASS_EXT_14, 85 PASS_EXT_15, 86 PASS_EXT_16, 87 PASS_EXT_17, 88 PASS_EXT_18, 89 PASS_EXT_19, 90 PASS_EXT_20, 91 PASS_EXT_21, 92 PASS_EXT_22, 93 PASS_EXT_23, 94 PASS_EXT_24, 95 PASS_EXT_25, 96 PASS_EXT_26, 97 PASS_EXT_27, 98 PASS_EXT_28, 99 PASS_EXT_29, 100 PASS_EXT_30, 101 PASS_EXT_31, 102 PASS_EXT_32, 103 PASS_EXT_TOTAL_PASSES //IMPORTANT: KEEP THIS ALWAYS IN THE LAST POSITION 104 }; 105 106 enum externalPassTileTypes_t : int 107 { 108 PASS_EXT_TILE_1_GRAYSCALE = 1, 109 PASS_EXT_TILE_3_RGB = 3, 110 PASS_EXT_TILE_4_RGBA = 4 111 }; 112 113 enum intPassTypes_t : int 114 { 115 PASS_INT_DISABLED = -1, 116 PASS_INT_COMBINED = 0, 117 PASS_INT_Z_DEPTH_NORM, 118 PASS_INT_Z_DEPTH_ABS, 119 PASS_INT_NORMAL_SMOOTH, 120 PASS_INT_NORMAL_GEOM, 121 PASS_INT_UV, 122 PASS_INT_RADIANCE, 123 PASS_INT_EMIT, 124 PASS_INT_DIFFUSE, 125 PASS_INT_DIFFUSE_NO_SHADOW, 126 PASS_INT_AO, 127 PASS_INT_AO_CLAY, 128 PASS_INT_ENV, 129 PASS_INT_MIST, 130 PASS_INT_INDIRECT, 131 PASS_INT_INDIRECT_ALL, 132 PASS_INT_SHADOW, 133 PASS_INT_REFLECT_PERFECT, 134 PASS_INT_REFRACT_PERFECT, 135 PASS_INT_REFLECT_ALL, 136 PASS_INT_REFRACT_ALL, 137 PASS_INT_OBJ_INDEX_ABS, 138 PASS_INT_OBJ_INDEX_NORM, 139 PASS_INT_OBJ_INDEX_AUTO, 140 PASS_INT_OBJ_INDEX_AUTO_ABS, 141 PASS_INT_MAT_INDEX_ABS, 142 PASS_INT_MAT_INDEX_NORM, 143 PASS_INT_MAT_INDEX_AUTO, 144 PASS_INT_MAT_INDEX_AUTO_ABS, 145 PASS_INT_OBJ_INDEX_MASK, 146 PASS_INT_OBJ_INDEX_MASK_SHADOW, 147 PASS_INT_OBJ_INDEX_MASK_ALL, 148 PASS_INT_MAT_INDEX_MASK, 149 PASS_INT_MAT_INDEX_MASK_SHADOW, 150 PASS_INT_MAT_INDEX_MASK_ALL, 151 PASS_INT_DIFFUSE_INDIRECT, 152 PASS_INT_DIFFUSE_COLOR, 153 PASS_INT_GLOSSY, 154 PASS_INT_GLOSSY_INDIRECT, 155 PASS_INT_GLOSSY_COLOR, 156 PASS_INT_TRANS, 157 PASS_INT_TRANS_INDIRECT, 158 PASS_INT_TRANS_COLOR, 159 PASS_INT_SUBSURFACE, 160 PASS_INT_SUBSURFACE_INDIRECT, 161 PASS_INT_SUBSURFACE_COLOR, 162 PASS_INT_SURFACE_INTEGRATION, 163 PASS_INT_VOLUME_INTEGRATION, 164 PASS_INT_VOLUME_TRANSMITTANCE, 165 PASS_INT_DEBUG_NU, 166 PASS_INT_DEBUG_NV, 167 PASS_INT_DEBUG_DPDU, 168 PASS_INT_DEBUG_DPDV, 169 PASS_INT_DEBUG_DSDU, 170 PASS_INT_DEBUG_DSDV, 171 PASS_INT_AA_SAMPLES, 172 PASS_INT_DEBUG_LIGHT_ESTIMATION_LIGHT_DIRAC, 173 PASS_INT_DEBUG_LIGHT_ESTIMATION_LIGHT_SAMPLING, 174 PASS_INT_DEBUG_LIGHT_ESTIMATION_MAT_SAMPLING, 175 PASS_INT_DEBUG_WIREFRAME, 176 PASS_INT_DEBUG_FACES_EDGES, 177 PASS_INT_DEBUG_OBJECTS_EDGES, 178 PASS_INT_TOON, 179 PASS_INT_DEBUG_SAMPLING_FACTOR, 180 PASS_INT_DEBUG_DP_LENGTHS, 181 PASS_INT_DEBUG_DPDX, 182 PASS_INT_DEBUG_DPDY, 183 PASS_INT_DEBUG_DPDXY, 184 PASS_INT_DEBUG_DUDX_DVDX, 185 PASS_INT_DEBUG_DUDY_DVDY, 186 PASS_INT_DEBUG_DUDXY_DVDXY, 187 PASS_INT_TOTAL_PASSES //IMPORTANT: KEEP THIS ALWAYS IN THE LAST POSITION 188 }; 189 190 191 192 class YAFRAYCORE_EXPORT extPass_t //Render pass to be exported, for example, to Blender, and mapping to the internal YafaRay render passes generated in different points of the rendering process 193 { 194 public: 195 extPass_t(extPassTypes_t extPassType, intPassTypes_t intPassType); 196 extPassTypes_t extPassType; 197 externalPassTileTypes_t tileType; 198 intPassTypes_t intPassType; 199 }; 200 201 202 class YAFRAYCORE_EXPORT auxPass_t //Render pass to be used internally only, without exporting to images/Blender and mapping to the internal YafaRay render passes generated in different points of the rendering process 203 { 204 public: 205 auxPass_t(intPassTypes_t intPassType); 206 intPassTypes_t intPassType; 207 }; 208 209 210 class YAFRAYCORE_EXPORT renderPasses_t 211 { 212 friend class colorPasses_t; 213 214 public: 215 renderPasses_t(); 216 int extPassesSize() const; 217 int auxPassesSize() const; 218 int intPassesSize() const; 219 void generate_pass_maps(); //Generate text strings <-> pass type maps pass_enabled(intPassTypes_t intPassType)220 bool pass_enabled(intPassTypes_t intPassType) const { return indexIntPasses[intPassType] != PASS_INT_DISABLED; } 221 void extPass_add(const std::string& sExternalPass, const std::string& sInternalPass); //Adds a new External Pass associated to an internal pass. Strings are used as parameters and they must match the strings in the maps generated by generate_pass_maps() 222 void auxPass_add(intPassTypes_t intPassType); //Adds a new Auxiliary Pass associated to an internal pass. Strings are used as parameters and they must match the strings in the maps generated by generate_pass_maps() 223 void intPass_add(intPassTypes_t intPassType); 224 void auxPasses_generate(); 225 226 extPassTypes_t extPassTypeFromIndex(int extPassIndex) const; 227 intPassTypes_t intPassTypeFromIndex(int intPassIndex) const; 228 std::string extPassTypeStringFromIndex(int extPassIndex) const; 229 std::string extPassTypeStringFromType(extPassTypes_t extPassType) const; 230 std::string intPassTypeStringFromType(intPassTypes_t intPassType) const; 231 extPassTypes_t extPassTypeFromString(std::string extPassTypeString) const; 232 intPassTypes_t intPassTypeFromString(std::string intPassTypeString) const; 233 int extPassIndexFromType(extPassTypes_t extPassType) const; 234 int intPassIndexFromType(intPassTypes_t intPassType) const; 235 intPassTypes_t intPassTypeFromExtPassIndex(int extPassIndex) const; 236 intPassTypes_t intPassTypeFromAuxPassIndex(int auxPassIndex) const; 237 externalPassTileTypes_t tileType(int extPassIndex) const; 238 239 void set_pass_mask_obj_index(float new_obj_index); //Object Index used for masking in/out in the Mask Render Passes 240 void set_pass_mask_mat_index(float new_mat_index); //Material Index used for masking in/out in the Mask Render Passes 241 void set_pass_mask_invert(bool mask_invert); //False=mask in, True=mask out 242 void set_pass_mask_only(bool mask_only); 243 244 std::map<extPassTypes_t, std::string> extPassMapIntString; //Map int-string for external passes 245 std::map<std::string, extPassTypes_t> extPassMapStringInt; //Reverse map string-int for external passes 246 std::map<intPassTypes_t, std::string> intPassMapIntString; //Map int-string for internal passes 247 std::map<std::string, intPassTypes_t> intPassMapStringInt; //Reverse map string-int for internal passes 248 std::vector<std::string> view_names; //Render Views names 249 250 //Options for Edge detection and Toon Render Pass 251 std::vector<float> toonEdgeColor = std::vector<float> (3, 0.f); //Color of the edges used in the Toon Render Pass 252 int objectEdgeThickness = 2; //Thickness of the edges used in the Object Edge and Toon Render Passes 253 float objectEdgeThreshold = 0.3f; //Threshold for the edge detection process used in the Object Edge and Toon Render Passes 254 float objectEdgeSmoothness = 0.75f; //Smoothness (blur) of the edges used in the Object Edge and Toon Render Passes 255 float toonPreSmooth = 3.f; //Toon effect: smoothness applied to the original image 256 float toonQuantization = 0.1f; //Toon effect: color Quantization applied to the original image 257 float toonPostSmooth = 3.f; //Toon effect: smoothness applied after Quantization 258 259 int facesEdgeThickness = 1; //Thickness of the edges used in the Faces Edge Render Pass 260 float facesEdgeThreshold = 0.01f; //Threshold for the edge detection process used in the Faces Edge Render Pass 261 float facesEdgeSmoothness = 0.5f; //Smoothness (blur) of the edges used in the Faces Edge Render Pass 262 263 protected: 264 std::vector<extPass_t> extPasses; //List of the external Render passes to be exported 265 std::vector<auxPass_t> auxPasses; //List of the intermediate auxiliary Render passes used for other operations 266 std::vector<intPassTypes_t> intPasses; //List of the internal passes to be generated by the YafaRay engine 267 std::vector<int> indexExtPasses; //List with all possible external passes and to which pass index are they mapped. -1 = pass disabled 268 std::vector<int> indexIntPasses; //List with all possible internal passes and to which pass index are they mapped. -1 = pass disabled 269 270 float pass_mask_obj_index; //Object Index used for masking in/out in the Mask Render Passes 271 float pass_mask_mat_index; //Material Index used for masking in/out in the Mask Render Passes 272 bool pass_mask_invert; //False=mask in, True=mask out 273 bool pass_mask_only; //False=rendered image is masked, True=only the mask is shown without rendered image 274 }; 275 276 277 class YAFRAYCORE_EXPORT colorPasses_t //Internal YafaRay color passes generated in different points of the rendering process 278 { 279 public: 280 colorPasses_t(const renderPasses_t *renderPasses); 281 int size() const; 282 bool enabled(intPassTypes_t intPassType) const; 283 intPassTypes_t intPassTypeFromIndex(int intPassIndex) const; 284 colorA_t& color(int intPassIndex); 285 colorA_t& color(intPassTypes_t intPassType); 286 colorA_t& operator()(int intPassIndex); 287 colorA_t& operator()(intPassTypes_t intPassType); 288 void reset_colors(); 289 colorA_t init_color(intPassTypes_t intPassType); 290 void multiply_colors(float factor); 291 colorA_t probe_set(const intPassTypes_t& intPassType, const colorA_t& renderedColor, const bool& condition = true); 292 colorA_t probe_set(const intPassTypes_t& intPassType, const colorPasses_t& colorPasses, const bool& condition = true); 293 colorA_t probe_add(const intPassTypes_t& intPassType, const colorA_t& renderedColor, const bool& condition = true); 294 colorA_t probe_add(const intPassTypes_t& intPassType, const colorPasses_t& colorPasses, const bool& condition = true); 295 colorA_t probe_mult(const intPassTypes_t& intPassType, const colorA_t& renderedColor, const bool& condition = true); 296 colorA_t probe_mult(const intPassTypes_t& intPassType, const colorPasses_t& colorPasses, const bool& condition = true); 297 298 colorPasses_t & operator *= (float f); 299 colorPasses_t & operator *= (const color_t &a); 300 colorPasses_t & operator *= (const colorA_t &a); 301 colorPasses_t & operator += (const colorPasses_t &a); 302 303 float get_pass_mask_obj_index() const; //Object Index used for masking in/out in the Mask Render Passes 304 float get_pass_mask_mat_index() const; //Material Index used for masking in/out in the Mask Render Passes 305 bool get_pass_mask_invert() const; //False=mask in, True=mask out 306 bool get_pass_mask_only() const; 307 308 protected: 309 std::vector <colorA_t> colVector; 310 const renderPasses_t *passDefinitions; 311 }; 312 313 __END_YAFRAY 314 315 #endif // Y_RENDERPASSES_H 316