diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-05-20 17:13:44 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-05-20 17:13:44 +0300 |
commit | b79214bbc54635ee76c41fd80a1bc67530770d63 (patch) | |
tree | f0041aba83bc50cbcb2e72ad5225296dd00ae731 /source/blender | |
parent | 0405bbeae2b61eec0fa0f598b7bf78a430c1c6f5 (diff) |
Support Cycles brick texture in GLSL viewport
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_material.glsl | 65 | ||||
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_tex_brick.c | 13 |
2 files changed, 72 insertions, 6 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index 3c6e2825acb..2e9dc9515ba 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -2315,6 +2315,20 @@ void generated_from_orco(vec3 orco, out vec3 generated) generated = orco * 0.5 + vec3(0.5); } +float integer_noise(int n) +{ + int nn; + n = (n + 1013) & 0x7fffffff; + n = (n >> 13) ^ n; + nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff; + return 0.5f * (float(nn) / 1073741824.0); +} + +int floor_to_int(float x) +{ + return int(floor(x)); +} + /*********** NEW SHADER NODES ***************/ #define NUM_LIGHTS 3 @@ -2598,10 +2612,55 @@ void node_tex_checker(vec3 co, vec4 color1, vec4 color2, float scale, out vec4 c fac = check ? 1.0 : 0.0; } -void node_tex_brick(vec3 co, vec4 color1, vec4 color2, vec4 mortar, float scale, float mortar_size, float bias, float brick_width, float row_height, out vec4 color, out float fac) +vec2 calc_brick_texture(vec3 p, float mortar_size, float bias, + float brick_width, float row_height, + float offset_amount, int offset_frequency, + float squash_amount, int squash_frequency) { - color = vec4(1.0); - fac = 1.0; + int bricknum, rownum; + float offset = 0.0; + float x, y; + + rownum = floor_to_int(p.y / row_height); + + if(offset_frequency != 0 && squash_frequency != 0) { + brick_width *= (rownum % squash_frequency != 0) ? 1.0 : squash_amount; /* squash */ + offset = (rownum % offset_frequency != 0) ? 0.0 : (brick_width*offset_amount); /* offset */ + } + + bricknum = floor_to_int((p.x+offset) / brick_width); + + x = (p.x+offset) - brick_width*bricknum; + y = p.y - row_height*rownum; + + return vec2(clamp((integer_noise((rownum << 16) + (bricknum & 0xFFFF)) + bias), 0.0, 1.0), + (x < mortar_size || y < mortar_size || + x > (brick_width - mortar_size) || + y > (row_height - mortar_size)) ? 1.0 : 0.0); +} + +void node_tex_brick(vec3 co, + vec4 color1, vec4 color2, + vec4 mortar, float scale, + float mortar_size, float bias, + float brick_width, float row_height, + float offset_amount, float offset_frequency, + float squash_amount, float squash_frequency, + out vec4 color, out float fac) +{ + vec2 f2 = calc_brick_texture(co*scale, + mortar_size, bias, + brick_width, row_height, + offset_amount, int(offset_frequency), + squash_amount, int(squash_frequency)); + float tint = f2.x; + float f = f2.y; + if(f != 1.0) { + float facm = 1.0 - tint; + color1 = facm * color1 + tint * color2; + } + color = (f == 1.0) ? mortar : color1; + fac = f; } void node_tex_clouds(vec3 co, float size, out vec4 color, out float fac) diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_brick.c b/source/blender/nodes/shader/nodes/node_shader_tex_brick.c index 569eaf5ff9b..bb7f2166a8a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_brick.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_brick.c @@ -64,12 +64,19 @@ static void node_shader_init_tex_brick(bNodeTree *UNUSED(ntree), bNode *node) static int node_shader_gpu_tex_brick(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - if (!in[0].link) + if (!in[0].link) { in[0].link = GPU_attribute(CD_ORCO, ""); + GPU_link(mat, "generated_from_orco", in[0].link, &in[0].link); + } node_shader_gpu_tex_mapping(mat, node, in, out); - - return GPU_stack_link(mat, "node_tex_brick", in, out); + NodeTexBrick *tex = (NodeTexBrick *)node->storage; + float offset_freq = tex->offset_freq; + float squash_freq = tex->squash_freq; + return GPU_stack_link(mat, "node_tex_brick", + in, out, + GPU_uniform(&tex->offset), GPU_uniform(&offset_freq), + GPU_uniform(&tex->squash), GPU_uniform(&squash_freq)); } /* node type definition */ |