diff options
author | Brecht Van Lommel <brecht@blender.org> | 2020-03-11 19:49:00 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-03-11 22:35:38 +0300 |
commit | ec3eeee46b4885b9167b0dc28d273993d77b8ce6 (patch) | |
tree | 9177fb4e62877f7cef35c528f10a0881db6f1316 /intern/cycles/render | |
parent | 5a169ae2f327f366137b6cefd2da75287f761a4f (diff) |
Cycles: add internal default volume shader, to be used for new volume object
This is mostly straightforward, but required some refactoring to ensure that
the default volume material does not always turn on the volume feature for GPU
rendering.
Diffstat (limited to 'intern/cycles/render')
-rw-r--r-- | intern/cycles/render/nodes.cpp | 4 | ||||
-rw-r--r-- | intern/cycles/render/osl.cpp | 7 | ||||
-rw-r--r-- | intern/cycles/render/scene.cpp | 6 | ||||
-rw-r--r-- | intern/cycles/render/scene.h | 1 | ||||
-rw-r--r-- | intern/cycles/render/session.cpp | 13 | ||||
-rw-r--r-- | intern/cycles/render/shader.cpp | 45 | ||||
-rw-r--r-- | intern/cycles/render/shader.h | 4 | ||||
-rw-r--r-- | intern/cycles/render/svm.cpp | 3 |
8 files changed, 58 insertions, 25 deletions
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 3967b4ef00e..e90b846f7e5 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -3358,7 +3358,7 @@ NODE_DEFINE(PrincipledVolumeNode) SOCKET_IN_COLOR(emission_color, "Emission Color", make_float3(1.0f, 1.0f, 1.0f)); SOCKET_IN_FLOAT(blackbody_intensity, "Blackbody Intensity", 0.0f); SOCKET_IN_COLOR(blackbody_tint, "Blackbody Tint", make_float3(1.0f, 1.0f, 1.0f)); - SOCKET_IN_FLOAT(temperature, "Temperature", 1500.0f); + SOCKET_IN_FLOAT(temperature, "Temperature", 1000.0f); SOCKET_IN_FLOAT(volume_mix_weight, "VolumeMixWeight", 0.0f, SocketType::SVM_INTERNAL); SOCKET_OUT_CLOSURE(volume, "Volume"); @@ -3369,6 +3369,8 @@ NODE_DEFINE(PrincipledVolumeNode) PrincipledVolumeNode::PrincipledVolumeNode() : VolumeNode(node_type) { closure = CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID; + density_attribute = ustring("density"); + temperature_attribute = ustring("temperature"); } void PrincipledVolumeNode::attributes(Shader *shader, AttributeRequestSet *attributes) diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp index d5d649e2207..d17d7270cd5 100644 --- a/intern/cycles/render/osl.cpp +++ b/intern/cycles/render/osl.cpp @@ -102,8 +102,8 @@ void OSLShaderManager::device_update(Device *device, device_free(device, dscene, scene); - /* determine which shaders are in use */ - device_update_shaders_used(scene); + /* set texture system */ + scene->image_manager->set_osl_texture_system((void *)ts); /* create shaders */ OSLGlobals *og = (OSLGlobals *)device->osl_memory(); @@ -142,9 +142,6 @@ void OSLShaderManager::device_update(Device *device, need_update = false; - /* set texture system */ - scene->image_manager->set_osl_texture_system((void *)ts); - /* add special builtin texture types */ services->textures.insert(ustring("@ao"), new OSLTextureHandle(OSLTextureHandle::AO)); services->textures.insert(ustring("@bevel"), new OSLTextureHandle(OSLTextureHandle::BEVEL)); diff --git a/intern/cycles/render/scene.cpp b/intern/cycles/render/scene.cpp index 7fab2fdedeb..1e20513e88a 100644 --- a/intern/cycles/render/scene.cpp +++ b/intern/cycles/render/scene.cpp @@ -104,9 +104,11 @@ Scene::Scene(const SceneParams ¶ms_, Device *device) /* OSL only works on the CPU */ if (device->info.has_osl) - shader_manager = ShaderManager::create(this, params.shadingsystem); + shader_manager = ShaderManager::create(params.shadingsystem); else - shader_manager = ShaderManager::create(this, SHADINGSYSTEM_SVM); + shader_manager = ShaderManager::create(SHADINGSYSTEM_SVM); + + shader_manager->add_default(this); } Scene::~Scene() diff --git a/intern/cycles/render/scene.h b/intern/cycles/render/scene.h index 1dceb93aef7..d2570138b53 100644 --- a/intern/cycles/render/scene.h +++ b/intern/cycles/render/scene.h @@ -230,6 +230,7 @@ class Scene { /* default shaders */ Shader *default_surface; + Shader *default_volume; Shader *default_light; Shader *default_background; Shader *default_empty; diff --git a/intern/cycles/render/session.cpp b/intern/cycles/render/session.cpp index 6bf2160f9fa..b5d434a604c 100644 --- a/intern/cycles/render/session.cpp +++ b/intern/cycles/render/session.cpp @@ -987,7 +987,8 @@ bool Session::update_scene() /* update scene */ if (scene->need_update()) { - bool new_kernels_needed = load_kernels(false); + /* Updated used shader tag so we know which features are need for the kernel. */ + scene->shader_manager->update_shaders_used(scene); /* Update max_closures. */ KernelIntegrator *kintegrator = &scene->dscene.data.integrator; @@ -999,6 +1000,9 @@ bool Session::update_scene() kintegrator->max_closures = MAX_CLOSURE; } + /* Load render kernels, before device update where we upload data to the GPU. */ + bool new_kernels_needed = load_kernels(false); + progress.set_status("Updating Scene"); MEM_GUARDED_CALL(&progress, scene->device_update, device, progress); @@ -1271,8 +1275,11 @@ int Session::get_max_closure_count() int max_closures = 0; for (int i = 0; i < scene->shaders.size(); i++) { - int num_closures = scene->shaders[i]->graph->get_num_closures(); - max_closures = max(max_closures, num_closures); + Shader *shader = scene->shaders[i]; + if (shader->used) { + int num_closures = shader->graph->get_num_closures(); + max_closures = max(max_closures, num_closures); + } } max_closure_global = max(max_closure_global, max_closures); diff --git a/intern/cycles/render/shader.cpp b/intern/cycles/render/shader.cpp index 60f38aa14da..cc6eb2e5e7f 100644 --- a/intern/cycles/render/shader.cpp +++ b/intern/cycles/render/shader.cpp @@ -168,7 +168,7 @@ NODE_DEFINE(Shader) SOCKET_ENUM(volume_sampling_method, "Volume Sampling Method", volume_sampling_method_enum, - VOLUME_SAMPLING_DISTANCE); + VOLUME_SAMPLING_MULTIPLE_IMPORTANCE); static NodeEnum volume_interpolation_method_enum; volume_interpolation_method_enum.insert("linear", VOLUME_INTERPOLATION_LINEAR); @@ -415,7 +415,7 @@ ShaderManager::~ShaderManager() { } -ShaderManager *ShaderManager::create(Scene *scene, int shadingsystem) +ShaderManager *ShaderManager::create(int shadingsystem) { ShaderManager *manager; @@ -431,8 +431,6 @@ ShaderManager *ShaderManager::create(Scene *scene, int shadingsystem) manager = new SVMShaderManager(); } - add_default(scene); - return manager; } @@ -471,8 +469,12 @@ int ShaderManager::get_shader_id(Shader *shader, bool smooth) return id; } -void ShaderManager::device_update_shaders_used(Scene *scene) +void ShaderManager::update_shaders_used(Scene *scene) { + if (!need_update) { + return; + } + /* figure out which shaders are in use, so SVM/OSL can skip compiling them * for speed and avoid loading image textures into memory */ uint id = 0; @@ -623,9 +625,27 @@ void ShaderManager::add_default(Scene *scene) Shader *shader = new Shader(); shader->name = "default_surface"; - shader->graph = graph; + shader->set_graph(graph); scene->shaders.push_back(shader); scene->default_surface = shader; + shader->tag_update(scene); + } + + /* default volume */ + { + ShaderGraph *graph = new ShaderGraph(); + + PrincipledVolumeNode *principled = new PrincipledVolumeNode(); + graph->add(principled); + + graph->connect(principled->output("Volume"), graph->output()->input("Volume")); + + Shader *shader = new Shader(); + shader->name = "default_volume"; + shader->set_graph(graph); + scene->shaders.push_back(shader); + scene->default_volume = shader; + shader->tag_update(scene); } /* default light */ @@ -641,9 +661,10 @@ void ShaderManager::add_default(Scene *scene) Shader *shader = new Shader(); shader->name = "default_light"; - shader->graph = graph; + shader->set_graph(graph); scene->shaders.push_back(shader); scene->default_light = shader; + shader->tag_update(scene); } /* default background */ @@ -652,9 +673,10 @@ void ShaderManager::add_default(Scene *scene) Shader *shader = new Shader(); shader->name = "default_background"; - shader->graph = graph; + shader->set_graph(graph); scene->shaders.push_back(shader); scene->default_background = shader; + shader->tag_update(scene); } /* default empty */ @@ -663,9 +685,10 @@ void ShaderManager::add_default(Scene *scene) Shader *shader = new Shader(); shader->name = "default_empty"; - shader->graph = graph; + shader->set_graph(graph); scene->shaders.push_back(shader); scene->default_empty = shader; + shader->tag_update(scene); } } @@ -704,6 +727,10 @@ void ShaderManager::get_requested_features(Scene *scene, requested_features->nodes_features = 0; for (int i = 0; i < scene->shaders.size(); i++) { Shader *shader = scene->shaders[i]; + if (!shader->used) { + continue; + } + /* Gather requested features from all the nodes from the graph nodes. */ get_requested_graph_features(shader->graph, requested_features); ShaderNode *output_node = shader->graph->output(); diff --git a/intern/cycles/render/shader.h b/intern/cycles/render/shader.h index c6f40bb7833..5a5b42de994 100644 --- a/intern/cycles/render/shader.h +++ b/intern/cycles/render/shader.h @@ -163,7 +163,7 @@ class ShaderManager { public: bool need_update; - static ShaderManager *create(Scene *scene, int shadingsystem); + static ShaderManager *create(int shadingsystem); virtual ~ShaderManager(); virtual void reset(Scene *scene) = 0; @@ -180,7 +180,6 @@ class ShaderManager { Progress &progress) = 0; virtual void device_free(Device *device, DeviceScene *dscene, Scene *scene) = 0; - void device_update_shaders_used(Scene *scene); void device_update_common(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress); void device_free_common(Device *device, DeviceScene *dscene, Scene *scene); @@ -196,6 +195,7 @@ class ShaderManager { static void add_default(Scene *scene); /* Selective nodes compilation. */ + void update_shaders_used(Scene *scene); void get_requested_features(Scene *scene, DeviceRequestedFeatures *requested_features); static void free_memory(); diff --git a/intern/cycles/render/svm.cpp b/intern/cycles/render/svm.cpp index 7c33f6c04ae..2946614a3b7 100644 --- a/intern/cycles/render/svm.cpp +++ b/intern/cycles/render/svm.cpp @@ -85,9 +85,6 @@ void SVMShaderManager::device_update(Device *device, /* test if we need to update */ device_free(device, dscene, scene); - /* determine which shaders are in use */ - device_update_shaders_used(scene); - /* Build all shaders. */ TaskPool task_pool; vector<array<int4>> shader_svm_nodes(num_shaders); |