[Bf-blender-cvs] [9622b708291] cycles_procedural_api: use getters and setters for Shader

Kévin Dietrich noreply at git.blender.org
Mon Sep 7 05:03:34 CEST 2020


Commit: 9622b708291f35bb73d31ccc46742a102ce61876
Author: Kévin Dietrich
Date:   Wed Sep 2 03:40:21 2020 +0200
Branches: cycles_procedural_api
https://developer.blender.org/rB9622b708291f35bb73d31ccc46742a102ce61876

use getters and setters for Shader

some notes:
- needs some for members only used in Cycles as well
- check usages of tag_update and need_update_geometry
- pass_id is now a socket

===================================================================

M	intern/cycles/blender/blender_shader.cpp
M	intern/cycles/render/osl.cpp
M	intern/cycles/render/shader.cpp
M	intern/cycles/render/shader.h
M	intern/cycles/render/svm.cpp

===================================================================

diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index 8229a8d43cd..3f783366c11 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -1245,7 +1245,7 @@ void BlenderSync::sync_materials(BL::Depsgraph &b_depsgraph, bool update_all)
       ShaderGraph *graph = new ShaderGraph();
 
       shader->name = b_mat.name().c_str();
-      shader->pass_id = b_mat.pass_index();
+      shader->set_pass_id(b_mat.pass_index());
 
       /* create nodes */
       if (b_mat.use_nodes() && b_mat.node_tree()) {
@@ -1264,13 +1264,13 @@ void BlenderSync::sync_materials(BL::Depsgraph &b_depsgraph, bool update_all)
 
       /* settings */
       PointerRNA cmat = RNA_pointer_get(&b_mat.ptr, "cycles");
-      shader->use_mis = get_boolean(cmat, "sample_as_light");
-      shader->use_transparent_shadow = get_boolean(cmat, "use_transparent_shadow");
-      shader->heterogeneous_volume = !get_boolean(cmat, "homogeneous_volume");
-      shader->volume_sampling_method = get_volume_sampling(cmat);
-      shader->volume_interpolation_method = get_volume_interpolation(cmat);
-      shader->volume_step_rate = get_float(cmat, "volume_step_rate");
-      shader->displacement_method = get_displacement_method(cmat);
+      shader->set_use_mis(get_boolean(cmat, "sample_as_light"));
+      shader->set_use_transparent_shadow(get_boolean(cmat, "use_transparent_shadow"));
+      shader->set_heterogeneous_volume(!get_boolean(cmat, "homogeneous_volume"));
+      shader->set_volume_sampling_method(get_volume_sampling(cmat));
+      shader->set_volume_interpolation_method(get_volume_interpolation(cmat));
+      shader->set_volume_step_rate(get_float(cmat, "volume_step_rate"));
+      shader->set_displacement_method(get_displacement_method(cmat));
 
       shader->set_graph(graph);
 
@@ -1330,10 +1330,10 @@ void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d,
 
       /* volume */
       PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
-      shader->heterogeneous_volume = !get_boolean(cworld, "homogeneous_volume");
-      shader->volume_sampling_method = get_volume_sampling(cworld);
-      shader->volume_interpolation_method = get_volume_interpolation(cworld);
-      shader->volume_step_rate = get_float(cworld, "volume_step_size");
+      shader->set_heterogeneous_volume(!get_boolean(cworld, "homogeneous_volume"));
+      shader->set_volume_sampling_method(get_volume_sampling(cworld));
+      shader->set_volume_interpolation_method(get_volume_interpolation(cworld));
+      shader->set_volume_step_rate(get_float(cworld, "volume_step_size"));
     }
     else if (new_viewport_parameters.use_scene_world && b_world) {
       BackgroundNode *background = graph->create_node<BackgroundNode>();
diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp
index 1c54dc2d531..8f2a8743c46 100644
--- a/intern/cycles/render/osl.cpp
+++ b/intern/cycles/render/osl.cpp
@@ -138,7 +138,7 @@ void OSLShaderManager::device_update(Device *device,
   og->use = true;
 
   foreach (Shader *shader, scene->shaders)
-    shader->need_update = false;
+    shader->clear_modified();
 
   need_update = false;
 
@@ -1113,7 +1113,7 @@ OSL::ShaderGroupRef OSLCompiler::compile_type(Shader *shader, ShaderGraph *graph
 
 void OSLCompiler::compile(OSLGlobals *og, Shader *shader)
 {
-  if (shader->need_update) {
+  if (shader->is_modified()) {
     ShaderGraph *graph = shader->graph;
     ShaderNode *output = (graph) ? graph->output() : NULL;
 
diff --git a/intern/cycles/render/shader.cpp b/intern/cycles/render/shader.cpp
index 2d4257a0f71..e5e04eb9c9d 100644
--- a/intern/cycles/render/shader.cpp
+++ b/intern/cycles/render/shader.cpp
@@ -187,6 +187,8 @@ NODE_DEFINE(Shader)
   displacement_method_enum.insert("both", DISPLACE_BOTH);
   SOCKET_ENUM(displacement_method, "Displacement Method", displacement_method_enum, DISPLACE_BUMP);
 
+  SOCKET_INT(pass_id, "Pass ID", 0);
+
   return type;
 }
 
@@ -216,7 +218,6 @@ Shader::Shader() : Node(node_type)
   id = -1;
   used = false;
 
-  need_update = true;
   need_update_geometry = true;
 }
 
@@ -306,7 +307,7 @@ void Shader::set_graph(ShaderGraph *graph_)
 void Shader::tag_update(Scene *scene)
 {
   /* update tag */
-  need_update = true;
+  tag_modified();
   scene->shader_manager->need_update = true;
 
   /* if the shader previously was emissive, update light distribution,
@@ -369,7 +370,7 @@ void Shader::tag_used(Scene *scene)
   /* if an unused shader suddenly gets used somewhere, it needs to be
    * recompiled because it was skipped for compilation before */
   if (!used) {
-    need_update = true;
+    tag_modified();
     scene->shader_manager->need_update = true;
   }
 }
diff --git a/intern/cycles/render/shader.h b/intern/cycles/render/shader.h
index 897b0984a7e..f8f455a12f3 100644
--- a/intern/cycles/render/shader.h
+++ b/intern/cycles/render/shader.h
@@ -81,22 +81,25 @@ class Shader : public Node {
  public:
   NODE_DECLARE
 
-  int pass_id;
-
   /* shader graph */
   ShaderGraph *graph;
 
+  NODE_PUBLIC_API(int, pass_id)
+
   /* sampling */
-  bool use_mis;
-  bool use_transparent_shadow;
-  bool heterogeneous_volume;
-  VolumeSampling volume_sampling_method;
-  int volume_interpolation_method;
-  float volume_step_rate;
+  NODE_PUBLIC_API(bool, use_mis)
+  NODE_PUBLIC_API(bool, use_transparent_shadow)
+  NODE_PUBLIC_API(bool, heterogeneous_volume)
+  NODE_PUBLIC_API(VolumeSampling, volume_sampling_method)
+  NODE_PUBLIC_API(int, volume_interpolation_method)
+  NODE_PUBLIC_API(float, volume_step_rate)
+
+  /* displacement */
+  NODE_PUBLIC_API(DisplacementMethod, displacement_method)
+
   float prev_volume_step_rate;
 
   /* synchronization */
-  bool need_update;
   bool need_update_geometry;
 
   /* If the shader has only volume components, the surface is assumed to
@@ -122,9 +125,6 @@ class Shader : public Node {
   bool has_volume_attribute_dependency;
   bool has_integrator_dependency;
 
-  /* displacement */
-  DisplacementMethod displacement_method;
-
   /* requested mesh attributes */
   AttributeRequestSet attributes;
 
diff --git a/intern/cycles/render/svm.cpp b/intern/cycles/render/svm.cpp
index 88714e20a90..f596af9c7ab 100644
--- a/intern/cycles/render/svm.cpp
+++ b/intern/cycles/render/svm.cpp
@@ -116,7 +116,7 @@ void SVMShaderManager::device_update(Device *device,
   for (int i = 0; i < num_shaders; i++) {
     Shader *shader = scene->shaders[i];
 
-    shader->need_update = false;
+    shader->clear_modified();
     if (shader->use_mis && shader->has_surface_emission) {
       scene->light_manager->need_update = true;
     }



More information about the Bf-blender-cvs mailing list