52 intensity(0.0
f), default_intensity(0.0
f), div(1.0
f), add(0.0
f),
60 static int Post_initialized = 0;
64 static int Post_active_shader_index = -1;
66 static GLuint Post_framebuffer_id[2] = { 0 };
67 static GLuint Post_bloom_texture_id[3] = { 0 };
68 static GLuint Post_shadow_framebuffer_id = 0;
69 static GLuint Post_shadow_texture_id = 0;
70 static GLuint Post_shadow_depth_texture_id = 0;
72 static int Post_texture_width = 0;
73 static int Post_texture_height = 0;
75 static bool opengl_post_pass_bloom()
89 int width = Post_texture_width >> 1;
90 int height = Post_texture_height >> 1;
125 for (
int pass = 0; pass < 2; pass++) {
160 if ( !Post_initialized ) {
282 vec3d local_light_dir;
332 bool bloomed = opengl_post_pass_bloom();
341 for (
int i = 0;
i < (
int)Post_effects.size();
i++) {
342 if (Post_effects[
i].always_on) {
347 int post_sdr_handle = Post_active_shader_index;
349 if ( post_sdr_handle < 0 ) {
361 for (
size_t idx = 0;
idx < Post_effects.size();
idx++) {
363 const char *
name = Post_effects[
idx].uniform_name.c_str();
364 float value = Post_effects[
idx].intensity;
411 extern GLuint Post_shadow_texture_id;
478 for (idx = 0; idx < Post_effects.size(); idx++) {
479 names.push_back(Post_effects[idx].
name);
485 for (
int idx = 0;
idx < (
int)Post_effects.size();
idx++) {
486 if (flags & (1 <<
idx)) {
494 if ( !Post_initialized ) {
505 if(!
stricmp(
"lightshafts",name))
512 for (idx = 0; idx < Post_effects.size(); idx++) {
513 const char *eff_name = Post_effects[
idx].name.c_str();
515 if ( !
stricmp(eff_name, name) ) {
516 Post_effects[
idx].intensity = (value / Post_effects[
idx].div) + Post_effects[idx].add;
522 for (idx = 0; idx < Post_effects.size(); idx++) {
523 if ( Post_effects[idx].always_on || (Post_effects[idx].intensity != Post_effects[idx].default_intensity) ) {
535 if ( !Post_initialized ) {
540 for (idx = 0; idx < Post_effects.size(); idx++) {
541 Post_effects[
idx].intensity = Post_effects[
idx].default_intensity;
544 Post_active_shader_index = -1;
550 if (Post_initialized)
565 static bool opengl_post_init_table()
610 if (Post_effects.size() < 32) {
611 Post_effects.push_back(eff);
614 mprintf((
"WARNING: post_processing.tbl can only have a max of 32 effects! Ignoring extra...\n"));
676 mprintf((
"Unable to parse 'post_processing.tbl'! Error message = %s.\n", e.what()));
684 for (
size_t idx = 0;
idx < Post_effects.size();
idx++) {
685 if (flags & (1 <<
idx)) {
686 sflags <<
"#define ";
687 sflags << Post_effects[
idx].define_name.c_str();
700 sflags <<
"#define FXAA_GLSL_120 1\n";
701 sflags <<
"#define FXAA_GLSL_130 0\n";
704 sflags <<
"#define FXAA_GLSL_120 0\n";
705 sflags <<
"#define FXAA_GLSL_130 1\n";
710 sflags <<
"#define FXAA_QUALITY_PRESET 10\n";
711 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD (1.0/6.0)\n";
712 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD_MIN (1.0/12.0)\n";
713 sflags <<
"#define FXAA_QUALITY_SUBPIX 0.33\n";
716 sflags <<
"#define FXAA_QUALITY_PRESET 11\n";
717 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD (1.0/7.0)\n";
718 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD_MIN (1.0/14.0)\n";
719 sflags <<
"#define FXAA_QUALITY_SUBPIX 0.33\n";
722 sflags <<
"#define FXAA_QUALITY_PRESET 12\n";
723 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD (1.0/8.0)\n";
724 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD_MIN (1.0/16.0)\n";
725 sflags <<
"#define FXAA_QUALITY_SUBPIX 0.33\n";
728 sflags <<
"#define FXAA_QUALITY_PRESET 13\n";
729 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD (1.0/9.0)\n";
730 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD_MIN (1.0/18.0)\n";
731 sflags <<
"#define FXAA_QUALITY_SUBPIX 0.33\n";
734 sflags <<
"#define FXAA_QUALITY_PRESET 14\n";
735 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD (1.0/10.0)\n";
736 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD_MIN (1.0/20.0)\n";
737 sflags <<
"#define FXAA_QUALITY_SUBPIX 0.33\n";
740 sflags <<
"#define FXAA_QUALITY_PRESET 25\n";
741 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD (1.0/11.0)\n";
742 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD_MIN (1.0/22.0)\n";
743 sflags <<
"#define FXAA_QUALITY_SUBPIX 0.33\n";
746 sflags <<
"#define FXAA_QUALITY_PRESET 26\n";
747 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD (1.0/12.0)\n";
748 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD_MIN (1.0/24.0)\n";
749 sflags <<
"#define FXAA_QUALITY_SUBPIX 0.33\n";
752 sflags <<
"#define FXAA_PC 1\n";
753 sflags <<
"#define FXAA_QUALITY_PRESET 27\n";
754 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD (1.0/13.0)\n";
755 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD_MIN (1.0/26.0)\n";
756 sflags <<
"#define FXAA_QUALITY_SUBPIX 0.33\n";
759 sflags <<
"#define FXAA_QUALITY_PRESET 28\n";
760 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD (1.0/14.0)\n";
761 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD_MIN (1.0/28.0)\n";
762 sflags <<
"#define FXAA_QUALITY_SUBPIX 0.33\n";
765 sflags <<
"#define FXAA_QUALITY_PRESET 39\n";
766 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD (1.0/15.0)\n";
767 sflags <<
"#define FXAA_QUALITY_EDGE_THRESHOLD_MIN (1.0/32.0)\n";
768 sflags <<
"#define FXAA_QUALITY_SUBPIX 0.33\n";
780 for (idx = 0; idx < (
int)Post_effects.size(); idx++) {
781 if (Post_effects[idx].always_on) {
802 mprintf((
"Error while compiling FXAA shaders. FXAA will be unavailable.\n"));
809 static bool opengl_post_init_framebuffer()
834 int width = Post_texture_width >> 1;
835 int height = Post_texture_height >> 1;
837 for (
int tex = 0; tex < 3; tex++) {
860 Post_framebuffer_id[0] = 0;
861 Post_framebuffer_id[1] = 0;
864 memset(Post_bloom_texture_id, 0,
sizeof(Post_bloom_texture_id));
884 Post_framebuffer_id[0] = 0;
885 Post_framebuffer_id[1] = 0;
888 memset(Post_bloom_texture_id, 0,
sizeof(Post_bloom_texture_id));
968 Post_initialized = 0;
971 if ( !opengl_post_init_table() ) {
972 mprintf((
" Unable to read post-processing table! Disabling post-processing...\n\n"));
1000 mprintf((
" Unable to initialize post-processing shaders! Disabling post-processing...\n\n"));
1005 if ( !opengl_post_init_framebuffer() ) {
1006 mprintf((
" Unable to initialize post-processing framebuffer! Disabling post-processing...\n\n"));
1011 Post_initialized = 1;
1016 if ( !Post_initialized ) {
1020 if (Post_bloom_texture_id[0]) {
1022 memset(Post_bloom_texture_id, 0,
sizeof(Post_bloom_texture_id));
1025 if (Post_framebuffer_id[0]) {
1027 Post_framebuffer_id[0] = 0;
1029 if (Post_framebuffer_id[1]) {
1031 Post_framebuffer_id[1] = 0;
1035 Post_effects.clear();
1038 Post_active_shader_index = 0;
1040 Post_initialized = 0;
GLuint Cockpit_depth_texture
#define OGL_EXT_FRAMEBUFFER_OBJECT
void opengl_post_process_shutdown()
void opengl_post_shader_header(SCP_stringstream &sflags, shader_type shader_t, int flags)
#define vglFramebufferTextureEXT
#define vglBindFramebufferEXT
std::basic_stringstream< char, std::char_traits< char >, std::allocator< char > > SCP_stringstream
GLsizei const GLfloat * value
GLint opengl_shader_get_uniform(const char *uniform_text)
int required_string_one_of(int arg_count,...)
Checks for one of any of the given required strings.
#define GL_TEXTURE_2D_ARRAY_EXT
void Color(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha=255)
GLuint Scene_luminance_texture
GLboolean ScissorTest(GLint state=-1)
WINGDIAPI void APIENTRY glClear(GLbitfield mask)
GLuint Shadow_map_texture
#define GL_DEPTH_COMPONENT32
WINGDIAPI void APIENTRY glDeleteTextures(GLsizei n, const GLuint *textures)
GLint GLint GLsizei GLsizei GLsizei depth
int Fxaa_preset_last_frame
void opengl_draw_textured_quad(GLfloat x1, GLfloat y1, GLfloat u1, GLfloat v1, GLfloat x2, GLfloat y2, GLfloat u2, GLfloat v2)
GLboolean DepthTest(GLint state=-1)
GLuint opengl_get_rtt_framebuffer()
Gets the current RTT framebuffer.
int light_get_global_dir(vec3d *pos, int n)
const char * defaults_get_file(const char *filename)
vec3d * vm_vec_rotate(vec3d *dest, const vec3d *src, const matrix *m)
SCP_vector< opengl_shader_t > GL_shader
#define GL_TEXTURE_2D_ARRAY
opengl_texture_state Texture
GLboolean CullFace(GLint state=-1)
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
GLuint Shadow_map_depth_texture
GLuint Scene_depth_texture
void opengl_post_pass_fxaa()
#define GL_TEXTURE_WRAP_S
void get_post_process_effect_names(SCP_vector< SCP_string > &names)
void stuff_float(float *f)
void opengl_delete_shader(int sdr_handle)
void opengl_shader_init_uniform(const char *uniform_text)
#define vglFramebufferTexture2DEXT
#define GL_DEPTH_ATTACHMENT_EXT
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
GLboolean DepthMask(GLint state=-1)
struct matrix::@228::@230 vec
int Scene_texture_initialized
int cf_exists_full(const char *filename, int dir_type)
bool GL_rendering_to_texture
#define GL_FRAMEBUFFER_EXT
void stuff_string(char *outstr, int type, int len, char *terminators)
WINGDIAPI void APIENTRY glGenTextures(GLsizei n, GLuint *textures)
sprintf(buf,"(%f,%f,%f)", v3->xyz.x, v3->xyz.y, v3->xyz.z)
void SetAlphaBlendMode(gr_alpha_blend ab)
int required_string(const char *pstr)
WINGDIAPI void APIENTRY glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
int optional_string(const char *pstr)
void recompile_fxaa_shader()
void gr_opengl_post_process_end()
#define GL_TEXTURE_WRAP_R
void read_file_text(const char *filename, int mode, char *processed_text, char *raw_text)
int opengl_check_framebuffer()
GLuint Scene_color_texture
#define GL_TEXTURE_MAG_FILTER
int Cmdline_bloom_intensity
opengl_uniform_state Uniform
#define Is_Extension_Enabled(x)
void SetTarget(GLenum tex_target)
WINGDIAPI void APIENTRY glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
int Cmdline_shadow_quality
GLint GLint GLint GLint GLint x
void Enable(GLuint tex_id=0)
WINGDIAPI void APIENTRY glDrawBuffer(GLenum mode)
void read_file_text_from_array(const char *array, char *processed_text, char *raw_text)
void stuff_boolean(int *i, bool a_to_eol)
WINGDIAPI void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
GLboolean Blend(GLint state=-1)
void gr_opengl_post_process_save_zbuffer()
#define GL_UNSIGNED_INT_8_8_8_8_REV
SCP_vector< post_effect_t > Post_effects
void reset_parse(char *text)
void gr_opengl_post_process_begin()
GLuint const GLchar * name
int light_get_global_count()
GLfloat Scene_texture_u_scale
bool opengl_post_init_shaders()
SCP_vector< ship_effect > Ship_effects
#define GL_TEXTURE_WRAP_T
int gr_opengl_maybe_create_shader(shader_type shader_t, unsigned int flags)
#define SDR_FLAG_BLUR_HORIZONTAL
GLint GLsizei GLsizei height
#define vglGenFramebuffersEXT
#define vglDeleteFramebuffersEXT
#define GL_TEXTURE_MIN_FILTER
GLuint Scene_normal_texture
#define OGL_ARB_TEXTURE_NON_POWER_OF_TWO
struct post_effect_t post_effect_t
GLint GL_max_renderbuffer_size
void SetShaderMode(GLboolean mode)
float vm_vec_dot(const vec3d *v0, const vec3d *v1)
WINGDIAPI void APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param)
#define GL_DEPTH_COMPONENT
GLuint Scene_specular_texture
#define SDR_FLAG_BLUR_VERTICAL
void gr_opengl_post_process_set_effect(const char *name, int value)
bool is_minimum_GLSL_version()
bool PostProcessing_override
void opengl_post_process_init()
bool stars_sun_has_glare(int index)
void opengl_shader_set_current(opengl_shader_t *shader_obj)
#define GL_COLOR_BUFFER_BIT
int timer_get_milliseconds()
GLuint Scene_position_texture
void SetActiveUnit(GLuint id=0)
#define GL_COLOR_ATTACHMENT0_EXT
int opengl_check_for_errors(char *err_at)
#define GL_DEPTH_BUFFER_BIT
void opengl_post_init_uniforms(int flags)
GLboolean Lighting(GLint state=-1)
void gr_opengl_post_process_set_defaults()