layout(set=0) uniform samplerCube environment_map;
layout(set=0) uniform samplerCube irradiance_map;
+layout(constant_id=auto) const bool use_instancing = false;
layout(constant_id=auto) const bool use_normal_map = false;
#pragma MSP stage(vertex)
virtual mat4 get_vertex_transform()
{
- return world_obj_matrix;
+ if(use_instancing)
+ return transpose(mat4(instance_transform[0], instance_transform[1], instance_transform[2], vec4(0.0, 0.0, 0.0, 1.0)));
+ else
+ return world_obj_matrix;
}
virtual mat3 get_normal_transform()
{
- return world_obj_normal_matrix;
+ if(use_instancing)
+ return transpose(mat3(instance_transform[0].xyz, instance_transform[1].xyz, instance_transform[2].xyz));
+ else
+ return world_obj_normal_matrix;
}
void standard_transform()
layout(set=1) uniform sampler2D alpha_map;
layout(constant_id=auto) const bool use_alpha_cutoff = false;
+layout(constant_id=auto) const bool use_instancing = false;
#pragma MSP stage(vertex)
virtual vec4 get_vertex_position()
virtual mat4 get_vertex_transform()
{
- return world_obj_matrix;
+ if(use_instancing)
+ return transpose(mat4(instance_transform[0], instance_transform[1], instance_transform[2], vec4(0.0, 0.0, 0.0, 1.0)));
+ else
+ return world_obj_matrix;
}
virtual void clipping(vec3 eye_vertex)
extra_spec["use_shadow_map"] = true;
if(image_based_lighting)
extra_spec["use_image_based_lighting"] = true;
+ if(instancing)
+ extra_spec["use_instancing"] = true;
shprog = material->create_compatible_shader(extra_spec);
add("face_cull", &RenderMethod::face_cull);
add("shader", &Loader::shader);
add("image_based_lighting", &RenderMethod::image_based_lighting);
+ add("instancing", &RenderMethod::instancing);
add("material", &Loader::material_inline);
add("material", &Loader::material);
add("material_slot", &RenderMethod::material_slot);
Blend blend;
bool receive_shadows = false;
bool image_based_lighting = false;
+ bool instancing = false;
void maybe_create_material_shader();
void set_material_textures();
bool get_image_based_lighting() const { return image_based_lighting; }
+ /** Toggles instanced rendering. Only affects shaders created from
+ materials. Should be used with InstanceArray. */
+ void set_instancing(bool);
+
+ bool get_instancing() const { return instancing; }
+
void apply(Renderer &) const;
void set_debug_name(const std::string &);