distortion.sha 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //Cg
  2. //
  3. // time
  4. //
  5. // You need to pass the frame time here.
  6. //
  7. // desat.x
  8. //
  9. // Desaturation level. If zero, the bloom's color is equal to
  10. // the color of the input pixel. If one, the bloom's color is
  11. // white.
  12. //
  13. // trigger.x
  14. //
  15. // Must be equal to mintrigger.
  16. //
  17. // mintrigger is the minimum brightness to trigger a bloom,
  18. // and maxtrigger is the brightness at which the bloom
  19. // reaches maximum intensity.
  20. //
  21. // trigger.y
  22. //
  23. // Must be equal to (1.0/(maxtrigger-mintrigger)) where
  24. //
  25. // mintrigger is the minimum brightness to trigger a bloom,
  26. // and maxtrigger is the brightness at which the bloom
  27. // reaches maximum intensity.
  28. //
  29. void vshader(float4 vtx_position : POSITION,
  30. uniform float4x4 mat_modelproj,
  31. uniform float4x4 trans_model_to_clip,
  32. out float4 l_position : POSITION,
  33. out float4 l_texcoord0 : TEXCOORD0)
  34. {
  35. l_position = mul(mat_modelproj, vtx_position);
  36. l_texcoord0 = mul(trans_model_to_clip, vtx_position);
  37. l_texcoord0.z = l_texcoord0.w;
  38. }
  39. void fshader(float4 l_texcoord0 : TEXCOORD0,
  40. uniform sampler2D k_screen : TEXUNIT1,
  41. uniform sampler2D k_waves : TEXUNIT0,
  42. uniform float4 texpad_screen,
  43. in uniform float sys_time,
  44. out float4 o_color : COLOR)
  45. {
  46. float3 screen = l_texcoord0.xyz / l_texcoord0.w;
  47. float2 texcoords = float2(screen.xy) * texpad_screen.xy + texpad_screen.xy;
  48. float4 disturbance = tex2D(k_waves, texcoords);
  49. //o_color = tex2D(k_screen, texcoords + disturbance.xy * 0.05 * disturbance.z * sys_time.x * 1);
  50. o_color = tex2D(k_screen, texcoords + disturbance.xy * 0.05 * disturbance.z * sin(sys_time.x) * 1);
  51. }