1 # SPDX-License-Identifier: GPL-2.0-or-later
3 """Translate blender texture influences into POV."""
7 local_material_names
= []
11 def write_texture_influence(
14 material_names_dictionary
,
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
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
47 # procedural_flag=False
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
:
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
]
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"):
67 image_filename
= "PAT_%s" % string_strip_hyphen(bpy
.path
.clean_name(tex
.name
))
69 if t
.use_map_color_diffuse
:
70 texture_dif
= image_filename
71 # colvalue = t.default_value # UNUSED
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
80 texture_norm
= image_filename
81 # colvalue = t.normal_factor/10 # UNUSED
82 # textNormName=tex.image.name + ".normal"
83 # was the above used? --MR
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
92 elif tex
.type == "IMAGE" and tex
.image
and tex
.pov
.tex_pattern_type
== "emulator":
93 # NOT A PROCEDURAL TEXTURE
95 if tex
.image
.packed_file
:
96 orig_image_filename
= tex
.image
.filepath_raw
97 unpackedfilename
= os
.path
.join(
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
104 unpacked_images
.append(unpackedfilename
)
105 tex
.image
.filepath_raw
= unpackedfilename
107 image_filename
= unpackedfilename
.replace("\\", "/")
108 # .replace("\\","/") to get only forward slashes as it's what POV prefers,
110 tex
.image
.filepath_raw
= orig_image_filename
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
)
119 print(image_filename
)
120 # IMAGE SEQUENCE ENDS
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
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
136 texture_norm
= image_filename
137 # colvalue = t.normal_factor/10 # UNUSED
138 # textNormName=tex.image.name + ".normal"
139 # was the above used? --MR
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
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")
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.
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
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)),
194 "[%.3g\n" % ((mater
.pov
.diffuse_fresnel_factor
/ 5) * (mater
.pov
.diffuse_fresnel
/ 5.0)),
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
:
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
)
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")
223 tab_write(file, "\n")
225 mapping_alpha
= img_map_transforms(t_alpha
)
227 if texture_alpha
and texture_alpha
.startswith("PAT_"):
229 file, "function{f%s(x,y,z).transmit}%s\n" % (texture_alpha
, mapping_alpha
)
235 "pigment {pigment_pattern {uv_mapping image_map"
238 image_format(texture_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")
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")
259 "pigment {rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>}\n"
260 % (col
[0], col
[1], col
[2], pov_filter
, trans
),
264 mapping_dif
= img_map_transforms(t_dif
)
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_"):
273 file, "function{f%s(x,y,z).transmit}%s\n" % (texture_alpha
, mapping_alpha
)
278 'uv_mapping image_map{%s "%s" %s}%s}\n'
280 image_format(texture_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)
291 if not texture_dif
.startswith("PAT_"):
294 '[1 uv_mapping image_map {%s "%s" %s} %s]\n'
296 image_format(texture_dif
),
298 (img_gamma
+ img_map(t_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")
310 if texture_dif
and texture_dif
.startswith("PAT_"):
311 tab_write(file, "pigment{%s}\n" % texture_dif
)
315 'pigment {uv_mapping image_map {%s "%s" %s}%s}\n'
317 image_format(texture_dif
),
319 (img_gamma
+ img_map(t_dif
)),
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)))
334 # ref_level_bound 1 is no specular
335 tab_write(file, "finish {%s}\n" % (safety(material_finish
, ref_level_bound
=1)))
338 # ref_level_bound 2 is translated spec
339 tab_write(file, "finish {%s}\n" % (safety(material_finish
, ref_level_bound
=2)))
344 mapping_normal
= img_map_transforms(t_nor
)
346 if texture_norm
and texture_norm
.startswith("PAT_"):
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
),
353 tab_write(file, "normal {\n")
354 # XXX TODO: fix and propagate the micro normals reflection blur below
355 # to non textured materials
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
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
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
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
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
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
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
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
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
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
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...
449 "uv_mapping bump_map "
450 '{%s "%s" %s bump_size %.4g }%s'
452 image_format(texture_norm
),
455 (-t_nor
.normal_factor
* 9.5),
459 # ...Then close its last entry and the the normal_map itself
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")
467 tab_write(file, r
"}" + "\n")
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
:
475 mapping_alpha
= img_map_transforms(t_alpha
)
477 if texture_alpha
and texture_alpha
.startswith("PAT_"):
479 file, "function{f%s(x,y,z).transmit %s}\n" % (texture_alpha
, mapping_alpha
)
484 "pigment {pigment_pattern {uv_mapping image_map"
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")
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")
501 "pigment {rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>}\n"
502 % (col
[0], col
[1], col
[2], pov_filter
, trans
),
506 # ref_level_bound 3 is full specular
507 tab_write(file, "finish {%s}\n" % (safety(material_finish
, ref_level_bound
=3)))
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
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
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
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
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
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
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
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
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
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
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
604 ) # Blurry reflection or not Proceed with user bump in either case...
607 "uv_mapping bump_map "
608 '{%s "%s" %s bump_size %.4g }%s\n'
610 image_format(texture_norm
),
613 (-t_nor
.normal_factor
* 9.5),
617 # ...Then close the normal_map itself if blurry reflection
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")
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)))
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
)
639 mapping_alpha
= img_map_transforms(t_alpha
)
641 if texture_alpha
and texture_alpha
.startswith("PAT_"):
644 "pigment{pigment_pattern {function{f%s(x,y,z).transmit}%s}\n"
645 % (texture_alpha
, mapping_alpha
),
650 "pigment {pigment_pattern {uv_mapping image_map"
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_"):
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_"):
663 '[1 uv_mapping image_map {%s "%s" %s} %s]\n'
665 image_format(texture_dif
),
667 (img_map(t_dif
) + img_gamma
),
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")
677 if texture_dif
and texture_dif
.startswith("PAT_"):
678 tab_write(file, "pigment{%s %s}\n" % (texture_dif
, mapping_dif
))
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")
692 # ref_level_bound 3 is full specular
693 tab_write(file, "finish {%s}\n" % (safety(material_finish
, ref_level_bound
=3)))
695 # ref_level_bound 2 is translated specular
696 tab_write(file, "finish {%s}\n" % (safety(material_finish
, ref_level_bound
=2)))
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_"):
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
),
718 tab_write(file, "normal {\n")
719 # XXX TODO: fix and propagate the micro normals reflection blur below
720 # to non textured materials
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
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
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
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
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
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
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
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
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
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
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
813 ) # Blurry reflection or not Proceed with user bump in either case...
816 "uv_mapping bump_map "
817 '{%s "%s" %s bump_size %.4g }%s\n'
819 image_format(texture_norm
),
822 (-t_nor
.normal_factor
* 9.5),
826 # ...Then close the normal_map itself if blurry reflection
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")
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
:
846 while c
<= exported_lights_count
:
847 tab_write(file, "]\n")
848 tab_write(file, "}\n")
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
862 for t
in mater
.pov_texture_slots
:
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(
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
:
878 tab_write(file, " // colored highlights with a stransparent metallic layer\n")
880 tab_write(file, "\n")
882 tab_write(file, "texture {\n")
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],
893 file, "finish {%s}\n" % (safety(material_finish
, ref_level_bound
=2))
894 ) # ref_level_bound 2 is translated spec
897 for t
in mater
.pov_texture_slots
:
899 if tex
.pov
.tex_pattern_type
!= "emulator":
901 image_filename
= string_strip_hyphen(bpy
.path
.clean_name(tex
.name
))
906 and tex
.pov
.tex_pattern_type
== "emulator"
908 procedural_flag
= False
909 image_filename
= path_image(tex
.image
)
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
921 "{f%s(x,y,z).grey} bump_size %.4g}\n"
922 % (texture_norm
, (-t_nor
.normal_factor
* 9.5)),
927 "normal {uv_mapping bump_map "
928 '{%s "%s" %s bump_size %.4g }%s}\n'
930 image_format(texture_norm
),
933 (-t_nor
.normal_factor
* 9.5),
938 tab_write(file, "}\n") # THEN IT CAN CLOSE LAST LAYER OF TEXTURE