[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1246] trunk/py/scripts/addons/ render_povray/render.py: Added a function to simplify Specular map export.
Maurice Raybaud
mauriceraybaud at hotmail.fr
Tue Dec 7 18:07:59 CET 2010
Revision: 1246
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1246
Author: mauriceraybaud
Date: 2010-12-07 18:07:59 +0100 (Tue, 07 Dec 2010)
Log Message:
-----------
Added a function to simplify Specular map export.
Modified Paths:
--------------
trunk/py/scripts/addons/render_povray/render.py
Modified: trunk/py/scripts/addons/render_povray/render.py
===================================================================
--- trunk/py/scripts/addons/render_povray/render.py 2010-12-07 16:29:07 UTC (rev 1245)
+++ trunk/py/scripts/addons/render_povray/render.py 2010-12-07 17:07:59 UTC (rev 1246)
@@ -221,289 +221,152 @@
name = materialNames[name_orig] = uniqueName(bpy.path.clean_name(name_orig), materialNames)
- file.write('#declare %s = finish {\n' % safety0(name))
- if material:
+ ##################Several versions of the finish: Level conditions are variations for specular/Mirror texture channel map with alternative finish of 0 specular and no mirror reflection
+ def povHasnoSpecularMaps():
+ if Level == 2:
+ file.write('#declare %s = finish {\n' % safety(name))
+ elif Level == 1:
+ file.write('#declare %s = finish {\n' % safety0(name))
+ elif Level == 3:
+ file.write('#declare %s = finish {\n' % safety1(name))
- #Povray 3.7 now uses two diffuse values respectively for front and back shading (the back diffuse is like blender translucency)
- frontDiffuse=material.diffuse_intensity
- backDiffuse=material.translucency
-
- #But the conserve energy keyword does not keep their sum realistic in pov
- #we can add this feature before the script writes their values to pov scene
- if material.pov_conserve_energy:
- #Total of spec + diff should not go above one
- if (frontDiffuse + backDiffuse) <= 1.0:
- pass
- elif frontDiffuse==backDiffuse:
- frontDiffuse = backDiffuse = 0.5 # Try to respect the user's "intention" by comparing the two values but bringing the total back to one
- elif frontDiffuse>backDiffuse: # Let the highest value stay the highest value
- backDiffuse = 1-(1-frontDiffuse)
- else:
- frontDiffuse = 1-(1-backDiffuse)
+ if material:
+ #Povray 3.7 now uses two diffuse values respectively for front and back shading (the back diffuse is like blender translucency)
+ frontDiffuse=material.diffuse_intensity
+ backDiffuse=material.translucency
+
+ if material.pov_conserve_energy:
- # map hardness between 0.0 and 1.0
- roughness = ((1.0 - ((material.specular_hardness - 1.0) / 510.0)))
- ## scale from 0.0 to 0.1
- roughness *= 0.1
- # add a small value because 0.0 is invalid
- roughness += (1 / 511.0)
+ #Total should not go above one
+ if (frontDiffuse + backDiffuse) <= 1.0:
+ pass
+ elif frontDiffuse==backDiffuse:
+ frontDiffuse = backDiffuse = 0.5 # Try to respect the user's "intention" by comparing the two values but bringing the total back to one
+ elif frontDiffuse>backDiffuse: # Let the highest value stay the highest value
+ backDiffuse = 1-(1-frontDiffuse)
+ else:
+ frontDiffuse = 1-(1-backDiffuse)
+
- #####################################Diffuse Shader######################################
- if material.diffuse_shader == 'OREN_NAYAR':
- file.write('\tbrilliance %.3g\n' % (0.9+material.roughness))#blender roughness is what is generally called oren nayar Sigma, and brilliance in povray
+ # map hardness between 0.0 and 1.0
+ roughness = ((1.0 - ((material.specular_hardness - 1.0) / 510.0)))
+ ## scale from 0.0 to 0.1
+ roughness *= 0.1
+ # add a small value because 0.0 is invalid
+ roughness += (1 / 511.0)
- if material.diffuse_shader == 'TOON':
- file.write('\tbrilliance %.3g\n' % (0.01+material.diffuse_toon_smooth*0.25))
- frontDiffuse*=0.5 #Lower diffuse and increase specular for toon effect seems to look better in povray
-
- if material.diffuse_shader == 'MINNAERT':
- #file.write('\taoi %.3g\n' % material.darkness) #not real syntax, aoi is a pattern.
- pass # Have to put this in texture since AOI and slope map are patterns
- if material.diffuse_shader == 'FRESNEL':
- #file.write('\taoi %.3g\n' % material.diffuse_fresnel_factor) #not real syntax, aoi is a pattern.
- pass # Have to put this in texture since AOI and slope map are patterns
- if material.diffuse_shader == 'LAMBERT':
- file.write('\tbrilliance 1.8\n') #trying to best match lambert attenuation by that constant brilliance value
-
-
- #########################################################################################
+ #####################################Diffuse Shader######################################
+ if material.diffuse_shader == 'OREN_NAYAR':
+ file.write('\tbrilliance %.3g\n' % (0.9+material.roughness))#blender roughness is what is generally called oren nayar Sigma, and brilliance in povray
- file.write('\tdiffuse %.3g %.3g\n' % (frontDiffuse, backDiffuse))
-
+ if material.diffuse_shader == 'TOON':
+ file.write('\tbrilliance %.3g\n' % (0.01+material.diffuse_toon_smooth*0.25))
+ frontDiffuse*=0.5 #Lower diffuse and increase specular for toon effect seems to look better in povray
- file.write('\tspecular 0\n')
+ if material.diffuse_shader == 'MINNAERT':
+ #file.write('\taoi %.3g\n' % material.darkness)
+ pass #let's keep things simple for now
+ if material.diffuse_shader == 'FRESNEL':
+ #file.write('\taoi %.3g\n' % material.diffuse_fresnel_factor)
+ pass #let's keep things simple for now
+ if material.diffuse_shader == 'LAMBERT':
+ file.write('\tbrilliance 1.8\n') #trying to best match lambert attenuation by that constant brilliance value
- file.write('\tambient %.3g\n' % material.ambient)
- #file.write('\tambient rgb <%.3g, %.3g, %.3g>\n' % tuple([c*material.ambient for c in world.ambient_color])) # povray blends the global value
- file.write('\temission %.3g\n' % material.emit) #New in povray 3.7
+ if Level == 2:
+ ####################################Specular Shader######################################
+ if material.specular_shader == 'COOKTORR' or material.specular_shader == 'PHONG':#No difference between phong and cook torrence in blender HaHa!
+ file.write('\tphong %.3g\n' % (material.specular_intensity))
+ file.write('\tphong_size %.3g\n'% (material.specular_hardness / 2 + 0.25))
- if material.pov_conserve_energy:
- file.write('\tconserve_energy\n')#added for more realistic shading. Needs some checking to see if it really works. --Maurice.
+ if material.specular_shader == 'BLINN':#Povray "specular" keyword corresponds to a Blinn model, without the ior.
+ file.write('\tspecular %.3g\n' % (material.specular_intensity * (material.specular_ior/4))) #Use blender Blinn's IOR just as some factor for spec intensity
+ file.write('\troughness %.3g\n' % roughness)
+ #Could use brilliance 2(or varying around 2 depending on ior or factor) too.
- # 'phong 70.0 '
- if material.subsurface_scattering.use:
- subsurface_scattering = material.subsurface_scattering
- file.write('\tsubsurface { <%.3g, %.3g, %.3g>, <%.3g, %.3g, %.3g> }\n' % (sqrt(subsurface_scattering.radius[0])*1.5, sqrt(subsurface_scattering.radius[1])*1.5, sqrt(subsurface_scattering.radius[2])*1.5, 1-subsurface_scattering.color[0], 1-subsurface_scattering.color[1], 1-subsurface_scattering.color[2]))
+ if material.specular_shader == 'TOON':
+ file.write('\tphong %.3g\n' % (material.specular_intensity * 2))
+ file.write('\tphong_size %.3g\n' % (0.1+material.specular_toon_smooth / 2)) #use extreme phong_size
- if material.pov_irid_enable:
- file.write('\tirid { %.4g thickness %.4g turbulence %.4g }' % (material.pov_irid_amount, material.pov_irid_thickness, material.pov_irid_turbulence))
- file.write('}\n')
- ##################Plain version of the finish (previous ones are variations for specular/Mirror texture channel map with alternative finish of 0 specular and no mirror reflection###
- file.write('#declare %s = finish {\n' % safety(name))
+ if material.specular_shader == 'WARDISO':
+ file.write('\tspecular %.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.
+ file.write('\troughness %.4g\n' % (0.0005+material.specular_slope/10)) #find best suited default constant for brilliance Use both phong and specular for some values.
+ file.write('\tbrilliance %.4g\n' % (1.8-material.specular_slope*1.8)) #find best suited default constant for brilliance Use both phong and specular for some values.
+
- if material:
- #Povray 3.7 now uses two diffuse values respectively for front and back shading (the back diffuse is like blender translucency)
- frontDiffuse=material.diffuse_intensity
- backDiffuse=material.translucency
-
-
- if material.pov_conserve_energy:
-
- #Total should not go above one
- if (frontDiffuse + backDiffuse) <= 1.0:
- pass
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list