Advertisement
Nick_Nishort

GMS2 CRT Shader

Feb 15th, 2024
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Game Maker 1.74 KB | Source Code | 0 0
  1. // Vertex shader is default
  2. // Fragment shader
  3. varying vec2 v_vTexcoord;
  4. varying vec4 v_vColour;
  5.  
  6. uniform vec2 u_resolution;
  7. uniform float u_opacity;
  8.  
  9. vec2 curveRemapUV(vec2 orig_uv)
  10. {
  11.     // as we near the edge of our screen apply greater distortion using a cubic function
  12.     vec2 uv = vec2(orig_uv.x * 2.0 - 1.0, orig_uv.y * 2.0 - 1.0);
  13.     vec2 offset;
  14.     offset.x = abs(uv.y) / 3.0;
  15.     offset.y = abs(uv.x) / 3.0;
  16.     uv = uv + uv * offset * offset;
  17.     uv = uv * 0.5 + 0.5;
  18.     return uv;
  19. }
  20.  
  21. vec4 vignetteIntensity(vec2 uv, vec2 resolution, float opacity)
  22. {
  23.     float intensity = uv.x * uv.y * (1.0 - uv.x) * (1.0 - uv.y);
  24.     return vec4(vec3(clamp(pow((resolution.x / 4.0) * intensity, opacity), 0.0, 1.0)), 1.0);
  25. }
  26.  
  27. vec4 scanLineIntensity(float uv, float resolution, float opacity)
  28. {
  29.     float intensity = sin(uv * resolution * 3.1415926 * 2.0);
  30.     intensity = ((0.5 * intensity) + 0.5) * 0.9 + 0.1;
  31.     return vec4(vec3(pow(intensity, opacity)), 1.0);
  32. }
  33.  
  34. void main()
  35. {
  36.     vec2 remappedUV = curveRemapUV(vec2(v_vTexcoord.x, v_vTexcoord.y));
  37.    
  38.     if (remappedUV.x < 0.0 || remappedUV.y < 0.0 || remappedUV.x > 1.0 || remappedUV.y > 1.0){
  39.         gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
  40.     } else {
  41.         vec4 base_col = texture2D( gm_BaseTexture, remappedUV );
  42.        
  43.         base_col *= vignetteIntensity(remappedUV, u_resolution, 1.0);
  44.        
  45.         base_col *= scanLineIntensity(v_vTexcoord.x, u_resolution.y * 0.75, u_opacity); // 2.0, 0.5
  46.         base_col *= scanLineIntensity(v_vTexcoord.y, u_resolution.x * 0.75, u_opacity);
  47.         gl_FragColor = v_vColour * base_col;
  48.     }
  49.    
  50.     //base_col *= scanLineIntensity(v_vTexcoord.x, RES_H, OPACITY);
  51.     //base_col *= scanLineIntensity(v_vTexcoord.y, RES_W, OPACITY);
  52.     //gl_FragColor = v_vColour * base_col;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement