Export_3ds: Improved distance cue node search
[blender-addons.git] / render_povray / texturing.py
blobf8c403ba75ee5b3e1f461716db2fe9f1695067d8
1 # SPDX-FileCopyrightText: 2021-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 """Translate blender texture influences into POV."""
6 import os
7 import bpy
9 local_material_names = []
10 material_finish = None
13 def write_texture_influence(
14 file,
15 mater,
16 material_names_dictionary,
17 image_format,
18 img_map,
19 img_map_transforms,
20 tab_write,
21 comments,
22 col,
23 preview_dir,
24 unpacked_images,
26 """Translate Blender texture influences to various POV texture tricks and write to pov file."""
28 from .scenography import path_image, exported_lights_count
29 from .render import string_strip_hyphen, safety, using_uberpov
31 material_finish = material_names_dictionary[mater.name]
32 trans = 1.0 - mater.pov.alpha if mater.pov.use_transparency else 0.0
33 if (mater.pov.specular_color.s == 0.0) or (mater.pov.diffuse_shader == "MINNAERT"):
34 # No layered texture because of aoi pattern used for minnaert and pov can't layer patterned
35 colored_specular_found = False
36 else:
37 colored_specular_found = True
39 if mater.pov.use_transparency and mater.pov.transparency_method == "RAYTRACE":
40 pov_filter = mater.pov_raytrace_transparency.filter * (1.0 - mater.pov.alpha)
41 trans = (1.0 - mater.pov.alpha) - pov_filter
42 else:
43 pov_filter = 0.0
45 texture_dif = ""
46 texture_spec = ""
47 texture_norm = ""
48 texture_alpha = ""
49 # procedural_flag=False
50 tmpidx = -1
51 used_texture_slots = (tesl for tesl in mater.pov_texture_slots if tesl.use)
52 # and (bpy.data.textures[mater.pov_texture_slots[tmpidx-1].texture] is not None)
53 for t in used_texture_slots:
55 tmpidx += 1
56 # index = mater.pov.active_texture_index
57 slot = mater.pov_texture_slots[tmpidx] # [index]
58 povtex = slot.texture # slot.name
59 tex = bpy.data.textures[povtex]
60 if tex is None:
61 continue # move to next slot
62 # 'NONE' ('NONE' type texture is different from no texture covered above)
63 if tex.type == "NONE" and tex.pov.tex_pattern_type == "emulator":
64 continue # move to next slot
66 # Implicit else-if (as not skipped by previous "continue")
67 if tex.type not in ("IMAGE","NONE"):
68 # PROCEDURAL TEXTURE
69 image_filename = "PAT_%s" % string_strip_hyphen(bpy.path.clean_name(tex.name))
70 if image_filename:
71 if t.use_map_color_diffuse:
72 texture_dif = image_filename
73 # colvalue = t.default_value # UNUSED
74 t_dif = t
75 if t_dif.texture.pov.tex_gamma_enable:
76 img_gamma = " gamma %.3g " % t_dif.texture.pov.tex_gamma_value
77 if t.use_map_specular or t.use_map_raymir:
78 texture_spec = image_filename
79 # colvalue = t.default_value # UNUSED
80 t_spec = t
81 if t.use_map_normal:
82 texture_norm = image_filename
83 # colvalue = t.normal_factor/10 # UNUSED
84 # textNormName=tex.image.name + ".normal"
85 # was the above used? --MR
86 t_nor = t
87 if t.use_map_alpha:
88 texture_alpha = image_filename
89 # colvalue = t.alpha_factor * 10.0 # UNUSED
90 # textDispName=tex.image.name + ".displ"
91 # was the above used? --MR
92 t_alpha = t
93 # RASTER IMAGE
94 elif tex.type == "IMAGE" and tex.image and tex.pov.tex_pattern_type == "emulator":
95 # NOT A PROCEDURAL TEXTURE
96 # PACKED
97 if tex.image.packed_file:
98 orig_image_filename = tex.image.filepath_raw
99 unpackedfilename = os.path.join(
100 preview_dir,
101 ("unpacked_img_" + (string_strip_hyphen(bpy.path.clean_name(tex.name)))),
103 if not os.path.exists(unpackedfilename):
104 # record which images that were newly copied and can be safely
105 # cleaned up
106 unpacked_images.append(unpackedfilename)
107 tex.image.filepath_raw = unpackedfilename
108 tex.image.save()
109 image_filename = unpackedfilename.replace("\\", "/")
110 # .replace("\\","/") to get only forward slashes as it's what POV prefers,
111 # even on windows
112 tex.image.filepath_raw = orig_image_filename
113 # FILE
114 else:
115 image_filename = path_image(tex.image)
116 # IMAGE SEQUENCE BEGINS
117 if image_filename and bpy.data.images[tex.image.name].source == "SEQUENCE":
118 korvaa = "." + str(tex.image_user.frame_offset + 1).zfill(3) + "."
119 image_filename = image_filename.replace(".001.", korvaa)
120 print(" seq debug ")
121 print(image_filename)
122 # IMAGE SEQUENCE ENDS
123 img_gamma = ""
124 if image_filename:
125 texdata = bpy.data.textures[t.texture]
126 if t.use_map_color_diffuse:
127 texture_dif = image_filename
128 # colvalue = t.default_value # UNUSED
129 t_dif = t
130 print(texdata)
131 if texdata.pov.tex_gamma_enable:
132 img_gamma = " gamma %.3g " % t_dif.texture.pov.tex_gamma_value
133 if t.use_map_specular or t.use_map_raymir:
134 texture_spec = image_filename
135 # colvalue = t.default_value # UNUSED
136 t_spec = t
137 if t.use_map_normal:
138 texture_norm = image_filename
139 # colvalue = t.normal_factor/10 # UNUSED
140 # textNormName=tex.image.name + ".normal"
141 # was the above used? --MR
142 t_nor = t
143 if t.use_map_alpha:
144 texture_alpha = image_filename
145 # colvalue = t.alpha_factor * 10.0 # UNUSED
146 # textDispName=tex.image.name + ".displ"
147 # was the above used? --MR
148 t_alpha = t
150 # -----------------------------------------------------------------------------
152 tab_write(file, "\n")
153 # THIS AREA NEEDS TO LEAVE THE TEXTURE OPEN UNTIL ALL MAPS ARE WRITTEN DOWN.
155 current_material_name = string_strip_hyphen(material_names_dictionary[mater.name])
156 global local_material_names
157 local_material_names.append(current_material_name)
158 tab_write(file, "\n#declare MAT_%s = \ntexture{\n" % current_material_name)
159 # -----------------------------------------------------------------------------
161 if mater.pov.replacement_text:
162 tab_write(file, "%s\n" % mater.pov.replacement_text)
163 # -----------------------------------------------------------------------------
164 # XXX TODO: replace by new POV MINNAERT rather than aoi
165 if mater.pov.diffuse_shader == "MINNAERT":
166 tab_write(file, "\n")
167 tab_write(file, "aoi\n")
168 tab_write(file, "texture_map {\n")
169 tab_write(
170 file, "[%.3g finish {diffuse %.3g}]\n" % (mater.pov.darkness / 2.0,
171 2.0 - mater.pov.darkness)
173 tab_write(file, "[%.3g\n" % (1.0 - (mater.pov.darkness / 2.0)))
175 if mater.pov.diffuse_shader == "FRESNEL":
176 # For FRESNEL diffuse in POV, we'll layer slope patterned textures
177 # with lamp vector as the slope vector and nest one slope per lamp
178 # into each texture map's entry.
180 c = 1
181 while c <= exported_lights_count:
182 tab_write(file, "slope { lampTarget%s }\n" % c)
183 tab_write(file, "texture_map {\n")
184 # Diffuse Fresnel value and factor go up to five,
185 # other kind of values needed: used the number 5 below to remap
186 tab_write(
187 file,
188 "[%.3g finish {diffuse %.3g}]\n"
190 (5.0 - mater.pov.diffuse_fresnel) / 5,
191 (mater.pov.diffuse_intensity * ((5.0 - mater.pov.diffuse_fresnel_factor) / 5)),
194 tab_write(
195 file,
196 "[%.3g\n" % ((mater.pov.diffuse_fresnel_factor / 5) * (mater.pov.diffuse_fresnel / 5.0)),
198 c += 1
200 # if shader is a 'FRESNEL' or 'MINNAERT': slope pigment pattern or aoi
201 # and texture map above, the rest below as one of its entry
203 if texture_spec or texture_alpha:
204 if texture_spec:
205 # tab_write(file, "\n")
206 tab_write(file, "pigment_pattern {\n")
208 mapping_spec = img_map_transforms(t_spec)
209 if texture_spec and texture_spec.startswith("PAT_"):
210 tab_write(file, "function{f%s(x,y,z).grey}\n" % texture_spec)
211 else:
213 tab_write(
214 file,
215 'uv_mapping image_map{%s "%s" %s}\n'
216 % (image_format(texture_spec), texture_spec, img_map(t_spec)),
218 tab_write(file, "%s\n" % mapping_spec)
219 tab_write(file, "}\n")
220 tab_write(file, "texture_map {\n")
221 tab_write(file, "[0 \n")
223 if not texture_dif:
224 if texture_alpha:
225 tab_write(file, "\n")
227 mapping_alpha = img_map_transforms(t_alpha)
229 if texture_alpha and texture_alpha.startswith("PAT_"):
230 tab_write(
231 file, "function{f%s(x,y,z).transmit}%s\n" % (texture_alpha, mapping_alpha)
233 else:
235 tab_write(
236 file,
237 "pigment {pigment_pattern {uv_mapping image_map"
238 '{%s "%s" %s}%s'
240 image_format(texture_alpha),
241 texture_alpha,
242 img_map(t_alpha),
243 mapping_alpha,
246 tab_write(file, "}\n")
247 tab_write(file, "pigment_map {\n")
248 tab_write(file, "[0 color rgbft<0,0,0,1,1>]\n")
249 tab_write(
250 file,
251 "[1 color rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>]\n"
252 % (col[0], col[1], col[2], pov_filter, trans),
254 tab_write(file, "}\n")
255 tab_write(file, "}\n")
257 else:
259 tab_write(
260 file,
261 "pigment {rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>}\n"
262 % (col[0], col[1], col[2], pov_filter, trans),
265 else:
266 mapping_dif = img_map_transforms(t_dif)
268 if texture_alpha:
269 mapping_alpha = img_map_transforms(t_alpha)
271 tab_write(file, "pigment {\n")
272 tab_write(file, "pigment_pattern {\n")
273 if texture_alpha and texture_alpha.startswith("PAT_"):
274 tab_write(
275 file, "function{f%s(x,y,z).transmit}%s\n" % (texture_alpha, mapping_alpha)
277 else:
278 tab_write(
279 file,
280 'uv_mapping image_map{%s "%s" %s}%s}\n'
282 image_format(texture_alpha),
283 texture_alpha,
284 img_map(t_alpha),
285 mapping_alpha,
288 tab_write(file, "pigment_map {\n")
289 tab_write(file, "[0 color rgbft<0,0,0,1,1>]\n")
290 # if texture_alpha and texture_alpha.startswith("PAT_"):
291 # tab_write(file, "[1 pigment{%s}]\n" %texture_dif)
292 if texture_dif:
293 if not texture_dif.startswith("PAT_"):
294 tab_write(
295 file,
296 '[1 uv_mapping image_map {%s "%s" %s} %s]\n'
298 image_format(texture_dif),
299 texture_dif,
300 (img_gamma + img_map(t_dif)),
301 mapping_dif,
304 elif texture_dif.startswith("PAT_"):
305 tab_write(file, "[1 %s]\n" % texture_dif)
306 tab_write(file, "}\n")
307 tab_write(file, "}\n")
308 if texture_alpha and texture_alpha.startswith("PAT_"):
309 tab_write(file, "}\n")
311 else:
312 if texture_dif and texture_dif.startswith("PAT_"):
313 tab_write(file, "pigment{%s}\n" % texture_dif)
314 else:
315 tab_write(
316 file,
317 'pigment {uv_mapping image_map {%s "%s" %s}%s}\n'
319 image_format(texture_dif),
320 texture_dif,
321 (img_gamma + img_map(t_dif)),
322 mapping_dif,
326 # scale 1 rotate y*0
327 # imageMap = ("{image_map {%s \"%s\" %s }\n" % \
328 # (image_format(textures),textures,img_map(t_dif)))
329 # tab_write(file, "uv_mapping pigment %s} %s finish {%s}\n" % \
330 # (imageMap,mapping,safety(material_finish)))
331 # tab_write(file, "pigment {uv_mapping image_map {%s \"%s\" %s}%s} " \
332 # "finish {%s}\n" % \
333 # (image_format(texture_dif), texture_dif, img_map(t_dif),
334 # mapping_dif, safety(material_finish)))
335 if texture_spec:
336 # ref_level_bound 1 is no specular
337 tab_write(file, "finish {%s}\n" % (safety(material_finish, ref_level_bound=1)))
339 else:
340 # ref_level_bound 2 is translated spec
341 tab_write(file, "finish {%s}\n" % (safety(material_finish, ref_level_bound=2)))
343 if texture_norm:
344 # scale 1 rotate y*0
346 mapping_normal = img_map_transforms(t_nor)
348 if texture_norm and texture_norm.startswith("PAT_"):
349 tab_write(
350 file,
351 "normal{function{f%s(x,y,z).grey} bump_size %.4g %s}\n"
352 % (texture_norm, (-t_nor.normal_factor * 9.5), mapping_normal),
354 else:
355 tab_write(file, "normal {\n")
356 # XXX TODO: fix and propagate the micro normals reflection blur below
357 # to non textured materials
358 if (
359 mater.pov_raytrace_mirror.use
360 and mater.pov_raytrace_mirror.gloss_factor < 1.0
361 and not using_uberpov
363 tab_write(file, "average\n")
364 tab_write(file, "normal_map{\n")
365 # 0.5 for entries below means a 50 percent mix
366 # between the micro normal and user bump map
367 # order seems indifferent as commutative
368 tab_write(
369 file,
370 "[0.025 bumps %.4g scale 0.1*%.4g]\n"
372 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
373 (10 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
375 ) # micronormals blurring
376 tab_write(
377 file,
378 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.1]\n"
380 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
381 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
383 ) # micronormals blurring
384 tab_write(
385 file,
386 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.15]\n"
388 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
389 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
391 ) # micronormals blurring
392 tab_write(
393 file,
394 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.2]\n"
396 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
397 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
399 ) # micronormals blurring
400 tab_write(
401 file,
402 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.25]\n"
404 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
405 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
407 ) # micronormals blurring
408 tab_write(
409 file,
410 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.3]\n"
412 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
413 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
415 ) # micronormals blurring
416 tab_write(
417 file,
418 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.35]\n"
420 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
421 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
423 ) # micronormals blurring
424 tab_write(
425 file,
426 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.4]\n"
428 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
429 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
431 ) # micronormals blurring
432 tab_write(
433 file,
434 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.45]\n"
436 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
437 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
439 ) # micronormals blurring
440 tab_write(
441 file,
442 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.5]\n"
444 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
445 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
447 ) # micronormals blurring
448 tab_write(file, "[1.0 ") # Proceed with user bump...
449 tab_write(
450 file,
451 "uv_mapping bump_map "
452 '{%s "%s" %s bump_size %.4g }%s'
454 image_format(texture_norm),
455 texture_norm,
456 img_map(t_nor),
457 (-t_nor.normal_factor * 9.5),
458 mapping_normal,
461 # ...Then close its last entry and the the normal_map itself
462 if (
463 mater.pov_raytrace_mirror.use
464 and mater.pov_raytrace_mirror.gloss_factor < 1.0
465 and not using_uberpov
467 tab_write(file, r"]}}" + "\n")
468 else:
469 tab_write(file, r"}" + "\n")
470 if texture_spec:
471 tab_write(file, "]\n")
472 # -------- Second index for mapping specular max value -------- #
473 tab_write(file, "[1 \n")
475 if not texture_dif and not mater.pov.replacement_text:
476 if texture_alpha:
477 mapping_alpha = img_map_transforms(t_alpha)
479 if texture_alpha and texture_alpha.startswith("PAT_"):
480 tab_write(
481 file, "function{f%s(x,y,z).transmit %s}\n" % (texture_alpha, mapping_alpha)
483 else:
484 tab_write(
485 file,
486 "pigment {pigment_pattern {uv_mapping image_map"
487 '{%s "%s" %s}%s}\n'
488 % (image_format(texture_alpha), texture_alpha, img_map(t_alpha), mapping_alpha),
490 tab_write(file, "pigment_map {\n")
491 tab_write(file, "[0 color rgbft<0,0,0,1,1>]\n")
492 tab_write(
493 file,
494 "[1 color rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>]\n"
495 % (col[0], col[1], col[2], pov_filter, trans),
497 tab_write(file, "}\n")
498 tab_write(file, "}\n")
500 else:
501 tab_write(
502 file,
503 "pigment {rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>}\n"
504 % (col[0], col[1], col[2], pov_filter, trans),
507 if texture_spec:
508 # ref_level_bound 3 is full specular
509 tab_write(file, "finish {%s}\n" % (safety(material_finish, ref_level_bound=3)))
511 if (
512 mater.pov_raytrace_mirror.use
513 and mater.pov_raytrace_mirror.gloss_factor < 1
514 and not using_uberpov
516 tab_write(file, "normal {\n")
517 tab_write(file, "average\n")
518 tab_write(file, "normal_map{\n")
519 # 0.5 for entries below means a 50 percent mix
520 # between the micro normal and user bump map
521 # order seems indifferent as commutative
522 tab_write(
523 file,
524 "[0.025 bumps %.4g scale 0.1*%.4g]\n"
526 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
527 (10 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
529 ) # micronormals blurring
530 tab_write(
531 file,
532 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.1]\n"
534 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
535 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
537 ) # micronormals blurring
538 tab_write(
539 file,
540 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.15]\n"
542 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
543 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
545 ) # micronormals blurring
546 tab_write(
547 file,
548 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.2]\n"
550 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
551 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
553 ) # micronormals blurring
554 tab_write(
555 file,
556 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.25]\n"
558 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
559 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
561 ) # micronormals blurring
562 tab_write(
563 file,
564 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.3]\n"
566 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
567 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
569 ) # micronormals blurring
570 tab_write(
571 file,
572 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.35]\n"
574 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
575 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
577 ) # micronormals blurring
578 tab_write(
579 file,
580 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.4]\n"
582 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
583 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
585 ) # micronormals blurring
586 tab_write(
587 file,
588 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.45]\n"
590 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
591 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
593 ) # micronormals blurring
594 tab_write(
595 file,
596 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.5]\n"
598 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
599 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
601 ) # micronormals blurring
602 # XXX IF USER BUMP_MAP
603 if texture_norm:
604 tab_write(
605 file, "[1.0 "
606 ) # Blurry reflection or not Proceed with user bump in either case...
607 tab_write(
608 file,
609 "uv_mapping bump_map "
610 '{%s "%s" %s bump_size %.4g }%s\n'
612 image_format(texture_norm),
613 texture_norm,
614 img_map(t_nor),
615 (-t_nor.normal_factor * 9.5),
616 mapping_normal,
619 # ...Then close the normal_map itself if blurry reflection
620 if (
621 mater.pov_raytrace_mirror.use
622 and mater.pov_raytrace_mirror.gloss_factor < 1
623 and not using_uberpov
625 tab_write(file, "]\n}}\n")
626 else:
627 tab_write(file, "}\n")
628 elif colored_specular_found:
629 # ref_level_bound 1 is no specular
630 tab_write(file, "finish {%s}\n" % (safety(material_finish, ref_level_bound=1)))
632 else:
633 # ref_level_bound 2 is translated specular
634 tab_write(file, "finish {%s}\n" % (safety(material_finish, ref_level_bound=2)))
636 elif not mater.pov.replacement_text:
637 mapping_dif = img_map_transforms(t_dif)
639 if texture_alpha:
641 mapping_alpha = img_map_transforms(t_alpha)
643 if texture_alpha and texture_alpha.startswith("PAT_"):
644 tab_write(
645 file,
646 "pigment{pigment_pattern {function{f%s(x,y,z).transmit}%s}\n"
647 % (texture_alpha, mapping_alpha),
649 else:
650 tab_write(
651 file,
652 "pigment {pigment_pattern {uv_mapping image_map"
653 '{%s "%s" %s}%s}\n'
654 % (image_format(texture_alpha), texture_alpha, img_map(t_alpha), mapping_alpha),
656 tab_write(file, "pigment_map {\n")
657 tab_write(file, "[0 color rgbft<0,0,0,1,1>]\n")
658 if texture_alpha and texture_alpha.startswith("PAT_"):
659 tab_write(
660 file, "[1 function{f%s(x,y,z).transmit}%s]\n" % (texture_alpha, mapping_alpha)
662 elif texture_dif and not texture_dif.startswith("PAT_"):
663 tab_write(
664 file,
665 '[1 uv_mapping image_map {%s "%s" %s} %s]\n'
667 image_format(texture_dif),
668 texture_dif,
669 (img_map(t_dif) + img_gamma),
670 mapping_dif,
673 elif texture_dif and texture_dif.startswith("PAT_"):
674 tab_write(file, "[1 %s %s]\n" % (texture_dif, mapping_dif))
675 tab_write(file, "}\n")
676 tab_write(file, "}\n")
678 else:
679 if texture_dif and texture_dif.startswith("PAT_"):
680 tab_write(file, "pigment{%s %s}\n" % (texture_dif, mapping_dif))
681 else:
682 tab_write(file, "pigment {\n")
683 tab_write(file, "uv_mapping image_map {\n")
684 # tab_write(file, "%s \"%s\" %s}%s\n" % \
685 # (image_format(texture_dif), texture_dif,
686 # (img_gamma + img_map(t_dif)),mapping_dif))
687 tab_write(file, '%s "%s" \n' % (image_format(texture_dif), texture_dif))
688 tab_write(file, "%s\n" % (img_gamma + img_map(t_dif)))
689 tab_write(file, "}\n")
690 tab_write(file, "%s\n" % mapping_dif)
691 tab_write(file, "}\n")
693 if texture_spec:
694 # ref_level_bound 3 is full specular
695 tab_write(file, "finish {%s}\n" % (safety(material_finish, ref_level_bound=3)))
696 else:
697 # ref_level_bound 2 is translated specular
698 tab_write(file, "finish {%s}\n" % (safety(material_finish, ref_level_bound=2)))
700 # scale 1 rotate y*0
701 # imageMap = ("{image_map {%s \"%s\" %s }" % \
702 # (image_format(textures), textures,img_map(t_dif)))
703 # tab_write(file, "\n\t\t\tuv_mapping pigment %s} %s finish {%s}" % \
704 # (imageMap, mapping, safety(material_finish)))
705 # tab_write(file, "\n\t\t\tpigment {uv_mapping image_map " \
706 # "{%s \"%s\" %s}%s} finish {%s}" % \
707 # (image_format(texture_dif), texture_dif,img_map(t_dif),
708 # mapping_dif, safety(material_finish)))
709 if texture_norm and not mater.pov.replacement_text:
711 mapping_normal = img_map_transforms(t_nor)
713 if texture_norm and texture_norm.startswith("PAT_"):
714 tab_write(
715 file,
716 "normal{function{f%s(x,y,z).grey} bump_size %.4g %s}\n"
717 % (texture_norm, (-t_nor.normal_factor * 9.5), mapping_normal),
719 else:
720 tab_write(file, "normal {\n")
721 # XXX TODO: fix and propagate the micro normals reflection blur below
722 # to non textured materials
723 if (
724 mater.pov_raytrace_mirror.use
725 and mater.pov_raytrace_mirror.gloss_factor < 1.0
726 and not using_uberpov
728 tab_write(file, "average\n")
729 tab_write(file, "normal_map{\n")
730 # 0.5 for entries below means a 50 percent mix
731 # between the micro normal and user bump map
732 # order seems indifferent as commutative
733 tab_write(
734 file,
735 "[0.025 bumps %.4g scale 0.1*%.4g]\n"
737 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
738 (10 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
740 ) # micronormals blurring
741 tab_write(
742 file,
743 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.1]\n"
745 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
746 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
748 ) # micronormals blurring
749 tab_write(
750 file,
751 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.15]\n"
753 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
754 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
756 ) # micronormals blurring
757 tab_write(
758 file,
759 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.2]\n"
761 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
762 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
764 ) # micronormals blurring
765 tab_write(
766 file,
767 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.25]\n"
769 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
770 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
772 ) # micronormals blurring
773 tab_write(
774 file,
775 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.3]\n"
777 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
778 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
780 ) # micronormals blurring
781 tab_write(
782 file,
783 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.35]\n"
785 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
786 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
788 ) # micronormals blurring
789 tab_write(
790 file,
791 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.4]\n"
793 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
794 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
796 ) # micronormals blurring
797 tab_write(
798 file,
799 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.45]\n"
801 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
802 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
804 ) # micronormals blurring
805 tab_write(
806 file,
807 "[0.025 bumps %.4g scale 0.1*%.4g phase 0.5]\n"
809 (10 / (mater.pov_raytrace_mirror.gloss_factor + 0.01)),
810 (1 / (mater.pov_raytrace_mirror.gloss_samples + 0.001)),
812 ) # micronormals blurring
813 tab_write(
814 file, "[1.0 "
815 ) # Blurry reflection or not Proceed with user bump in either case...
816 tab_write(
817 file,
818 "uv_mapping bump_map "
819 '{%s "%s" %s bump_size %.4g }%s\n'
821 image_format(texture_norm),
822 texture_norm,
823 img_map(t_nor),
824 (-t_nor.normal_factor * 9.5),
825 mapping_normal,
828 # ...Then close the normal_map itself if blurry reflection
829 if (
830 mater.pov_raytrace_mirror.use
831 and mater.pov_raytrace_mirror.gloss_factor < 1
832 and not using_uberpov
834 tab_write(file, "]}}\n")
835 else:
836 tab_write(file, "}\n")
837 if texture_spec and not mater.pov.replacement_text:
838 tab_write(file, "]\n")
840 tab_write(file, "}\n")
842 # End of slope/ior texture_map
843 if mater.pov.diffuse_shader == "MINNAERT" and not mater.pov.replacement_text:
844 tab_write(file, "]\n")
845 tab_write(file, "}\n")
846 if mater.pov.diffuse_shader == "FRESNEL" and not mater.pov.replacement_text:
847 c = 1
848 while c <= exported_lights_count:
849 tab_write(file, "]\n")
850 tab_write(file, "}\n")
851 c += 1
853 # Close first layer of POV "texture" (Blender material)
854 tab_write(file, "}\n")
856 colored_specular_found = bool(
857 (mater.pov.specular_color.s > 0) and (mater.pov.diffuse_shader != "MINNAERT")
860 # Write another layered texture using invisible diffuse and metallic trick
861 # to emulate colored specular highlights
862 special_texture_found = False
863 tmpidx = -1
864 for t in mater.pov_texture_slots:
865 tmpidx += 1
866 # index = mater.pov.active_texture_index
867 slot = mater.pov_texture_slots[tmpidx] # [index]
868 povtex = slot.texture # slot.name
869 tex = bpy.data.textures[povtex]
870 # Specular mapped textures would conflict with colored specular
871 # because POV can't layer over or under pigment patterned textures
872 special_texture_found = bool(
874 and t.use
875 and ((tex.type == "IMAGE" and tex.image) or tex.type != "IMAGE")
876 and (t.use_map_specular or t.use_map_raymir)
878 if colored_specular_found and not special_texture_found:
879 if comments:
880 tab_write(file, " // colored highlights with a stransparent metallic layer\n")
881 else:
882 tab_write(file, "\n")
884 tab_write(file, "texture {\n")
885 tab_write(
886 file,
887 "pigment {rgbft<%.3g, %.3g, %.3g, 0, 1>}\n"
889 mater.pov.specular_color[0],
890 mater.pov.specular_color[1],
891 mater.pov.specular_color[2],
894 tab_write(
895 file, "finish {%s}\n" % (safety(material_finish, ref_level_bound=2))
896 ) # ref_level_bound 2 is translated spec
898 texture_norm = ""
899 for t in mater.pov_texture_slots:
901 if tex.pov.tex_pattern_type != "emulator":
902 # PROCEDURAL TEXTURE
903 image_filename = string_strip_hyphen(bpy.path.clean_name(tex.name))
904 if (
905 tex.type == "IMAGE"
906 and t.use
907 and tex.image
908 and tex.pov.tex_pattern_type == "emulator"
910 procedural_flag = False
911 image_filename = path_image(tex.image)
912 img_gamma = ""
913 if image_filename and t.use_map_normal:
914 texture_norm = image_filename
915 # colvalue = t.normal_factor/10 # UNUSED XXX *-9.5 !
916 # textNormName=tex.image.name + ".normal"
917 # was the above used? --MR
918 t_nor = t
919 if procedural_flag:
920 tab_write(
921 file,
922 "normal{function"
923 "{f%s(x,y,z).grey} bump_size %.4g}\n"
924 % (texture_norm, (-t_nor.normal_factor * 9.5)),
926 else:
927 tab_write(
928 file,
929 "normal {uv_mapping bump_map "
930 '{%s "%s" %s bump_size %.4g }%s}\n'
932 image_format(texture_norm),
933 texture_norm,
934 img_map(t_nor),
935 (-t_nor.normal_factor * 9.5),
936 mapping_normal,
940 tab_write(file, "}\n") # THEN IT CAN CLOSE LAST LAYER OF TEXTURE