diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/space_view3d/drawvolume.c | 15 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl | 38 |
2 files changed, 25 insertions, 28 deletions
diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c index 801419b81c0..58142d7ee4a 100644 --- a/source/blender/editors/space_view3d/drawvolume.c +++ b/source/blender/editors/space_view3d/drawvolume.c @@ -327,7 +327,8 @@ void draw_smoke_volume(SmokeDomainSettings *sds, Object *ob, int shadow_location = GPU_shader_get_uniform(shader, "shadow_texture"); int flame_location = GPU_shader_get_uniform(shader, "flame_texture"); int actcol_location = GPU_shader_get_uniform(shader, "active_color"); - int cellspace_location = GPU_shader_get_uniform(shader, "cell_spacing"); + int stepsize_location = GPU_shader_get_uniform(shader, "step_size"); + int densityscale_location = GPU_shader_get_uniform(shader, "density_scale"); int invsize_location = GPU_shader_get_uniform(shader, "invsize"); int ob_sizei_location = GPU_shader_get_uniform(shader, "ob_sizei"); int min_location = GPU_shader_get_uniform(shader, "min"); @@ -351,12 +352,14 @@ void draw_smoke_volume(SmokeDomainSettings *sds, Object *ob, GPU_shader_uniform_texture(shader, spec_location, tex_spec); } - float active_color[4] = { 0.7, 0.7, 0.7, 10.0 }; - if ((sds->active_fields & SM_ACTIVE_COLORS) != 0) - copy_v3_v3(active_color, sds->active_color); + float active_color[3] = { 0.9, 0.9, 0.9 }; + float density_scale = 10.0f; + if ((sds->active_fields & SM_ACTIVE_COLORS) == 0) + mul_v3_v3(active_color, sds->active_color); - GPU_shader_uniform_vector(shader, actcol_location, 4, 1, active_color); - GPU_shader_uniform_vector(shader, cellspace_location, 1, 1, &sds->dx); + GPU_shader_uniform_vector(shader, actcol_location, 3, 1, active_color); + GPU_shader_uniform_vector(shader, stepsize_location, 1, 1, &sds->dx); + GPU_shader_uniform_vector(shader, densityscale_location, 1, 1, &density_scale); GPU_shader_uniform_vector(shader, min_location, 3, 1, min); GPU_shader_uniform_vector(shader, ob_sizei_location, 3, 1, ob_sizei); GPU_shader_uniform_vector(shader, invsize_location, 3, 1, invsize); 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; |