mirror of
https://github.com/korenkonder/ReDIVA.git
synced 2026-10-03 12:18:11 +03:00
Temp commit. Need to store all sh... Changes
This commit is contained in:
+116
-34
@@ -19,6 +19,27 @@ lens_flare_count(), lens_flare_pos(), lens_shaft_scale(), lens_shaft_inv_scale()
|
||||
lens_flare_power(), field_A10(), lens_flare_appear_power(), render_width(), render_height(),
|
||||
view_point(), interest(), view_point_prev(), interest_prev(), reset_exposure(), sprite_width(),
|
||||
sprite_height(), screen_x_offset(), screen_y_offset(), screen_width(), screen_height(), mag_filter() {
|
||||
static const char* query_vert_shader =
|
||||
"#version 430 core\n"
|
||||
"layout(location = 0) in vec4 a_position;\n"
|
||||
"\n"
|
||||
"uniform mat4 mat;\n"
|
||||
"uniform float scale;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" vec4 pos = a_position;\n"
|
||||
" pos.xy *= scale;\n"
|
||||
" gl_Position = mat * pos;\n"
|
||||
"}\n";
|
||||
|
||||
static const char* query_frag_shader =
|
||||
"#version 430 core\n"
|
||||
"layout(location = 0) out vec4 result;\n"
|
||||
"\n"
|
||||
"void main() {\n"
|
||||
" result = vec4(0.0); \n"
|
||||
"}\n";
|
||||
|
||||
static const char* alpha_layer_vert_shader =
|
||||
"#version 430 core\n"
|
||||
"out VertexData {\n"
|
||||
@@ -52,11 +73,11 @@ sprite_height(), screen_x_offset(), screen_y_offset(), screen_width(), screen_he
|
||||
" result = mix(cb, cl, g_opacity.x);\n"
|
||||
"}\n";
|
||||
|
||||
aa = post_process_aa_init();
|
||||
blur = post_process_blur_init();
|
||||
aa = new post_process_aa();
|
||||
blur = new post_process_blur();
|
||||
dof = new post_process_dof();
|
||||
exposure = post_process_exposure_init();
|
||||
tone_map = post_process_tone_map_init();
|
||||
exposure = new post_process_exposure();
|
||||
tone_map = new post_process_tone_map();
|
||||
stage_index = -1;
|
||||
stage_index_prev = -1;
|
||||
|
||||
@@ -70,8 +91,34 @@ sprite_height(), screen_x_offset(), screen_y_offset(), screen_width(), screen_he
|
||||
glSamplerParameteri(samplers[1], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||
glSamplerParameteri(samplers[1], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
|
||||
shader_glsl_param param;
|
||||
memset(¶m, 0, sizeof(shader_glsl_param));
|
||||
const float_t verts_quad[] = {
|
||||
-1.0f, 1.0f, 0.15f, 0.85f,
|
||||
-1.0f, -1.0f, 0.15f, 0.15f,
|
||||
1.0f, -1.0f, 0.85f, 0.15f,
|
||||
1.0f, 1.0f, 0.85f, 0.85f,
|
||||
};
|
||||
|
||||
glGenVertexArrays(1, &query_vao);
|
||||
glGenBuffers(1, &query_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, query_vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(verts_quad), verts_quad, GL_STATIC_DRAW);
|
||||
|
||||
gl_state_bind_vertex_array(query_vao);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 16, (void*)0); // Pos
|
||||
glVertexAttrib4f(3, 1.0f, 1.0f, 1.0f, 1.0f); // Color0
|
||||
glVertexAttrib4f(4, 1.0f, 1.0f, 1.0f, 1.0f); // Color1
|
||||
glEnableVertexAttribArray(8);
|
||||
glVertexAttribPointer(8, 2, GL_FLOAT, GL_FALSE, 16, (void*)8); // TexCoord0
|
||||
gl_state_bind_vertex_array(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
shader_glsl_param param = {};
|
||||
param.name = "Exposure Chara";
|
||||
query_shader.load(query_vert_shader,
|
||||
query_frag_shader, 0, ¶m);
|
||||
|
||||
param = {};
|
||||
param.name = "Alpha Layer";
|
||||
alpha_layer_shader.load(alpha_layer_vert_shader,
|
||||
alpha_layer_frag_shader, 0, ¶m);
|
||||
@@ -79,16 +126,31 @@ sprite_height(), screen_x_offset(), screen_y_offset(), screen_width(), screen_he
|
||||
}
|
||||
|
||||
post_process::~post_process() {
|
||||
post_process_aa_dispose(aa);
|
||||
post_process_blur_dispose(blur);
|
||||
if (aa) {
|
||||
delete aa;
|
||||
aa = 0;
|
||||
}
|
||||
|
||||
if (blur) {
|
||||
delete blur;
|
||||
blur = 0;
|
||||
}
|
||||
|
||||
if (dof) {
|
||||
delete dof;
|
||||
dof = 0;
|
||||
}
|
||||
|
||||
post_process_exposure_dispose(exposure);
|
||||
post_process_tone_map_dispose(tone_map);
|
||||
if (exposure) {
|
||||
delete exposure;
|
||||
exposure = 0;
|
||||
}
|
||||
|
||||
if (tone_map) {
|
||||
delete tone_map;
|
||||
tone_map = 0;
|
||||
}
|
||||
|
||||
::render_texture_free(&rend_texture);
|
||||
::render_texture_free(&buf_texture);
|
||||
::render_texture_free(&sss_contour_texture);
|
||||
@@ -97,12 +159,24 @@ post_process::~post_process() {
|
||||
::render_texture_free(&fbo_texture);
|
||||
::render_texture_free(&alpha_layer_texture);
|
||||
::render_texture_free(&screen_texture);
|
||||
alpha_layer_shader.unload();
|
||||
|
||||
if (samplers[0]) {
|
||||
glDeleteSamplers(2, samplers);
|
||||
samplers[0] = 0;
|
||||
}
|
||||
|
||||
if (query_vao) {
|
||||
glDeleteVertexArrays(1, &query_vao);
|
||||
query_vao = 0;
|
||||
}
|
||||
|
||||
if (query_vbo) {
|
||||
glDeleteBuffers(1, &query_vbo);
|
||||
query_vbo = 0;
|
||||
}
|
||||
|
||||
query_shader.unload();
|
||||
alpha_layer_shader.unload();
|
||||
}
|
||||
|
||||
void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param) {
|
||||
@@ -115,19 +189,17 @@ void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param
|
||||
|
||||
dof->apply(&rend_texture, samplers, cam);
|
||||
|
||||
shader_state_matrix_set_mvp_separate(&shaders_ft,
|
||||
&mat4_identity, &mat4_identity, &mat4_identity);
|
||||
shaders_ft.state_matrix_set_mvp(mat4_identity, mat4_identity, mat4_identity);
|
||||
|
||||
post_process_get_blur(blur, &rend_texture);
|
||||
post_process_get_exposure(exposure, cam, render_width, render_height, reset_exposure,
|
||||
blur->get_blur(&rend_texture);
|
||||
exposure->get_exposure(cam, render_width, render_height, reset_exposure,
|
||||
blur->tex[4].color_texture->tex, blur->tex[2].color_texture->tex);
|
||||
post_process_apply_tone_map(tone_map, &rend_texture, light_proj_tex, 0,
|
||||
tone_map->apply(&rend_texture, light_proj_tex, 0,
|
||||
&rend_texture, &buf_texture, &sss_contour_texture,
|
||||
blur->tex[0].color_texture->tex,
|
||||
exposure->exposure.color_texture->tex, npr_param);
|
||||
if (mlaa)
|
||||
post_process_apply_mlaa(aa, &rend_texture,
|
||||
&buf_texture, samplers, parent_bone_node);
|
||||
aa->apply_mlaa(&rend_texture, &buf_texture, samplers, parent_bone_node);
|
||||
|
||||
for (int32_t i = 0; i < 16; i++) {
|
||||
if (!render_textures_data[i])
|
||||
@@ -144,7 +216,7 @@ void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param
|
||||
glViewport(0, 0, t->width, t->height);
|
||||
gl_state_active_bind_texture_2d(0, rend_texture.color_texture->tex);
|
||||
gl_state_bind_sampler(0, samplers[0]);
|
||||
shader_set(&shaders_ft, SHADER_FT_REDUCE);
|
||||
shaders_ft.set(SHADER_FT_REDUCE);
|
||||
render_texture_draw_params(&shaders_ft, render_width,
|
||||
render_height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
@@ -160,7 +232,7 @@ void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param
|
||||
gl_state_bind_sampler(0, samplers[0]);
|
||||
uniform_value[U01] = parent_bone_node ? 1 : 0;
|
||||
uniform_value[U_REDUCE] = 0;
|
||||
shader_set(&shaders_ft, SHADER_FT_REDUCE);
|
||||
shaders_ft.set(SHADER_FT_REDUCE);
|
||||
render_texture_draw_params(&shaders_ft, render_width,
|
||||
render_height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
uniform_value[U01] = 0;
|
||||
@@ -186,11 +258,11 @@ void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param
|
||||
break;
|
||||
}
|
||||
|
||||
shader_set(&shaders_ft, SHADER_FT_MAGNIFY);
|
||||
shaders_ft.set(SHADER_FT_MAGNIFY);
|
||||
render_texture_draw_params(&shaders_ft, render_width,
|
||||
render_height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
shader_unbind();
|
||||
shader::unbind();
|
||||
|
||||
for (int32_t i = 0; i < 8; i++)
|
||||
gl_state_bind_sampler(i, 0);
|
||||
@@ -234,6 +306,16 @@ void post_process::ctrl(camera* cam) {
|
||||
reset_exposure = true;
|
||||
}
|
||||
|
||||
void post_process::draw_query_samples(GLuint query, float_t scale, mat4& mat) {
|
||||
glBeginQuery(GL_SAMPLES_PASSED, query);
|
||||
gl_state_bind_vertex_array(query_vao);
|
||||
query_shader.set("mat", false, mat);
|
||||
query_shader.set("scale", scale);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
gl_state_bind_vertex_array(0);
|
||||
glEndQuery(GL_SAMPLES_PASSED);
|
||||
}
|
||||
|
||||
void post_process::init_fbo(int32_t render_width, int32_t render_height,
|
||||
int32_t sprite_width, int32_t sprite_height, int32_t screen_width, int32_t screen_height) {
|
||||
if (this->render_width == render_width && this->render_height == render_height
|
||||
@@ -241,11 +323,11 @@ void post_process::init_fbo(int32_t render_width, int32_t render_height,
|
||||
return;
|
||||
|
||||
if (this->render_width != render_width || this->render_height != render_height) {
|
||||
post_process_aa_init_fbo(aa, render_width, render_height);
|
||||
post_process_blur_init_fbo(blur, render_width, render_height);
|
||||
aa->init_fbo(render_width, render_height);
|
||||
blur->init_fbo(render_width, render_height);
|
||||
dof->init_fbo(render_width, render_height);
|
||||
post_process_exposure_init_fbo(exposure);
|
||||
post_process_tone_map_init_fbo(tone_map);
|
||||
exposure->init_fbo();
|
||||
tone_map->init_fbo();
|
||||
render_texture_init(&rend_texture, render_width,
|
||||
render_height, 0, GL_RGBA16F, GL_DEPTH24_STENCIL8);
|
||||
render_texture_init(&buf_texture, render_width,
|
||||
@@ -350,13 +432,13 @@ void post_process::reset() {
|
||||
mlaa = true;
|
||||
mag_filter = POST_PROCESS_MAG_FILTER_BILINEAR;
|
||||
dof->initialize_data(0, 0);
|
||||
vec3 radius = { 2.0f, 2.0f, 2.0f };
|
||||
vec3 intensity = { 1.0f, 1.0f, 1.0f };
|
||||
post_process_blur_initialize_data(blur, &radius, &intensity);
|
||||
vec3 scene_fade_color = { 1.0f, 1.0f, 1.0f };
|
||||
vec3 tone_trans_start = { 0.0f, 0.0f, 0.0f };
|
||||
vec3 tone_trans_end = { 1.0f, 1.0f, 1.0f };
|
||||
post_process_tone_map_initialize_data(tone_map, 2.0f, true, 1.0f, 1, 1.0f,
|
||||
&scene_fade_color, 0.0f, 0, &tone_trans_start, &tone_trans_end, TONE_MAP_YCC_EXPONENT);
|
||||
const vec3 radius = { 2.0f, 2.0f, 2.0f };
|
||||
const vec3 intensity = { 1.0f, 1.0f, 1.0f };
|
||||
blur->initialize_data(radius, intensity);
|
||||
const vec3 scene_fade_color = { 1.0f, 1.0f, 1.0f };
|
||||
const vec3 tone_trans_start = { 0.0f, 0.0f, 0.0f };
|
||||
const vec3 tone_trans_end = { 1.0f, 1.0f, 1.0f };
|
||||
tone_map->initialize_data(2.0f, true, 1.0f, 1, 1.0f, scene_fade_color, 0.0f,
|
||||
0, tone_trans_start, tone_trans_end, TONE_MAP_YCC_EXPONENT);
|
||||
reset_exposure = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user