Don't like ads? PRO users don't see any ads ;-)
Guest

sauerbraten temporal supersampling

By: a guest on May 6th, 2012  |  syntax: Diff  |  size: 4.47 KB  |  hits: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Index: engine/rendergl.cpp
  2. ===================================================================
  3. --- engine/rendergl.cpp (revision 4089)
  4. +++ engine/rendergl.cpp (working copy)
  5. @@ -1717,6 +1717,8 @@
  6.  VARP(motionblurmillis, 1, 5, 1000);
  7.  FVARP(motionblurscale, 0, 0.5f, 1);
  8.  
  9. +extern int subframe;
  10. +
  11.  void addmotionblur()
  12.  {
  13.      if(!motionblur || !hasTR || max(screen->w, screen->h) > hwtexsize) return;
  14. @@ -1732,6 +1734,8 @@
  15.          createtexture(motiontex, motionw, motionh, NULL, 3, 0, GL_RGB, GL_TEXTURE_RECTANGLE_ARB);
  16.      }
  17.  
  18. +    if (subframe == 1) {
  19. +
  20.      glBindTexture(GL_TEXTURE_RECTANGLE_ARB, motiontex);
  21.  
  22.      glMatrixMode(GL_PROJECTION);
  23. @@ -1750,12 +1754,14 @@
  24.  
  25.      rectshader->set();
  26.  
  27. -    glColor4f(1, 1, 1, lastmotion ? pow(motionblurscale, max(float(lastmillis - lastmotion)/motionblurmillis, 1.0f)) : 0);
  28. +//    fprintf(stderr,"%f",lastmotion ? pow(motionblurscale, max(float(lastmillis - lastmotion)/motionblurmillis, 1.0f)) : 0);
  29. +//    glColor4f(1, 1, 1, lastmotion ? pow(motionblurscale, max(float(lastmillis - lastmotion)/motionblurmillis, 1.0f)) : 0);
  30. +    glColor4f(1, 1, 1, 0.5);
  31.      glBegin(GL_TRIANGLE_STRIP);
  32.      glTexCoord2f(      0,       0); glVertex2f(-1, -1);
  33.      glTexCoord2f(motionw,       0); glVertex2f( 1, -1);
  34.      glTexCoord2f(      0, motionh); glVertex2f(-1,  1);
  35. -    glTexCoord2f(motionw, motionh); glVertex2f( 1,  1);
  36. +//    glTexCoord2f(motionw, motionh); glVertex2f( 1,  1);
  37.      glEnd();
  38.  
  39.      glDisable(GL_TEXTURE_RECTANGLE_ARB);
  40. @@ -1768,13 +1774,16 @@
  41.  
  42.      glMatrixMode(GL_MODELVIEW);
  43.      glPopMatrix();
  44. +
  45. +    fprintf(stderr,"_");
  46. +    }
  47.  
  48. -    if(lastmillis - lastmotion >= motionblurmillis)
  49. -    {
  50. -        lastmotion = lastmillis - lastmillis%motionblurmillis;
  51. +//    if(lastmillis - lastmotion >= motionblurmillis)
  52. +//    {
  53. +//       lastmotion = lastmillis - lastmillis%motionblurmillis;
  54.  
  55.          glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, 0, 0, screen->w, screen->h);
  56. -    }
  57. +//    }
  58.  }
  59.  
  60.  bool dopostfx = false;
  61. Index: engine/main.cpp
  62. ===================================================================
  63. --- engine/main.cpp     (revision 4089)
  64. +++ engine/main.cpp     (working copy)
  65. @@ -993,6 +993,18 @@
  66.      return max(millis, totalmillis);
  67.  }
  68.  
  69. +long long int getclockmicros()
  70. +{
  71. +       struct timeval timestamp;
  72. +       gettimeofday(&timestamp,NULL);
  73. +       return timestamp.tv_sec*1000000ll+timestamp.tv_usec;
  74. +}
  75. +
  76. +
  77. +int subframe = 0;
  78. +long long int lastrealframemicros = getclockmicros();
  79. +
  80. +
  81.  int main(int argc, char **argv)
  82.  {
  83.      #ifdef WIN32
  84. @@ -1188,11 +1200,22 @@
  85.      inputgrab(grabinput = true);
  86.      ignoremousemotion();
  87.  
  88. +    lastrealframemicros = getclockmicros();
  89. +
  90.      for(;;)
  91.      {
  92.          static int frames = 0;
  93.          int millis = getclockmillis();
  94. -        limitfps(millis, totalmillis);
  95. +//        limitfps(millis, totalmillis);
  96. +//        long long int currentsubframemicros = getclockmicros();
  97. +
  98. +        fprintf(stderr,"|%i:",subframe);
  99. +//        if (!mainmenu) {
  100. +//             long long int subframestart = lastrealframemicros + 1000000ll*(subframe)/120;
  101. +//             int delay = (subframestart - getclockmicros())/1000;
  102. +//             if (delay>0 && subframe>0) SDL_Delay(delay);
  103. +//      }
  104. +
  105.          int elapsed = millis-totalmillis;
  106.          if(multiplayer(false)) curtime = game::ispaused() ? 0 : elapsed;
  107.          else
  108. @@ -1232,8 +1255,29 @@
  109.          inbetweenframes = false;
  110.          if(mainmenu) gl_drawmainmenu(screen->w, screen->h);
  111.          else gl_drawframe(screen->w, screen->h);
  112. -        swapbuffers();
  113. +//        swapbuffers();
  114.          renderedframe = inbetweenframes = true;
  115. +
  116. +//        glFinish();
  117. +//        glFlush();
  118. +        long long int now = getclockmicros();
  119. +        bool slowsubframe = 0;//(now - lastrealframemicros) > (1000000*(subframe+1)/120);
  120. +        if (slowsubframe) {
  121. +               fprintf(stderr,"s:");
  122. +        }
  123. +        fprintf(stderr,"%lli ",(now - lastrealframemicros)/1000);
  124. +        if (subframe == 1 && slowsubframe) fprintf(stderr,"o");
  125. +        if ((subframe == 0 && slowsubframe) || (subframe == 1 && !slowsubframe)) {
  126. +               long long int j = getclockmicros();
  127. +               swapbuffers();
  128. +               glFinish();
  129. +               long long int i = getclockmicros();
  130. +               fprintf(stderr," w:%lli S:%lli\n",(i-j)/1000,(i-lastrealframemicros)/1000);
  131. +               lastrealframemicros = i;
  132. +        }
  133. +        if (!(subframe == 0 && slowsubframe))
  134. +               subframe = !subframe;
  135. +
  136.      }
  137.      
  138.      ASSERT(0);