Advertisement
Guest User

Factorio Perspective V2 game.glsl

a guest
May 9th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | None | 0 0
  1. uniform sampler2D gameview; // "diffuse" texture
  2. uniform sampler2D lightmap;
  3.  
  4. uniform vec4 nv_color;
  5. uniform float nv_intensity;
  6. uniform vec4 nv_desaturation_params;
  7. uniform vec4 nv_light_params;
  8.  
  9. uniform float darkness;
  10. uniform float timer;
  11. uniform bool render_darkness;
  12.  
  13. bool use_nightvision = nv_intensity > 0.0;
  14.  
  15. void main()
  16. {
  17.   vec2 uv = gl_TexCoord[0].xy;
  18.  
  19.   vec2 st = uv - vec2(0.5, 0.5);
  20.  
  21.   float angle = -0.5;
  22.   float distance = 2.5;
  23.   float f = 1 + sin(angle) / distance * st.y;
  24.   st.x = st.x / f * 0.92;
  25.   st.y = st.y * cos(angle) / f * 0.92;
  26.  
  27.   //st.x /= (1.15 - 0.3 * st.y);
  28.   //st.y /= (1.15 - 0.3 * st.y);
  29.   uv = st + vec2(0.5, 0.5);
  30.  
  31.   vec4 color = texture2D(gameview, uv);
  32.   if (!render_darkness)
  33.   {
  34.     gl_FragColor = color;
  35.     return;
  36.   }
  37.  
  38.   vec4 light = texture2D(lightmap, uv);
  39.  
  40.   if (use_nightvision)
  41.   {
  42.     float luminance = dot(color.rgb, vec3(0.299, 0.587, 0.114));
  43.     float lightLuminance = max(light.r, max(light.g, light.b));
  44.     vec3 grayscale = vec3(luminance * nv_intensity); // * nv_color.a * nv_color.rgb;
  45.     float lightIntensity = smoothstep(nv_desaturation_params.x, nv_desaturation_params.y, lightLuminance) * nv_desaturation_params.z + nv_desaturation_params.w;
  46.    
  47.     color.rgb = mix(grayscale, color.rgb, lightIntensity);
  48.     lightIntensity = smoothstep(nv_light_params.x, nv_light_params.y, lightLuminance) * nv_light_params.z + nv_light_params.w;
  49.     gl_FragColor = vec4(color.rgb * lightIntensity , color.a);  
  50.   }
  51.   else
  52.   {
  53.     color.rgb = color.rgb * light.rgb;
  54.     gl_FragColor = vec4(color.rgb, color.a);  
  55.   }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement