diff options
author | OmarSquircleArt <omar.squircleart@gmail.com> | 2019-08-30 18:23:04 +0300 |
---|---|---|
committer | OmarSquircleArt <omar.squircleart@gmail.com> | 2019-08-30 18:28:57 +0300 |
commit | 8cd0da88e55a0c0f88297a5f0f770eb40acc6219 (patch) | |
tree | 585b9bcc07ce392c6164ac0230d56d617ac051ca /source/blender/gpu/shaders/material/gpu_shader_material_volume_principled.glsl | |
parent | ac646bc20dafe176c1b84ee5beddf980aba11358 (diff) |
GPU: Split gpu_shader_material into multiple files.
This patch continue the efforts to split the `gpu_shader_material` file
started in D5569.
Dependency resolution is now recursive. Each shading node gets its own
file. Additionally, some utility files are added to be shared between
files, like `math_util`, `color_util`, and `hash`. Some files are always
included because they may be used in the execution function, like
`world_normals`.
Some glsl functions appeared to be unused, so they were removed, like
`output_node`, `bits_to_01`, and `exp_blender`. Other functions have
been renamed to be more general and get used as utils, like `texco_norm`
which became `vector_normalize`.
A lot of the opengl tests fails, but those same tests also fail in
master, so this is probably unrelated to this patch.
Reviewers: brecht
Differential Revision: https://developer.blender.org/D5616
Diffstat (limited to 'source/blender/gpu/shaders/material/gpu_shader_material_volume_principled.glsl')
-rw-r--r-- | source/blender/gpu/shaders/material/gpu_shader_material_volume_principled.glsl | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_volume_principled.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_volume_principled.glsl new file mode 100644 index 00000000000..884d5415c51 --- /dev/null +++ b/source/blender/gpu/shaders/material/gpu_shader_material_volume_principled.glsl @@ -0,0 +1,67 @@ +void node_volume_principled(vec4 color, + float density, + float anisotropy, + vec4 absorption_color, + float emission_strength, + vec4 emission_color, + float blackbody_intensity, + vec4 blackbody_tint, + float temperature, + float density_attribute, + vec4 color_attribute, + float temperature_attribute, + sampler1DArray spectrummap, + float layer, + out Closure result) +{ +#ifdef VOLUMETRICS + vec3 absorption_coeff = vec3(0.0); + vec3 scatter_coeff = vec3(0.0); + vec3 emission_coeff = vec3(0.0); + + /* Compute density. */ + density = max(density, 0.0); + + if (density > 1e-5) { + density = max(density * density_attribute, 0.0); + } + + if (density > 1e-5) { + /* Compute scattering and absorption coefficients. */ + vec3 scatter_color = color.rgb * color_attribute.rgb; + + scatter_coeff = scatter_color * density; + absorption_color.rgb = sqrt(max(absorption_color.rgb, 0.0)); + absorption_coeff = max(1.0 - scatter_color, 0.0) * max(1.0 - absorption_color.rgb, 0.0) * + density; + } + + /* Compute emission. */ + emission_strength = max(emission_strength, 0.0); + + if (emission_strength > 1e-5) { + emission_coeff += emission_strength * emission_color.rgb; + } + + if (blackbody_intensity > 1e-3) { + /* Add temperature from attribute. */ + float T = max(temperature * max(temperature_attribute, 0.0), 0.0); + + /* Stefan-Boltzman law. */ + float T2 = T * T; + float T4 = T2 * T2; + float sigma = 5.670373e-8 * 1e-6 / M_PI; + float intensity = sigma * mix(1.0, T4, blackbody_intensity); + + if (intensity > 1e-5) { + vec4 bb; + node_blackbody(T, spectrummap, layer, bb); + emission_coeff += bb.rgb * blackbody_tint.rgb * intensity; + } + } + + result = Closure(absorption_coeff, scatter_coeff, emission_coeff, anisotropy); +#else + result = CLOSURE_DEFAULT; +#endif +} |