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:
Diffstat (limited to 'source/blender/gpu/shaders/gpu_shader_material.glsl')
-rw-r--r--source/blender/gpu/shaders/gpu_shader_material.glsl45
1 files changed, 42 insertions, 3 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 2e9dc9515ba..faeb9bb17f6 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -2587,10 +2587,49 @@ void node_tex_coord_background(vec3 I, vec3 N, mat4 viewinvmat, mat4 obinvmat, v
/* textures */
-void node_tex_gradient(vec3 co, out vec4 color, out float fac)
+float calc_gradient(vec3 p, int gradient_type)
+{
+ float x, y, z;
+ x = p.x;
+ y = p.y;
+ z = p.z;
+ if(gradient_type == 0) { /* linear */
+ return x;
+ }
+ else if(gradient_type == 1) { /* quadratic */
+ float r = max(x, 0.0);
+ return r*r;
+ }
+ else if(gradient_type == 2) { /* easing */
+ float r = min(max(x, 0.0), 1.0);
+ float t = r*r;
+ return (3.0*t - 2.0*t*r);
+ }
+ else if(gradient_type == 3) { /* diagonal */
+ return (x + y) * 0.5;
+ }
+ else if(gradient_type == 4) { /* radial */
+ return atan(y, x) / (M_PI * 2) + 0.5;
+ }
+ else {
+ float r = max(1.0 - sqrt(x*x + y*y + z*z), 0.0);
+ if(gradient_type == 5) { /* quadratic sphere */
+ return r*r;
+ }
+ else if(gradient_type == 6) { /* sphere */
+ return r;
+ }
+ }
+ return 0.0;
+}
+
+void node_tex_gradient(vec3 co, float gradient_type, out vec4 color, out float fac)
{
- color = vec4(1.0);
- fac = 1.0;
+ float f = calc_gradient(co, int(gradient_type));
+ f = clamp(f, 0.0, 1.0);
+
+ color = vec4(f, f, f, 1.0);
+ fac = f;
}
void node_tex_checker(vec3 co, vec4 color1, vec4 color2, float scale, out vec4 color, out float fac)