22#define NEBULA_PUFF_BUFFER 300
35static int nebu_dofbo = 0;
36static GLuint nebu_fbo = GL_INVALID_VALUE;
37static GLuint nebu_tex = GL_INVALID_VALUE;
38static GLfloat nebu_render_w = 0.;
39static GLfloat nebu_render_h = 0.;
40static mat4 nebu_render_P;
47typedef struct NebulaPuff_ {
56static double puff_x = 0.;
57static double puff_y = 0.;
89 scale = conf.nebu_scale *
gl_screen.scale;
92 if ( scale ==
nebu_scale && fbo_w == nebu_render_w &&
93 fbo_h == nebu_render_h )
97 nebu_render_w = fbo_w;
98 nebu_render_h = fbo_h;
100 glDeleteTextures( 1, &nebu_tex );
101 glDeleteFramebuffers( 1, &nebu_fbo );
104 gl_fboCreate( &nebu_fbo, &nebu_tex, nebu_render_w, nebu_render_h );
108 mat4_translate_scale_xy( &nebu_render_P, -nebu_render_w / 2.,
109 -nebu_render_h / 2., nebu_render_w, nebu_render_h );
110 glUseProgram( shaders.nebula_background.program );
111 gl_uniformMat4( shaders.nebula_background.projection, &nebu_render_P );
112 glUseProgram( shaders.nebula.program );
113 gl_uniformMat4( shaders.nebula.projection, &nebu_render_P );
135 glDeleteFramebuffers( 1, &nebu_fbo );
136 glDeleteTextures( 1, &nebu_tex );
147 NTracingZone( _ctx, 1 );
152 NTracingZoneEnd( _ctx );
166 glBindFramebuffer( GL_FRAMEBUFFER, nebu_fbo );
167 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
171 glUseProgram( shaders.nebula_background.program );
174 glUniform1f( shaders.nebula_background.eddy_scale,
176 glUniform1f( shaders.nebula_background.time,
nebu_time );
177 glUniform1f( shaders.nebula_background.nonuniformity,
178 conf.nebu_nonuniformity );
181 glEnableVertexAttribArray( shaders.nebula_background.vertex );
184 glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
188 glDisableVertexAttribArray( shaders.nebula_background.vertex );
201 glBindFramebuffer( GL_FRAMEBUFFER,
gl_screen.current_fbo );
217 mod =
player.p->stats.ew_detect;
218 bonus =
player.p->stats.nebu_visibility;
262 NTracingZone( _ctx, 1 );
277 glBindFramebuffer( GL_FRAMEBUFFER, nebu_fbo );
278 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
282 glUseProgram( shaders.nebula.program );
287 glUniform1f( shaders.nebula.time,
nebu_time );
288 glUniform1f( shaders.nebula.nonuniformity, conf.nebu_nonuniformity );
291 glEnableVertexAttribArray( shaders.nebula.vertex );
294 glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
298 glDisableVertexAttribArray( shaders.nebula.vertex );
306 NTracingZoneEnd( _ctx );
326 if ( ( !below_player && ( puff->
height < 1. ) ) ||
327 ( below_player && ( puff->
height > 1. ) ) )
336 if ( ( x < -s ) || ( x > SCREEN_W + s ) || ( y < -s ) ||
337 ( y > SCREEN_H + s ) )
341 glUseProgram( shaders.nebula_puff.program );
343 projection = gl_view_matrix;
344 mat4_translate_scale_xy( &projection, x, y, s, s );
345 glEnableVertexAttribArray( shaders.nebula_puff.vertex );
350 gl_uniformMat4( shaders.nebula_puff.projection, &projection );
351 glUniform1f( shaders.nebula_puff.time,
nebu_time / 1.5 );
352 glUniform2f( shaders.nebula_puff.r, puff->
rx, puff->
ry );
354 glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
356 glDisableVertexAttribArray( shaders.nebula_puff.vertex );
362void nebu_updateColour(
void )
365 double saturation = conf.nebu_saturation;
366 double value = conf.nebu_saturation * 0.5 + 0.5;
368 glUseProgram( shaders.nebula.program );
369 glUniform1f( shaders.nebula.saturation, conf.nebu_saturation );
370 glUseProgram( shaders.nebula_background.program );
371 glUniform1f( shaders.nebula_background.saturation, conf.nebu_saturation );
375 gltf_lightAmbient( 3.0 * col.r, 3.0 * col.g, 3.0 * col.b );
376 gltf_lightIntensity( 0.5 );
384 glUseProgram( shaders.nebula_puff.program );
385 glUniform3f( shaders.nebula_puff.nebu_col, col.r, col.g, col.b );
397void nebu_prep(
double density,
double volatility,
double hue )
399 NTracingZone( _ctx, 1 );
403 glUseProgram( shaders.nebula.program );
404 glUniform1f( shaders.nebula.hue,
nebu_hue );
405 glUseProgram( shaders.nebula_background.program );
406 glUniform1f( shaders.nebula_background.hue,
nebu_hue );
407 glUniform1f( shaders.nebula_background.volatility, volatility );
412 if ( density > 0. ) {
416 nebu_dt = ( 2. * density + 200. ) / 10e3;
417 nebu_dx = 15e3 / pow( density, 1. / 3. );
430 np->
s = RNG( 10, 32 );
431 np->
height = RNGF() + 0.2;
434 np->
rx = RNGF() * 2000. - 1000.;
435 np->
ry = RNGF() * 2000. - 1000.;
439 NTracingZoneEnd( _ctx );
void cam_getDPos(double *dx, double *dy)
Gets the camera position differential (change in last frame).
double cam_getZoom(void)
Gets the camera zoom.
void col_hsv2rgb(glColour *c, float h, float s, float v)
Changes colour space from HSV to RGB.
void gui_getOffset(double *x, double *y)
Gets the GUI offset.
mat4 mat4_identity(void)
Creates an identity matrix.
mat4 mat4_ortho(double left, double right, double bottom, double top, double nearVal, double farVal)
Creates an orthographic projection matrix.
void nebu_update(double dt)
Updates visibility and stuff.
void nebu_exit(void)
Cleans up the nebu subsystem.
static NebulaPuff * nebu_puffs
int nebu_resize(void)
Handles a screen s.
#define NEBULA_PUFF_BUFFER
static void nebu_renderPuffs(int below_player)
Renders the puffs.
void nebu_renderOverlay(const double dt)
Renders the nebula overlay (hides what player can't see).
double nebu_getSightRadius(void)
Gets the nebula view radius.
void nebu_render(const double dt)
Renders the nebula.
static void nebu_blitFBO(void)
If we're drawing the nebula buffered, copy to the screen.
static double nebu_density
void nebu_prep(double density, double volatility, double hue)
Prepares the nebualae to be rendered.
int nebu_init(void)
Initializes the nebula.
static void nebu_renderBackground(const double dt)
Renders the nebula using the multitexture approach.
void gl_renderTextureRawH(GLuint texture, const mat4 *projection, const mat4 *tex_mat, const glColour *c)
Texture blitting backend.
int gl_fboCreate(GLuint *fbo, GLuint *tex, GLsizei width, GLsizei height)
Creates a framebuffer and its associated texture.
void gl_vboActivateAttribOffset(gl_vbo *vbo, GLuint index, GLuint offset, GLint size, GLenum type, GLsizei stride)
Activates a VBO's offset.
int space_isSimulation(void)
returns whether we're just simulating.
void spfx_setNebulaColour(double r, double g, double b)
Sets the nebula colour where applicable.
Represents a nebula puff.