Cycles: change Ambient Occlusion shader to output colors.
[blender.git] / source / blender / nodes / shader / nodes / node_shader_ambient_occlusion.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_ambient_occlusion_in[] = {
33         {       SOCK_RGBA, 1, N_("Color"),              0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
34         {       SOCK_FLOAT, 0, N_("Distance"),  1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f},
35         {       SOCK_VECTOR, 1, N_("Normal"),   0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
36         {       -1, 0, ""       }
37 };
38
39 static bNodeSocketTemplate sh_node_ambient_occlusion_out[] = {
40         {       SOCK_RGBA, 1, N_("Color"),      0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
41         {       SOCK_FLOAT, 0, N_("AO"),        0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
42         {       -1, 0, ""       }
43 };
44
45 static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
46 {
47         return GPU_stack_link(mat, "node_ambient_occlusion", in, out, GPU_builtin(GPU_VIEW_NORMAL));
48 }
49
50 static void node_shader_init_ambient_occlusion(bNodeTree *UNUSED(ntree), bNode *node)
51 {
52         node->custom1 = 8; /* samples */
53         node->custom2 = SHD_AO_LOCAL;
54 }
55
56 /* node type definition */
57 void register_node_type_sh_ambient_occlusion(void)
58 {
59         static bNodeType ntype;
60
61         sh_node_type_base(&ntype, SH_NODE_AMBIENT_OCCLUSION, "Ambient Occlusion", NODE_CLASS_INPUT, 0);
62         node_type_compatibility(&ntype, NODE_NEW_SHADING);
63         node_type_socket_templates(&ntype, sh_node_ambient_occlusion_in, sh_node_ambient_occlusion_out);
64         node_type_init(&ntype, node_shader_init_ambient_occlusion);
65         node_type_storage(&ntype, "", NULL, NULL);
66         node_type_gpu(&ntype, node_shader_gpu_ambient_occlusion);
67
68         nodeRegisterType(&ntype);
69 }
70