ReignEngine: Support (nolighting) mesh attribute

In ReignEngine, the mesh name field may contain keywords that change
rendering behavior. The "(nolighting)" keyword disables lighting and
fog.
This commit is contained in:
kichikuou
2022-11-05 20:56:25 +09:00
parent 31823f5731
commit 1a9a2e9753
4 changed files with 25 additions and 7 deletions
+6
View File
@@ -48,6 +48,7 @@ struct model {
};
struct mesh {
uint32_t flags;
GLuint vao;
GLuint attr_buffer;
int nr_vertices;
@@ -380,8 +381,13 @@ struct pol_material_group {
struct pol_material *children;
};
enum mesh_flags {
MESH_NOLIGHTING = 1 << 0,
};
struct pol_mesh {
char *name;
uint32_t flags;
uint32_t material;
uint32_t nr_vertices;
struct pol_vertex *vertices;
+1
View File
@@ -271,6 +271,7 @@ static void add_mesh(struct model *model, struct pol_mesh *m, int material_index
}
model->meshes = xrealloc_array(model->meshes, model->nr_meshes, model->nr_meshes + 1, sizeof(struct mesh));
struct mesh *mesh = &model->meshes[model->nr_meshes++];
mesh->flags = m->flags;
mesh->material = material;
mesh->nr_vertices = nr_vertices;
+9
View File
@@ -148,6 +148,14 @@ static void parse_triangle(struct buffer *r, struct pol_mesh *mesh, int triangle
t->material = buffer_read_int32(r);
}
static uint32_t parse_mesh_attributes(const char *name)
{
uint32_t flags = 0;
if (strstr(name, "(nolighting)"))
flags |= MESH_NOLIGHTING;
return flags;
}
static struct pol_mesh *parse_mesh(struct buffer *r, int pol_version)
{
int type = buffer_read_int32(r);
@@ -158,6 +166,7 @@ static struct pol_mesh *parse_mesh(struct buffer *r, int pol_version)
}
struct pol_mesh *mesh = xcalloc(1, sizeof(struct pol_mesh));
mesh->name = read_cstring(r);
mesh->flags = parse_mesh_attributes(mesh->name);
mesh->material = buffer_read_int32(r);
mesh->nr_vertices = buffer_read_int32(r);
+9 -7
View File
@@ -303,8 +303,11 @@ static void render_model(struct RE_instance *inst, struct RE_renderer *r)
struct mesh *mesh = &model->meshes[i];
struct material *material = &model->materials[mesh->material];
glUniform1i(r->fog_type, (inst->plugin->fog_mode && !(mesh->flags & MESH_NOLIGHTING))
? inst->plugin->fog_type : 0);
GLboolean use_specular_map = GL_FALSE;
if (inst->plugin->specular_mode) {
if (inst->plugin->specular_mode && !(mesh->flags & MESH_NOLIGHTING)) {
glUniform1f(r->specular_strength, material->specular_strength);
glUniform1f(r->specular_shininess, material->specular_shininess);
if (material->specular_map) {
@@ -326,7 +329,9 @@ static void render_model(struct RE_instance *inst, struct RE_renderer *r)
glBindTexture(GL_TEXTURE_2D, material->color_map);
glUniform1i(r->texture, COLOR_TEXTURE_UNIT);
if (material->light_map && inst->plugin->light_map_mode) {
if (mesh->flags & MESH_NOLIGHTING) {
glUniform1i(r->diffuse_type, DIFFUSE_EMISSIVE);
} else if (material->light_map && inst->plugin->light_map_mode) {
glUniform1i(r->diffuse_type, DIFFUSE_LIGHT_MAP);
glActiveTexture(GL_TEXTURE0 + LIGHT_TEXTURE_UNIT);
glBindTexture(GL_TEXTURE_2D, material->light_map);
@@ -422,6 +427,7 @@ static void render_billboard(struct RE_instance *inst, struct RE_renderer *r, ma
glUniform1i(r->use_normal_map, GL_FALSE);
glUniform1i(r->use_shadow_map, GL_FALSE);
glUniform1i(r->use_alpha_map, GL_FALSE);
glUniform1i(r->fog_type, inst->plugin->fog_mode ? inst->plugin->fog_type : 0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, bt->texture);
@@ -472,8 +478,6 @@ static void render_billboard_particles(struct RE_renderer *r, struct RE_instance
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D, 0);
glUniform1i(r->fog_type, inst->plugin->fog_type);
}
static void render_polygon_particles(struct RE_renderer *r, struct RE_instance *inst, struct particle_object *po, float frame)
@@ -483,6 +487,7 @@ static void render_polygon_particles(struct RE_renderer *r, struct RE_instance *
return;
glUniform1i(r->diffuse_type, DIFFUSE_NORMAL);
glUniform1i(r->fog_type, inst->plugin->fog_mode ? inst->plugin->fog_type : 0);
for (int index = 0; index < po->nr_particles; index++) {
struct particle_instance *pi = &po->instances[index];
@@ -789,7 +794,6 @@ void RE_render(struct sact_sprite *sp)
glUniformMatrix4fv(r->shadow_transform, 1, GL_FALSE, shadow_transform[0]);
glUniform1f(r->shadow_bias, plugin->shadow_bias);
if (plugin->fog_mode) {
glUniform1i(r->fog_type, plugin->fog_type);
switch (plugin->fog_type) {
case RE_FOG_LINEAR:
glUniform1f(r->fog_near, plugin->fog_near);
@@ -803,8 +807,6 @@ void RE_render(struct sact_sprite *sp)
glUniform3fv(r->ls_sun_color, 1, plugin->ls_sun_color);
break;
}
} else {
glUniform1i(r->fog_type, 0);
}
glEnable(GL_BLEND);