Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_material.c
| Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
| #include "IMB_imbuf_types.h" | #include "IMB_imbuf_types.h" | ||||
| #include "GPU_extensions.h" | #include "GPU_extensions.h" | ||||
| #include "GPU_framebuffer.h" | #include "GPU_framebuffer.h" | ||||
| #include "GPU_lamp.h" | #include "GPU_lamp.h" | ||||
| #include "GPU_material.h" | #include "GPU_material.h" | ||||
| #include "GPU_shader.h" | #include "GPU_shader.h" | ||||
| #include "GPU_texture.h" | #include "GPU_texture.h" | ||||
| #include "GPU_uniformbuffer.h" | |||||
| #include "gpu_codegen.h" | #include "gpu_codegen.h" | ||||
| #include "gpu_lamp_private.h" | #include "gpu_lamp_private.h" | ||||
| #ifdef WITH_OPENSUBDIV | #ifdef WITH_OPENSUBDIV | ||||
| # include "BKE_DerivedMesh.h" | # include "BKE_DerivedMesh.h" | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | struct GPUMaterial { | ||||
| int partangvel; | int partangvel; | ||||
| int objectinfoloc; | int objectinfoloc; | ||||
| ListBase lamps; | ListBase lamps; | ||||
| bool bound; | bool bound; | ||||
| bool is_opensubdiv; | bool is_opensubdiv; | ||||
| GPUUniformBuffer *ubo; /* UBOs for shader uniforms. */ | |||||
| }; | }; | ||||
| /* Forward declaration so shade_light_textures() can use this, while still keeping the code somewhat organized */ | /* Forward declaration so shade_light_textures() can use this, while still keeping the code somewhat organized */ | ||||
| static void texture_rgb_blend( | static void texture_rgb_blend( | ||||
| GPUMaterial *mat, GPUNodeLink *tex, GPUNodeLink *out, GPUNodeLink *fact, GPUNodeLink *facg, | GPUMaterial *mat, GPUNodeLink *tex, GPUNodeLink *out, GPUNodeLink *fact, GPUNodeLink *facg, | ||||
| int blendtype, GPUNodeLink **in); | int blendtype, GPUNodeLink **in); | ||||
| /* Functions */ | /* Functions */ | ||||
| ▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | |||||
| void GPU_material_free(ListBase *gpumaterial) | void GPU_material_free(ListBase *gpumaterial) | ||||
| { | { | ||||
| for (LinkData *link = gpumaterial->first; link; link = link->next) { | for (LinkData *link = gpumaterial->first; link; link = link->next) { | ||||
| GPUMaterial *material = link->data; | GPUMaterial *material = link->data; | ||||
| if (material->pass) | if (material->pass) | ||||
| GPU_pass_free(material->pass); | GPU_pass_free(material->pass); | ||||
| if (material->ubo != NULL) { | |||||
| GPU_uniformbuffer_free(material->ubo); | |||||
| } | |||||
| BLI_freelistN(&material->lamps); | BLI_freelistN(&material->lamps); | ||||
| MEM_freeN(material); | MEM_freeN(material); | ||||
| } | } | ||||
| BLI_freelistN(gpumaterial); | BLI_freelistN(gpumaterial); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | GPUMatType GPU_Material_get_type(GPUMaterial *material) | ||||
| return material->type; | return material->type; | ||||
| } | } | ||||
| GPUPass *GPU_material_get_pass(GPUMaterial *material) | GPUPass *GPU_material_get_pass(GPUMaterial *material) | ||||
| { | { | ||||
| return material->pass; | return material->pass; | ||||
| } | } | ||||
| GPUUniformBuffer *GPU_material_get_uniform_buffer(GPUMaterial *material) | |||||
| { | |||||
| return material->ubo; | |||||
| } | |||||
| /** | |||||
| * Create dynamic UBO from parameters | |||||
| * \param ListBase of BLI_genericNodeN(GPUInput) | |||||
| */ | |||||
| void GPU_material_create_uniform_buffer(GPUMaterial *material, ListBase *inputs) | |||||
| { | |||||
| material->ubo = GPU_uniformbuffer_dynamic_create(inputs, NULL); | |||||
| } | |||||
| void GPU_material_uniform_buffer_tag_dirty(ListBase *gpumaterials) | |||||
| { | |||||
| for (LinkData *link = gpumaterials->first; link; link = link->next) { | |||||
| GPUMaterial *material = link->data; | |||||
| if (material->ubo != NULL) { | |||||
| GPU_uniformbuffer_tag_dirty(material->ubo); | |||||
| } | |||||
| } | |||||
| } | |||||
| void GPU_material_vertex_attributes(GPUMaterial *material, GPUVertexAttribs *attribs) | void GPU_material_vertex_attributes(GPUMaterial *material, GPUVertexAttribs *attribs) | ||||
| { | { | ||||
| *attribs = material->attribs; | *attribs = material->attribs; | ||||
| } | } | ||||
| void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link) | void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link) | ||||
| { | { | ||||
| if (!material->outlink) | if (!material->outlink) | ||||
| ▲ Show 20 Lines • Show All 1,617 Lines • ▼ Show 20 Lines | GPUMaterial *GPU_material_world(struct Scene *scene, struct World *wo) | ||||
| /* allocate material */ | /* allocate material */ | ||||
| mat = GPU_material_construct_begin(NULL); | mat = GPU_material_construct_begin(NULL); | ||||
| mat->scene = scene; | mat->scene = scene; | ||||
| mat->type = GPU_MATERIAL_TYPE_WORLD; | mat->type = GPU_MATERIAL_TYPE_WORLD; | ||||
| /* create nodes */ | /* create nodes */ | ||||
| if (BKE_scene_use_new_shading_nodes(scene) && wo->nodetree && wo->use_nodes) { | if (BKE_scene_use_new_shading_nodes(scene) && wo->nodetree && wo->use_nodes) { | ||||
| ntreeGPUMaterialNodes(wo->nodetree, mat, NODE_NEW_SHADING); | ntreeGPUMaterialNodes_local(wo->nodetree, mat, NODE_NEW_SHADING); | ||||
| } | } | ||||
| else { | else { | ||||
| gpu_material_old_world(mat, wo); | gpu_material_old_world(mat, wo); | ||||
| } | } | ||||
| if (GPU_material_do_color_management(mat)) | if (GPU_material_do_color_management(mat)) | ||||
| if (mat->outlink) | if (mat->outlink) | ||||
| GPU_link(mat, "linearrgb_to_srgb", mat->outlink, &mat->outlink); | GPU_link(mat, "linearrgb_to_srgb", mat->outlink, &mat->outlink); | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | GPUMaterial *GPU_material_from_nodetree( | ||||
| BLI_assert(GPU_material_from_nodetree_find(gpumaterials, engine_type, options) == NULL); | BLI_assert(GPU_material_from_nodetree_find(gpumaterials, engine_type, options) == NULL); | ||||
| /* allocate material */ | /* allocate material */ | ||||
| mat = GPU_material_construct_begin(NULL); /* TODO remove GPU_material_construct_begin */ | mat = GPU_material_construct_begin(NULL); /* TODO remove GPU_material_construct_begin */ | ||||
| mat->scene = scene; | mat->scene = scene; | ||||
| mat->engine_type = engine_type; | mat->engine_type = engine_type; | ||||
| mat->options = options; | mat->options = options; | ||||
| ntreeGPUMaterialNodes(ntree, mat, NODE_NEWER_SHADING); | ntreeGPUMaterialNodes(ntree, mat); | ||||
| /* Let Draw manager finish the construction. */ | /* Let Draw manager finish the construction. */ | ||||
| if (mat->outlink) { | if (mat->outlink) { | ||||
| outlink = mat->outlink; | outlink = mat->outlink; | ||||
| mat->pass = GPU_generate_pass_new( | mat->pass = GPU_generate_pass_new( | ||||
| &mat->nodes, outlink, &mat->attribs, vert_code, geom_code, frag_lib, defines); | mat, &mat->nodes, outlink, &mat->attribs, vert_code, geom_code, frag_lib, defines); | ||||
| } | } | ||||
| /* note that even if building the shader fails in some way, we still keep | /* note that even if building the shader fails in some way, we still keep | ||||
| * it to avoid trying to compile again and again, and simple do not use | * it to avoid trying to compile again and again, and simple do not use | ||||
| * the actual shader on drawing */ | * the actual shader on drawing */ | ||||
| link = MEM_callocN(sizeof(LinkData), "GPUMaterialLink"); | link = MEM_callocN(sizeof(LinkData), "GPUMaterialLink"); | ||||
| link->data = mat; | link->data = mat; | ||||
| Show All 28 Lines | GPUMaterial *GPU_material_from_blender(Scene *scene, Material *ma, bool use_opensubdiv) | ||||
| if (!new_shading_nodes && (ma->mode & MA_TRANSP)) | if (!new_shading_nodes && (ma->mode & MA_TRANSP)) | ||||
| GPU_material_enable_alpha(mat); | GPU_material_enable_alpha(mat); | ||||
| else if (new_shading_nodes && ma->alpha < 1.0f) | else if (new_shading_nodes && ma->alpha < 1.0f) | ||||
| GPU_material_enable_alpha(mat); | GPU_material_enable_alpha(mat); | ||||
| if (!(scene->gm.flag & GAME_GLSL_NO_NODES) && ma->nodetree && ma->use_nodes) { | if (!(scene->gm.flag & GAME_GLSL_NO_NODES) && ma->nodetree && ma->use_nodes) { | ||||
| /* create nodes */ | /* create nodes */ | ||||
| if (new_shading_nodes) | if (new_shading_nodes) | ||||
| ntreeGPUMaterialNodes(ma->nodetree, mat, NODE_NEW_SHADING); | ntreeGPUMaterialNodes_local(ma->nodetree, mat, NODE_NEW_SHADING); | ||||
| else | else | ||||
| ntreeGPUMaterialNodes(ma->nodetree, mat, NODE_OLD_SHADING); | ntreeGPUMaterialNodes_local(ma->nodetree, mat, NODE_OLD_SHADING); | ||||
| } | } | ||||
| else { | else { | ||||
| if (new_shading_nodes) { | if (new_shading_nodes) { | ||||
| /* create simple diffuse material instead of nodes */ | /* create simple diffuse material instead of nodes */ | ||||
| outlink = gpu_material_diffuse_bsdf(mat, ma); | outlink = gpu_material_diffuse_bsdf(mat, ma); | ||||
| } | } | ||||
| else { | else { | ||||
| /* create blender material */ | /* create blender material */ | ||||
| ▲ Show 20 Lines • Show All 339 Lines • Show Last 20 Lines | |||||