Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/shaders/node_brick_texture.osl
| Show All 22 Lines | |||||
| { | { | ||||
| int nn; | int nn; | ||||
| n = (n + 1013) & 2147483647; | n = (n + 1013) & 2147483647; | ||||
| n = (n >> 13) ^ n; | n = (n >> 13) ^ n; | ||||
| nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 2147483647; | nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 2147483647; | ||||
| return 0.5 * ((float)nn / 1073741824.0); | return 0.5 * ((float)nn / 1073741824.0); | ||||
| } | } | ||||
| float brick(point p, float mortar_size, float bias, | float smoothstep(float x) | ||||
| { | |||||
| float x2 = x*x; | |||||
| return 3*x2 - 2*x2*x; | |||||
| } | |||||
brecht: The builtin OSL `smoothstep(0.0, 1.0, x)` does the same I think. | |||||
| float brick(point p, float mortar_size, float mortar_smooth, float bias, | |||||
| float BrickWidth, float row_height, float offset_amount, int offset_frequency, | float BrickWidth, float row_height, float offset_amount, int offset_frequency, | ||||
| float squash_amount, int squash_frequency, float tint) | float squash_amount, int squash_frequency, float tint) | ||||
| { | { | ||||
| int bricknum, rownum; | int bricknum, rownum; | ||||
| float offset = 0.0; | float offset = 0.0; | ||||
| float brick_width = BrickWidth; | float brick_width = BrickWidth; | ||||
| float x, y; | float x, y; | ||||
| rownum = (int)floor(p[1] / row_height); | rownum = (int)floor(p[1] / row_height); | ||||
| if (offset_frequency && squash_frequency) { | if (offset_frequency && squash_frequency) { | ||||
| brick_width *= (rownum % squash_frequency) ? 1.0 : squash_amount; /* squash */ | brick_width *= (rownum % squash_frequency) ? 1.0 : squash_amount; /* squash */ | ||||
| offset = (rownum % offset_frequency) ? 0.0 : (brick_width * offset_amount); /* offset */ | offset = (rownum % offset_frequency) ? 0.0 : (brick_width * offset_amount); /* offset */ | ||||
| } | } | ||||
| bricknum = (int)floor((p[0] + offset) / brick_width); | bricknum = (int)floor((p[0] + offset) / brick_width); | ||||
| x = (p[0] + offset) - brick_width * bricknum; | x = (p[0] + offset) - brick_width * bricknum; | ||||
| y = p[1] - row_height * rownum; | y = p[1] - row_height * rownum; | ||||
| tint = clamp((brick_noise((rownum << 16) + (bricknum & 65535)) + bias), 0.0, 1.0); | tint = clamp((brick_noise((rownum << 16) + (bricknum & 65535)) + bias), 0.0, 1.0); | ||||
| return (x < mortar_size || y < mortar_size || | float min_dist = min(min(x, y), min(brick_width - x, row_height - y)); | ||||
| x > (brick_width - mortar_size) || | if(min_dist >= mortar_size) { | ||||
| y > (row_height - mortar_size)) ? 1.0 : 0.0; | return 0.0; | ||||
| } | |||||
| else if(mortar_smooth == 0.0) { | |||||
| return 1.0; | |||||
| } | |||||
| else { | |||||
| min_dist = 1.0 - min_dist/mortar_size; | |||||
| return (min_dist < mortar_smooth)? smoothstep(min_dist / mortar_smooth) : 1.0; | |||||
| } | |||||
| } | } | ||||
| shader node_brick_texture( | shader node_brick_texture( | ||||
| int use_mapping = 0, | int use_mapping = 0, | ||||
| matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), | matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), | ||||
| float offset = 0.5, | float offset = 0.5, | ||||
| int offset_frequency = 2, | int offset_frequency = 2, | ||||
| float squash = 1.0, | float squash = 1.0, | ||||
| int squash_frequency = 1, | int squash_frequency = 1, | ||||
| point Vector = P, | point Vector = P, | ||||
| color Color1 = 0.2, | color Color1 = 0.2, | ||||
| color Color2 = 0.8, | color Color2 = 0.8, | ||||
| color Mortar = 0.0, | color Mortar = 0.0, | ||||
| float Scale = 5.0, | float Scale = 5.0, | ||||
| float MortarSize = 0.02, | float MortarSize = 0.02, | ||||
| float MortarSmooth = 0.0, | |||||
| float Bias = 0.0, | float Bias = 0.0, | ||||
| float BrickWidth = 0.5, | float BrickWidth = 0.5, | ||||
| float RowHeight = 0.25, | float RowHeight = 0.25, | ||||
| output float Fac = 0.0, | output float Fac = 0.0, | ||||
| output color Color = 0.2) | output color Color = 0.2) | ||||
| { | { | ||||
| point p = Vector; | point p = Vector; | ||||
| if (use_mapping) | if (use_mapping) | ||||
| p = transform(mapping, p); | p = transform(mapping, p); | ||||
| float tint = 0.0; | float tint = 0.0; | ||||
| color Col = Color1; | color Col = Color1; | ||||
| Fac = brick(p * Scale, MortarSize, Bias, BrickWidth, RowHeight, | Fac = brick(p * Scale, MortarSize, MortarSmooth, Bias, BrickWidth, RowHeight, | ||||
| offset, offset_frequency, squash, squash_frequency, tint); | offset, offset_frequency, squash, squash_frequency, tint); | ||||
| if (Fac != 1.0) { | if (Fac != 1.0) { | ||||
| float facm = 1.0 - tint; | float facm = 1.0 - tint; | ||||
| Col = facm * Color1 + tint * Color2; | Col = facm * Color1 + tint * Color2; | ||||
| } | } | ||||
| Color = (Fac == 1.0) ? Mortar : Col; | Color = mix(Col, Mortar, Fac); | ||||
| } | } | ||||
The builtin OSL smoothstep(0.0, 1.0, x) does the same I think.