~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to intern/cycles/kernel/osl/nodes/node_voronoi_texture.osl

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2011, Blender Foundation.
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or
5
 
 * modify it under the terms of the GNU General Public License
6
 
 * as published by the Free Software Foundation; either version 2
7
 
 * of the License, or (at your option) any later version.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software Foundation,
16
 
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
 
 */
18
 
 
19
 
#include "stdosl.h"
20
 
#include "node_texture.h"
21
 
 
22
 
/* Voronoi */
23
 
 
24
 
shader node_voronoi_texture(
25
 
        string DistanceMetric = "Actual Distance",
26
 
        string Coloring = "Intensity",
27
 
        float Weight1 = 1.0,
28
 
        float Weight2 = 0.0,
29
 
        float Weight3 = 0.0,
30
 
        float Weight4 = 0.0,
31
 
        float Exponent = 2.5,
32
 
        float Intensity = 1.0,
33
 
        float Size = 0.25,
34
 
        point Vector = P,
35
 
        output float Fac = 0.0,
36
 
        output color Color = color(0.0, 0.0, 0.0))
37
 
{
38
 
        float exponent = max(Exponent, 1e-5);
39
 
        float size = nonzero(Size, 1e-5);
40
 
 
41
 
        float aw1 = fabs(Weight1);
42
 
        float aw2 = fabs(Weight2);
43
 
        float aw3 = fabs(Weight3);
44
 
        float aw4 = fabs(Weight4);
45
 
        float sc = (aw1 + aw2 + aw3 + aw4);
46
 
 
47
 
        if(sc != 0.0)
48
 
                sc = Intensity/sc;
49
 
        
50
 
        /* compute distance and point coordinate of 4 nearest neighbours */
51
 
        float da[4];
52
 
        point pa[4];
53
 
 
54
 
        voronoi(Vector/size, DistanceMetric, exponent, da, pa);
55
 
 
56
 
        /* Scalar output */
57
 
        Fac = sc * fabs(Weight1*da[0] + Weight2*da[1] + Weight3*da[2] + Weight4*da[3]);
58
 
 
59
 
        /* Colored output */
60
 
        if(Coloring == "Intensity") {
61
 
                Color = color(Fac, Fac, Fac);
62
 
        }
63
 
        else {
64
 
                Color = aw1*cellnoise_color(pa[0]);
65
 
                Color += aw2*cellnoise_color(pa[1]);
66
 
                Color += aw3*cellnoise_color(pa[2]);
67
 
                Color += aw4*cellnoise_color(pa[3]);
68
 
 
69
 
                if(Coloring != "Position") {
70
 
                        float t1 = min((da[1] - da[0])*10.0, 1.0);
71
 
 
72
 
                        if(Coloring == "Position, Outline, and Intensity")
73
 
                                Color *= t1*Fac;
74
 
                        else if(Coloring == "Position and Outline")
75
 
                                Color *= t1*sc;
76
 
                }
77
 
                else {
78
 
                        Color *= sc;
79
 
                }
80
 
        }
81
 
}
82