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 /* Magic */ 00022 00023 __device_noinline float3 svm_magic(float3 p, int n, float distortion) 00024 { 00025 float x = sinf((p.x + p.y + p.z)*5.0f); 00026 float y = cosf((-p.x + p.y - p.z)*5.0f); 00027 float z = -cosf((-p.x - p.y + p.z)*5.0f); 00028 00029 if(n > 0) { 00030 x *= distortion; 00031 y *= distortion; 00032 z *= distortion; 00033 y = -cosf(x-y+z); 00034 y *= distortion; 00035 00036 if(n > 1) { 00037 x= cosf(x-y-z); 00038 x *= distortion; 00039 00040 if(n > 2) { 00041 z= sinf(-x-y-z); 00042 z *= distortion; 00043 00044 if(n > 3) { 00045 x= -cosf(-x+y-z); 00046 x *= distortion; 00047 00048 if(n > 4) { 00049 y= -sinf(-x+y+z); 00050 y *= distortion; 00051 00052 if(n > 5) { 00053 y= -cosf(-x+y+z); 00054 y *= distortion; 00055 00056 if(n > 6) { 00057 x= cosf(x+y+z); 00058 x *= distortion; 00059 00060 if(n > 7) { 00061 z= sinf(x+y-z); 00062 z *= distortion; 00063 00064 if(n > 8) { 00065 x= -cosf(-x-y+z); 00066 x *= distortion; 00067 00068 if(n > 9) { 00069 y= -sinf(x-y+z); 00070 y *= distortion; 00071 } 00072 } 00073 } 00074 } 00075 } 00076 } 00077 } 00078 } 00079 } 00080 } 00081 00082 if(distortion != 0.0f) { 00083 distortion *= 2.0f; 00084 x /= distortion; 00085 y /= distortion; 00086 z /= distortion; 00087 } 00088 00089 return make_float3(0.5f - x, 0.5f - y, 0.5f - z); 00090 } 00091 00092 __device void svm_node_tex_magic(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) 00093 { 00094 uint depth; 00095 uint scale_offset, distortion_offset, co_offset, fac_offset, color_offset; 00096 00097 decode_node_uchar4(node.y, &depth, &color_offset, &fac_offset, NULL); 00098 decode_node_uchar4(node.z, &co_offset, &scale_offset, &distortion_offset, NULL); 00099 00100 uint4 node2 = read_node(kg, offset); 00101 float3 co = stack_load_float3(stack, co_offset); 00102 float scale = stack_load_float_default(stack, scale_offset, node2.x); 00103 float distortion = stack_load_float_default(stack, distortion_offset, node2.y); 00104 00105 float3 color = svm_magic(co*scale, depth, distortion); 00106 00107 if(stack_valid(fac_offset)) 00108 stack_store_float(stack, fac_offset, average(color)); 00109 if(stack_valid(color_offset)) 00110 stack_store_float3(stack, color_offset, color); 00111 } 00112 00113 CCL_NAMESPACE_END 00114