diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2020-03-17 18:27:08 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2020-03-18 13:23:05 +0300 |
commit | fd53b72871e045dfebfb9ddbe2b3c491491aa913 (patch) | |
tree | 892721f97e6bff16c9d87bc3ffee295d2f4a77bc /source/blender/draw/engines/workbench/shaders | |
parent | b0a1cf2c9ae696b07f7a236bc855a5ab4a493dcb (diff) |
Objects: Eevee and workbench rendering of new Volume, Hair, PointCloud
Only the volume drawing part is really finished and exposed to the user. Hair
plugs into the existing hair rendering code and is fairly straightforward. The
pointcloud drawing is a hack using overlays rather than Eevee and workbench.
The most tricky part for volume rendering is the case where each volume grid
has a different transform, which requires an additional matrix in the shader
and non-trivial logic in Eevee volume drawing. In the common case were all the
transforms match we don't use the additional per-grid matrix in the shader.
Ref T73201, T68981
Differential Revision: https://developer.blender.org/D6955
Diffstat (limited to 'source/blender/draw/engines/workbench/shaders')
-rw-r--r-- | source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl | 16 | ||||
-rw-r--r-- | source/blender/draw/engines/workbench/shaders/workbench_volume_vert.glsl | 7 |
2 files changed, 21 insertions, 2 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 e957f8bbe9c..0c2b7850f94 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl @@ -11,6 +11,7 @@ uniform sampler3D shadowTexture; uniform sampler3D flameTexture; uniform sampler1D flameColorTexture; uniform sampler1D transferTexture; +uniform mat4 volumeObjectToTexture; uniform int samplesLen = 256; uniform float noiseOfs = 0.0; @@ -110,20 +111,24 @@ void volume_properties(vec3 ls_pos, out vec3 scattering, out float extinction) scattering = tval.rgb * 1500.0; extinction = max(1e-4, tval.a * 50.0); #else +# ifdef VOLUME_SMOKE float flame = sample_volume_texture(flameTexture, co).r; vec4 emission = texture(flameColorTexture, flame); +# endif + vec3 density = sample_volume_texture(densityTexture, co).rgb; float shadows = sample_volume_texture(shadowTexture, co).r; - vec4 density = sample_volume_texture(densityTexture, co); /* rgb: color, a: density */ - scattering = density.rgb * densityScale; + scattering = density * densityScale; extinction = max(1e-4, dot(scattering, vec3(0.33333))); scattering *= activeColor; /* Scale shadows in log space and clamp them to avoid completely black shadows. */ scattering *= exp(clamp(log(shadows) * densityScale * 0.1, -2.5, 0.0)) * M_PI; +# ifdef VOLUME_SMOKE /* 800 is arbitrary and here to mimic old viewport. TODO make it a parameter */ scattering += pow(emission.rgb, vec3(2.2)) * emission.a * 800.0; +# endif #endif } @@ -201,9 +206,16 @@ void main() vec3 ls_ray_ori = point_view_to_object(vs_ray_ori); vec3 ls_ray_end = point_view_to_object(vs_ray_end); +# ifdef VOLUME_SMOKE ls_ray_dir = (OrcoTexCoFactors[0].xyz + ls_ray_dir * OrcoTexCoFactors[1].xyz) * 2.0 - 1.0; ls_ray_ori = (OrcoTexCoFactors[0].xyz + ls_ray_ori * OrcoTexCoFactors[1].xyz) * 2.0 - 1.0; ls_ray_end = (OrcoTexCoFactors[0].xyz + ls_ray_end * OrcoTexCoFactors[1].xyz) * 2.0 - 1.0; +# else + ls_ray_dir = (volumeObjectToTexture * vec4(ls_ray_dir, 1.0)).xyz * 2.0f - 1.0; + ls_ray_ori = (volumeObjectToTexture * vec4(ls_ray_ori, 1.0)).xyz * 2.0f - 1.0; + ls_ray_end = (volumeObjectToTexture * vec4(ls_ray_end, 1.0)).xyz * 2.0f - 1.0; +# endif + ls_ray_dir -= ls_ray_ori; /* TODO: Align rays to volume center so that it mimics old behaviour of slicing the volume. */ diff --git a/source/blender/draw/engines/workbench/shaders/workbench_volume_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_volume_vert.glsl index 1a32a202290..7327a92e04f 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_volume_vert.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_volume_vert.glsl @@ -5,6 +5,8 @@ uniform float slicePosition; uniform int sliceAxis; /* -1 is no slice, 0 is X, 1 is Y, 2 is Z. */ +uniform mat4 volumeTextureToObject; + in vec3 pos; RESOURCE_ID_VARYING @@ -31,7 +33,12 @@ void main() #else vec3 final_pos = pos; #endif + +#ifdef VOLUME_SMOKE final_pos = ((final_pos * 0.5 + 0.5) - OrcoTexCoFactors[0].xyz) / OrcoTexCoFactors[1].xyz; +#else + final_pos = (volumeTextureToObject * vec4(final_pos * 0.5 + 0.5, 1.0)).xyz; +#endif gl_Position = point_object_to_ndc(final_pos); PASS_RESOURCE_ID |