Merge branch 'master' into blender2.8
[blender.git] / source / blender / nodes / shader / nodes / node_shader_ambient_occlusion.c
index f835822469c6a490215b06b6feb50fedd552184a..eae35b4cd22dad6d9f7039d052e25e255be1d23c 100644 (file)
 
 static bNodeSocketTemplate sh_node_ambient_occlusion_in[] = {
        {       SOCK_RGBA, 1, N_("Color"),              0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
+       {       SOCK_FLOAT, 0, N_("Distance"),  1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f},
+       {       SOCK_VECTOR, 1, N_("Normal"),   0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
        {       -1, 0, ""       }
 };
 
 static bNodeSocketTemplate sh_node_ambient_occlusion_out[] = {
-       {       SOCK_SHADER, 0, N_("AO")},
+       {       SOCK_RGBA, 1, N_("Color"),      0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
+       {       SOCK_FLOAT, 0, N_("AO"),        0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
        {       -1, 0, ""       }
 };
 
 static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
 {
-       return GPU_stack_link(mat, node, "node_ambient_occlusion", in, out, GPU_builtin(GPU_VIEW_NORMAL));
+       if (!in[2].link)
+               GPU_link(mat, "world_normals_get", &in[2].link);
+
+       return GPU_stack_link(mat, node, "node_ambient_occlusion", in, out);
+}
+
+static void node_shader_init_ambient_occlusion(bNodeTree *UNUSED(ntree), bNode *node)
+{
+       node->custom1 = 8; /* samples */
+       node->custom2 = SHD_AO_LOCAL;
 }
 
 /* node type definition */
@@ -49,10 +61,10 @@ void register_node_type_sh_ambient_occlusion(void)
 {
        static bNodeType ntype;
 
-       sh_node_type_base(&ntype, SH_NODE_AMBIENT_OCCLUSION, "Ambient Occlusion", NODE_CLASS_SHADER, 0);
+       sh_node_type_base(&ntype, SH_NODE_AMBIENT_OCCLUSION, "Ambient Occlusion", NODE_CLASS_INPUT, 0);
        node_type_compatibility(&ntype, NODE_NEW_SHADING);
        node_type_socket_templates(&ntype, sh_node_ambient_occlusion_in, sh_node_ambient_occlusion_out);
-       node_type_init(&ntype, NULL);
+       node_type_init(&ntype, node_shader_init_ambient_occlusion);
        node_type_storage(&ntype, "", NULL, NULL);
        node_type_gpu(&ntype, node_shader_gpu_ambient_occlusion);