Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct PS_INPUT {
- float2 uv: TEXCOORD0;
- };
- struct PS_OUTPUT {
- float4 color_0: SV_TARGET0;
- float4 color_1: SV_TARGET1;
- };
- uniform sampler2D texture_material_1;
- uniform sampler2D texture_velocity;
- uniform sampler2D texture_world;
- uniform float2 texel_size;
- uniform float dissipation;
- uniform float time_step;
- uniform float maccormack_amount;
- float2 unpack_velocity(float4 data) {return float2(data.x + (data.y / 255.0), data.z + (data.w / 255.0));}
- 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));}
- 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));}
- void main(in PS_INPUT IN, out PS_OUTPUT OUT) {
- float velocity_range = 10.0;
- if (tex2D(texture_world, IN.uv).w == 0.0) {
- float2 velocity = (unpack_velocity(tex2D(texture_velocity, IN.uv)) - 128.0 / 255.0) * velocity_range;
- float2 was = IN.uv - time_step * texel_size * velocity;
- float phi_hat_next = tex2D(gm_BaseTexture, was).w + (tex2D(texture_material_1, was).w / 255.0);
- float2 phi_hat_next_velocity = (unpack_velocity(tex2D(texture_velocity, was)) - 128.0 / 255.0) * velocity_range;
- float2 to = IN.uv + time_step * texel_size * phi_hat_next_velocity;
- float phi_hat_now = tex2D(gm_BaseTexture, to).w + (tex2D(texture_material_1, to).w / 255.0);
- 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;
- float color = phi_next;
- // Clamps color.
- float2 coord = round(was / texel_size) * texel_size;
- float top_left = tex2D(gm_BaseTexture, coord - 0.5 * texel_size).w + (tex2D(texture_material_1, coord - 0.5 * texel_size).w / 255.0);
- float bottom_right = tex2D(gm_BaseTexture, coord + 0.5 * texel_size).w + (tex2D(texture_material_1, coord + 0.5 * texel_size).w / 255.0);
- 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);
- 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);
- 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));
- color = saturate(color - dissipation);
- OUT.color_0 = float4(0.0, 0.0, 0.0, floor(color * 255.0) / 255.0);
- OUT.color_1 = float4(0.0, 0.0, 0.0, frac(color * 255.0));
- } else {
- OUT.color_0 = float4(0.0, 0.0, 0.0, 0.0);
- OUT.color_1 = float4(0.0, 0.0, 0.0, 0.0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment