diff options
author | Lukas Stockner <lukas.stockner@freenet.de> | 2016-10-30 02:33:10 +0300 |
---|---|---|
committer | Lukas Stockner <lukas.stockner@freenet.de> | 2016-10-30 03:16:22 +0300 |
commit | b2974d7ab79a257f8628c24c05d43da25791018d (patch) | |
tree | cd7b6376d8c5f5cd105bce74d82f991845d511e4 /intern/cycles/kernel/shaders | |
parent | 5aa6a2ec06bbfa9ddd255c90ee02da5f9be36f30 (diff) |
Cycles: Add smoothing option to the Brick Texture
This option allows to create a smoother transition between Bricks and Mortar - 0 applies no smoothing, and 1 smooths across the whole mortar width.
Mainly useful for displacement textures.
The new default value for the smoothing option is 0.1 to give some smoothing that helps with antialiasing, but existing nodes are loaded with smoothing 0 to preserve compatibility.
Reviewers: sergey, dingto, juicyfruit, brecht
Reviewed By: brecht
Subscribers: Blendify, nutel
Differential Revision: https://developer.blender.org/D2230
Diffstat (limited to 'intern/cycles/kernel/shaders')
-rw-r--r-- | intern/cycles/kernel/shaders/node_brick_texture.osl | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/intern/cycles/kernel/shaders/node_brick_texture.osl b/intern/cycles/kernel/shaders/node_brick_texture.osl index d5e0a7d4c8c..c303594681c 100644 --- a/intern/cycles/kernel/shaders/node_brick_texture.osl +++ b/intern/cycles/kernel/shaders/node_brick_texture.osl @@ -28,7 +28,7 @@ float brick_noise(int n) /* fast integer noise */ return 0.5 * ((float)nn / 1073741824.0); } -float brick(point p, float mortar_size, float bias, +float brick(point p, float mortar_size, float mortar_smooth, float bias, float BrickWidth, float row_height, float offset_amount, int offset_frequency, float squash_amount, int squash_frequency, float tint) { @@ -51,9 +51,17 @@ float brick(point p, float mortar_size, float bias, tint = clamp((brick_noise((rownum << 16) + (bricknum & 65535)) + bias), 0.0, 1.0); - return (x < mortar_size || y < mortar_size || - x > (brick_width - mortar_size) || - y > (row_height - mortar_size)) ? 1.0 : 0.0; + float min_dist = min(min(x, y), min(brick_width - x, row_height - y)); + if(min_dist >= mortar_size) { + return 0.0; + } + else if(mortar_smooth == 0.0) { + return 1.0; + } + else { + min_dist = 1.0 - min_dist/mortar_size; + return smoothstep(0.0, mortar_smooth, min_dist); + } } shader node_brick_texture( @@ -69,6 +77,7 @@ shader node_brick_texture( color Mortar = 0.0, float Scale = 5.0, float MortarSize = 0.02, + float MortarSmooth = 0.0, float Bias = 0.0, float BrickWidth = 0.5, float RowHeight = 0.25, @@ -83,7 +92,7 @@ shader node_brick_texture( float tint = 0.0; 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); if (Fac != 1.0) { @@ -91,6 +100,6 @@ shader node_brick_texture( Col = facm * Color1 + tint * Color2; } - Color = (Fac == 1.0) ? Mortar : Col; + Color = mix(Col, Mortar, Fac); } |