Blender  V2.59
SHD_camera.c
Go to the documentation of this file.
00001 /*
00002  * $Id: SHD_camera.c 35237 2011-02-27 20:13:22Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version. 
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2005 Blender Foundation.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00035 #include "../SHD_util.h"
00036 
00037 /* **************** CAMERA INFO  ******************** */
00038 static bNodeSocketType sh_node_camera_out[]= {
00039         {       SOCK_VECTOR, 0, "View Vector",                  1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f},           /* None of these actually */
00040         {       SOCK_VALUE, 0, "View Z Depth",                  0.f, 0.0f, 0.0f, 0.0f, 0.0f, 99999999999.0f},   /* have any limits on their */
00041         {       SOCK_VALUE, 0, "View Distance",                 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 99999999999.0f},  /* values. */
00042         {       -1, 0, ""       }
00043 };
00044 
00045 
00046 static void node_shader_exec_camera(void *data, bNode *UNUSED(node), bNodeStack **UNUSED(in), bNodeStack **out)
00047 {
00048         if(data) {
00049                 ShadeInput *shi= ((ShaderCallData *)data)->shi;  /* Data we need for shading. */
00050                 
00051                 VECCOPY(out[0]->vec, shi->co);          /* get view vector */
00052                 out[1]->vec[0]= fabs(shi->co[2]);               /* get view z-depth */
00053                 out[2]->vec[0]= normalize_v3(out[0]->vec);      /* get view distance */
00054         }
00055 }
00056 
00057 static int gpu_shader_camera(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out)
00058 {
00059         return GPU_stack_link(mat, "camera", in, out, GPU_builtin(GPU_VIEW_POSITION));
00060 }
00061 
00062 void register_node_type_sh_camera(ListBase *lb)
00063 {
00064         static bNodeType ntype;
00065 
00066         node_type_base(&ntype, SH_NODE_CAMERA, "Camera Data", NODE_CLASS_INPUT, 0,
00067                 NULL, sh_node_camera_out);
00068         node_type_size(&ntype, 95, 95, 120);
00069         node_type_storage(&ntype, "node_camera", NULL, NULL);
00070         node_type_exec(&ntype, node_shader_exec_camera);
00071         node_type_gpu(&ntype, gpu_shader_camera);
00072 
00073         nodeRegisterType(lb, &ntype);
00074 }
00075 
00076