Changeset adb104f in opengl-game


Ignore:
Timestamp:
Jan 10, 2019, 4:38:01 AM (6 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
8fbd34f
Parents:
db06984
Message:

Make the explosion shader only emit particles for a short time instead of forever and make it look more like an explosion

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • explosion.frag

    rdb06984 radb104f  
    55out vec4 frag_color;
    66
    7 vec4 particle_color = vec4 (0.5, 0.5, 0.8, 0.8);
    8 
    97void main() {
    10    frag_color.a = opacity;
    11    frag_color.rgb = particle_color.rgb;
     8   frag_color = vec4(1.0, opacity * opacity, 0.0, opacity);
    129}
  • explosion.vert

    rdb06984 radb104f  
    11#version 410 core
    22
    3 uniform float elapsed_system_time;
     3// TODO: Pass the explosion center in as a uniform
     4
     5uniform float explosion_start_time;
     6uniform float cur_time;
    47
    58layout (location = 0) in vec3 v_i; // initial velocity
     
    912
    1013void main() {
    11    float t = elapsed_system_time - start_time;
    12    t = mod(t, 3.0); // allow time to loop around so particle emitter keeps going
     14   float duration = 0.5;
     15   float t = cur_time - explosion_start_time - start_time;
    1316
    14    vec3 p = vec3(0.0, 0.0, 0.0);
    15    vec3 a = vec3(0.0, -1.0, 0.0); // gravity
    16    p += v_i * t + 0.5 * a * t * t;
     17   if (t < 0.0) {
     18      opacity = 0.0;
     19   } else {
     20      // Need to find out the last time this particle was at the origin
     21      // If that is greater than the duration, hide the particle
     22      float cur = floor(t / duration);
     23      float end = floor((duration - start_time) / duration);
     24      if (cur > end) {
     25         opacity = 0.0;
     26      } else {
     27         opacity = 1.0 - (t / duration);
     28      }
     29   }
    1730
    18    opacity = 1.0 - (t / 3.0);
     31   vec3 p = vec3(0.0, 0.0, 0.0); //  this is the center of the explosion
     32   vec3 a = vec3(0.0, 0.1, 0.0);
     33   p += normalize(v_i) * mod(t, duration) / duration * 0.3; // allow time to loop around so particle emitter keeps going
    1934
    2035   gl_Position = vec4(p, 1.0);
  • new-game.cpp

    rdb06984 radb104f  
    618618   GLuint laser_sp_models_ub_index = glGetUniformBlockIndex(laser_sp, "models");
    619619
    620    GLuint elapsed_system_time_loc = glGetUniformLocation(explosion_sp, "elapsed_system_time");
     620   GLuint explosion_start_time_loc = glGetUniformLocation(explosion_sp, "explosion_start_time");
     621   GLuint cur_time_loc = glGetUniformLocation(explosion_sp, "cur_time");
    621622
    622623
     
    820821                  removeObjectFromScene(*objects[i], ubo);
    821822                  score++;
     823
     824                  // render an explosion
     825                  glUseProgram(explosion_sp);
     826                  glUniform1f(explosion_start_time_loc, (GLfloat)glfwGetTime());
     827                  cout << "REMOVED" << endl;
     828                  cout << i << endl;
    822829               }
    823830            }
     
    915922
    916923      glUseProgram(explosion_sp);
    917       glUniform1f(elapsed_system_time_loc, (GLfloat)current_seconds);
     924      glUniform1f(cur_time_loc, (GLfloat)current_seconds);
    918925
    919926      // Render scene
     
    19071914      t_accum += 0.01f;
    19081915
    1909       float randx = ((float)rand() / (float)RAND_MAX) * 1.0f - 0.5f;
    1910       float randz = ((float)rand() / (float)RAND_MAX) * 1.0f - 0.5f;
     1916      float randx = ((float)rand() / (float)RAND_MAX) - 0.5f;
     1917      float randy = ((float)rand() / (float)RAND_MAX) - 0.5f;
    19111918      vv[i*3] = randx;
    1912       vv[i*3 + 1] = 1.0f;
    1913       vv[i*3 + 2] = randz;
     1919      vv[i*3 + 1] = randy;
     1920      vv[i*3 + 2] = 0.0f;
    19141921   }
    19151922
Note: See TracChangeset for help on using the changeset viewer.