Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2016-05-20 16:18:40 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2016-05-20 16:18:40 +0300
commit0405bbeae2b61eec0fa0f598b7bf78a430c1c6f5 (patch)
treee5d919cca34c40907ba3b4c5fb3f7df319037eaf
parent9d1953311774673453da4a8f33ff37c771762c49 (diff)
Support Cycles's checker texture in GLSL shading
-rw-r--r--source/blender/gpu/shaders/gpu_shader_material.glsl22
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_checker.c4
2 files changed, 23 insertions, 3 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 72a59e6843d..3c6e2825acb 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -2310,6 +2310,11 @@ float hypot(float x, float y)
return sqrt(x*x + y*y);
}
+void generated_from_orco(vec3 orco, out vec3 generated)
+{
+ generated = orco * 0.5 + vec3(0.5);
+}
+
/*********** NEW SHADER NODES ***************/
#define NUM_LIGHTS 3
@@ -2576,8 +2581,21 @@ void node_tex_gradient(vec3 co, out vec4 color, out float fac)
void node_tex_checker(vec3 co, vec4 color1, vec4 color2, float scale, out vec4 color, out float fac)
{
- color = vec4(1.0);
- fac = 1.0;
+ vec3 p = co * scale;
+
+ /* Prevent precision issues on unit coordinates. */
+ p.x = (p.x + 0.000001)*0.999999;
+ p.y = (p.y + 0.000001)*0.999999;
+ p.z = (p.z + 0.000001)*0.999999;
+
+ int xi = abs(int(floor(p.x)));
+ int yi = abs(int(floor(p.y)));
+ int zi = abs(int(floor(p.z)));
+
+ bool check = ((xi % 2 == yi % 2) == bool(zi % 2));
+
+ color = check ? color1 : color2;
+ 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)
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_checker.c b/source/blender/nodes/shader/nodes/node_shader_tex_checker.c
index b7498df1706..77edd0e115e 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_checker.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_checker.c
@@ -54,8 +54,10 @@ static void node_shader_init_tex_checker(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_tex_checker(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);