Skip to content
Snippets Groups Projects
shading.py 55.4 KiB
Newer Older
  • Learn to ignore specific revisions
  • Maurice Raybaud's avatar
    Maurice Raybaud committed
                              mappingAlpha))
                tabWrite("pigment_map {\n")
                tabWrite("[0 color rgbft<0,0,0,1,1>]\n")
                tabWrite("[1 color rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>]\n" % \
                         (col[0], col[1], col[2], povFilter, trans))
                tabWrite("}\n")
                tabWrite("}\n")
    
            else:
                tabWrite("pigment {rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>}\n" % \
                         (col[0], col[1], col[2], povFilter, trans))
                         
                                        
            if texturesSpec != "":
                # Level 3 is full specular
                tabWrite("finish {%s}\n" % (safety(material_finish, Level=3)))
                
            elif colored_specular_found:
                # Level 1 is no specular
                tabWrite("finish {%s}\n" % (safety(material_finish, Level=1)))
    
            else:
                # Level 2 is translated specular
                tabWrite("finish {%s}\n" % (safety(material_finish, Level=2)))
    
        elif mater.pov.replacement_text == "":
            mappingDif = imgMapTransforms(t_dif)
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            if texturesAlpha != "":
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
                mappingAlpha = imgMapTransforms(t_alpha)
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
                if texturesAlpha and texturesAlpha.startswith("PAT_"):
    
                    tabWrite("pigment{pigment_pattern {function{f%s(x,y,z).transmit}%s}\n" %(texturesAlpha, mappingAlpha))
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
                else:
                    tabWrite("pigment {pigment_pattern {uv_mapping image_map" \
                             "{%s \"%s\" %s}%s}\n" % \
                             (imageFormat(texturesAlpha), texturesAlpha, imgMap(t_alpha),
                              mappingAlpha))
                tabWrite("pigment_map {\n")
                tabWrite("[0 color rgbft<0,0,0,1,1>]\n")
                if texturesAlpha and texturesAlpha.startswith("PAT_"):
    
                    tabWrite("[1 function{f%s(x,y,z).transmit}%s]\n" %(texturesAlpha, mappingAlpha)) 
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
                elif texturesDif and not texturesDif.startswith("PAT_"):                                       
                    tabWrite("[1 uv_mapping image_map {%s \"%s\" %s} %s]\n" % \
                             (imageFormat(texturesDif), texturesDif,
                              (imgMap(t_dif) + imgGamma), mappingDif))
                elif texturesDif and texturesDif.startswith("PAT_"):
    
                    tabWrite("[1 %s %s]\n" %(texturesDif, mappingDif))
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
                tabWrite("}\n")
                tabWrite("}\n")
    
            else:
                if texturesDif and texturesDif.startswith("PAT_"):
    
                    tabWrite("pigment{%s %s}\n" %(texturesDif, mappingDif)) 
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
                else:                                    
                    tabWrite("pigment {\n")
                    tabWrite("uv_mapping image_map {\n")
                    #tabWrite("%s \"%s\" %s}%s\n" % \
                    #         (imageFormat(texturesDif), texturesDif,
                    #         (imgGamma + imgMap(t_dif)),mappingDif))
                    tabWrite("%s \"%s\" \n" % (imageFormat(texturesDif), texturesDif))
                    tabWrite("%s\n" % (imgGamma + imgMap(t_dif)))
                    tabWrite("}\n")
                    tabWrite("%s\n" % mappingDif)
                    tabWrite("}\n")
                  
            if texturesSpec != "":
                # Level 3 is full specular
                tabWrite("finish {%s}\n" % (safety(material_finish, Level=3)))                  
            else:
                # Level 2 is translated specular
                tabWrite("finish {%s}\n" % (safety(material_finish, Level=2)))
    
            ## scale 1 rotate y*0
            #imageMap = ("{image_map {%s \"%s\" %s }" % \
            #            (imageFormat(textures), textures,imgMap(t_dif)))
    
            #tabWrite("\n\t\t\tuv_mapping pigment %s} %s finish {%s}" % \
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            #           (imageMap, mapping, safety(material_finish)))
    
            #tabWrite("\n\t\t\tpigment {uv_mapping image_map " \
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            #           "{%s \"%s\" %s}%s} finish {%s}" % \
            #           (imageFormat(texturesDif), texturesDif,imgMap(t_dif),
            #            mappingDif, safety(material_finish)))
        if texturesNorm != "" and mater.pov.replacement_text == "":
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            mappingNor =imgMapTransforms(t_nor)
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            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))
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            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.0, mappingNor))
        if texturesSpec != "" and mater.pov.replacement_text == "":
            tabWrite("]\n")
    
            tabWrite("}\n")
    
        #End of slope/ior texture_map
        if mater.diffuse_shader == 'MINNAERT' and mater.pov.replacement_text == "":
            tabWrite("]\n")
            tabWrite("}\n")
        if mater.diffuse_shader == 'FRESNEL' and mater.pov.replacement_text == "":
            c = 1
            while (c <= lampCount):
                tabWrite("]\n")
                tabWrite("}\n")
                c += 1
    
          
                
        # Close first layer of POV "texture" (Blender material)
        tabWrite("}\n")
        
        if (mater.specular_color.s > 0.0):
            colored_specular_found = True
        else:
            colored_specular_found = False
            
        # Write another layered texture using invisible diffuse and metallic trick 
        # to emulate colored specular highlights
        special_texture_found = False
        for t in mater.texture_slots:
            if(t and t.use and ((t.texture.type == 'IMAGE' and t.texture.image) or t.texture.type != 'IMAGE') and
               (t.use_map_specular or t.use_map_raymir)):
                # Specular mapped textures would conflict with colored specular
                # because POV can't layer over or under pigment patterned textures
                special_texture_found = True
        
        if colored_specular_found and not special_texture_found:
            if comments:
    
                tabWrite("  // colored highlights with a stransparent metallic layer\n")
    
    Maurice Raybaud's avatar
    Maurice Raybaud committed
            else:
                tabWrite("\n")
        
            tabWrite("texture {\n")
            tabWrite("pigment {rgbft<%.3g, %.3g, %.3g, 0, 1>}\n" % \
                             (mater.specular_color[0], mater.specular_color[1], mater.specular_color[2]))
            tabWrite("finish {%s}\n" % (safety(material_finish, Level=2))) # Level 2 is translated spec
    
            texturesNorm = ""
            for t in mater.texture_slots:
    
                if t and t.texture.pov.tex_pattern_type != 'emulator':
                    proceduralFlag=True
                    image_filename = string_strip_hyphen(bpy.path.clean_name(t.texture.name))
                if (t and t.texture.type == 'IMAGE' and
                        t.use and t.texture.image and
                        t.texture.pov.tex_pattern_type == 'emulator'):
                    proceduralFlag=False 
                    image_filename = path_image(t.texture.image)
                    imgGamma = ""
                    if image_filename:
                        if t.use_map_normal:
                            texturesNorm = image_filename
                            # colvalue = t.normal_factor * 10.0  # UNUSED
                            #textNormName=t.texture.image.name + ".normal"
                            #was the above used? --MR
                            t_nor = t
                            if proceduralFlag:
                                tabWrite("normal{function" \
                                         "{f%s(x,y,z).grey} bump_size %.4g}\n" % \
                                         (texturesNorm,
                                         t_nor.normal_factor * 10))
                            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))
                                          
            tabWrite("}\n") # THEN IT CAN CLOSE LAST LAYER OF TEXTURE