mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-09-22 23:18:01 +03:00
ReignEngine: Implement alpha mapping
This commit is contained in:
@@ -31,6 +31,7 @@ struct dir_light {
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform sampler2D specular_texture;
|
||||
uniform sampler2D alpha_texture;
|
||||
uniform sampler2D light_texture;
|
||||
uniform sampler2D shadow_texture;
|
||||
uniform float alpha_mod;
|
||||
@@ -52,6 +53,7 @@ uniform int fog_type;
|
||||
uniform float fog_near;
|
||||
uniform float fog_far;
|
||||
uniform vec3 fog_color;
|
||||
uniform bool use_alpha_map;
|
||||
|
||||
in vec2 tex_coord;
|
||||
in vec2 light_tex_coord;
|
||||
@@ -135,5 +137,11 @@ void main() {
|
||||
frag_rgb *= shadow_factor;
|
||||
}
|
||||
|
||||
frag_color = vec4(frag_rgb, texel.a * alpha_mod);
|
||||
// Alpha mapping
|
||||
float alpha = texel.a * alpha_mod;
|
||||
if (use_alpha_map) {
|
||||
alpha *= texture(alpha_texture, tex_coord).r;
|
||||
}
|
||||
|
||||
frag_color = vec4(frag_rgb, alpha);
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ struct mesh {
|
||||
struct material {
|
||||
GLuint color_map;
|
||||
GLuint specular_map;
|
||||
GLuint alpha_map;
|
||||
GLuint light_map;
|
||||
GLuint normal_map;
|
||||
float specular_strength;
|
||||
@@ -149,6 +150,8 @@ struct RE_renderer {
|
||||
GLint ls_light_dir;
|
||||
GLint ls_light_color;
|
||||
GLint ls_sun_color;
|
||||
GLint use_alpha_map;
|
||||
GLint alpha_texture;
|
||||
|
||||
GLuint billboard_vao;
|
||||
GLuint billboard_attr_buffer;
|
||||
@@ -358,6 +361,7 @@ struct pol {
|
||||
enum pol_texture_type {
|
||||
COLOR_MAP = 1,
|
||||
SPECULAR_MAP = 4,
|
||||
ALPHA_MAP = 6,
|
||||
LIGHT_MAP = 7,
|
||||
NORMAL_MAP = 8,
|
||||
MAX_TEXTURE_TYPE
|
||||
|
||||
@@ -99,6 +99,8 @@ static bool init_material(struct material *material, const struct pol_material *
|
||||
|
||||
if (m->textures[SPECULAR_MAP])
|
||||
material->specular_map = load_texture(aar, path, m->textures[SPECULAR_MAP]);
|
||||
if (m->textures[ALPHA_MAP])
|
||||
material->alpha_map = load_texture(aar, path, m->textures[ALPHA_MAP]);
|
||||
if (m->textures[LIGHT_MAP])
|
||||
material->light_map = load_texture(aar, path, m->textures[LIGHT_MAP]);
|
||||
if (m->textures[NORMAL_MAP])
|
||||
@@ -129,6 +131,8 @@ static void destroy_material(struct material *material)
|
||||
glDeleteTextures(1, &material->color_map);
|
||||
if (material->specular_map)
|
||||
glDeleteTextures(1, &material->specular_map);
|
||||
if (material->alpha_map)
|
||||
glDeleteTextures(1, &material->alpha_map);
|
||||
if (material->light_map)
|
||||
glDeleteTextures(1, &material->light_map);
|
||||
if (material->normal_map)
|
||||
|
||||
+17
-2
@@ -32,6 +32,7 @@
|
||||
enum {
|
||||
COLOR_TEXTURE_UNIT,
|
||||
SPECULAR_TEXTURE_UNIT,
|
||||
ALPHA_TEXTURE_UNIT,
|
||||
LIGHT_TEXTURE_UNIT,
|
||||
NORMAL_TEXTURE_UNIT,
|
||||
SHADOW_TEXTURE_UNIT,
|
||||
@@ -199,6 +200,8 @@ struct RE_renderer *RE_renderer_new(struct texture *texture)
|
||||
r->ls_light_dir = glGetUniformLocation(r->program, "ls_light_dir");
|
||||
r->ls_light_color = glGetUniformLocation(r->program, "ls_light_color");
|
||||
r->ls_sun_color = glGetUniformLocation(r->program, "ls_sun_color");
|
||||
r->use_alpha_map = glGetUniformLocation(r->program, "use_alpha_map");
|
||||
r->alpha_texture = glGetUniformLocation(r->program, "alpha_texture");
|
||||
|
||||
glGenRenderbuffers(1, &r->depth_buffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, r->depth_buffer);
|
||||
@@ -339,6 +342,15 @@ static void render_model(struct RE_instance *inst, struct RE_renderer *r)
|
||||
glUniform1i(r->use_normal_map, GL_FALSE);
|
||||
}
|
||||
|
||||
if (material->alpha_map) {
|
||||
glUniform1i(r->use_alpha_map, GL_TRUE);
|
||||
glActiveTexture(GL_TEXTURE0 + ALPHA_TEXTURE_UNIT);
|
||||
glBindTexture(GL_TEXTURE_2D, material->alpha_map);
|
||||
glUniform1i(r->alpha_texture, ALPHA_TEXTURE_UNIT);
|
||||
} else {
|
||||
glUniform1i(r->use_alpha_map, GL_FALSE);
|
||||
}
|
||||
|
||||
glBindVertexArray(mesh->vao);
|
||||
glDrawArrays(GL_TRIANGLES, 0, mesh->nr_vertices);
|
||||
glBindVertexArray(0);
|
||||
@@ -407,6 +419,7 @@ static void render_billboard(struct RE_instance *inst, struct RE_renderer *r, ma
|
||||
glUniform1i(r->diffuse_type, DIFFUSE_NORMAL);
|
||||
glUniform1i(r->use_normal_map, GL_FALSE);
|
||||
glUniform1i(r->use_shadow_map, GL_FALSE);
|
||||
glUniform1i(r->use_alpha_map, GL_FALSE);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, bt->texture);
|
||||
@@ -516,6 +529,7 @@ static void render_particle_effect(struct RE_instance *inst, struct RE_renderer
|
||||
glUniform1f(r->rim_exponent, 0.0);
|
||||
glUniform1i(r->use_normal_map, GL_FALSE);
|
||||
glUniform1i(r->use_shadow_map, GL_FALSE);
|
||||
glUniform1i(r->use_alpha_map, GL_FALSE);
|
||||
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
@@ -543,7 +557,7 @@ static void render_particle_effect(struct RE_instance *inst, struct RE_renderer
|
||||
break;
|
||||
}
|
||||
}
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
@@ -758,7 +772,7 @@ void RE_render(struct sact_sprite *sp)
|
||||
}
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
|
||||
|
||||
setup_lights(plugin);
|
||||
|
||||
@@ -791,6 +805,7 @@ void RE_render(struct sact_sprite *sp)
|
||||
glUseProgram(0);
|
||||
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
|
||||
gfx_reset_framebuffer(GL_DRAW_FRAMEBUFFER, fbo);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
struct height_detector {
|
||||
|
||||
Reference in New Issue
Block a user