Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2018-01-30 17:05:19 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2018-02-23 20:57:58 +0300
commit0aec2dcd3ae0ed382ffe7b3311a4e30fc88398e4 (patch)
treea3ebe2b22f375e35f3aee068c8570280b1cc93a2 /intern/cycles/kernel/shaders
parentacd619d7c9250282d68b917d6cae5c08301bb989 (diff)
Cycles: add Principled Volume shader.
Similar to the Principled BSDF, this should make it easier to set up volume materials. Smoke and fire can be rendererd with just a single principled volume node, the appropriate attributes will be used when available. The node also works for simpler homogeneous volumes like water or mist. Differential Revision: https://developer.blender.org/D3033
Diffstat (limited to 'intern/cycles/kernel/shaders')
-rw-r--r--intern/cycles/kernel/shaders/CMakeLists.txt1
-rw-r--r--intern/cycles/kernel/shaders/node_principled_volume.osl94
2 files changed, 95 insertions, 0 deletions
diff --git a/intern/cycles/kernel/shaders/CMakeLists.txt b/intern/cycles/kernel/shaders/CMakeLists.txt
index 19b7769200e..6ec651a96d8 100644
--- a/intern/cycles/kernel/shaders/CMakeLists.txt
+++ b/intern/cycles/kernel/shaders/CMakeLists.txt
@@ -36,6 +36,7 @@ set(SRC_OSL
node_hair_info.osl
node_scatter_volume.osl
node_absorption_volume.osl
+ node_principled_volume.osl
node_holdout.osl
node_hsv.osl
node_image_texture.osl
diff --git a/intern/cycles/kernel/shaders/node_principled_volume.osl b/intern/cycles/kernel/shaders/node_principled_volume.osl
new file mode 100644
index 00000000000..609fb95866d
--- /dev/null
+++ b/intern/cycles/kernel/shaders/node_principled_volume.osl
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2011-2013 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "stdosl.h"
+
+shader node_principled_volume(
+ color Color = color(0.5, 0.5, 0.5),
+ float Density = 1.0,
+ float Anisotropy = 0.0,
+ color AbsorptionColor = color(0.0, 0.0, 0.0),
+ float EmissionStrength = 0.0,
+ color EmissionColor = color(1.0, 1.0, 1.0),
+ float BlackbodyIntensity = 0.0,
+ color BlackbodyTint = color(1.0, 1.0, 1.0),
+ float Temperature = 1500.0,
+ string DensityAttribute = "geom:density",
+ string ColorAttribute = "geom:color",
+ string TemperatureAttribute = "geom:temperature",
+ output closure color Volume = 0)
+{
+ /* Compute density. */
+ float primitive_density = 1.0;
+ float density = max(Density, 0.0);
+
+ if(density > 1e-5) {
+ if(getattribute(DensityAttribute, primitive_density)) {
+ density = max(density * primitive_density, 0.0);
+ }
+ }
+
+ if(density > 1e-5) {
+ /* Compute scattering color. */
+ color scatter_color = Color;
+ color primitive_color;
+ if(getattribute(ColorAttribute, primitive_color)) {
+ scatter_color *= primitive_color;
+ }
+
+ /* Add scattering and absorption closures. */
+ color scatter_coeff = scatter_color;
+ color absorption_coeff = max(1.0 - scatter_color, 0.0) * max(1.0 - AbsorptionColor, 0.0);
+ Volume = scatter_coeff * density * henyey_greenstein(Anisotropy) +
+ absorption_coeff * density * absorption();
+ }
+
+ /* Compute emission. */
+ float emission_strength = max(EmissionStrength, 0.0);
+ float blackbody_intensity = BlackbodyIntensity;
+
+ if(emission_strength > 1e-5) {
+ Volume += emission_strength * EmissionColor * emission();
+ }
+
+ if(blackbody_intensity > 1e-3) {
+ float T = Temperature;
+
+ /* Add temperature from attribute if available. */
+ float temperature;
+ if(getattribute(TemperatureAttribute, temperature)) {
+ T *= max(temperature, 0.0);
+ }
+
+ T = max(T, 0.0);
+
+ /* Stefan-Boltzman law. */
+ float T4 = (T * T) * (T * T);
+ float sigma = 5.670373e-8 * 1e-6 / M_PI;
+ float intensity = sigma * mix(1.0, T4, blackbody_intensity);
+
+ if(intensity > 1e-5) {
+ color bb = blackbody(T);
+ float l = luminance(bb);
+
+ if(l != 0.0) {
+ bb *= BlackbodyTint * intensity / l;
+ Volume += bb * emission();
+ }
+ }
+ }
+}
+