闲来无事跟大家分享一下POV渲染技巧

来源:湖北师范大学-先进材料研究院作者:日期:2019-07-10浏览:7

2019年6月7日,端午佳节,在家闲来无事,整理电脑文件时碰巧找到当年用捣鼓POV-Ray作出的一些图。想想当初硕士时候,每天捧着200多页全英文的POV手册艰难的啃着,时有收获便不禁拍案而起:我靠,原来是这样的!殊不知我的老师已经神不知鬼不觉的站在我身后了……直到现在,想起当初的种种场景依然会心一笑。现在已经告别学生身份的我决定整理一点我学习的经验,供后来人参考。

        POV,也就是POV-Ray,是一款非常小巧却功能强大的渲染器,通常会和diamond软件联用。利用diamond读取cif文件构建结构模型,再导出为.pov文件,在POV里渲染。当然也可以纯粹利用POV进行建模,不过需要掌握一些它特有的POV语言,个人认为POV语言还是比较易学的,跟Python差不多吧。接下来我会以几个实例来讲解一下POV里的一些功能,前提是你已经会diamond的一些基本操作,同时稍微有一点编程的知识。

        利用POV渲染出高质量的图,无非是材质、光线、介质以及特殊函数的运用。我以MOF-5这个结构为例来进行说明。将MOF-5的cif文件导入diamond中,初步渲染的效果图见下图左图,虽然忠于原结构,但是平淡无奇。下图右图是在原图基础上引入介质后作出的效果图。这里用的是全屏介质,创造出一种迷雾朦胧的感觉。同时迷雾还能显现光线的路径,营造出光影斑驳的效果。核心代码如下:
media {
        scattering {1, 0.05
                extinction 0.8
                }
                intervals 20
                density {
                        granite
                        scale 20
                        color_map {
                                [0 rgb <1,1,1>*0.1]
                                [0.5 rgb <1,1,1>*0.3]
                                [1 rgb <1,1,1>*1]
                        }
                }
}

 
         在上面的例子中用的是全屏介质,还可以将介质限域在特定的空间或形状里,这在MOF结构中凸显孔道效果尤其好用。下图是截取NU-1000的结构,在其六方孔道中填充介质作出的效果图。需要注意的是hollow这个指令的使用。核心代码如下:
cylinder {
                <0.00002,0.00005,-45.32700>, <0.00002,0.00005,42.84921>, 15
                rotate <59.29753,0.64667,-1.41331>
                hollow
                pigment {color rgbt 1}
                interior {
                        media {
                                emission 0.05
                                density {
                                        bozo
                                        scale 10
                                        color_map {
                                                   [0.2 rgb White*0.2]
                                                   [0.4 rgb White*0.4]
                                                   [0.6 rgb White*0.6]
                                                   [0.8 rgb White*0.8]
                                                   [1 rgb White*1]
                                        }  scale 20
                                        }
                }  }
}  

 

         除去介质的使用外,还需要注意材质的运用。POV自带诸多材质,如玻璃、金属、木材等,可以在它的头文件如glass.inc、metal.inc等里直接调用就行,这样就可以营造出玻璃的剔透、金属的光泽、塑料的质感等效果。下图是介质和材质结合作出的效果图,其核心代码如下:
cone {
        <0.00005,-0.00004,13.60000>,10, <0.00005,-0.00004,-53.60000>, 25   
        rotate <73.37910,2.70824,-0.22183>
        pigment {color rgbt 1}
        hollow
        interior {
                media {
                        emission 0.01
                        density {
                               
                                gradient y
                                color_map {
                                                [0 rgb <1,0,0>]
                                                [0.2 rgb <0,1,0>]
                                                [0.4 rgb <0,0,1>]
                                                [0.6 rgb <1,1,0>]
                                                [0.8 rgb <0,1,1>]
                                                [1 rgb <1,1,1>]  
                                                
                                }  scale 80
                        }
                }
        }
}  

 

         如果懂一些matlab的函数以及C语言里的循环、嵌套等语法,就可以随心所欲的构筑自己想要的模型,不必借助于diamond和cif文件。下图是利用循环语句构筑的一个弯曲的孔道图,其核心代码如下:
# declare ran1 = seed(1);
# declare ran2 = seed(2);
# declare ran3 = seed(3);
#declare Y =0;
# declare YZ=1;
# declare step = 0.02;
#while (Y < YZ)
        # declare X = 0;
        # declare XZ = 1.01;
        # declare step1=1/20;
         #while (X < XZ)
                       blob{
                       threshold 0.6
                        sphere {
                        0,2,1.5   
                        pigment {color <0.8,0.8,0>*Y+<0.05,0.2,0.5>}
          
                                finish {phong 0.5
                                        reflection 0.4
                                        metallic
                                        specular 0.001  
                                       
                                        ambient 0.2
                                }
                            
                                           
                        translate <5,0,0>
                        rotate X*360*z
                       
                        
                        translate -15*x
                        rotate 0.5*Y*360*y
                        }
                        }                    
          # declare X = X + step1;
          # end
         
 # declare Y = Y + step;
 # end

 

         还可以借助POV自带的一些特殊函数来实现特定的效果。这里以random函数为例来说明。下图是利用POV的循环语句构建的孔道模型,利用random函数对孔壁进行随机着色,从而创造出类似于彩虹的五彩斑斓效果,其核心代码如下:
# declare a = 1;
# declare an = 20;
# declare step = 0.5;
# while (a < an + step)
 
                sphere {
                        0,0.5
                        texture {
                                pigment {color rgb <rand(ran1),rand(ran2),rand(ran3)>}
                                finish {
                                        phong 1
                                        phong_size 400
                                        specular 0.0001
                                }
                      }
                translate <3*(-1+2*rand(ran1)),3*(-1+2*rand(ran2)),100*rand(ran3)>
                rotate 0.05*360*z   
}               
              # declare a = a + 1;
                # end                

 


                POV这个软件功能太多,能实现的效果无法想象,需要细细钻研。想要玩转它,非数年的功力不可。鄙人在此也不过抛砖引玉,班门弄斧而已。
                最后,我非常希望和技术达人交流,如若愿意加入我们,那也是极好。原创不易,如若转载请注明出处。
上一篇:下一篇: