Guest User

Untitled

a guest
Jun 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.19 KB | None | 0 0
  1. Index: gl_rmain.c
  2. ===================================================================
  3. --- gl_rmain.c (revision 9017)
  4. +++ gl_rmain.c (working copy)
  5. @@ -35,6 +35,13 @@
  6. //
  7. r_refdef_t r_refdef;
  8.  
  9. +cvar_t r_motionblur = {CVAR_SAVE, "r_motionblur", "0", "motionblur frame-by-frame alpha control {0 to 1} - 0.7 recommended"};
  10. +cvar_t r_damageblur = {CVAR_SAVE, "r_damageblur", "0", "motionblur based on damage; requires r_motionblur to have a value"};
  11. +cvar_t r_motionblur_adj = {CVAR_SAVE, "r_motionblur_adj", "0.000015", "motionblur fps adjustment value - do not change unless you know what you're doing"};
  12. +cvar_t r_motionblur_min = {CVAR_SAVE, "r_motionblur_min", "0.3", "motionblur velocity minimum - do not change unless you know what you're doing"};
  13. +cvar_t r_motionblur_max = {CVAR_SAVE, "r_motionblur_max", "0.6", "motionblur velocity maximum - do not change unless you know what you're doing"};
  14. +cvar_t r_motionblur_debug = {0, "r_motionblur_debug", "0", "testing motionblur - developer tool"};
  15. +
  16. cvar_t r_depthfirst = {CVAR_SAVE, "r_depthfirst", "0", "renders a depth-only version of the scene before normal rendering begins to eliminate overdraw, values: 0 = off, 1 = world depth, 2 = world and model depth"};
  17. cvar_t r_useinfinitefarclip = {CVAR_SAVE, "r_useinfinitefarclip", "1", "enables use of a special kind of projection matrix that has an extremely large farclip"};
  18. cvar_t r_nearclip = {0, "r_nearclip", "1", "distance from camera of nearclip plane" };
  19. @@ -142,7 +149,7 @@
  20. int bloomwidth, bloomheight;
  21.  
  22. int screentexturewidth, screentextureheight;
  23. - rtexture_t *texture_screen;
  24. + rtexture_t *texture_screen; // also used for motion blur if enabled!
  25.  
  26. int bloomtexturewidth, bloomtextureheight;
  27. rtexture_t *texture_bloom;
  28. @@ -2376,6 +2383,12 @@
  29. Cvar_RegisterVariable (&gl_fogend);
  30. Cvar_RegisterVariable (&gl_skyclip);
  31. }
  32. + Cvar_RegisterVariable(&r_motionblur);
  33. + Cvar_RegisterVariable(&r_motionblur_adj);
  34. + Cvar_RegisterVariable(&r_motionblur_min);
  35. + Cvar_RegisterVariable(&r_motionblur_max);
  36. + Cvar_RegisterVariable(&r_damageblur);
  37. + Cvar_RegisterVariable(&r_motionblur_debug);
  38. Cvar_RegisterVariable(&r_depthfirst);
  39. Cvar_RegisterVariable(&r_useinfinitefarclip);
  40. Cvar_RegisterVariable(&r_nearclip);
  41. @@ -3318,13 +3331,14 @@
  42. for (bloomtextureheight = 1;bloomtextureheight < r_bloomstate.bloomheight;bloomtextureheight *= 2);
  43. }
  44.  
  45. - if ((r_hdr.integer || r_bloom.integer) && ((r_bloom_resolution.integer < 4 || r_bloom_blur.value < 1 || r_bloom_blur.value >= 512) || r_refdef.view.width > gl_max_texture_size || r_refdef.view.height > gl_max_texture_size))
  46. + if ((r_hdr.integer || r_bloom.integer || r_motionblur.value) && ((r_bloom_resolution.integer < 4 || r_bloom_blur.value < 1 || r_bloom_blur.value >= 512) || r_refdef.view.width > gl_max_texture_size || r_refdef.view.height > gl_max_texture_size))
  47. {
  48. Cvar_SetValueQuick(&r_hdr, 0);
  49. Cvar_SetValueQuick(&r_bloom, 0);
  50. + Cvar_SetValueQuick(&r_motionblur, 0);
  51. }
  52.  
  53. - if (!(r_glsl.integer && (r_glsl_postprocess.integer || r_glsl_saturation.value != 1 || (v_glslgamma.integer && !vid_gammatables_trivial) || r_bloom.integer || r_hdr.integer)) && !r_bloom.integer)
  54. + if (!(r_glsl.integer && (r_glsl_postprocess.integer || (v_glslgamma.integer && !vid_gammatables_trivial))) && !r_bloom.integer && !r_hdr.integer && !r_motionblur.value)
  55. screentexturewidth = screentextureheight = 0;
  56. if (!r_hdr.integer && !r_bloom.integer)
  57. bloomtexturewidth = bloomtextureheight = 0;
  58. @@ -3580,12 +3594,55 @@
  59. {
  60. if (r_bloomstate.texture_screen)
  61. {
  62. - // copy view into the screen texture
  63. + r_motionblur.value = bound(0.0, r_motionblur.value, 1.0);
  64. + r_damageblur.value = bound(0.0, r_damageblur.value, 1.0);
  65. + r_motionblur_min.value = bound(0.0, r_motionblur_min.value, 1.0);
  66. + r_motionblur_max.value = bound(0.0, r_motionblur_max.value, 1.0);
  67. R_ResetViewRendering2D();
  68. R_Mesh_VertexPointer(r_screenvertex3f, 0, 0);
  69. R_Mesh_ColorPointer(NULL, 0, 0);
  70. R_Mesh_TexBind(0, R_GetTexture(r_bloomstate.texture_screen));
  71. GL_ActiveTexture(0);CHECKGLERROR
  72. + if(r_motionblur.value)
  73. + {
  74. + double rspeed = bound(r_motionblur_min.value,(sqrt(cl.movement_velocity[0] * cl.movement_velocity[0] + cl.movement_velocity[1] * cl.movement_velocity[1]) / 1000),r_motionblur_max.value);
  75. + float a;
  76. + float calc;
  77. + static double nexttime = 0, lasttime = 0;
  78. + static double framerate = 0;
  79. + static int framecount = 0;
  80. + double interval = 0.25;
  81. + double newtime;
  82. + newtime = realtime;
  83. + if (newtime >= nexttime)
  84. + {
  85. + framerate = framecount / (newtime - lasttime);
  86. + if (nexttime < newtime - interval * 1.5)
  87. + nexttime = newtime;
  88. + lasttime = newtime;
  89. + nexttime += interval;
  90. + framecount = 0;
  91. + }
  92. + framecount++;
  93. + calc = framerate;
  94. + a = exp( - (1 / (calc + 0.5)) / (((r_motionblur.value / 25) * rspeed) + (r_damageblur.value * (cl.cshifts[CSHIFT_DAMAGE].percent / 300)) - ((calc + 0.5) * r_motionblur_adj.value)));
  95. + //1.0f - cl.realframetime / (((r_motionblur.value / 15) * rspeed) + (r_damageblur.value * (cl.cshifts[CSHIFT_DAMAGE].percent / 300)));
  96. + if (r_motionblur_debug.value) { Con_Printf("rft - fpsm is %f\n", cl.realframetime - (1 / (calc + 0.5))); }
  97. + if (a > 0)
  98. + {
  99. + //a = (a * bound(0.5,(speedxy / 1000),1)) + (r_damageblur.value * (cl.cshifts[CSHIFT_DAMAGE].percent / 300));
  100. + R_SetupGenericShader(true);
  101. + GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  102. + GL_Color(1, 1, 1, a);
  103. + R_Mesh_TexBind(0, R_GetTexture(r_bloomstate.texture_screen));
  104. + R_Mesh_TexCoordPointer(0, 2, r_bloomstate.screentexcoord2f, 0, 0);
  105. + R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0);
  106. + r_refdef.stats.bloom_drawpixels += r_refdef.view.width * r_refdef.view.height;
  107. +
  108. + }
  109. + }
  110. +
  111. + // copy view into the screen texture
  112. qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r_refdef.view.x, vid.height - (r_refdef.view.y + r_refdef.view.height), r_refdef.view.width, r_refdef.view.height);CHECKGLERROR
  113. r_refdef.stats.bloom_copypixels += r_refdef.view.width * r_refdef.view.height;
  114. }
  115. @@ -3984,7 +4041,7 @@
  116.  
  117. R_RenderScene();
  118. r_waterstate.numwaterplanes = 0;
  119. -
  120. +
  121. R_BlendView();
  122. if (r_timereport_active)
  123. R_TimeReport("blendview");
Add Comment
Please, Sign In to add comment