Advertisement
Guest User

Factorio Perspective V2 zoom-to-world.glsl

a guest
May 9th, 2017
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.48 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. uniform vec4 ztw_params; // zoom-to-world parameters
  9.  
  10. uniform float darkness;
  11. uniform float timer;
  12. uniform bool render_darkness;
  13.  
  14. bool use_nightvision = nv_intensity > 0.0;
  15.  
  16. float hmix(float a, float b)
  17. {
  18.   // Not stolen at all
  19.   return fract(sin(a * 12.9898 + b) * 43758.5453);
  20. }
  21.  
  22. float hash3(float a, float b, float c)
  23. {
  24.   float ab = hmix(a, b);
  25.   float ac = hmix(a, c);
  26.   float bc = hmix(b, c);
  27.  
  28.   return hmix(ab, hmix(ac, bc));
  29. }
  30.  
  31. vec3 getnoise3(vec2 p)
  32. {
  33.   return vec3(hash3(p.x, p.y, floor(timer / 3.)));
  34. }
  35.  
  36. void main()
  37. {
  38.   vec2 uv = gl_TexCoord[0].xy;
  39.  
  40.   vec2 st = uv - vec2(0.5, 0.5);
  41. //  st.x /= (1.15 - 0.3 * st.y);
  42. //  st.y /= (1.15 - 0.3 * st.y);
  43.  
  44.   // Model a board at distance d, turned by angle a.
  45.   float angle = -0.5;
  46.   float distance = 2.5;
  47.   float f = 1 + sin(angle) / distance * st.y;
  48.   st.x = st.x / f * 0.92; // Magic number: The minimal width of the board in the projection plane gets smaller as we rotate it.
  49.   st.y = st.y * cos(angle) / f * 0.92;
  50.   uv = st + vec2(0.5, 0.5);
  51.  
  52.  
  53.   vec4 color = texture2D(gameview, uv);
  54.  
  55.   //gl_FragColor = color; return;
  56.  
  57.   //vec3 noise = getnoise3(uv);
  58.   //color.rgb += noise.rgb * ztw_params.x + ztw_params.y;
  59.  
  60.   //float stripe = 0;
  61.   //if (sin(timer * 0.02 + uv.y) > 0.99999)
  62.   //  stripe = 0.1;
  63.   //
  64.   //color.rgb += stripe.xxx;
  65.  
  66.   //float vigAmt = 2.; //+.3*sin(tm + 5.*cos(tm*5.));
  67.   //float vignette = (1.-vigAmt*(uv.y-.5)*(uv.y-.5))*(1.-vigAmt*(uv.x-.5)*(uv.x-.5));
  68.   //color.rgb *= vignette;
  69.   vec4 light = texture2D(lightmap, uv);
  70.  
  71.   if (use_nightvision)
  72.   {
  73.     float luminance = dot(color.rgb, vec3(0.299, 0.587, 0.114));
  74.     float lightLuminance = max(light.r, max(light.g, light.b));
  75.     vec3 grayscale = vec3(luminance * nv_intensity); // * nv_color.a * nv_color.rgb;
  76.     float lightIntensity = smoothstep(nv_desaturation_params.x, nv_desaturation_params.y, lightLuminance) * nv_desaturation_params.z + nv_desaturation_params.w;
  77.  
  78.     color.rgb = mix(grayscale, color.rgb, lightIntensity);
  79.     lightIntensity = smoothstep(nv_light_params.x, nv_light_params.y, lightLuminance) * nv_light_params.z + nv_light_params.w;
  80.     gl_FragColor = vec4(color.rgb * lightIntensity , color.a);
  81.   }
  82.   else
  83.   {
  84.     color.rgb = color.rgb * light.rgb;
  85.     gl_FragColor = vec4(color.rgb, color.a);
  86.   }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement