diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2016-01-10 19:53:08 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2016-01-10 21:05:10 +0300 |
commit | 82049cbe7e6003cf9941008a155af4ec08504009 (patch) | |
tree | 1ca391828f32df89f0902cc61539df6a4a940a6e /source/blender/gpu | |
parent | f1e8204f5afc88903edff5719d0bb159a5f483ba (diff) |
OpenGL Smoke: fix color issue, and clarify meaning of variables in the shader.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl b/source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl index c467925725d..7bee7ef47a7 100644 --- a/source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl @@ -1,8 +1,9 @@ varying vec3 coords; -uniform vec4 active_color; -uniform float cell_spacing; +uniform vec3 active_color; +uniform float step_size; +uniform float density_scale; uniform sampler3D soot_texture; uniform sampler3D shadow_texture; @@ -14,34 +15,27 @@ uniform sampler1D spectrum_texture; void main() { + /* compute color and density from volume texture */ vec4 soot = texture3D(soot_texture, coords); + vec3 soot_color = active_color * soot.rgb / soot.a; + float soot_density = density_scale * soot.a; - /* unpremultiply volume texture */ - float value = 1.0f / soot.a; - soot.xyz *= vec3(value); + /* compute transmittance and alpha */ + float soot_transmittance = pow(2.71828182846, -soot_density * step_size); + float soot_alpha = 1.0 - soot_transmittance; - /* calculate shading factor from soot */ - value = soot.a * active_color.a; - value *= cell_spacing; - value *= 1.442695041; - soot = vec4(pow(2.0, -value)); - - /* alpha */ - soot.a = 1.0 - soot.r; - - /* shade colors */ - vec3 shadow = texture3D(shadow_texture, coords).rrr; - soot.xyz *= shadow; - soot.xyz *= active_color.xyz; + /* shade */ + float shadow = texture3D(shadow_texture, coords).r; + soot_color *= soot_transmittance * shadow; /* premultiply alpha */ - vec4 color = vec4(soot.a * soot.rgb, soot.a); + vec4 color = vec4(soot_alpha * soot_color, soot_alpha); #ifdef USE_FIRE - /* blend in fire */ + /* fire */ float flame = texture3D(flame_texture, coords).r; - vec4 spec = texture1D(spectrum_texture, flame); - color = vec4(color.rgb + (1 - color.a) * spec.a * spec.rgb, color.a); + vec4 emission = texture1D(spectrum_texture, flame); + color.rgb += (1 - color.a) * emission.a * emission.rgb; #endif gl_FragColor = color; |