Cycles: support for image sequences in image/environment texture node.
[blender.git] / source / blender / nodes / shader / nodes / node_shader_tex_environment.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2005 Blender Foundation.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 #include "../node_shader_util.h"
29
30 /* **************** OUTPUT ******************** */
31
32 static bNodeSocketTemplate sh_node_tex_environment_in[]= {
33         {       SOCK_VECTOR, 1, N_("Vector"),           0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
34         {       -1, 0, ""       }
35 };
36
37 static bNodeSocketTemplate sh_node_tex_environment_out[]= {
38         {       SOCK_RGBA, 0, N_("Color"),              0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
39         {       -1, 0, ""       }
40 };
41
42 static void node_shader_init_tex_environment(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
43 {
44         NodeTexEnvironment *tex = MEM_callocN(sizeof(NodeTexEnvironment), "NodeTexEnvironment");
45         default_tex_mapping(&tex->base.tex_mapping);
46         default_color_mapping(&tex->base.color_mapping);
47         tex->color_space = SHD_COLORSPACE_COLOR;
48         tex->projection = SHD_PROJ_EQUIRECTANGULAR;
49         tex->iuser.frames= 1;
50         tex->iuser.sfra= 1;
51         tex->iuser.fie_ima= 2;
52         tex->iuser.ok= 1;
53
54         node->storage = tex;
55 }
56
57 static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out)
58 {
59         Image *ima= (Image*)node->id;
60         ImageUser *iuser= NULL;
61
62         if (!ima)
63                 return GPU_stack_link(mat, "node_tex_environment_empty", in, out);
64
65         if (!in[0].link)
66                 in[0].link = GPU_builtin(GPU_VIEW_POSITION);
67
68         node_shader_gpu_tex_mapping(mat, node, in, out);
69
70         return GPU_stack_link(mat, "node_tex_environment", in, out, GPU_image(ima, iuser));
71 }
72
73 /* node type definition */
74 void register_node_type_sh_tex_environment(bNodeTreeType *ttype)
75 {
76         static bNodeType ntype;
77
78         node_type_base(ttype, &ntype, SH_NODE_TEX_ENVIRONMENT, "Environment Texture", NODE_CLASS_TEXTURE, NODE_OPTIONS);
79         node_type_compatibility(&ntype, NODE_NEW_SHADING);
80         node_type_socket_templates(&ntype, sh_node_tex_environment_in, sh_node_tex_environment_out);
81         node_type_size(&ntype, 150, 60, 200);
82         node_type_init(&ntype, node_shader_init_tex_environment);
83         node_type_storage(&ntype, "NodeTexEnvironment", node_free_standard_storage, node_copy_standard_storage);
84         node_type_exec(&ntype, NULL);
85         node_type_gpu(&ntype, node_shader_gpu_tex_environment);
86
87         nodeRegisterType(ttype, &ntype);
88 }