/* Raydium - CQFD Corp. http://raydium.org/ License: GPL - GNU General Public License, see "gpl.txt" file. */ #ifndef DONT_INCLUDE_HEADERS #include "index.h" #else #include "headers/hdr.h" #endif void raydium_hdr_settings_color_local(GLfloat r, GLfloat g, GLfloat b, GLfloat a) { raydium_hdr_color_local[0]=r; raydium_hdr_color_local[1]=g; raydium_hdr_color_local[2]=b; raydium_hdr_color_local[3]=a; } void raydium_hdr_settings_color_ambient(GLfloat r, GLfloat g, GLfloat b, GLfloat a) { raydium_hdr_color_ambient[0]=r; raydium_hdr_color_ambient[1]=g; raydium_hdr_color_ambient[2]=b; raydium_hdr_color_ambient[3]=a; } void raydium_hdr_settings_eye(float speed, float alpha_max) { raydium_hdr_alpha_max=alpha_max; raydium_hdr_eye_speed=speed; } void raydium_hdr_settings(GLfloat *color_local, GLfloat *color_ambient, float eye_speed, float alpha_max) { GLfloat r,g,b,a; r=color_ambient[0]; g=color_ambient[1]; b=color_ambient[2]; a=color_ambient[3]; raydium_hdr_settings_color_ambient(r,g,b,a); r=color_local[0]; g=color_local[1]; b=color_local[2]; a=color_local[3]; raydium_hdr_settings_color_local(r,g,b,a); raydium_hdr_settings_eye(eye_speed,alpha_max); } void raydium_hdr_init(void) { glClearStencil(0); // default stencil "color" glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glStencilFunc(GL_ALWAYS, 0, 0xffffffff); glEnable(GL_STENCIL_TEST); raydium_hdr_eye=0; raydium_hdr_state=0; raydium_hdr_texture_id=-1; raydium_hdr_generated=0; raydium_hdr_settings_color_local(1,1,1,1); raydium_hdr_settings_color_ambient(0.45,0.45,0.45,0.45); raydium_hdr_settings_eye(RAYDIUM_HDR_EYE_SPEED_DEFAULT,1); raydium_log("HDR: OK"); } void raydium_hdr_internal_window_malloc(void) { if(!raydium_hdr_state) return; if(raydium_hdr_mem) free(raydium_hdr_mem); raydium_hdr_mem=malloc(raydium_window_tx*raydium_window_ty); } void raydium_hdr_enable(void) { raydium_hdr_state=1; if(raydium_hdr_texture_id<0) { raydium_hdr_texture_id=raydium_texture_load_internal("","hdrmap",1,RAYDIUM_HDR_SIZE,RAYDIUM_HDR_SIZE,3,-1); raydium_hdr_mem=NULL; raydium_hdr_internal_window_malloc(); raydium_hdr_mem_hdr=malloc(RAYDIUM_HDR_SIZE*RAYDIUM_HDR_SIZE); raydium_hdr_mem_hdr2=malloc(RAYDIUM_HDR_SIZE*RAYDIUM_HDR_SIZE); raydium_hdr_mem_hdr3=malloc(RAYDIUM_HDR_SIZE*RAYDIUM_HDR_SIZE*3); } } void raydium_hdr_disable(void) { raydium_hdr_state=0; } void raydium_hdr_block(signed char blocking) { if(blocking) glStencilFunc(GL_ALWAYS, 0, 0xffffffff); else glStencilFunc(GL_ALWAYS, 1, 0xffffffff); } void raydium_hdr_blur(unsigned char *in, unsigned char *out) { int x,y; float p; // 1st row and last row for(x=1;x0) { raydium_hdr_eye-=(hdr_exposure*(raydium_hdr_eye_speed*raydium_frame_time)); if(raydium_hdr_eye<=0) raydium_hdr_eye=-9999; // the eye is now ok } // we're in "total" drak if(hdr_exposure==0) raydium_hdr_eye=0; // be ready for another "flash" if(hdr_exposure>0 && raydium_hdr_eye==0) raydium_hdr_eye=raydium_hdr_alpha_max; //printf("%i/%i (%f)\n",total,RAYDIUM_HDR_SIZE*RAYDIUM_HDR_SIZE,hdr_exposure*100); if(raydium_hdr_eye>0) // if(!raydium_key[GLUT_KEY_F11]) for(x=0;x0?raydium_hdr_eye:0); // clamp for(i=0;i=0 && texture