diff options
author | Brecht Van Lommel <brecht> | 2020-03-11 16:58:19 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-03-11 16:59:05 +0300 |
commit | b9f6d033beecd75398be14419d37d8aab0609812 (patch) | |
tree | b2385a92388dfb1d17a99a72dd442bc5bc38de85 /source/blender/gpu/shaders/material | |
parent | e1e772a80243f3c279fcd076c8311301e8885d41 (diff) |
Eevee: internal support for arbitrary number of volume grids
This has no user visible impact yet since smoke volumes only support a fixed
set of attributes, but will become important with the new volume object.
For GPU shader compilation, volume grids are now handled separately from
image textures. They are somewhere between a vertex attribute and an image
texture, basically an attribute that is stored as a texture.
Differential Revision: https://developer.blender.org/D6952
Diffstat (limited to 'source/blender/gpu/shaders/material')
-rw-r--r-- | source/blender/gpu/shaders/material/gpu_shader_material_volume_info.glsl | 78 |
1 files changed, 21 insertions, 57 deletions
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_volume_info.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_volume_info.glsl index 0fecb5bd1f9..a80cd3cb329 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_volume_info.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_volume_info.glsl @@ -1,18 +1,21 @@ -void node_attribute_volume_density(sampler3D tex, out vec4 outcol, out vec3 outvec, out float outf) + +/* Uniforms to convert smoke grid values into standard range. */ +uniform vec3 volumeColor = vec3(1.0); +uniform vec2 volumeTemperature = vec2(0.0); + +/* Generic volume attribute. */ +void node_attribute_volume(sampler3D tex, out vec3 outvec) { #if defined(MESH_SHADER) && defined(VOLUMETRICS) vec3 cos = volumeObjectLocalCoord; #else vec3 cos = vec3(0.0); #endif - outf = texture(tex, cos).r; - outvec = vec3(outf, outf, outf); - outcol = vec4(outf, outf, outf, 1.0); + outvec = texture(tex, cos).rgb; } -uniform vec3 volumeColor = vec3(1.0); - -void node_attribute_volume_color(sampler3D tex, out vec4 outcol, out vec3 outvec, out float outf) +/* Special color attribute for smoke. */ +void node_attribute_volume_color(sampler3D tex, out vec3 outvec) { #if defined(MESH_SHADER) && defined(VOLUMETRICS) vec3 cos = volumeObjectLocalCoord; @@ -20,70 +23,31 @@ void node_attribute_volume_color(sampler3D tex, out vec4 outcol, out vec3 outvec vec3 cos = vec3(0.0); #endif - vec4 value = texture(tex, cos).rgba; /* Density is premultiplied for interpolation, divide it out here. */ + vec4 value = texture(tex, cos).rgba; if (value.a > 1e-8) { value.rgb /= value.a; } outvec = value.rgb * volumeColor; - outcol = vec4(outvec, 1.0); - outf = avg(outvec); -} - -void node_attribute_volume_flame(sampler3D tex, out vec4 outcol, out vec3 outvec, out float outf) -{ -#if defined(MESH_SHADER) && defined(VOLUMETRICS) - vec3 cos = volumeObjectLocalCoord; -#else - vec3 cos = vec3(0.0); -#endif - outf = texture(tex, cos).r; - outvec = vec3(outf, outf, outf); - outcol = vec4(outf, outf, outf, 1.0); } -void node_attribute_volume_temperature( - sampler3D tex, vec2 temperature, out vec4 outcol, out vec3 outvec, out float outf) +/* Special temperature attribute for smoke. */ +void node_attribute_volume_temperature(sampler3D tex, out float outf) { #if defined(MESH_SHADER) && defined(VOLUMETRICS) vec3 cos = volumeObjectLocalCoord; #else vec3 cos = vec3(0.0); #endif - float flame = texture(tex, cos).r; - - outf = (flame > 0.01) ? temperature.x + flame * (temperature.y - temperature.x) : 0.0; - outvec = vec3(outf, outf, outf); - outcol = vec4(outf, outf, outf, 1.0); -} -void node_volume_info(sampler3D densitySampler, - sampler3D colorSampler, - sampler3D flameSampler, - vec2 temperature, - out vec4 outColor, - out float outDensity, - out float outFlame, - out float outTemprature) -{ -#if defined(MESH_SHADER) && defined(VOLUMETRICS) - vec3 p = volumeObjectLocalCoord; -#else - vec3 p = vec3(0.0); -#endif - - outDensity = texture(densitySampler, p).r; - - /* Color is premultiplied for interpolation, divide it out here. */ - vec4 color = texture(colorSampler, p); - if (color.a > 1e-8) { - color.rgb /= color.a; + float value = texture(tex, cos).r; + if (volumeTemperature.x < volumeTemperature.y) { + outf = (value > 0.01) ? + volumeTemperature.x + value * (volumeTemperature.y - volumeTemperature.x) : + 0.0; + } + else { + outf = value; } - outColor = vec4(color.rgb * volumeColor, 1.0); - - float flame = texture(flameSampler, p).r; - outFlame = flame; - - outTemprature = (flame > 0.01) ? temperature.x + flame * (temperature.y - temperature.x) : 0.0; } |