1 # SPDX-FileCopyrightText: 2021-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 """Translate blender texture influences into POV."""
9 local_material_names
= []
10 material_finish
= None
13 def write_texture_influence(
16 material_names_dictionary
,
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
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
49 # procedural_flag=False
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
:
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
]
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"):
69 image_filename
= "PAT_%s" % string_strip_hyphen(bpy
.path
.clean_name(tex
.name
))
71 if t
.use_map_color_diffuse
:
72 texture_dif
= image_filename
73 # colvalue = t.default_value # UNUSED
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
82 texture_norm
= image_filename
83 # colvalue = t.normal_factor/10 # UNUSED
84 # textNormName=tex.image.name + ".normal"
85 # was the above used? --MR
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
94 elif tex
.type == "IMAGE" and tex
.image
and tex
.pov
.tex_pattern_type
== "emulator":
95 # NOT A PROCEDURAL TEXTURE
97 if tex
.image
.packed_file
:
98 orig_image_filename
= tex
.image
.filepath_raw
99 unpackedfilename
= os
.path
.join(
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
106 unpacked_images
.append(unpackedfilename
)
107 tex
.image
.filepath_raw
= unpackedfilename
109 image_filename
= unpackedfilename
.replace("\\", "/")
110 # .replace("\\","/") to get only forward slashes as it's what POV prefers,
112 tex
.image
.filepath_raw
= orig_image_filename
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
)
121 print(image_filename
)
122 # IMAGE SEQUENCE ENDS
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
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
138 texture_norm
= image_filename
139 # colvalue = t.normal_factor/10 # UNUSED
140 # textNormName=tex.image.name + ".normal"
141 # was the above used? --MR
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
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")
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.
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
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)),
196 "[%.3g\n" % ((mater
.pov
.diffuse_fresnel_factor
/ 5) * (mater
.pov
.diffuse_fresnel
/ 5.0)),
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
:
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
)
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")
225 tab_write(file, "\n")
227 mapping_alpha
= img_map_transforms(t_alpha
)
229 if texture_alpha
and texture_alpha
.startswith("PAT_"):
231 file, "function{f%s(x,y,z).transmit}%s\n" % (texture_alpha
, mapping_alpha
)
237 "pigment {pigment_pattern {uv_mapping image_map"
240 image_format(texture_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")
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")
261 "pigment {rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>}\n"
262 % (col
[0], col
[1], col
[2], pov_filter
, trans
),
266 mapping_dif
= img_map_transforms(t_dif
)
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_"):
275 file, "function{f%s(x,y,z).transmit}%s\n" % (texture_alpha
, mapping_alpha
)
280 'uv_mapping image_map{%s "%s" %s}%s}\n'
282 image_format(texture_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)
293 if not texture_dif
.startswith("PAT_"):
296 '[1 uv_mapping image_map {%s "%s" %s} %s]\n'
298 image_format(texture_dif
),
300 (img_gamma
+ img_map(t_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")
312 if texture_dif
and texture_dif
.startswith("PAT_"):
313 tab_write(file, "pigment{%s}\n" % texture_dif
)
317 'pigment {uv_mapping image_map {%s "%s" %s}%s}\n'
319 image_format(texture_dif
),
321 (img_gamma
+ img_map(t_dif
)),
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)))
336 # ref_level_bound 1 is no specular
337 tab_write(file, "finish {%s}\n" % (safety(material_finish
, ref_level_bound
=1)))
340 # ref_level_bound 2 is translated spec
341 tab_write(file, "finish {%s}\n" % (safety(material_finish
, ref_level_bound
=2)))
346 mapping_normal
= img_map_transforms(t_nor
)
348 if texture_norm
and texture_norm
.startswith("PAT_"):
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
),
355 tab_write(file, "normal {\n")
356 # XXX TODO: fix and propagate the micro normals reflection blur below
357 # to non textured materials
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
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
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
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
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
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
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
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
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
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
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...
451 "uv_mapping bump_map "
452 '{%s "%s" %s bump_size %.4g }%s'
454 image_format(texture_norm
),
457 (-t_nor
.normal_factor
* 9.5),
461 # ...Then close its last entry and the the normal_map itself
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")
469 tab_write(file, r
"}" + "\n")
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
:
477 mapping_alpha
= img_map_transforms(t_alpha
)
479 if texture_alpha
and texture_alpha
.startswith("PAT_"):
481 file, "function{f%s(x,y,z).transmit %s}\n" % (texture_alpha
, mapping_alpha
)
486 "pigment {pigment_pattern {uv_mapping image_map"
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")
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")
503 "pigment {rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>}\n"
504 % (col
[0], col
[1], col
[2], pov_filter
, trans
),
508 # ref_level_bound 3 is full specular
509 tab_write(file, "finish {%s}\n" % (safety(material_finish
, ref_level_bound
=3)))
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
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
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
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
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
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
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
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
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
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
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
606 ) # Blurry reflection or not Proceed with user bump in either case...
609 "uv_mapping bump_map "
610 '{%s "%s" %s bump_size %.4g }%s\n'
612 image_format(texture_norm
),
615 (-t_nor
.normal_factor
* 9.5),
619 # ...Then close the normal_map itself if blurry reflection
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")
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)))
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
)
641 mapping_alpha
= img_map_transforms(t_alpha
)
643 if texture_alpha
and texture_alpha
.startswith("PAT_"):
646 "pigment{pigment_pattern {function{f%s(x,y,z).transmit}%s}\n"
647 % (texture_alpha
, mapping_alpha
),
652 "pigment {pigment_pattern {uv_mapping image_map"
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_"):
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_"):
665 '[1 uv_mapping image_map {%s "%s" %s} %s]\n'
667 image_format(texture_dif
),
669 (img_map(t_dif
) + img_gamma
),
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")
679 if texture_dif
and texture_dif
.startswith("PAT_"):
680 tab_write(file, "pigment{%s %s}\n" % (texture_dif
, mapping_dif
))
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")
694 # ref_level_bound 3 is full specular
695 tab_write(file, "finish {%s}\n" % (safety(material_finish
, ref_level_bound
=3)))
697 # ref_level_bound 2 is translated specular
698 tab_write(file, "finish {%s}\n" % (safety(material_finish
, ref_level_bound
=2)))
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_"):
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
),
720 tab_write(file, "normal {\n")
721 # XXX TODO: fix and propagate the micro normals reflection blur below
722 # to non textured materials
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
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
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
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
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
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
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
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
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
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
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
815 ) # Blurry reflection or not Proceed with user bump in either case...
818 "uv_mapping bump_map "
819 '{%s "%s" %s bump_size %.4g }%s\n'
821 image_format(texture_norm
),
824 (-t_nor
.normal_factor
* 9.5),
828 # ...Then close the normal_map itself if blurry reflection
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")
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
:
848 while c
<= exported_lights_count
:
849 tab_write(file, "]\n")
850 tab_write(file, "}\n")
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
864 for t
in mater
.pov_texture_slots
:
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(
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
:
880 tab_write(file, " // colored highlights with a stransparent metallic layer\n")
882 tab_write(file, "\n")
884 tab_write(file, "texture {\n")
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],
895 file, "finish {%s}\n" % (safety(material_finish
, ref_level_bound
=2))
896 ) # ref_level_bound 2 is translated spec
899 for t
in mater
.pov_texture_slots
:
901 if tex
.pov
.tex_pattern_type
!= "emulator":
903 image_filename
= string_strip_hyphen(bpy
.path
.clean_name(tex
.name
))
908 and tex
.pov
.tex_pattern_type
== "emulator"
910 procedural_flag
= False
911 image_filename
= path_image(tex
.image
)
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
923 "{f%s(x,y,z).grey} bump_size %.4g}\n"
924 % (texture_norm
, (-t_nor
.normal_factor
* 9.5)),
929 "normal {uv_mapping bump_map "
930 '{%s "%s" %s bump_size %.4g }%s}\n'
932 image_format(texture_norm
),
935 (-t_nor
.normal_factor
* 9.5),
940 tab_write(file, "}\n") # THEN IT CAN CLOSE LAST LAYER OF TEXTURE