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

« back to all changes in this revision

Viewing changes to intern/cycles/kernel/shaders/node_brick_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 2012, 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
/* Brick */
 
23
 
 
24
float brick_noise(int n) /* fast integer noise */
 
25
{
 
26
        int nn;
 
27
        n = (n >> 13) ^ n;
 
28
        nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 2147483647;
 
29
        return 0.5 * ((float)nn / 1073741824.0);
 
30
}
 
31
 
 
32
float brick(point p, float mortar_size, float bias,
 
33
        float BrickWidth, float row_height, float offset_amount, int offset_frequency,
 
34
        float squash_amount, int squash_frequency, float tint)
 
35
{
 
36
        int bricknum, rownum;
 
37
        float offset = 0.0;
 
38
        float brick_width = BrickWidth;
 
39
        float x, y;
 
40
 
 
41
        rownum = (int)floor(p[1] / row_height);
 
42
        
 
43
        if (offset_frequency && squash_frequency) {
 
44
                brick_width *= ((int)(rownum) % squash_frequency) ? 1.0 : squash_amount;                /* squash */
 
45
                offset       = ((int)(rownum) % offset_frequency) ? 0 : (brick_width * offset_amount);  /* offset */
 
46
        }
 
47
 
 
48
        bricknum = (int)floor((p[0] + offset) / brick_width);
 
49
 
 
50
        x = (p[0] + offset) - brick_width * bricknum;
 
51
        y = p[1] - row_height * rownum;
 
52
 
 
53
        tint = clamp((brick_noise((rownum << 16) + (bricknum & 65535)) + bias), 0.0, 1.0);
 
54
 
 
55
        return (x < mortar_size || y < mortar_size ||
 
56
                x > (brick_width - mortar_size) ||
 
57
                y > (row_height - mortar_size)) ? 1.0 : 0.0;
 
58
}
 
59
 
 
60
shader node_brick_texture(
 
61
        int use_mapping = 0,
 
62
        matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
 
63
        float Offset = 0.5,
 
64
        int OffsetFrequency = 2,
 
65
        float Squash = 1.0,
 
66
        int SquashFrequency = 1,
 
67
        point Vector = P,
 
68
        color Color1 = 0.2,
 
69
        color Color2 = 0.8,
 
70
        color Mortar = 0.0,
 
71
        float Scale = 5.0,
 
72
        float MortarSize = 0.02,
 
73
        float Bias = 0.0,
 
74
        float BrickWidth = 0.5,
 
75
        float RowHeight = 0.25,
 
76
        output float Fac = 0.0,
 
77
        output color Color = 0.2)
 
78
{
 
79
        point p = Vector;
 
80
 
 
81
        if (use_mapping)
 
82
                p = transform(mapping, p);
 
83
 
 
84
        float tint = 0.0;
 
85
        color Col = Color1;
 
86
        
 
87
        Fac = brick(p * Scale, MortarSize, Bias, BrickWidth, RowHeight,
 
88
                Offset, OffsetFrequency, Squash, SquashFrequency, tint);
 
89
                
 
90
        if (Fac != 1.0) {
 
91
                float facm = 1.0 - tint;
 
92
 
 
93
                Col[0] = facm * (Color1[0]) + tint * Color2[0];
 
94
                Col[1] = facm * (Color1[1]) + tint * Color2[1];
 
95
                Col[2] = facm * (Color1[2]) + tint * Color2[2];
 
96
        }
 
97
        
 
98
        Color = (Fac == 1.0) ? Mortar: Col;
 
99
}
 
100