Advertisement
Guest User

Untitled

a guest
May 21st, 2025
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "depth_utils.glslh"
  2.  
  3. in float log_z;
  4. in vec3 vertex_color_out;
  5. in vec3 vertex_normal_out;
  6. in vec3 vertex_world_position_out;
  7. in vec3 vertex_object_position_out; // Added: object-space position
  8. in vec4 vertex_position_prev_out;
  9. in vec4 vertex_position_next_out;
  10.  
  11. out vec4 gnormal_light_factor_out;
  12. out vec4 gcolor_out;
  13. #if VELOCITY_ENABLED == 1
  14. out vec2 gvelocity_out;
  15. #endif
  16.  
  17. uniform float light_factor;
  18. uniform int is_motion_blur_affected;
  19.  
  20. #if CLIP_PLANE == 1
  21. uniform vec4 clip_plane;
  22. #endif
  23.  
  24. #if DITHER == 1
  25. uniform float dither_opacity;
  26. mat4 thresholdMatrix = mat4
  27. (
  28. 1.0 / 17.0,  9.0 / 17.0,  3.0 / 17.0, 11.0 / 17.0,
  29. 13.0 / 17.0,  5.0 / 17.0, 15.0 / 17.0,  7.0 / 17.0,
  30. 4.0 / 17.0, 12.0 / 17.0,  2.0 / 17.0, 10.0 / 17.0,
  31. 16.0 / 17.0,  8.0 / 17.0, 14.0 / 17.0,  6.0 / 17.0
  32. );
  33. #endif
  34.  
  35. // Grain function using object-local position
  36. float getGrain(vec3 object_pos) {
  37.     vec3 scaled_pos = object_pos * 16.0; // <- Increase for finer grain
  38.     vec3 tile = floor(scaled_pos);
  39.  
  40.     float val = dot(tile, vec3(12.9898, 78.233, 45.164));
  41.     return fract(sin(val) * 43758.5453);
  42. }
  43.  
  44. void main()
  45. {
  46.     gl_FragDepth = log_z_to_frag_depth(log_z);
  47.  
  48. #if CLIP_PLANE == 1
  49.     if(dot(vertex_world_position_out, clip_plane.xyz) < clip_plane.w)
  50.     {
  51.         discard;
  52.     }
  53. #endif
  54.  
  55. #if DITHER == 1
  56.     int pix_x = int(gl_FragCoord.x);
  57.     int pix_y = int(gl_FragCoord.y);
  58.     float dither_threshold = thresholdMatrix[pix_x % 4][pix_y % 4];
  59.     if(dither_threshold > dither_opacity)
  60.     {
  61.         discard;
  62.     }
  63. #endif
  64.  
  65. #if VELOCITY_ENABLED == 1
  66.     // Velocity
  67.     vec2 screen_pos_next = (vertex_position_next_out.xy / vertex_position_next_out.w) * 0.5 + 0.5;
  68.     vec2 screen_pos_prev = (vertex_position_prev_out.xy / vertex_position_prev_out.w) * 0.5 + 0.5;
  69.     gvelocity_out = (screen_pos_next - screen_pos_prev);
  70. #endif
  71.  
  72.     gnormal_light_factor_out = vec4(normalize(vertex_normal_out), light_factor);
  73.  
  74.     // Subtle grain shading
  75.     float grain = getGrain(vertex_object_position_out);
  76.     float brightness = mix(0.95, 1.0, grain); // <- change range (0.95-1.0) for custom brightness
  77.     vec3 final_color = vertex_color_out * brightness;
  78.  
  79.     // Convert from sRGB to linear
  80.     gcolor_out = vec4(pow(final_color, vec3(2.2)), 1.0);
  81. }
Tags: Stormworks
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement