Advertisement
Guest User

Factorio Perspective game.glsl

a guest
May 9th, 2017
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 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.   st.x /= (1.15 - 0.3 * st.y);
  21.   st.y /= (1.15 - 0.3 * st.y);
  22.   uv = st + vec2(0.5, 0.5);
  23.  
  24.   vec4 color = texture2D(gameview, uv);
  25.   if (!render_darkness)
  26.   {
  27.     gl_FragColor = color;
  28.     return;
  29.   }
  30.  
  31.   vec4 light = texture2D(lightmap, uv);
  32.  
  33.   if (use_nightvision)
  34.   {
  35.     float luminance = dot(color.rgb, vec3(0.299, 0.587, 0.114));
  36.     float lightLuminance = max(light.r, max(light.g, light.b));
  37.     vec3 grayscale = vec3(luminance * nv_intensity); // * nv_color.a * nv_color.rgb;
  38.     float lightIntensity = smoothstep(nv_desaturation_params.x, nv_desaturation_params.y, lightLuminance) * nv_desaturation_params.z + nv_desaturation_params.w;
  39.    
  40.     color.rgb = mix(grayscale, color.rgb, lightIntensity);
  41.     lightIntensity = smoothstep(nv_light_params.x, nv_light_params.y, lightLuminance) * nv_light_params.z + nv_light_params.w;
  42.     gl_FragColor = vec4(color.rgb * lightIntensity , color.a);  
  43.   }
  44.   else
  45.   {
  46.     color.rgb = color.rgb * light.rgb;
  47.     gl_FragColor = vec4(color.rgb, color.a);  
  48.   }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement