Merge branch 'master' into blender2.8
[blender.git] / source / blender / gpu / intern / gpu_codegen.c
index c3f79bc9492bfa7be84c3631bcc93ffd3637ad29..9f41253b176e34ff08ab3a772cd9787cb067ce5e 100644 (file)
@@ -318,7 +318,9 @@ static void codegen_convert_datatype(DynStr *ds, int from, int to, const char *t
                BLI_dynstr_append(ds, name);
        }
        else if (to == GPU_FLOAT) {
-               if (from == GPU_VEC4 || from == GPU_VEC3)
+               if (from == GPU_VEC4)
+                       BLI_dynstr_appendf(ds, "convert_rgba_to_float(%s)", name);
+               else if (from == GPU_VEC3)
                        BLI_dynstr_appendf(ds, "(%s.r + %s.g + %s.b) / 3.0", name, name, name);
                else if (from == GPU_VEC2)
                        BLI_dynstr_appendf(ds, "%s.r", name);
@@ -398,14 +400,6 @@ const char *GPU_builtin_name(GPUBuiltin builtin)
                return "unfobautobumpscale";
        else if (builtin == GPU_CAMERA_TEXCO_FACTORS)
                return "unfcameratexfactors";
-       else if (builtin == GPU_PARTICLE_SCALAR_PROPS)
-               return "unfparticlescalarprops";
-       else if (builtin == GPU_PARTICLE_LOCATION)
-               return "unfparticleco";
-       else if (builtin == GPU_PARTICLE_VELOCITY)
-               return "unfparticlevel";
-       else if (builtin == GPU_PARTICLE_ANG_VELOCITY)
-               return "unfparticleangvel";
        else
                return "";
 }
@@ -747,6 +741,7 @@ static char *code_generate_vertex(ListBase *nodes, const GPUMatType type)
                                BLI_dynstr_appendf(ds, "%s %s att%d;\n",
                                        GLEW_VERSION_3_0 ? "in" : "attribute",
                                        GPU_DATATYPE_STR[input->type], input->attribid);
+                               BLI_dynstr_appendf(ds, "uniform int att%d_info;\n",  input->attribid);
                                BLI_dynstr_appendf(ds, "%s %s var%d;\n",
                                        GLEW_VERSION_3_0 ? "out" : "varying",
                                        GPU_DATATYPE_STR[input->type], input->attribid);
@@ -799,7 +794,8 @@ static char *code_generate_vertex(ListBase *nodes, const GPUMatType type)
                                                BLI_dynstr_appendf(ds, "#ifndef USE_OPENSUBDIV\n");
                                        }
 #endif
-                                       BLI_dynstr_appendf(ds, "\tvar%d = att%d;\n", input->attribid, input->attribid);
+                                       BLI_dynstr_appendf(ds, "\tset_var_from_attr(att%d, att%d_info, var%d);\n",
+                                                          input->attribid, input->attribid, input->attribid);
 #ifdef WITH_OPENSUBDIV
                                        if (is_mtface) {
                                                BLI_dynstr_appendf(ds, "#endif\n");
@@ -1494,7 +1490,7 @@ bool GPU_link(GPUMaterial *mat, const char *name, ...)
        function = gpu_lookup_function(name);
        if (!function) {
                fprintf(stderr, "GPU failed to find function %s\n", name);
-               return 0;
+               return false;
        }
 
        node = GPU_node_begin(name);
@@ -1514,7 +1510,7 @@ bool GPU_link(GPUMaterial *mat, const char *name, ...)
 
        gpu_material_add_node(mat, node);
 
-       return 1;
+       return true;
 }
 
 bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNodeStack *out, ...)
@@ -1528,7 +1524,7 @@ bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNod
        function = gpu_lookup_function(name);
        if (!function) {
                fprintf(stderr, "GPU failed to find function %s\n", name);
-               return 0;
+               return false;
        }
 
        node = GPU_node_begin(name);
@@ -1575,7 +1571,7 @@ bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNod
 
        gpu_material_add_node(mat, node);
        
-       return 1;
+       return true;
 }
 
 int GPU_link_changed(GPUNodeLink *link)
@@ -1641,7 +1637,9 @@ static void gpu_nodes_prune(ListBase *nodes, GPUNodeLink *outlink)
 GPUPass *GPU_generate_pass(
         ListBase *nodes, GPUNodeLink *outlink,
         GPUVertexAttribs *attribs, int *builtins,
-        const GPUMatType type, const char *UNUSED(name), const bool use_opensubdiv)
+        const GPUMatType type, const char *UNUSED(name),
+        const bool use_opensubdiv,
+        const bool use_new_shading)
 {
        GPUShader *shader;
        GPUPass *pass;
@@ -1664,6 +1662,14 @@ GPUPass *GPU_generate_pass(
        fragmentcode = code_generate_fragment(nodes, outlink->output);
        vertexcode = code_generate_vertex(nodes, type);
        geometrycode = code_generate_geometry(nodes, use_opensubdiv);
+
+       int flags = GPU_SHADER_FLAGS_NONE;
+       if (use_opensubdiv) {
+               flags |= GPU_SHADER_FLAGS_SPECIAL_OPENSUBDIV;
+       }
+       if (use_new_shading) {
+               flags |= GPU_SHADER_FLAGS_NEW_SHADING;
+       }
        shader = GPU_shader_create_ex(vertexcode,
                                      fragmentcode,
                                      geometrycode,
@@ -1672,8 +1678,7 @@ GPUPass *GPU_generate_pass(
                                      0,
                                      0,
                                      0,
-                                     use_opensubdiv ? GPU_SHADER_FLAGS_SPECIAL_OPENSUBDIV
-                                                    : GPU_SHADER_FLAGS_NONE);
+                                     flags);
 
        /* failed? */
        if (!shader) {