Guest User

Untitled

a guest
May 15th, 2020
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.09 KB | None | 0 0
  1. diff -u -r a/Effects/hud.eff b/Effects/hud.eff
  2. --- a/Effects/hud.eff   2020-05-15 10:29:23.699964741 +0200
  3. +++ b/Effects/hud.eff   2020-05-15 10:31:49.192893138 +0200
  4. @@ -75,6 +75,22 @@
  5.     <sample-res>0.0006</sample-res>
  6.     <sample-far>2.5</sample-far>
  7.     <hud-brightness>1.0</hud-brightness>
  8. +   <!-- Parallax correction.
  9. +       If enabled, the HUD texture is displayed straight in front of the view point,
  10. +       and with a constant angular width. This simulates collimation.
  11. +       In that case, the HUD object UV mapping is completely ignored. -->
  12. +   <use-parallax type="bool">false</use-parallax>
  13. +   <!-- Angular width/height of the HUD texture (when using parallax). -->
  14. +   <hud-width-deg>25</hud-width-deg>
  15. +   <hud-height-deg>25</hud-height-deg>
  16. +   <!-- The optical axis is the direction from the viewpoint at which the texture
  17. +       is centered when using parallax correction.
  18. +       By default, it is the '-x' axis in the HUD object model space, which is forward
  19. +       if no rotation offsets are applied to the HUD object.
  20. +       Additional offsets to the optical axis can be given here. -->
  21. +   <optical-offset-yaw>0</optical-offset-yaw>
  22. +   <optical-offset-pitch>0</optical-offset-pitch>
  23. +   <optical-offset-roll>0</optical-offset-roll>
  24.  </parameters>
  25.  
  26.  <technique n="4">
  27. @@ -452,6 +468,36 @@
  28.          <type>int</type>
  29.          <value><use>material/color-mode-uniform</use></value>
  30.        </uniform>
  31. +      <uniform>
  32. +        <name>use_parallax</name>
  33. +        <type>bool</type>
  34. +        <value><use>use-parallax</use></value>
  35. +      </uniform>
  36. +      <uniform>
  37. +        <name>hud_width</name>
  38. +        <type>float</type>
  39. +        <value><use>hud-width-deg</use></value>
  40. +      </uniform>
  41. +      <uniform>
  42. +        <name>hud_height</name>
  43. +        <type>float</type>
  44. +        <value><use>hud-height-deg</use></value>
  45. +      </uniform>
  46. +      <uniform>
  47. +        <name>optical_yaw</name>
  48. +        <type>float</type>
  49. +        <value><use>optical-offset-yaw</use></value>
  50. +      </uniform>
  51. +      <uniform>
  52. +        <name>optical_pitch</name>
  53. +        <type>float</type>
  54. +        <value><use>optical-offset-pitch</use></value>
  55. +      </uniform>
  56. +      <uniform>
  57. +        <name>optical_roll</name>
  58. +        <type>float</type>
  59. +        <value><use>optical-offset-roll</use></value>
  60. +      </uniform>
  61.      </pass>
  62.    </technique>
  63.  
  64. diff -u -r a/Shaders/hud-ALS.frag b/Shaders/hud-ALS.frag
  65. --- a/Shaders/hud-ALS.frag  2020-05-15 10:29:31.814960102 +0200
  66. +++ b/Shaders/hud-ALS.frag  2020-05-15 10:30:04.372941491 +0200
  67. @@ -7,6 +7,7 @@
  68.  varying vec3 normal;
  69.  varying vec3 refl_vec;
  70.  varying vec3 light_diffuse;
  71. +varying vec3 optical_relpos;
  72.  varying float splash_angle;
  73.  varying float Mie;
  74.  varying float ambient_fraction;
  75. @@ -41,6 +42,11 @@
  76.  uniform float sample_far;
  77.  uniform float hud_brightness;
  78.  
  79. +uniform bool use_parallax;
  80. +
  81. +uniform float hud_width;
  82. +uniform float hud_height;
  83. +
  84.  uniform int use_reflection;
  85.  uniform int use_reflection_lightmap;
  86.  uniform int use_mask;
  87. @@ -69,23 +75,34 @@
  88.  vec4 frost_texel;
  89.  vec4 func_texel;
  90.  
  91. +vec2 TexCoord;
  92.  
  93. -texel = texture2D(texture, gl_TexCoord[0].st);
  94. -
  95. -texel+= texture2D(texture, vec2 (gl_TexCoord[0].s + sample_res, gl_TexCoord[0].t));
  96. -texel+= texture2D(texture, vec2 (gl_TexCoord[0].s - sample_res, gl_TexCoord[0].t));
  97. -texel+= texture2D(texture, vec2 (gl_TexCoord[0].s, gl_TexCoord[0].t + sample_res));
  98. -texel+= texture2D(texture, vec2 (gl_TexCoord[0].s, gl_TexCoord[0].t - sample_res));
  99. -
  100. -texel+= 0.75* texture2D(texture, vec2 (gl_TexCoord[0].s + sample_far * sample_res, gl_TexCoord[0].t+ sample_far * sample_res));
  101. -texel+= 0.75* texture2D(texture, vec2 (gl_TexCoord[0].s - sample_far * sample_res, gl_TexCoord[0].t+ sample_far * sample_res));
  102. -texel+= 0.75* texture2D(texture, vec2 (gl_TexCoord[0].s + sample_far * sample_res, gl_TexCoord[0].t- sample_far * sample_res));
  103. -texel+= 0.75* texture2D(texture, vec2 (gl_TexCoord[0].s - sample_far * sample_res, gl_TexCoord[0].t- sample_far * sample_res));
  104. -
  105. -texel+= 0.5 * texture2D(texture, vec2 (gl_TexCoord[0].s + 2.0 * sample_far * sample_res, gl_TexCoord[0].t - sample_res));
  106. -texel+= 0.5 * texture2D(texture, vec2 (gl_TexCoord[0].s - 2.0 * sample_far * sample_res, gl_TexCoord[0].t + sample_res));
  107. -texel+= 0.5 * texture2D(texture, vec2 (gl_TexCoord[0].s - sample_res, gl_TexCoord[0].t + 2.0 * sample_far * sample_res));
  108. -texel+= 0.5 * texture2D(texture, vec2 (gl_TexCoord[0].s + sample_res, gl_TexCoord[0].t - 2.0 * sample_far * sample_res));
  109. +if (use_parallax) {
  110. +   vec2 relAngle = vec2(
  111. +       atan(optical_relpos.y, -optical_relpos.x),
  112. +       atan(optical_relpos.z, -optical_relpos.x)
  113. +   );
  114. +   TexCoord = (relAngle / vec2(radians(hud_width), radians(hud_height))) + 0.5;
  115. +} else {
  116. +   TexCoord = gl_TexCoord[0].st;
  117. +}
  118. +
  119. +texel = texture2D(texture, TexCoord.st);
  120. +
  121. +texel+= texture2D(texture, vec2 (TexCoord.s + sample_res, TexCoord.t));
  122. +texel+= texture2D(texture, vec2 (TexCoord.s - sample_res, TexCoord.t));
  123. +texel+= texture2D(texture, vec2 (TexCoord.s, TexCoord.t + sample_res));
  124. +texel+= texture2D(texture, vec2 (TexCoord.s, TexCoord.t - sample_res));
  125. +
  126. +texel+= 0.75* texture2D(texture, vec2 (TexCoord.s + sample_far * sample_res, TexCoord.t+ sample_far * sample_res));
  127. +texel+= 0.75* texture2D(texture, vec2 (TexCoord.s - sample_far * sample_res, TexCoord.t+ sample_far * sample_res));
  128. +texel+= 0.75* texture2D(texture, vec2 (TexCoord.s + sample_far * sample_res, TexCoord.t- sample_far * sample_res));
  129. +texel+= 0.75* texture2D(texture, vec2 (TexCoord.s - sample_far * sample_res, TexCoord.t- sample_far * sample_res));
  130. +
  131. +texel+= 0.5 * texture2D(texture, vec2 (TexCoord.s + 2.0 * sample_far * sample_res, TexCoord.t - sample_res));
  132. +texel+= 0.5 * texture2D(texture, vec2 (TexCoord.s - 2.0 * sample_far * sample_res, TexCoord.t + sample_res));
  133. +texel+= 0.5 * texture2D(texture, vec2 (TexCoord.s - sample_res, TexCoord.t + 2.0 * sample_far * sample_res));
  134. +texel+= 0.5 * texture2D(texture, vec2 (TexCoord.s + sample_res, TexCoord.t - 2.0 * sample_far * sample_res));
  135.  
  136.  texel/=10.0;
  137.  
  138. diff -u -r a/Shaders/hud-ALS.vert b/Shaders/hud-ALS.vert
  139. --- a/Shaders/hud-ALS.vert  2020-05-15 10:29:31.815960102 +0200
  140. +++ b/Shaders/hud-ALS.vert  2020-05-15 10:30:10.168938178 +0200
  141. @@ -7,6 +7,7 @@
  142.  varying vec3 normal;
  143.  varying vec3 light_diffuse;
  144.  varying vec3 refl_vec;
  145. +varying vec3 optical_relpos;
  146.  varying float splash_angle;
  147.  varying float Mie;
  148.  varying float ambient_fraction;
  149. @@ -19,9 +20,31 @@
  150.  uniform float splash_y;
  151.  uniform float splash_z;
  152.  
  153. +uniform bool use_parallax;
  154. +uniform float optical_yaw;
  155. +uniform float optical_pitch;
  156. +uniform float optical_roll;
  157. +
  158.  const float EarthRadius = 5800000.0;
  159.  const float terminator_width = 200000.0;
  160.  
  161. +
  162. +void   rotationMatrixPR(in float sinRx, in float cosRx, in float sinRy, in float cosRy, out mat4 rotmat)
  163. +{
  164. +   rotmat = mat4(  cosRy , sinRx * sinRy , cosRx * sinRy,  0.0,
  165. +                                   0.0   , cosRx        ,  -sinRx * cosRx, 0.0,
  166. +                                   -sinRy, sinRx * cosRy,  cosRx * cosRy , 0.0,
  167. +                                   0.0   , 0.0          ,  0.0           , 1.0 );
  168. +}
  169. +
  170. +void   rotationMatrixH(in float sinRz, in float cosRz, out mat4 rotmat)
  171. +{
  172. +   rotmat = mat4(  cosRz,  -sinRz, 0.0,    0.0,
  173. +                                   sinRz,  cosRz,  0.0,    0.0,
  174. +                                   0.0  ,  0.0  ,  1.0,    0.0,
  175. +                                   0.0  ,  0.0  ,  0.0,    1.0 );
  176. +}
  177. +
  178.  float light_func (in float x, in float a, in float b, in float c, in float d, in float e)
  179.  {
  180.  //x = x - 0.5;
  181. @@ -124,6 +147,21 @@
  182.  
  183.  ambient_fraction = length(light_ambient.rgb)/(length(light_diffuse.rgb +light_ambient.rgb ) + 0.01);
  184.  
  185. +// Eye to vertex vector in the optical centerline coordinate system, for parallax correction.
  186. +if (use_parallax) {
  187. +   mat4 RotMatPR;
  188. +   mat4 RotMatH;
  189. +   float cosRx = cos(radians(-optical_roll));
  190. +   float sinRx = sin(radians(-optical_roll));
  191. +   float cosRy = cos(radians(optical_pitch));
  192. +   float sinRy = sin(radians(optical_pitch));
  193. +   float cosRz = cos(radians(-optical_yaw));
  194. +   float sinRz = sin(radians(-optical_yaw));
  195. +   rotationMatrixPR(sinRx, cosRx, sinRy, cosRy, RotMatPR);
  196. +   rotationMatrixH(sinRz, cosRz, RotMatH);
  197. +   optical_relpos = (RotMatH * (RotMatPR * (gl_Vertex - ep))).xyz;
  198. +}
  199. +
  200.  
  201.  gl_Position = ftransform();
  202.  gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
Add Comment
Please, Sign In to add comment