diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-11-07 15:22:22 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-11-07 15:25:28 +0300 |
commit | 84ad9b102e708da54188752bde34daba8b6611b2 (patch) | |
tree | 63a79d141fe9b934ae33d86d25a148e817b04272 /source/blender/draw/engines/workbench/shaders | |
parent | faecd16d3168981b5af95be613e5a91de5c28133 (diff) |
Workbench: Add cubic filtering for smoke simulation
The option is per domain and only affects the solid / xray / wireframe view.
Eevee is not yet supported.
Diffstat (limited to 'source/blender/draw/engines/workbench/shaders')
-rw-r--r-- | source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl | 61 |
1 files changed, 57 insertions, 4 deletions
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl index 023ebb8e111..f14078a71eb 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl @@ -67,20 +67,73 @@ float line_unit_box_intersect_dist(vec3 lineorigin, vec3 linedirection) return max_v3(furthestplane); } +#define sample_trilinear(ima, co) texture(ima, co) + +vec4 sample_tricubic(sampler3D ima, vec3 co) +{ + vec3 tex_size = vec3(textureSize(ima, 0).xyz); + + co *= tex_size; + /* texel center */ + vec3 tc = floor(co - 0.5) + 0.5; + vec3 f = co - tc; + vec3 f2 = f * f; + vec3 f3 = f2 * f; + /* Bspline coefs (optimized) */ + vec3 w3 = f3 / 6.0; + vec3 w0 = -w3 + f2 * 0.5 - f * 0.5 + 1.0 / 6.0; + vec3 w1 = f3 * 0.5 - f2 + 2.0 / 3.0; + vec3 w2 = 1.0 - w0 - w1 - w3; + + vec3 s0 = w0 + w1; + vec3 s1 = w2 + w3; + + vec3 f0 = w1 / (w0 + w1); + vec3 f1 = w3 / (w2 + w3); + + vec2 final_z; + vec4 final_co; + final_co.xy = tc.xy - 1.0 + f0.xy; + final_co.zw = tc.xy + 1.0 + f1.xy; + final_z = tc.zz + vec2(-1.0, 1.0) + vec2(f0.z, f1.z); + + final_co /= tex_size.xyxy; + final_z /= tex_size.zz; + + vec4 color; + color = texture(ima, vec3(final_co.xy, final_z.x)) * s0.x * s0.y * s0.z; + color += texture(ima, vec3(final_co.zy, final_z.x)) * s1.x * s0.y * s0.z; + color += texture(ima, vec3(final_co.xw, final_z.x)) * s0.x * s1.y * s0.z; + color += texture(ima, vec3(final_co.zw, final_z.x)) * s1.x * s1.y * s0.z; + + color += texture(ima, vec3(final_co.xy, final_z.y)) * s0.x * s0.y * s1.z; + color += texture(ima, vec3(final_co.zy, final_z.y)) * s1.x * s0.y * s1.z; + color += texture(ima, vec3(final_co.xw, final_z.y)) * s0.x * s1.y * s1.z; + color += texture(ima, vec3(final_co.zw, final_z.y)) * s1.x * s1.y * s1.z; + + return color; +} + +#ifdef USE_TRICUBIC +# define sample_volume_texture sample_tricubic +#else +# define sample_volume_texture sample_trilinear +#endif + void volume_properties(vec3 ls_pos, out vec3 scattering, out float extinction) { vec3 co = ls_pos * 0.5 + 0.5; #ifdef USE_COBA - float val = texture(densityTexture, co).r; + float val = sample_volume_texture(densityTexture, co).r; vec4 tval = texture(transferTexture, val) * densityScale; tval.rgb = pow(tval.rgb, vec3(2.2)); scattering = tval.rgb * 1500.0; extinction = max(1e-4, tval.a * 50.0); #else - float flame = texture(flameTexture, co).r; + float flame = sample_volume_texture(flameTexture, co).r; vec4 emission = texture(flameColorTexture, flame); - float shadows = texture(shadowTexture, co).r; - vec4 density = texture(densityTexture, co); /* rgb: color, a: density */ + float shadows = sample_volume_texture(shadowTexture, co).r; + vec4 density = sample_volume_texture(densityTexture, co); /* rgb: color, a: density */ scattering = density.rgb * density.a * densityScale; extinction = max(1e-4, dot(scattering, vec3(0.33333))); |