diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-11-06 23:58:48 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-11-06 23:58:48 +0400 |
commit | 64467e3ffa250233b25d14d1b46927c54780eefd (patch) | |
tree | a43be71e61ca08fdf7156dea2e85c9802276ee49 /source/blender/gpu | |
parent | 1c6c3ead4f689d1b282ceec2b2756438abc0e11c (diff) |
Fixes related to #33087:
* Fix GLSL memory leak in the (vector) math node.
* Fix GLSL math node pow behavior for negative values, same as was done for C.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/GPU_material.h | 1 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_codegen.c | 9 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_material.glsl | 30 |
3 files changed, 26 insertions, 14 deletions
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index 97e8b756d08..c46230de8bf 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -110,7 +110,6 @@ GPUNodeLink *GPU_dynamic_uniform(float *num, int dynamictype, void *data); GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser, int isdata); GPUNodeLink *GPU_texture(int size, float *pixels); GPUNodeLink *GPU_dynamic_texture(struct GPUTexture *tex, int dynamictype, void *data); -GPUNodeLink *GPU_socket(GPUNodeStack *sock); GPUNodeLink *GPU_builtin(GPUBuiltin builtin); int GPU_link(GPUMaterial *mat, const char *name, ...); diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index b4490e656f3..4432627ee7e 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -1148,15 +1148,6 @@ GPUNodeLink *GPU_dynamic_texture(GPUTexture *tex, int dynamictype, void *data) return link; } -GPUNodeLink *GPU_socket(GPUNodeStack *sock) -{ - GPUNodeLink *link = GPU_node_link_create(0); - - link->socket= sock; - - return link; -} - GPUNodeLink *GPU_builtin(GPUBuiltin builtin) { GPUNodeLink *link = GPU_node_link_create(0); diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index b930058864c..9a238e979fa 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -4,6 +4,21 @@ float exp_blender(float f) return pow(2.71828182846, f); } +float compatible_pow(float x, float y) +{ + /* glsl pow doesn't accept negative x */ + if(x < 0.0) { + if(mod(-y, 2.0) == 0.0) + return pow(-x, y); + else + return -pow(-x, y); + } + else if(x == 0.0) + return 0.0; + + return pow(x, y); +} + void rgb_to_hsv(vec4 rgb, out vec4 outcol) { float cmax, cmin, h, s, v, cdelta; @@ -212,10 +227,17 @@ void math_atan(float val, out float outval) void math_pow(float val1, float val2, out float outval) { - if (val1 >= 0.0) - outval = pow(val1, val2); - else - outval = 0.0; + if (val1 >= 0.0) { + outval = compatible_pow(val1, val2); + } + else { + float val2_mod_1 = mod(abs(val2), 1.0); + + if (val2_mod_1 > 0.999 || val2_mod_1 < 0.001) + outval = compatible_pow(val1, floor(val2 + 0.5)); + else + outval = 0.0; + } } void math_log(float val1, float val2, out float outval) |