*Fixed texture normal_factor regression
*Fixed lighting attenuation for a closer match with Blender Internal
This commit is contained in:
parent
a87b9998d8
commit
1d9d466de8
|
@ -36,6 +36,7 @@ if "bpy" in locals():
|
|||
import importlib
|
||||
importlib.reload(ui)
|
||||
importlib.reload(render)
|
||||
importlib.reload(shading)
|
||||
importlib.reload(update_files)
|
||||
|
||||
else:
|
||||
|
|
|
@ -28,6 +28,7 @@ import re
|
|||
import random
|
||||
import platform#
|
||||
import subprocess#
|
||||
import tempfile #generate temporary files with random names
|
||||
from bpy.types import(Operator)
|
||||
from imghdr import what #imghdr is a python lib to identify image file types
|
||||
|
||||
|
@ -201,7 +202,7 @@ preview_dir = os.path.join(user_dir, "preview")
|
|||
|
||||
## Make sure Preview directory exists and is empty
|
||||
smokePath = os.path.join(preview_dir, "smoke.df3")
|
||||
|
||||
'''
|
||||
def write_global_setting(scene,file):
|
||||
file.write("global_settings {\n")
|
||||
file.write(" assumed_gamma %.6f\n"%scene.pov.assumed_gamma)
|
||||
|
@ -285,7 +286,7 @@ def write_global_setting(scene,file):
|
|||
file.write(' load_file "%s"\n'%fullFileName)
|
||||
file.write("}\n")
|
||||
file.write("}\n")
|
||||
|
||||
'''
|
||||
def write_object_modifiers(scene,ob,File):
|
||||
'''XXX WIP
|
||||
onceCSG = 0
|
||||
|
@ -574,7 +575,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
matrix = global_matrix * ob.matrix_world
|
||||
|
||||
# Color is modified by energy #muiltiplie by 2 for a better match --Maurice
|
||||
color = tuple([c * lamp.energy for c in lamp.color])
|
||||
color = tuple([c * (lamp.energy) for c in lamp.color])
|
||||
|
||||
tabWrite("light_source {\n")
|
||||
tabWrite("< 0,0,0 >\n")
|
||||
|
@ -655,14 +656,16 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
# Sun shouldn't be attenuated. Hemi and area lights have no falloff attribute so they
|
||||
# are put to type 2 attenuation a little higher above.
|
||||
if lamp.type not in {'SUN', 'AREA', 'HEMI'}:
|
||||
tabWrite("fade_distance %.6f\n" % (lamp.distance / 10.0))
|
||||
if lamp.falloff_type == 'INVERSE_SQUARE':
|
||||
tabWrite("fade_distance %.6f\n" % (sqrt(lamp.distance/2.0)))
|
||||
tabWrite("fade_power %d\n" % 2) # Use blenders lamp quad equivalent
|
||||
elif lamp.falloff_type == 'INVERSE_LINEAR':
|
||||
tabWrite("fade_distance %.6f\n" % (lamp.distance / 2.0))
|
||||
tabWrite("fade_power %d\n" % 1) # Use blenders lamp linear
|
||||
# supposing using no fade power keyword would default to constant, no attenuation.
|
||||
elif lamp.falloff_type == 'CONSTANT':
|
||||
pass
|
||||
tabWrite("fade_distance %.6f\n" % (lamp.distance / 2.0))
|
||||
tabWrite("fade_power %d\n" % 3)
|
||||
# Use blenders lamp constant equivalent no attenuation.
|
||||
# Using Custom curve for fade power 3 for now.
|
||||
elif lamp.falloff_type == 'CUSTOM_CURVE':
|
||||
tabWrite("fade_power %d\n" % 4)
|
||||
|
@ -2982,7 +2985,20 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
|
||||
file.write("\n")
|
||||
tabWrite("}\n")
|
||||
|
||||
|
||||
#XXX BOOLEAN
|
||||
onceCSG = 0
|
||||
for mod in ob.modifiers:
|
||||
if onceCSG == 0:
|
||||
if mod :
|
||||
if mod.type == 'BOOLEAN':
|
||||
if ob.pov.boolean_mod == "POV":
|
||||
file.write("\tinside_vector <%.6g, %.6g, %.6g>\n" %
|
||||
(ob.pov.inside_vector[0],
|
||||
ob.pov.inside_vector[1],
|
||||
ob.pov.inside_vector[2]))
|
||||
onceCSG = 1
|
||||
|
||||
if me.materials:
|
||||
try:
|
||||
material = me.materials[0] # dodgy
|
||||
|
@ -2990,6 +3006,10 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
except IndexError:
|
||||
print(me)
|
||||
|
||||
# POV object modifiers such as
|
||||
# hollow / sturm / double_illuminate etc.
|
||||
write_object_modifiers(scene,ob,file)
|
||||
|
||||
#Importance for radiosity sampling added here:
|
||||
tabWrite("radiosity { \n")
|
||||
tabWrite("importance %3g \n" % importance)
|
||||
|
@ -3221,7 +3241,20 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
|
||||
file.write("\n")
|
||||
tabWrite("}\n")
|
||||
|
||||
|
||||
#XXX BOOLEAN
|
||||
onceCSG = 0
|
||||
for mod in ob.modifiers:
|
||||
if onceCSG == 0:
|
||||
if mod :
|
||||
if mod.type == 'BOOLEAN':
|
||||
if ob.pov.boolean_mod == "POV":
|
||||
file.write("\tinside_vector <%.6g, %.6g, %.6g>\n" %
|
||||
(ob.pov.inside_vector[0],
|
||||
ob.pov.inside_vector[1],
|
||||
ob.pov.inside_vector[2]))
|
||||
onceCSG = 1
|
||||
|
||||
if me.materials:
|
||||
try:
|
||||
material = me.materials[0] # dodgy
|
||||
|
@ -3229,7 +3262,7 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
except IndexError:
|
||||
print(me)
|
||||
|
||||
# POV object inside_vector and modifiers such as
|
||||
# POV object modifiers such as
|
||||
# hollow / sturm / double_illuminate etc.
|
||||
write_object_modifiers(scene,ob,file)
|
||||
|
||||
|
@ -3435,18 +3468,13 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
if scene.pov.charset != 'ascii':
|
||||
file.write(" charset %s\n"%scene.pov.charset)
|
||||
if scene.pov.global_settings_advanced:
|
||||
if scene.pov.adc_bailout_enable and scene.pov.radio_enable == False:
|
||||
if scene.pov.radio_enable == False:
|
||||
file.write(" adc_bailout %.6f\n"%scene.pov.adc_bailout)
|
||||
if scene.pov.ambient_light_enable:
|
||||
file.write(" ambient_light <%.6f,%.6f,%.6f>\n"%scene.pov.ambient_light[:])
|
||||
if scene.pov.irid_wavelength_enable:
|
||||
file.write(" irid_wavelength <%.6f,%.6f,%.6f>\n"%scene.pov.irid_wavelength[:])
|
||||
if scene.pov.max_intersections_enable:
|
||||
file.write(" max_intersections %s\n"%scene.pov.max_intersections)
|
||||
if scene.pov.number_of_waves_enable:
|
||||
file.write(" number_of_waves %s\n"%scene.pov.number_of_waves)
|
||||
if scene.pov.noise_generator_enable:
|
||||
file.write(" noise_generator %s\n"%scene.pov.noise_generator)
|
||||
file.write(" ambient_light <%.6f,%.6f,%.6f>\n"%scene.pov.ambient_light[:])
|
||||
file.write(" irid_wavelength <%.6f,%.6f,%.6f>\n"%scene.pov.irid_wavelength[:])
|
||||
file.write(" max_intersections %s\n"%scene.pov.max_intersections)
|
||||
file.write(" number_of_waves %s\n"%scene.pov.number_of_waves)
|
||||
file.write(" noise_generator %s\n"%scene.pov.noise_generator)
|
||||
if scene.pov.radio_enable:
|
||||
tabWrite("radiosity {\n")
|
||||
tabWrite("adc_bailout %.4g\n" % scene.pov.radio_adc_bailout)
|
||||
|
@ -3499,6 +3527,21 @@ def write_pov(filename, scene=None, info_callback=None):
|
|||
tabWrite("adc_bailout %.3g\n" % scene.pov.photon_adc_bailout)
|
||||
tabWrite("gather %d, %d\n" % (scene.pov.photon_gather_min,
|
||||
scene.pov.photon_gather_max))
|
||||
if scene.pov.photon_map_file_save_load in {'save'}:
|
||||
filePhName = 'Photon_map_file.ph'
|
||||
if scene.pov.photon_map_file != '':
|
||||
filePhName = scene.pov.photon_map_file+'.ph'
|
||||
filePhDir = tempfile.gettempdir()
|
||||
path = bpy.path.abspath(scene.pov.photon_map_dir)
|
||||
if os.path.exists(path):
|
||||
filePhDir = path
|
||||
fullFileName = os.path.join(filePhDir,filePhName)
|
||||
tabWrite('save_file "%s"\n'%fullFileName)
|
||||
scene.pov.photon_map_file = fullFileName
|
||||
if scene.pov.photon_map_file_save_load in {'load'}:
|
||||
fullFileName = bpy.path.abspath(scene.pov.photon_map_file)
|
||||
if os.path.exists(fullFileName):
|
||||
tabWrite('load_file "%s"\n'%fullFileName)
|
||||
tabWrite("}\n")
|
||||
oncePhotons = 0
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ def writeMaterial(using_uberpov, DEF_MAT_NAME, scene, tabWrite, safety, comments
|
|||
pass # let's keep things simple for now
|
||||
if material.diffuse_shader == 'LAMBERT' and Level != 3:
|
||||
# trying to best match lambert attenuation by that constant brilliance value
|
||||
tabWrite("brilliance 1.8\n")
|
||||
tabWrite("brilliance 1\n")
|
||||
|
||||
if Level == 2:
|
||||
###########################Specular Shader######################################
|
||||
|
@ -101,7 +101,7 @@ def writeMaterial(using_uberpov, DEF_MAT_NAME, scene, tabWrite, safety, comments
|
|||
if (material.specular_shader == 'COOKTORR' or
|
||||
material.specular_shader == 'PHONG'):
|
||||
tabWrite("phong %.3g\n" % (material.specular_intensity))
|
||||
tabWrite("phong_size %.3g\n" % (material.specular_hardness / 2 + 0.25))
|
||||
tabWrite("phong_size %.3g\n" % (material.specular_hardness /3.14))
|
||||
|
||||
# POV-Ray 'specular' keyword corresponds to a Blinn model, without the ior.
|
||||
elif material.specular_shader == 'BLINN':
|
||||
|
@ -130,9 +130,38 @@ def writeMaterial(using_uberpov, DEF_MAT_NAME, scene, tabWrite, safety, comments
|
|||
|
||||
####################################################################################
|
||||
elif Level == 1:
|
||||
tabWrite("specular 0\n")
|
||||
if (material.specular_shader == 'COOKTORR' or
|
||||
material.specular_shader == 'PHONG'):
|
||||
tabWrite("phong %.3g\n" % (material.specular_intensity/5))
|
||||
tabWrite("phong_size %.3g\n" % (material.specular_hardness /3.14))
|
||||
|
||||
# POV-Ray 'specular' keyword corresponds to a Blinn model, without the ior.
|
||||
elif material.specular_shader == 'BLINN':
|
||||
# Use blender Blinn's IOR just as some factor for spec intensity
|
||||
tabWrite("specular %.3g\n" % (material.specular_intensity *
|
||||
(material.specular_ior / 4.0)))
|
||||
tabWrite("roughness %.3g\n" % roughness)
|
||||
#Could use brilliance 2(or varying around 2 depending on ior or factor) too.
|
||||
|
||||
elif material.specular_shader == 'TOON':
|
||||
tabWrite("phong %.3g\n" % (material.specular_intensity * 2.0))
|
||||
# use extreme phong_size
|
||||
tabWrite("phong_size %.3g\n" % (0.1 + material.specular_toon_smooth / 2.0))
|
||||
|
||||
elif material.specular_shader == 'WARDISO':
|
||||
# find best suited default constant for brilliance Use both phong and
|
||||
# specular for some values.
|
||||
tabWrite("specular %.3g\n" % (material.specular_intensity /
|
||||
(material.specular_slope + 0.0005)))
|
||||
# find best suited default constant for brilliance Use both phong and
|
||||
# specular for some values.
|
||||
tabWrite("roughness %.4g\n" % (0.0005 + material.specular_slope / 10.0))
|
||||
# find best suited default constant for brilliance Use both phong and
|
||||
# specular for some values.
|
||||
tabWrite("brilliance %.4g\n" % (1.8 - material.specular_slope * 1.8))
|
||||
elif Level == 3:
|
||||
tabWrite("specular 1\n")
|
||||
tabWrite("specular %.3g\n" % ((material.specular_intensity*material.specular_color.v)*5))
|
||||
tabWrite("roughness %.3g\n" % (1.1/material.specular_hardness))
|
||||
tabWrite("diffuse %.3g %.3g\n" % (frontDiffuse, backDiffuse))
|
||||
|
||||
tabWrite("ambient %.3g\n" % material.ambient)
|
||||
|
@ -982,12 +1011,12 @@ def writeTextureInfluence(mater, materialNames, LocalMaterialNames, path_image,
|
|||
mappingNor =imgMapTransforms(t_nor)
|
||||
|
||||
if texturesNorm and texturesNorm.startswith("PAT_"):
|
||||
tabWrite("normal{function{f%s(x,y,z).grey} bump_size %.4g %s}\n" %(texturesNorm, t_nor.normal_factor/10, mappingNor))
|
||||
tabWrite("normal{function{f%s(x,y,z).grey} bump_size %.4g %s}\n" %(texturesNorm, t_nor.normal_factor, mappingNor))
|
||||
else:
|
||||
tabWrite("normal {uv_mapping bump_map " \
|
||||
"{%s \"%s\" %s bump_size %.4g }%s}\n" % \
|
||||
(imageFormat(texturesNorm), texturesNorm, imgMap(t_nor),
|
||||
t_nor.normal_factor/10, mappingNor))
|
||||
t_nor.normal_factor, mappingNor))
|
||||
if texturesSpec != "":
|
||||
tabWrite("]\n")
|
||||
##################Second index for mapping specular max value###############
|
||||
|
@ -1093,11 +1122,11 @@ def writeTextureInfluence(mater, materialNames, LocalMaterialNames, path_image,
|
|||
mappingNor =imgMapTransforms(t_nor)
|
||||
|
||||
if texturesNorm and texturesNorm.startswith("PAT_"):
|
||||
tabWrite("normal{function{f%s(x,y,z).grey} bump_size %.4g %s}\n" %(texturesNorm, t_nor.normal_factor/10, mappingNor))
|
||||
tabWrite("normal{function{f%s(x,y,z).grey} bump_size %.4g %s}\n" %(texturesNorm, t_nor.normal_factor, mappingNor))
|
||||
else:
|
||||
tabWrite("normal {uv_mapping bump_map {%s \"%s\" %s bump_size %.4g }%s}\n" % \
|
||||
(imageFormat(texturesNorm), texturesNorm, imgMap(t_nor),
|
||||
t_nor.normal_factor/10, mappingNor))
|
||||
t_nor.normal_factor, mappingNor))
|
||||
if texturesSpec != "" and mater.pov.replacement_text == "":
|
||||
tabWrite("]\n")
|
||||
|
||||
|
@ -1169,13 +1198,13 @@ def writeTextureInfluence(mater, materialNames, LocalMaterialNames, path_image,
|
|||
tabWrite("normal{function" \
|
||||
"{f%s(x,y,z).grey} bump_size %.4g}\n" % \
|
||||
(texturesNorm,
|
||||
t_nor.normal_factor/10))
|
||||
t_nor.normal_factor))
|
||||
else:
|
||||
tabWrite("normal {uv_mapping bump_map " \
|
||||
"{%s \"%s\" %s bump_size %.4g }%s}\n" % \
|
||||
(imageFormat(texturesNorm),
|
||||
texturesNorm, imgMap(t_nor),
|
||||
t_nor.normal_factor/10,
|
||||
t_nor.normal_factor,
|
||||
mappingNor))
|
||||
|
||||
tabWrite("}\n") # THEN IT CAN CLOSE LAST LAYER OF TEXTURE
|
||||
|
|
Loading…
Reference in New Issue