GPU: Move Material index to nodetree evaluation
This removes the need to pass the Material* all over the place in the draw manager. Cleanup comming right after.
This commit is contained in:
@@ -394,6 +394,7 @@ GPUMaterial *DRW_shader_create_from_world(struct Scene *scene,
|
||||
if (mat == NULL) {
|
||||
scene = (Scene *)DEG_get_original_id(&DST.draw_ctx.scene->id);
|
||||
mat = GPU_material_from_nodetree(scene,
|
||||
NULL,
|
||||
wo->nodetree,
|
||||
&wo->gpumaterial,
|
||||
engine_type,
|
||||
@@ -430,6 +431,7 @@ GPUMaterial *DRW_shader_create_from_material(struct Scene *scene,
|
||||
if (mat == NULL) {
|
||||
scene = (Scene *)DEG_get_original_id(&DST.draw_ctx.scene->id);
|
||||
mat = GPU_material_from_nodetree(scene,
|
||||
ma,
|
||||
ma->nodetree,
|
||||
&ma->gpumaterial,
|
||||
engine_type,
|
||||
|
||||
@@ -177,6 +177,7 @@ GPUMaterial *GPU_material_from_nodetree_find(struct ListBase *gpumaterials,
|
||||
const void *engine_type,
|
||||
int options);
|
||||
GPUMaterial *GPU_material_from_nodetree(struct Scene *scene,
|
||||
struct Material *ma,
|
||||
struct bNodeTree *ntree,
|
||||
struct ListBase *gpumaterials,
|
||||
const void *engine_type,
|
||||
@@ -194,6 +195,7 @@ void GPU_materials_free(struct Main *bmain);
|
||||
struct Scene *GPU_material_scene(GPUMaterial *material);
|
||||
struct GPUPass *GPU_material_get_pass(GPUMaterial *material);
|
||||
struct ListBase *GPU_material_get_inputs(GPUMaterial *material);
|
||||
struct Material *GPU_material_get_material(GPUMaterial *material);
|
||||
eGPUMaterialStatus GPU_material_status(GPUMaterial *mat);
|
||||
|
||||
struct GPUUniformBuffer *GPU_material_uniform_buffer_get(GPUMaterial *material);
|
||||
|
||||
@@ -231,6 +231,12 @@ ListBase *GPU_material_get_inputs(GPUMaterial *material)
|
||||
return &material->inputs;
|
||||
}
|
||||
|
||||
/* Return can be NULL if it's a world material. */
|
||||
Material *GPU_material_get_material(GPUMaterial *material)
|
||||
{
|
||||
return material->ma;
|
||||
}
|
||||
|
||||
GPUUniformBuffer *GPU_material_uniform_buffer_get(GPUMaterial *material)
|
||||
{
|
||||
return material->ubo;
|
||||
@@ -637,6 +643,7 @@ GPUMaterial *GPU_material_from_nodetree_find(ListBase *gpumaterials,
|
||||
* so only do this when they are needed.
|
||||
*/
|
||||
GPUMaterial *GPU_material_from_nodetree(Scene *scene,
|
||||
struct Material *ma,
|
||||
struct bNodeTree *ntree,
|
||||
ListBase *gpumaterials,
|
||||
const void *engine_type,
|
||||
@@ -655,6 +662,7 @@ GPUMaterial *GPU_material_from_nodetree(Scene *scene,
|
||||
|
||||
/* allocate material */
|
||||
GPUMaterial *mat = MEM_callocN(sizeof(GPUMaterial), "GPUMaterial");
|
||||
mat->ma = ma;
|
||||
mat->scene = scene;
|
||||
mat->engine_type = engine_type;
|
||||
mat->options = options;
|
||||
|
||||
@@ -3234,6 +3234,7 @@ void node_light_falloff(
|
||||
|
||||
void node_object_info(mat4 obmat,
|
||||
vec4 info,
|
||||
float mat_index,
|
||||
out vec3 location,
|
||||
out float object_index,
|
||||
out float material_index,
|
||||
@@ -3241,7 +3242,7 @@ void node_object_info(mat4 obmat,
|
||||
{
|
||||
location = obmat[3].xyz;
|
||||
object_index = info.x;
|
||||
material_index = info.y;
|
||||
material_index = mat_index;
|
||||
random = info.z;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,13 +35,17 @@ static int node_shader_gpu_object_info(GPUMaterial *mat,
|
||||
GPUNodeStack *in,
|
||||
GPUNodeStack *out)
|
||||
{
|
||||
Material *ma = GPU_material_get_material(mat);
|
||||
/* Convert to float. */
|
||||
float index = ma ? ma->index : 0;
|
||||
return GPU_stack_link(mat,
|
||||
node,
|
||||
"node_object_info",
|
||||
in,
|
||||
out,
|
||||
GPU_builtin(GPU_OBJECT_MATRIX),
|
||||
GPU_builtin(GPU_OBJECT_INFO));
|
||||
GPU_builtin(GPU_OBJECT_INFO),
|
||||
GPU_constant(&index));
|
||||
}
|
||||
|
||||
static void node_shader_exec_object_info(void *UNUSED(data),
|
||||
|
||||
Reference in New Issue
Block a user