Cleanup: quiet float argument to in type warning
[blender-addons.git] / render_povray / texturing.py
blobb8aa8afb12eefc7cd334683a9d23356eb6cef779
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 """Translate blender texture influences into POV."""
4 import os
5 import bpy
7 local_material_names = []
8 material_finish = None
11 def write_texture_influence(
12 file,
13 mater,
14 material_names_dictionary,
15 image_format,
16 img_map,
17 img_map_transforms,
18 tab_write,
19 comments,
20 col,
21 preview_dir,
22 unpacked_images,
24 """Translate Blender texture influences to various POV texture tricks and write to pov file."""
26 from .scenography import path_image, exported_lights_count
27 from .render import string_strip_hyphen, safety, using_uberpov
29 material_finish = material_names_dictionary[mater.name]
30 trans = 1.0 - mater.pov.alpha if mater.pov.use_transparency else 0.0
31 if (mater.pov.specular_color.s == 0.0) or (mater.pov.diffuse_shader == "MINNAERT"):
32 # No layered texture because of aoi pattern used for minnaert and pov can't layer patterned
33 colored_specular_found = False
34 else:
35 colored_specular_found = True
37 if mater.pov.use_transparency and mater.pov.transparency_method == "RAYTRACE":
38 pov_filter = mater.pov_raytrace_transparency.filter * (1.0 - mater.pov.alpha)
39 trans = (1.0 - mater.pov.alpha) - pov_filter
40 else:
41 pov_filter = 0.0
43 texture_dif = ""
44 texture_spec = ""
45 texture_norm = ""
46 texture_alpha = ""
47 # procedural_flag=False
48 tmpidx = -1
49 used_texture_slots = (tesl for tesl in mater.pov_texture_slots if tesl.use)
50 # and (bpy.data.textures[mater.pov_texture_slots[tmpidx-1].texture] is not None)
51 for t in used_texture_slots:
53 tmpidx += 1
54 # index = mater.pov.active_texture_index
55 slot = mater.pov_texture_slots[tmpidx] # [index]
56 povtex = slot.texture # slot.name
57 tex = bpy.data.textures[povtex]
58 if tex is None:
59 continue # move to next slot
60 # 'NONE' ('NONE' type texture is different from no texture covered above)
61 if tex.type == "NONE" and tex.pov.tex_pattern_type == "emulator":
62 continue # move to next slot
64 # Implicit else-if (as not skipped by previous "continue")
65 if tex.type not in ("IMAGE","NONE"):
66 # PROCEDURAL TEXTURE
67 image_filename = "PAT_%s" % string_strip_hyphen(bpy.path.clean_name(tex.name))
68 if image_filename:
69 if t.use_map_color_diffuse:
70 texture_dif = image_filename
71 # colvalue = t.default_value # UNUSED
72 t_dif = t
73 if t_dif.texture.pov.tex_gamma_enable:
74 img_gamma = " gamma %.3g " % t_dif.texture.pov.tex_gamma_value
75 if t.use_map_specular or t.use_map_raymir:
76 texture_spec = image_filename
77 # colvalue = t.default_value # UNUSED
78 t_spec = t
79 if t.use_map_normal:
80 texture_norm = image_filename
81 # colvalue = t.normal_factor/10 # UNUSED
82 # textNormName=tex.image.name + ".normal"
83 # was the above used? --MR
84 t_nor = t
85 if t.use_map_alpha:
86 texture_alpha = image_filename
87 # colvalue = t.alpha_factor * 10.0 # UNUSED
88 # textDispName=tex.image.name + ".displ"
89 # was the above used? --MR
90 t_alpha = t
91 # RASTER IMAGE
92 elif tex.type == "IMAGE" and tex.image and tex.pov.tex_pattern_type == "emulator":
93 # NOT A PROCEDURAL TEXTURE
94 # PACKED
95 if tex.image.packed_file:
96 orig_image_filename = tex.image.filepath_raw
97 unpackedfilename = os.path.join(
98 preview_dir,
99 ("unpacked_img_" + (string_strip_hyphen(bpy.path.clean_name(tex.name)))),
101 if not os.path.exists(unpackedfilename):
102 # record which images that were newly copied and can be safely
103 # cleaned up
104 unpacked_images.append(unpackedfilename)
105 tex.image.filepath_raw = unpackedfilename
106 tex.image.save()
107 image_filename = unpackedfilename.replace("\\", "/")
108 # .replace("\\","/") to get only forward slashes as it's what POV prefers,
109 # even on windows
110 tex.image.filepath_raw = orig_image_filename
111 # FILE
112 else:
113 image_filename = path_image(tex.image)
114 # IMAGE SEQUENCE BEGINS
115 if image_filename and bpy.data.images[tex.image.name].source == "SEQUENCE":
116 korvaa = "." + str(tex.image_user.frame_offset + 1).zfill(3) + "."
117 image_filename = image_filename.replace(".001.", korvaa)
118 print(" seq debug ")
119 print(image_filename)
120 # IMAGE SEQUENCE ENDS
121 img_gamma = ""
122 if image_filename:
123 texdata = bpy.data.textures[t.texture]
124 if t.use_map_color_diffuse:
125 texture_dif = image_filename
126 # colvalue = t.default_value # UNUSED
127 t_dif = t
128 print(texdata)
129 if texdata.pov.tex_gamma_enable:
130 img_gamma = " gamma %.3g " % t_dif.texture.pov.tex_gamma_value
131 if t.use_map_specular or t.use_map_raymir:
132 texture_spec = image_filename
133 # colvalue = t.default_value # UNUSED
134 t_spec = t
135 if t.use_map_normal:
136 texture_norm = image_filename
137 # colvalue = t.normal_factor/10 # UNUSED
138 # textNormName=tex.image.name + ".normal"
139 # was the above used? --MR
140 t_nor = t
141 if t.use_map_alpha:
142 texture_alpha = image_filename
143 # colvalue = t.alpha_factor * 10.0 # UNUSED
144 # textDispName=tex.image.name + ".displ"
145 # was the above used? --MR
146 t_alpha = t
148 # -----------------------------------------------------------------------------
150 tab_write(file, "\n")
151 # THIS AREA NEEDS TO LEAVE THE TEXTURE OPEN UNTIL ALL MAPS ARE WRITTEN DOWN.
153 current_material_name = string_strip_hyphen(material_names_dictionary[mater.name])
154 global local_material_names
155 local_material_names.append(current_material_name)
156 tab_write(file, "\n#declare MAT_%s = \ntexture{\n" % current_material_name)
157 # -----------------------------------------------------------------------------
159 if mater.pov.replacement_text:
160 tab_write(file, "%s\n" % mater.pov.replacement_text)
161 # -----------------------------------------------------------------------------
162 # XXX TODO: replace by new POV MINNAERT rather than aoi
163 if mater.pov.diffuse_shader == "MINNAERT":
164 tab_write(file, "\n")
165 tab_write(file, "aoi\n")
166 tab_write(file, "texture_map {\n")
167 tab_write(
168 file, "[%.3g finish {diffuse %.3g}]\n" % (mater.pov.darkness / 2.0,
169 2.0 - mater.pov.darkness)
171 tab_write(file, "[%.3g\n" % (1.0 - (mater.pov.darkness / 2.0)))
173 if mater.pov.diffuse_shader == "FRESNEL":
174 # For FRESNEL diffuse in POV, we'll layer slope patterned textures
175 # with lamp vector as the slope vector and nest one slope per lamp
176 # into each texture map's entry.
178 c = 1
179 while c <= exported_lights_count:
180 tab_write(file, "slope { lampTarget%s }\n" % c)
181 tab_write(file, "texture_map {\n")
182 # Diffuse Fresnel value and factor go up to five,
183 # other kind of values needed: used the number 5 below to remap
184 tab_write(
185 file,
186 "[%.3g finish {diffuse %.3g}]\n"
188 (5.0 - mater.pov.diffuse_fresnel) / 5,
189 (mater.pov.diffuse_intensity * ((5.0 - mater.pov.diffuse_fresnel_factor) / 5)),
192 tab_write(
193 file,
194 "[%.3g\n" % ((mater.pov.diffuse_fresnel_factor / 5) * (mater.pov.diffuse_fresnel / 5.0)),
196 c += 1
198 # if shader is a 'FRESNEL' or 'MINNAERT': slope pigment pattern or aoi
199 # and texture map above, the rest below as one of its entry
201 if texture_spec or texture_alpha:
202 if texture_spec:
203 # tab_write(file, "\n")
204 tab_write(file, "pigment_pattern {\n")
206 mapping_spec = img_map_transforms(t_spec)
207 if texture_spec and texture_spec.startswith("PAT_"):
208 tab_write(file, "function{f%s(x,y,z).grey}\n" % texture_spec)
209 else:
211 tab_write(
212 file,
213 'uv_mapping image_map{%s "%s" %s}\n'
214 % (image_format(texture_spec), texture_spec, img_map(t_spec)),
216 tab_write(file, "%s\n" % mapping_spec)
217 tab_write(file, "}\n")
218 tab_write(file, "texture_map {\n")
219 tab_write(file, "[0 \n")
221 if not texture_dif:
222 if texture_alpha:
223 tab_write(file, "\n")
225 mapping_alpha = img_map_transforms(t_alpha)
227 if texture_alpha and texture_alpha.startswith("PAT_"):
228 tab_write(
229 file, "function{f%s(x,y,z).transmit}%s\n" % (texture_alpha, mapping_alpha)
231 else:
233 tab_write(
234 file,
235 "pigment {pigment_pattern {uv_mapping image_map"
236 '{%s "%s" %s}%s'
238 image_format(texture_alpha),
239 texture_alpha,
240 img_map(t_alpha),
241 mapping_alpha,
244 tab_write(file, "}\n")
245 tab_write(file, "pigment_map {\n")
246 tab_write(file, "[0 color rgbft<0,0,0,1,1>]\n")
247 tab_write(
248 file,
249 "[1 color rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>]\n"
250 % (col[0], col[1], col[2], pov_filter, trans),
252 tab_write(file, "}\n")
253 tab_write(file, "}\n")
255 else:
257 tab_write(
258 file,
259 "pigment {rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>}\n"
260 % (col[0], col[1], col[2], pov_filter, trans),
263 else:
264 mapping_dif = img_map_transforms(t_dif)
266 if texture_alpha:
267 mapping_alpha = img_map_transforms(t_alpha)
269 tab_write(file, "pigment {\n")
270 tab_write(file, "pigment_pattern {\n")
271 if texture_alpha and texture_alpha.startswith("PAT_"):
272 tab_write(
273 file, "function{f%s(x,y,z).transmit}%s\n" % (texture_alpha, mapping_alpha)
275 else:
276 tab_write(
277 file,
278 'uv_mapping image_map{%s "%s" %s}%s}\n'
280 image_format(texture_alpha),
281 texture_alpha,
282 img_map(t_alpha),
283 mapping_alpha,
286 tab_write(file, "pigment_map {\n")
287 tab_write(file, "[0 color rgbft<0,0,0,1,1>]\n")
288 # if texture_alpha and texture_alpha.startswith("PAT_"):
289 # tab_write(file, "[1 pigment{%s}]\n" %texture_dif)
290 if texture_dif:
291 if not texture_dif.startswith("PAT_"):
292 tab_write(
293 file,
294 '[1 uv_mapping image_map {%s "%s" %s} %s]\n'
296 image_format(texture_dif),
297 texture_dif,
298 (img_gamma + img_map(t_dif)),
299 mapping_dif,
302 elif texture_dif.startswith("PAT_"):
303 tab_write(file, "[1 %s]\n" % texture_dif)
304 tab_write(file, "}\n")
305 tab_write(file, "}\n")
306 if texture_alpha and texture_alpha.startswith("PAT_"):
307 tab_write(file, "}\n")
309 else:
310 if texture_dif and texture_dif.startswith("PAT_"):
311 tab_write(file, "pigment{%s}\n" % texture_dif)
312 else:
313 tab_write(
314 file,
315 'pigment {uv_mapping image_map {%s "%s" %s}%s}\n'
317 image_format(texture_dif),
318 texture_dif,
319 (img_gamma + img_map(t_dif)),
320 mapping_dif,
324 # scale 1 rotate y*0
325 # imageMap = ("{image_map {%s \"%s\" %s }\n" % \
326 # (image_format(textures),textures,img_map(t_dif)))
327 # tab_write(file, "uv_mapping pigment %s} %s finish {%s}\n" % \
328 # (imageMap,mapping,safety(material_finish)))
329 # tab_write(file, "pigment {uv_mapping image_map {%s \"%s\" %s}%s} " \
330 # "finish {%s}\n" % \
331 # (image_format(texture_dif), texture_dif, img_map(t_dif),
332 # mapping_dif, safety(material_finish)))
333 if texture_spec:
334 # ref_level_bound 1 is no specular
335 tab_write(file, "finish {%s}\n" % (safety(material_finish, ref_level_bound=1)))
337 else:
338 # ref_level_bound 2 is translated spec
339 tab_write(file, "finish {%s}\n" % (safety(material_finish, ref_level_bound=2)))
341 if texture_norm:
342 # scale 1 rotate y*0
344 mapping_normal = img_map_transforms(t_nor)
346 if texture_norm and texture_norm.startswith("PAT_"):
347 tab_write(
348 file,
349 "normal{function{f%s(x,y,z).grey} bump_size %.4g %s}\n"
350 % (texture_norm, (-t_nor.normal_factor * 9.5), mapping_normal),
352 else:
353 tab_write(file, "normal {\n")
354 # XXX TODO: fix and propagate the micro normals reflection blur below
355 # to non textured materials
356 if (
357 mater.pov_raytrace_mirror.use
358 and mater.pov_raytrace_mirror.gloss_factor < 1.0
359 and not using_uberpov
361 tab_write(file, "average\n")
362 tab_write(file, "normal_map{\n")
363 # 0.5 for entries below means a 50 percent mix
364 # between the micro normal and user bump map
365 # order seems indifferent as commutative
366 tab_write(
367 file,
368 "[0.025 bumps %.4g scale 0.1*%.4g]\n"
370 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
371 (10 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
373 ) # micronormals blurring
374 tab_write(
375 file,
376 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.1]\n"
378 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
379 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
381 ) # micronormals blurring
382 tab_write(
383 file,
384 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.15]\n"
386 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
387 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
389 ) # micronormals blurring
390 tab_write(
391 file,
392 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.2]\n"
394 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
395 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
397 ) # micronormals blurring
398 tab_write(
399 file,
400 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.25]\n"
402 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
403 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
405 ) # micronormals blurring
406 tab_write(
407 file,
408 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.3]\n"
410 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
411 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
413 ) # micronormals blurring
414 tab_write(
415 file,
416 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.35]\n"
418 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
419 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
421 ) # micronormals blurring
422 tab_write(
423 file,
424 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.4]\n"
426 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
427 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
429 ) # micronormals blurring
430 tab_write(
431 file,
432 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.45]\n"
434 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
435 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
437 ) # micronormals blurring
438 tab_write(
439 file,
440 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.5]\n"
442 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
443 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
445 ) # micronormals blurring
446 tab_write(file, "[1.0 ") # Proceed with user bump...
447 tab_write(
448 file,
449 "uv_mapping bump_map "
450 '{%s "%s" %s bump_size %.4g }%s'
452 image_format(texture_norm),
453 texture_norm,
454 img_map(t_nor),
455 (-t_nor.normal_factor * 9.5),
456 mapping_normal,
459 # ...Then close its last entry and the the normal_map itself
460 if (
461 mater.pov_raytrace_mirror.use
462 and mater.pov_raytrace_mirror.gloss_factor < 1.0
463 and not using_uberpov
465 tab_write(file, r"]}}" + "\n")
466 else:
467 tab_write(file, r"}" + "\n")
468 if texture_spec:
469 tab_write(file, "]\n")
470 # -------- Second index for mapping specular max value -------- #
471 tab_write(file, "[1 \n")
473 if not texture_dif and not mater.pov.replacement_text:
474 if texture_alpha:
475 mapping_alpha = img_map_transforms(t_alpha)
477 if texture_alpha and texture_alpha.startswith("PAT_"):
478 tab_write(
479 file, "function{f%s(x,y,z).transmit %s}\n" % (texture_alpha, mapping_alpha)
481 else:
482 tab_write(
483 file,
484 "pigment {pigment_pattern {uv_mapping image_map"
485 '{%s "%s" %s}%s}\n'
486 % (image_format(texture_alpha), texture_alpha, img_map(t_alpha), mapping_alpha),
488 tab_write(file, "pigment_map {\n")
489 tab_write(file, "[0 color rgbft<0,0,0,1,1>]\n")
490 tab_write(
491 file,
492 "[1 color rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>]\n"
493 % (col[0], col[1], col[2], pov_filter, trans),
495 tab_write(file, "}\n")
496 tab_write(file, "}\n")
498 else:
499 tab_write(
500 file,
501 "pigment {rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>}\n"
502 % (col[0], col[1], col[2], pov_filter, trans),
505 if texture_spec:
506 # ref_level_bound 3 is full specular
507 tab_write(file, "finish {%s}\n" % (safety(material_finish, ref_level_bound=3)))
509 if (
510 mater.pov_raytrace_mirror.use
511 and mater.pov_raytrace_mirror.gloss_factor < 1
512 and not using_uberpov
514 tab_write(file, "normal {\n")
515 tab_write(file, "average\n")
516 tab_write(file, "normal_map{\n")
517 # 0.5 for entries below means a 50 percent mix
518 # between the micro normal and user bump map
519 # order seems indifferent as commutative
520 tab_write(
521 file,
522 "[0.025 bumps %.4g scale 0.1*%.4g]\n"
524 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
525 (10 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
527 ) # micronormals blurring
528 tab_write(
529 file,
530 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.1]\n"
532 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
533 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
535 ) # micronormals blurring
536 tab_write(
537 file,
538 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.15]\n"
540 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
541 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
543 ) # micronormals blurring
544 tab_write(
545 file,
546 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.2]\n"
548 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
549 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
551 ) # micronormals blurring
552 tab_write(
553 file,
554 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.25]\n"
556 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
557 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
559 ) # micronormals blurring
560 tab_write(
561 file,
562 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.3]\n"
564 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
565 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
567 ) # micronormals blurring
568 tab_write(
569 file,
570 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.35]\n"
572 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
573 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
575 ) # micronormals blurring
576 tab_write(
577 file,
578 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.4]\n"
580 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
581 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
583 ) # micronormals blurring
584 tab_write(
585 file,
586 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.45]\n"
588 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
589 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
591 ) # micronormals blurring
592 tab_write(
593 file,
594 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.5]\n"
596 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
597 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
599 ) # micronormals blurring
600 # XXX IF USER BUMP_MAP
601 if texture_norm:
602 tab_write(
603 file, "[1.0 "
604 ) # Blurry reflection or not Proceed with user bump in either case...
605 tab_write(
606 file,
607 "uv_mapping bump_map "
608 '{%s "%s" %s bump_size %.4g }%s\n'
610 image_format(texture_norm),
611 texture_norm,
612 img_map(t_nor),
613 (-t_nor.normal_factor * 9.5),
614 mapping_normal,
617 # ...Then close the normal_map itself if blurry reflection
618 if (
619 mater.pov_raytrace_mirror.use
620 and mater.pov_raytrace_mirror.gloss_factor < 1
621 and not using_uberpov
623 tab_write(file, "]\n}}\n")
624 else:
625 tab_write(file, "}\n")
626 elif colored_specular_found:
627 # ref_level_bound 1 is no specular
628 tab_write(file, "finish {%s}\n" % (safety(material_finish, ref_level_bound=1)))
630 else:
631 # ref_level_bound 2 is translated specular
632 tab_write(file, "finish {%s}\n" % (safety(material_finish, ref_level_bound=2)))
634 elif not mater.pov.replacement_text:
635 mapping_dif = img_map_transforms(t_dif)
637 if texture_alpha:
639 mapping_alpha = img_map_transforms(t_alpha)
641 if texture_alpha and texture_alpha.startswith("PAT_"):
642 tab_write(
643 file,
644 "pigment{pigment_pattern {function{f%s(x,y,z).transmit}%s}\n"
645 % (texture_alpha, mapping_alpha),
647 else:
648 tab_write(
649 file,
650 "pigment {pigment_pattern {uv_mapping image_map"
651 '{%s "%s" %s}%s}\n'
652 % (image_format(texture_alpha), texture_alpha, img_map(t_alpha), mapping_alpha),
654 tab_write(file, "pigment_map {\n")
655 tab_write(file, "[0 color rgbft<0,0,0,1,1>]\n")
656 if texture_alpha and texture_alpha.startswith("PAT_"):
657 tab_write(
658 file, "[1 function{f%s(x,y,z).transmit}%s]\n" % (texture_alpha, mapping_alpha)
660 elif texture_dif and not texture_dif.startswith("PAT_"):
661 tab_write(
662 file,
663 '[1 uv_mapping image_map {%s "%s" %s} %s]\n'
665 image_format(texture_dif),
666 texture_dif,
667 (img_map(t_dif) + img_gamma),
668 mapping_dif,
671 elif texture_dif and texture_dif.startswith("PAT_"):
672 tab_write(file, "[1 %s %s]\n" % (texture_dif, mapping_dif))
673 tab_write(file, "}\n")
674 tab_write(file, "}\n")
676 else:
677 if texture_dif and texture_dif.startswith("PAT_"):
678 tab_write(file, "pigment{%s %s}\n" % (texture_dif, mapping_dif))
679 else:
680 tab_write(file, "pigment {\n")
681 tab_write(file, "uv_mapping image_map {\n")
682 # tab_write(file, "%s \"%s\" %s}%s\n" % \
683 # (image_format(texture_dif), texture_dif,
684 # (img_gamma + img_map(t_dif)),mapping_dif))
685 tab_write(file, '%s "%s" \n' % (image_format(texture_dif), texture_dif))
686 tab_write(file, "%s\n" % (img_gamma + img_map(t_dif)))
687 tab_write(file, "}\n")
688 tab_write(file, "%s\n" % mapping_dif)
689 tab_write(file, "}\n")
691 if texture_spec:
692 # ref_level_bound 3 is full specular
693 tab_write(file, "finish {%s}\n" % (safety(material_finish, ref_level_bound=3)))
694 else:
695 # ref_level_bound 2 is translated specular
696 tab_write(file, "finish {%s}\n" % (safety(material_finish, ref_level_bound=2)))
698 # scale 1 rotate y*0
699 # imageMap = ("{image_map {%s \"%s\" %s }" % \
700 # (image_format(textures), textures,img_map(t_dif)))
701 # tab_write(file, "\n\t\t\tuv_mapping pigment %s} %s finish {%s}" % \
702 # (imageMap, mapping, safety(material_finish)))
703 # tab_write(file, "\n\t\t\tpigment {uv_mapping image_map " \
704 # "{%s \"%s\" %s}%s} finish {%s}" % \
705 # (image_format(texture_dif), texture_dif,img_map(t_dif),
706 # mapping_dif, safety(material_finish)))
707 if texture_norm and not mater.pov.replacement_text:
709 mapping_normal = img_map_transforms(t_nor)
711 if texture_norm and texture_norm.startswith("PAT_"):
712 tab_write(
713 file,
714 "normal{function{f%s(x,y,z).grey} bump_size %.4g %s}\n"
715 % (texture_norm, (-t_nor.normal_factor * 9.5), mapping_normal),
717 else:
718 tab_write(file, "normal {\n")
719 # XXX TODO: fix and propagate the micro normals reflection blur below
720 # to non textured materials
721 if (
722 mater.pov_raytrace_mirror.use
723 and mater.pov_raytrace_mirror.gloss_factor < 1.0
724 and not using_uberpov
726 tab_write(file, "average\n")
727 tab_write(file, "normal_map{\n")
728 # 0.5 for entries below means a 50 percent mix
729 # between the micro normal and user bump map
730 # order seems indifferent as commutative
731 tab_write(
732 file,
733 "[0.025 bumps %.4g scale 0.1*%.4g]\n"
735 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
736 (10 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
738 ) # micronormals blurring
739 tab_write(
740 file,
741 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.1]\n"
743 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
744 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
746 ) # micronormals blurring
747 tab_write(
748 file,
749 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.15]\n"
751 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
752 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
754 ) # micronormals blurring
755 tab_write(
756 file,
757 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.2]\n"
759 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
760 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
762 ) # micronormals blurring
763 tab_write(
764 file,
765 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.25]\n"
767 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
768 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
770 ) # micronormals blurring
771 tab_write(
772 file,
773 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.3]\n"
775 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
776 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
778 ) # micronormals blurring
779 tab_write(
780 file,
781 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.35]\n"
783 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
784 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
786 ) # micronormals blurring
787 tab_write(
788 file,
789 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.4]\n"
791 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
792 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
794 ) # micronormals blurring
795 tab_write(
796 file,
797 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.45]\n"
799 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
800 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
802 ) # micronormals blurring
803 tab_write(
804 file,
805 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.5]\n"
807 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
808 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
810 ) # micronormals blurring
811 tab_write(
812 file, "[1.0 "
813 ) # Blurry reflection or not Proceed with user bump in either case...
814 tab_write(
815 file,
816 "uv_mapping bump_map "
817 '{%s "%s" %s bump_size %.4g }%s\n'
819 image_format(texture_norm),
820 texture_norm,
821 img_map(t_nor),
822 (-t_nor.normal_factor * 9.5),
823 mapping_normal,
826 # ...Then close the normal_map itself if blurry reflection
827 if (
828 mater.pov_raytrace_mirror.use
829 and mater.pov_raytrace_mirror.gloss_factor < 1
830 and not using_uberpov
832 tab_write(file, "]}}\n")
833 else:
834 tab_write(file, "}\n")
835 if texture_spec and not mater.pov.replacement_text:
836 tab_write(file, "]\n")
838 tab_write(file, "}\n")
840 # End of slope/ior texture_map
841 if mater.pov.diffuse_shader == "MINNAERT" and not mater.pov.replacement_text:
842 tab_write(file, "]\n")
843 tab_write(file, "}\n")
844 if mater.pov.diffuse_shader == "FRESNEL" and not mater.pov.replacement_text:
845 c = 1
846 while c <= exported_lights_count:
847 tab_write(file, "]\n")
848 tab_write(file, "}\n")
849 c += 1
851 # Close first layer of POV "texture" (Blender material)
852 tab_write(file, "}\n")
854 colored_specular_found = bool(
855 (mater.pov.specular_color.s > 0) and (mater.pov.diffuse_shader != "MINNAERT")
858 # Write another layered texture using invisible diffuse and metallic trick
859 # to emulate colored specular highlights
860 special_texture_found = False
861 tmpidx = -1
862 for t in mater.pov_texture_slots:
863 tmpidx += 1
864 # index = mater.pov.active_texture_index
865 slot = mater.pov_texture_slots[tmpidx] # [index]
866 povtex = slot.texture # slot.name
867 tex = bpy.data.textures[povtex]
868 # Specular mapped textures would conflict with colored specular
869 # because POV can't layer over or under pigment patterned textures
870 special_texture_found = bool(
872 and t.use
873 and ((tex.type == "IMAGE" and tex.image) or tex.type != "IMAGE")
874 and (t.use_map_specular or t.use_map_raymir)
876 if colored_specular_found and not special_texture_found:
877 if comments:
878 tab_write(file, " // colored highlights with a stransparent metallic layer\n")
879 else:
880 tab_write(file, "\n")
882 tab_write(file, "texture {\n")
883 tab_write(
884 file,
885 "pigment {rgbft<%.3g, %.3g, %.3g, 0, 1>}\n"
887 mater.pov.specular_color[0],
888 mater.pov.specular_color[1],
889 mater.pov.specular_color[2],
892 tab_write(
893 file, "finish {%s}\n" % (safety(material_finish, ref_level_bound=2))
894 ) # ref_level_bound 2 is translated spec
896 texture_norm = ""
897 for t in mater.pov_texture_slots:
899 if tex.pov.tex_pattern_type != "emulator":
900 # PROCEDURAL TEXTURE
901 image_filename = string_strip_hyphen(bpy.path.clean_name(tex.name))
902 if (
903 tex.type == "IMAGE"
904 and t.use
905 and tex.image
906 and tex.pov.tex_pattern_type == "emulator"
908 procedural_flag = False
909 image_filename = path_image(tex.image)
910 img_gamma = ""
911 if image_filename and t.use_map_normal:
912 texture_norm = image_filename
913 # colvalue = t.normal_factor/10 # UNUSED XXX *-9.5 !
914 # textNormName=tex.image.name + ".normal"
915 # was the above used? --MR
916 t_nor = t
917 if procedural_flag:
918 tab_write(
919 file,
920 "normal{function"
921 "{f%s(x,y,z).grey} bump_size %.4g}\n"
922 % (texture_norm, (-t_nor.normal_factor * 9.5)),
924 else:
925 tab_write(
926 file,
927 "normal {uv_mapping bump_map "
928 '{%s "%s" %s bump_size %.4g }%s}\n'
930 image_format(texture_norm),
931 texture_norm,
932 img_map(t_nor),
933 (-t_nor.normal_factor * 9.5),
934 mapping_normal,
938 tab_write(file, "}\n") # THEN IT CAN CLOSE LAST LAYER OF TEXTURE