smoke refactor

This commit is contained in:
Tanasart 2024-11-22 10:04:05 +07:00
parent d7d41501f6
commit ee78b0bd31
7 changed files with 41 additions and 59 deletions

View file

@ -198,41 +198,23 @@ function smokeSim_Domain(_width, _height) constructor {
shader_reset();
surface_reset_target();
if (pressure_type >= 0) {
shader_set(sh_fd_calculate_pressure_jacobi_glsl);
shader_set_f("texel_size", tx_width, tx_height);
shader_set_f("max_force", max_force);
repeat (pressure_type) {
surface_set_target(sf_pressure_t);
draw_surface_safe(sf_pressure);
surface_reset_target();
temporary = sf_pressure;
sf_pressure = sf_pressure_t;
sf_pressure_t = temporary;
}
shader_reset();
shader_set(sh_fd_calculate_pressure_srj_glsl);
shader_set_f("texel_size", tx_width, tx_height);
shader_set_f("max_force", max_force);
} else {
shader_set(sh_fd_calculate_pressure_srj_glsl);
shader_set_f("texel_size", tx_width, tx_height);
shader_set_f("max_force", max_force);
var length = array_length(pressure_relax);
for (var i = 0; i < length; ++i) {
if (pressure_relax[i] != -1) shader_set_f("precalculated", 1 - pressure_relax[i], 0.25 * pressure_relax[i]);
surface_set_target(sf_pressure_t);
draw_surface_safe(sf_pressure);
surface_reset_target();
var length = array_length(pressure_relax);
for (var i = 0; i < length; ++i) {
if (pressure_relax[i] != -1) shader_set_f("precalculated", 1 - pressure_relax[i], 0.25 * pressure_relax[i]);
surface_set_target(sf_pressure_t);
draw_surface_safe(sf_pressure);
surface_reset_target();
temporary = sf_pressure;
sf_pressure = sf_pressure_t;
sf_pressure_t = temporary;
}
shader_reset();
}
temporary = sf_pressure;
sf_pressure = sf_pressure_t;
sf_pressure_t = temporary;
}
shader_reset();
// Calculates the gradient of pressure and subtracts it from the velocity.
surface_set_target(sf_velocity_t);
shader_set(sh_fd_subtract_pressure_gradient_glsl);

View file

@ -1722,7 +1722,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
value_from = _valueFrom;
array_push(_valueFrom.value_to, self);
if(_valueFrom.node.inline_context != noone) {
if(!LOADING && !APPENDING && _valueFrom.node.inline_context != noone) {
var _inline = _valueFrom.node.inline_context;
if(node.manual_ungroupable) _inline.addNode(node);
}

View file

@ -34,10 +34,10 @@ void main() {
color = phi_hat_next + (texture2D(gm_BaseTexture, v_vTexcoord).w - phi_hat_now) * precalculated_2.z;
vec2 coord = floor(from / texel_size + 0.5) * texel_size;
float top_left = clampForce(texture2D(gm_BaseTexture, coord + precalculated_1.zw).w);
float bottom_right = clampForce(texture2D(gm_BaseTexture, coord + precalculated_1.xy).w);
float top_right = clampForce(texture2D(gm_BaseTexture, coord + precalculated_1.xw).w);
float bottom_left = clampForce(texture2D(gm_BaseTexture, coord + precalculated_1.zy).w);
float top_left = clamp(texture2D(gm_BaseTexture, coord + precalculated_1.zw).w, 0., 1.);
float bottom_right = clamp(texture2D(gm_BaseTexture, coord + precalculated_1.xy).w, 0., 1.);
float top_right = clamp(texture2D(gm_BaseTexture, coord + precalculated_1.xw).w, 0., 1.);
float bottom_left = clamp(texture2D(gm_BaseTexture, coord + precalculated_1.zy).w, 0., 1.);
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));
}

View file

@ -11,10 +11,10 @@ void main() {
gl_FragColor.zw = texture2D(gm_BaseTexture, v_vTexcoord).zw;
float divergence = gl_FragColor.y;
float right = clampForce(texture2D(gm_BaseTexture, v_vTexcoord + vec2(texel_size.x, 0.0)).x);
float left = clampForce(texture2D(gm_BaseTexture, v_vTexcoord - vec2(texel_size.x, 0.0)).x);
float bottom = clampForce(texture2D(gm_BaseTexture, v_vTexcoord + vec2(0.0, texel_size.y)).x);
float top = clampForce(texture2D(gm_BaseTexture, v_vTexcoord - vec2(0.0, texel_size.y)).x);
float right = texture2D(gm_BaseTexture, v_vTexcoord + vec2(texel_size.x, 0.0)).x;
float left = texture2D(gm_BaseTexture, v_vTexcoord - vec2(texel_size.x, 0.0)).x;
float bottom = texture2D(gm_BaseTexture, v_vTexcoord + vec2(0.0, texel_size.y)).x;
float top = texture2D(gm_BaseTexture, v_vTexcoord - vec2(0.0, texel_size.y)).x;
gl_FragColor.x = (left + right + top + bottom - divergence) * 0.25;
gl_FragColor.x = clamp((left + right + top + bottom - divergence) * 0.25, 0., 1.);
}

View file

@ -10,15 +10,15 @@ vec2 clampForce(vec2 v) { return vec2(clampForce(v.x), clampForce(v.y)); }
void main() {
gl_FragColor = texture2D(gm_BaseTexture, v_vTexcoord);
float pressure = clampForce(gl_FragColor.x);
float divergence = clampForce(gl_FragColor.y);
float pressure = gl_FragColor.x;
float divergence = gl_FragColor.y;
float right = clampForce(texture2D(gm_BaseTexture, v_vTexcoord + vec2(texel_size.x, 0.0)).x);
float left = clampForce(texture2D(gm_BaseTexture, v_vTexcoord - vec2(texel_size.x, 0.0)).x);
float bottom = clampForce(texture2D(gm_BaseTexture, v_vTexcoord + vec2(0.0, texel_size.y)).x);
float top = clampForce(texture2D(gm_BaseTexture, v_vTexcoord - vec2(0.0, texel_size.y)).x);
float right = texture2D(gm_BaseTexture, v_vTexcoord + vec2(texel_size.x, 0.0)).x;
float left = texture2D(gm_BaseTexture, v_vTexcoord - vec2(texel_size.x, 0.0)).x;
float bottom = texture2D(gm_BaseTexture, v_vTexcoord + vec2(0.0, texel_size.y)).x;
float top = texture2D(gm_BaseTexture, v_vTexcoord - vec2(0.0, texel_size.y)).x;
pressure = precalculated.x * pressure + (left + right + top + bottom - divergence) * precalculated.y;
gl_FragColor.x = clampForce(pressure);
gl_FragColor.x = pressure;
}

View file

@ -9,10 +9,10 @@ float clampForce(float v) { return clamp(v, -max_force, max_force); }
vec2 clampForce(vec2 v) { return vec2(clampForce(v.x), clampForce(v.y)); }
void main() {
vec2 right = clampForce(texture2D(gm_BaseTexture, v_vTexcoord + vec2(texel_size.x, 0.0)).xy);
vec2 left = clampForce(texture2D(gm_BaseTexture, v_vTexcoord - vec2(texel_size.x, 0.0)).xy);
vec2 bottom = clampForce(texture2D(gm_BaseTexture, v_vTexcoord + vec2(0.0, texel_size.y)).xy);
vec2 top = clampForce(texture2D(gm_BaseTexture, v_vTexcoord - vec2(0.0, texel_size.y)).xy);
vec2 right = clampForce(texture2D(gm_BaseTexture, v_vTexcoord + vec2(texel_size.x, 0.0)).xy) / max_force;
vec2 left = clampForce(texture2D(gm_BaseTexture, v_vTexcoord - vec2(texel_size.x, 0.0)).xy) / max_force;
vec2 bottom = clampForce(texture2D(gm_BaseTexture, v_vTexcoord + vec2(0.0, texel_size.y)).xy) / max_force;
vec2 top = clampForce(texture2D(gm_BaseTexture, v_vTexcoord - vec2(0.0, texel_size.y)).xy) / max_force;
gl_FragColor = vec4(initial_value_pressure, (right.x - left.x) + (bottom.y - top.y), 0., 0.);
}

View file

@ -9,15 +9,15 @@ float clampForce(float v) { return clamp(v, -max_force, max_force); }
vec2 clampForce(vec2 v) { return vec2(clampForce(v.x), clampForce(v.y)); }
void main() {
float right = clampForce(texture2D(texture_pressure, v_vTexcoord + vec2(texel_size.x, 0.0)).x);
float left = clampForce(texture2D(texture_pressure, v_vTexcoord - vec2(texel_size.x, 0.0)).x);
float bottom = clampForce(texture2D(texture_pressure, v_vTexcoord + vec2(0.0, texel_size.y)).x);
float top = clampForce(texture2D(texture_pressure, v_vTexcoord - vec2(0.0, texel_size.y)).x);
float right = texture2D(texture_pressure, v_vTexcoord + vec2(texel_size.x, 0.0)).x;
float left = texture2D(texture_pressure, v_vTexcoord - vec2(texel_size.x, 0.0)).x;
float bottom = texture2D(texture_pressure, v_vTexcoord + vec2(0.0, texel_size.y)).x;
float top = texture2D(texture_pressure, v_vTexcoord - vec2(0.0, texel_size.y)).x;
vec2 gradient = 0.5 * vec2(right - left, bottom - top);
vec2 velocity = clampForce(texture2D(gm_BaseTexture, v_vTexcoord).xy);
velocity -= gradient;
gl_FragColor = vec4(clampForce(velocity), 0.0, 0.0);
gl_FragColor = vec4(clampForce(velocity), 0.0, 1.0);
}