Guest User

Untitled

a guest
Dec 29th, 2016
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. struct PS_INPUT {
  2. float2 uv: TEXCOORD0;
  3. };
  4.  
  5. struct PS_OUTPUT {
  6. float4 color_0: SV_TARGET0;
  7. float4 color_1: SV_TARGET1;
  8. };
  9.  
  10. uniform sampler2D texture_material_1;
  11. uniform sampler2D texture_velocity;
  12. uniform sampler2D texture_world;
  13. uniform float2 texel_size;
  14. uniform float dissipation;
  15. uniform float time_step;
  16. uniform float maccormack_amount;
  17.  
  18. float2 unpack_velocity(float4 data) {return float2(data.x + (data.y / 255.0), data.z + (data.w / 255.0));}
  19. float unpack_alpha(float4 data) {return data.x + (data.y / 255.0) + (data.z / (255.0 * 255.0)) + (data.w / (255.0 * 255.0 * 255.0));}
  20. float4 pack_alpha(float data) {return float4(floor(data * 255.0) / 255.0, frac(data * 255.0), frac(data * 255.0 * 255.0), frac(data * 255.0 * 255.0 * 255.0));}
  21.  
  22. void main(in PS_INPUT IN, out PS_OUTPUT OUT) {
  23. float velocity_range = 10.0;
  24. if (tex2D(texture_world, IN.uv).w == 0.0) {
  25. float2 velocity = (unpack_velocity(tex2D(texture_velocity, IN.uv)) - 128.0 / 255.0) * velocity_range;
  26.  
  27. float2 was = IN.uv - time_step * texel_size * velocity;
  28. float phi_hat_next = tex2D(gm_BaseTexture, was).w + (tex2D(texture_material_1, was).w / 255.0);
  29. float2 phi_hat_next_velocity = (unpack_velocity(tex2D(texture_velocity, was)) - 128.0 / 255.0) * velocity_range;
  30.  
  31. float2 to = IN.uv + time_step * texel_size * phi_hat_next_velocity;
  32. float phi_hat_now = tex2D(gm_BaseTexture, to).w + (tex2D(texture_material_1, to).w / 255.0);
  33.  
  34. float phi_next = phi_hat_next + 0.5 * ((tex2D(gm_BaseTexture, IN.uv).w + (tex2D(texture_material_1, IN.uv).w / 255.0)) - phi_hat_now) * maccormack_amount;
  35. float color = phi_next;
  36.  
  37. // Clamps color.
  38. float2 coord = round(was / texel_size) * texel_size;
  39. float top_left = tex2D(gm_BaseTexture, coord - 0.5 * texel_size).w + (tex2D(texture_material_1, coord - 0.5 * texel_size).w / 255.0);
  40. float bottom_right = tex2D(gm_BaseTexture, coord + 0.5 * texel_size).w + (tex2D(texture_material_1, coord + 0.5 * texel_size).w / 255.0);
  41. float top_right = tex2D(gm_BaseTexture, coord + float2(0.5 * texel_size.x, -0.5 * texel_size.y)).w + (tex2D(texture_material_1, coord + float2(0.5 * texel_size.x, -0.5 * texel_size.y)).w / 255.0);
  42. float bottom_left = tex2D(gm_BaseTexture, coord + float2(-0.5 * texel_size.x, 0.5 * texel_size.y)).w + (tex2D(texture_material_1, coord + float2(-0.5 * texel_size.x, 0.5 * texel_size.y)).w / 255.0);
  43. color = clamp(color, min(min(min(top_left, top_right), bottom_left), bottom_right), max(max(max(top_left, top_right), bottom_left), bottom_right));
  44.  
  45. color = saturate(color - dissipation);
  46.  
  47. OUT.color_0 = float4(0.0, 0.0, 0.0, floor(color * 255.0) / 255.0);
  48. OUT.color_1 = float4(0.0, 0.0, 0.0, frac(color * 255.0));
  49. } else {
  50. OUT.color_0 = float4(0.0, 0.0, 0.0, 0.0);
  51. OUT.color_1 = float4(0.0, 0.0, 0.0, 0.0);
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment