This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl
Kévin Dietrich 116bab702e Fix T47639: OpenGL render with smoke and fire incorrect when using
transparency.

The issue is that we are rendering to a 0..1 clamped sRGB buffer with
unpremultiplied alpha, where the correct thing to do would be to render
to an unclamped linear premultiplied alpha buffer. Then we would just
make fire purely emissive without affecting the alpha channel at all,
but that doesn't work here.

So for now, draw fire and smoke separately using different shaders and
blend modes, like it used to before the smoke programs were rewritten
(see rB0372b642).
2016-08-28 16:50:59 +02:00

37 lines
843 B
GLSL

varying vec3 coords;
uniform vec3 active_color;
uniform float step_size;
uniform float density_scale;
uniform sampler3D soot_texture;
uniform sampler3D shadow_texture;
void main()
{
/* compute color and density from volume texture */
vec4 soot = texture3D(soot_texture, coords);
vec3 soot_color;
if (soot.a != 0) {
soot_color = active_color * soot.rgb / soot.a;
}
else {
soot_color = vec3(0, 0, 0);
}
float soot_density = density_scale * soot.a;
/* compute transmittance and alpha */
float soot_transmittance = pow(2.71828182846, -soot_density * step_size);
float soot_alpha = 1.0 - soot_transmittance;
/* shade */
float shadow = texture3D(shadow_texture, coords).r;
soot_color *= soot_transmittance * shadow;
/* premultiply alpha */
vec4 color = vec4(soot_alpha * soot_color, soot_alpha);
gl_FragColor = color;
}