Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var temporary;
- draw_enable_alphablend(false);
- // Advect velocity.
- surface_set_target(sf_temporary_0);
- if (maccormack_amount_velocity > 0) {
- shader_set(sh_advect_velocity_maccormack);
- texture_set_stage(shader_get_sampler_index(sh_advect_velocity_maccormack, "texture_world"), surface_get_texture(sf_world));
- texture_set_stage(shader_get_sampler_index(sh_advect_velocity_maccormack, "texture_material"), surface_get_texture(sf_material_0));
- shader_set_uniform_f(shader_get_uniform(sh_advect_velocity_maccormack, "texel_size"), sf_texel_width, sf_texel_height);
- shader_set_uniform_f(shader_get_uniform(sh_advect_velocity_maccormack, "dissipation"), velocity_dissipation);
- shader_set_uniform_f(shader_get_uniform(sh_advect_velocity_maccormack, "acceleration"), 0, acceleration_y);
- shader_set_uniform_f(shader_get_uniform(sh_advect_velocity_maccormack, "time_step"), time_step);
- shader_set_uniform_f(shader_get_uniform(sh_advect_velocity_maccormack, "maccormack_amount"), maccormack_amount_velocity);
- shader_set_uniform_f(shader_get_uniform(sh_advect_velocity_maccormack, "mode"), mode);
- draw_surface(sf_velocity, 0, 0);
- shader_reset();
- } else {
- shader_set(sh_advect_velocity);
- texture_set_stage(shader_get_sampler_index(sh_advect_velocity, "texture_world"), surface_get_texture(sf_world));
- texture_set_stage(shader_get_sampler_index(sh_advect_velocity, "texture_material"), surface_get_texture(sf_material_0));
- shader_set_uniform_f(shader_get_uniform(sh_advect_velocity, "texel_size"), sf_texel_width, sf_texel_height);
- shader_set_uniform_f(shader_get_uniform(sh_advect_velocity, "dissipation"), velocity_dissipation);
- shader_set_uniform_f(shader_get_uniform(sh_advect_velocity, "acceleration"), 0, acceleration_y);
- shader_set_uniform_f(shader_get_uniform(sh_advect_velocity, "time_step"), time_step);
- draw_surface(sf_velocity, 0, 0);
- shader_reset();
- }
- surface_reset_target();
- temporary = sf_velocity; sf_velocity = sf_temporary_0; sf_temporary_0 = temporary;
- // Calculates divergence of velocity.
- surface_set_target(sf_temporary_0);
- shader_set(sh_calculate_divergence);
- shader_set_uniform_f(shader_get_uniform(sh_calculate_divergence, "texel_size"), sf_texel_width, sf_texel_height);
- draw_surface(sf_velocity, 0, 0);
- shader_reset();
- surface_reset_target();
- temporary = sf_divergence; sf_divergence = sf_temporary_0; sf_temporary_0 = temporary;
- // Clears pressure.
- surface_set_target(sf_pressure);
- draw_clear_alpha($0000C0, 0);
- surface_reset_target();
- // Calculates pressure with jacobi iteration.
- shader_set(sh_calculate_pressure);
- texture_set_stage(shader_get_sampler_index(sh_calculate_pressure, "texture_divergence"), surface_get_texture(sf_divergence));
- shader_set_uniform_f(shader_get_uniform(sh_calculate_pressure, "texel_size"), sf_texel_width, sf_texel_height);
- repeat (pressure_jacobi_iterations) {
- surface_set_target(sf_temporary_0);
- draw_surface(sf_pressure, 0, 0);
- surface_reset_target();
- temporary = sf_pressure; sf_pressure = sf_temporary_0; sf_temporary_0 = temporary;
- }
- shader_reset();
- // Calculates the gradient of pressure and subtracts it from the velocity.
- surface_set_target(sf_temporary_0);
- shader_set(sh_subtract_pressure_gradient);
- texture_set_stage(shader_get_sampler_index(sh_subtract_pressure_gradient, "texture_pressure"), surface_get_texture(sf_pressure));
- shader_set_uniform_f(shader_get_uniform(sh_subtract_pressure_gradient, "texel_size"), sf_texel_width, sf_texel_height);
- draw_surface(sf_velocity, 0, 0);
- shader_reset();
- surface_reset_target();
- temporary = sf_velocity; sf_velocity = sf_temporary_0; sf_temporary_0 = temporary;
- // Advects material.
- if (mode == 2) {
- surface_set_target_ext(0, sf_temporary_0);
- surface_set_target_ext(1, sf_temporary_1);
- shader_set(sh_advect_material_smoke);
- texture_set_stage(shader_get_sampler_index(sh_advect_material_smoke, "texture_material_1"), surface_get_texture(sf_material_1));
- texture_set_stage(shader_get_sampler_index(sh_advect_material_smoke, "texture_velocity"), surface_get_texture(sf_velocity));
- texture_set_stage(shader_get_sampler_index(sh_advect_material_smoke, "texture_world"), surface_get_texture(sf_world));
- shader_set_uniform_f(shader_get_uniform(sh_advect_material_smoke, "texel_size"), sf_texel_width, sf_texel_height);
- shader_set_uniform_f(shader_get_uniform(sh_advect_material_smoke, "dissipation"), material_dissipation);
- shader_set_uniform_f(shader_get_uniform(sh_advect_material_smoke, "time_step"), time_step);
- shader_set_uniform_f(shader_get_uniform(sh_advect_material_smoke, "maccormack_amount"), maccormack_amount_material);
- draw_surface(sf_material_0, 0, 0);
- shader_reset();
- surface_reset_target();
- temporary = sf_material_0; sf_material_0 = sf_temporary_0; sf_temporary_0 = temporary;
- temporary = sf_material_1; sf_material_1 = sf_temporary_1; sf_temporary_1 = temporary;
- } else {
- surface_set_target_ext(0, sf_temporary_0);
- surface_set_target_ext(1, sf_temporary_1);
- if (maccormack_amount_material > 0) {
- shader_set(sh_advect_material_maccormack);
- texture_set_stage(shader_get_sampler_index(sh_advect_material_maccormack, "texture_material_1"), surface_get_texture(sf_material_1));
- texture_set_stage(shader_get_sampler_index(sh_advect_material_maccormack, "texture_velocity"), surface_get_texture(sf_velocity));
- texture_set_stage(shader_get_sampler_index(sh_advect_material_maccormack, "texture_world"), surface_get_texture(sf_world));
- shader_set_uniform_f(shader_get_uniform(sh_advect_material_maccormack, "texel_size"), sf_texel_width, sf_texel_height);
- shader_set_uniform_f(shader_get_uniform(sh_advect_material_maccormack, "dissipation"), material_dissipation);
- shader_set_uniform_f(shader_get_uniform(sh_advect_material_maccormack, "time_step"), time_step);
- shader_set_uniform_f(shader_get_uniform(sh_advect_material_maccormack, "maccormack_amount"), maccormack_amount_material);
- draw_surface(sf_material_0, 0, 0);
- shader_reset();
- } else {
- shader_set(sh_advect_material);
- texture_set_stage(shader_get_sampler_index(sh_advect_material, "texture_material_1"), surface_get_texture(sf_material_1));
- texture_set_stage(shader_get_sampler_index(sh_advect_material, "texture_velocity"), surface_get_texture(sf_velocity));
- texture_set_stage(shader_get_sampler_index(sh_advect_material, "texture_world"), surface_get_texture(sf_world));
- shader_set_uniform_f(shader_get_uniform(sh_advect_material, "texel_size"), sf_texel_width, sf_texel_height);
- shader_set_uniform_f(shader_get_uniform(sh_advect_material, "dissipation"), material_dissipation);
- shader_set_uniform_f(shader_get_uniform(sh_advect_material, "time_step"), time_step);
- draw_surface(sf_material_0, 0, 0);
- shader_reset();
- }
- surface_reset_target();
- temporary = sf_material_0; sf_material_0 = sf_temporary_0; sf_temporary_0 = temporary;
- temporary = sf_material_1; sf_material_1 = sf_temporary_1; sf_temporary_1 = temporary;
- }
- draw_enable_alphablend(true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement