Blender V2.61 - r43446
|
00001 /* 00002 * Copyright 2011, Blender Foundation. 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 CCL_NAMESPACE_BEGIN 00020 00021 /* Gradient */ 00022 00023 __device float svm_gradient(float3 p, NodeBlendType type) 00024 { 00025 float x, y, z; 00026 00027 x= p.x; 00028 y= p.y; 00029 z= p.z; 00030 00031 if(type == NODE_BLEND_LINEAR) { 00032 return x; 00033 } 00034 else if(type == NODE_BLEND_QUADRATIC) { 00035 float r = fmaxf(x, 0.0f); 00036 return r*r; 00037 } 00038 else if(type == NODE_BLEND_EASING) { 00039 float r = fminf(fmaxf(x, 0.0f), 1.0f); 00040 float t = r*r; 00041 00042 return (3.0f*t - 2.0f*t*r); 00043 } 00044 else if(type == NODE_BLEND_DIAGONAL) { 00045 return (x + y)/2.0f; 00046 } 00047 else if(type == NODE_BLEND_RADIAL) { 00048 return atan2(y, x)/(2.0f*M_PI_F) + 0.5f; 00049 } 00050 else { 00051 float r = fmaxf(1.0f - sqrtf(x*x + y*y + z*z), 0.0f); 00052 00053 if(type == NODE_BLEND_QUADRATIC_SPHERE) 00054 return r*r; 00055 else if(type == NODE_BLEND_SPHERICAL) 00056 return r; 00057 } 00058 00059 return 0.0f; 00060 } 00061 00062 __device void svm_node_tex_gradient(ShaderData *sd, float *stack, uint4 node) 00063 { 00064 uint type, co_offset, color_offset, fac_offset; 00065 00066 decode_node_uchar4(node.y, &type, &co_offset, &fac_offset, &color_offset); 00067 00068 float3 co = stack_load_float3(stack, co_offset); 00069 00070 float f = svm_gradient(co, (NodeBlendType)type); 00071 f = clamp(f, 0.0f, 1.0f); 00072 00073 if(stack_valid(fac_offset)) 00074 stack_store_float(stack, fac_offset, f); 00075 if(stack_valid(color_offset)) 00076 stack_store_float3(stack, color_offset, make_float3(f, f, f)); 00077 } 00078 00079 CCL_NAMESPACE_END 00080