Blender V2.61 - r43446

svm_tex_coord.h

Go to the documentation of this file.
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 /* Texture Coordinate Node */
00022 
00023 __device float3 svm_background_offset(KernelGlobals *kg)
00024 {
00025     Transform cameratoworld = kernel_data.cam.cameratoworld;
00026     return make_float3(cameratoworld.x.w, cameratoworld.y.w, cameratoworld.z.w);
00027 }
00028 
00029 __device void svm_node_tex_coord(KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset)
00030 {
00031     float3 data;
00032 
00033     switch(type) {
00034         case NODE_TEXCO_OBJECT: {
00035             if(sd->object != ~0) {
00036                 Transform tfm = object_fetch_transform(kg, sd->object, OBJECT_INVERSE_TRANSFORM);
00037                 data = transform(&tfm, sd->P);
00038             }
00039             else
00040                 data = sd->P;
00041             break;
00042         }
00043         case NODE_TEXCO_CAMERA: {
00044             Transform tfm = kernel_data.cam.worldtocamera;
00045 
00046             if(sd->object != ~0)
00047                 data = transform(&tfm, sd->P);
00048             else
00049                 data = transform(&tfm, sd->P + svm_background_offset(kg));
00050             break;
00051         }
00052         case NODE_TEXCO_WINDOW: {
00053             Transform tfm = kernel_data.cam.worldtondc;
00054 
00055             if(sd->object != ~0)
00056                 data = transform(&tfm, sd->P);
00057             else
00058                 data = transform(&tfm, sd->P + svm_background_offset(kg));
00059             break;
00060         }
00061         case NODE_TEXCO_REFLECTION: {
00062             if(sd->object != ~0)
00063                 data = sd->I - 2.0f*dot(sd->N, sd->I)*sd->N;
00064             else
00065                 data = sd->I;
00066             break;
00067         }
00068     }
00069 
00070     stack_store_float3(stack, out_offset, data);
00071 }
00072 
00073 __device void svm_node_tex_coord_bump_dx(KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset)
00074 {
00075 #ifdef __RAY_DIFFERENTIALS__
00076     float3 data;
00077 
00078     switch(type) {
00079         case NODE_TEXCO_OBJECT: {
00080             if(sd->object != ~0) {
00081                 Transform tfm = object_fetch_transform(kg, sd->object, OBJECT_INVERSE_TRANSFORM);
00082                 data = transform(&tfm, sd->P + sd->dP.dx);
00083             }
00084             else
00085                 data = sd->P + sd->dP.dx;
00086             break;
00087         }
00088         case NODE_TEXCO_CAMERA: {
00089             Transform tfm = kernel_data.cam.worldtocamera;
00090 
00091             if(sd->object != ~0)
00092                 data = transform(&tfm, sd->P + sd->dP.dx);
00093             else
00094                 data = transform(&tfm, sd->P + sd->dP.dx + svm_background_offset(kg));
00095             break;
00096         }
00097         case NODE_TEXCO_WINDOW: {
00098             Transform tfm = kernel_data.cam.worldtondc;
00099 
00100             if(sd->object != ~0)
00101                 data = transform(&tfm, sd->P + sd->dP.dx);
00102             else
00103                 data = transform(&tfm, sd->P + sd->dP.dx + svm_background_offset(kg));
00104             break;
00105         }
00106         case NODE_TEXCO_REFLECTION: {
00107             if(sd->object != ~0)
00108                 data = sd->I - 2.0f*dot(sd->N, sd->I)*sd->N;
00109             else
00110                 data = sd->I;
00111             break;
00112         }
00113     }
00114 
00115     stack_store_float3(stack, out_offset, data);
00116 #else
00117     svm_node_tex_coord(kg, sd, stack, type, out_offset);
00118 #endif
00119 }
00120 
00121 __device void svm_node_tex_coord_bump_dy(KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset)
00122 {
00123 #ifdef __RAY_DIFFERENTIALS__
00124     float3 data;
00125 
00126     switch(type) {
00127         case NODE_TEXCO_OBJECT: {
00128             if(sd->object != ~0) {
00129                 Transform tfm = object_fetch_transform(kg, sd->object, OBJECT_INVERSE_TRANSFORM);
00130                 data = transform(&tfm, sd->P + sd->dP.dy);
00131             }
00132             else
00133                 data = sd->P + sd->dP.dy;
00134             break;
00135         }
00136         case NODE_TEXCO_CAMERA: {
00137             Transform tfm = kernel_data.cam.worldtocamera;
00138 
00139             if(sd->object != ~0)
00140                 data = transform(&tfm, sd->P + sd->dP.dy);
00141             else
00142                 data = transform(&tfm, sd->P + sd->dP.dy + svm_background_offset(kg));
00143             break;
00144         }
00145         case NODE_TEXCO_WINDOW: {
00146             Transform tfm = kernel_data.cam.worldtondc;
00147 
00148             if(sd->object != ~0)
00149                 data = transform(&tfm, sd->P + sd->dP.dy);
00150             else
00151                 data = transform(&tfm, sd->P + sd->dP.dy + svm_background_offset(kg));
00152             break;
00153         }
00154         case NODE_TEXCO_REFLECTION: {
00155             if(sd->object != ~0)
00156                 data = sd->I - 2.0f*dot(sd->N, sd->I)*sd->N;
00157             else
00158                 data = sd->I;
00159             break;
00160         }
00161     }
00162 
00163     stack_store_float3(stack, out_offset, data);
00164 #else
00165     svm_node_tex_coord(kg, sd, stack, type, out_offset);
00166 #endif
00167 }
00168 
00169 CCL_NAMESPACE_END
00170