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>2019-05-02 13:40:24 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-05-03 16:36:20 +0300
commitfadb6f34662fb60e1a48c2c053c500f017206f27 (patch)
tree48c16c2215e7110e00b4255f6230aa3491d94ee0 /intern/cycles/render
parent08a44d29815f6b0b9b675a503829d2e2ce7f6426 (diff)
Cleanup: refactor Cycles OSL texture handling
This adds our own OSL texture handle, that has info for OIIO textures or our own custom texture types. A filename to handle hash map is used for lookups. This is efficient because it happens at OSL compile time, because the optimizer can figure out constant strings and replace them with texture handles.
Diffstat (limited to 'intern/cycles/render')
-rw-r--r--intern/cycles/render/nodes.cpp26
-rw-r--r--intern/cycles/render/osl.cpp38
-rw-r--r--intern/cycles/render/osl.h3
3 files changed, 45 insertions, 22 deletions
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 16416a9a009..35e9f8df5a8 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -374,18 +374,7 @@ void ImageTextureNode::compile(OSLCompiler &compiler)
is_linear = metadata.is_linear;
}
- if (slot == -1) {
- compiler.parameter(this, "filename");
- }
- else {
- /* TODO(sergey): It's not so simple to pass custom attribute
- * to the texture() function in order to make builtin images
- * support more clear. So we use special file name which is
- * "@i<slot_number>" and check whether file name matches this
- * mask in the OSLRenderServices::texture().
- */
- compiler.parameter("filename", string_printf("@i%d", slot).c_str());
- }
+ compiler.parameter_texture("filename", filename, slot);
if (is_linear || color_space != NODE_COLOR_SPACE_COLOR)
compiler.parameter("color_space", "linear");
else
@@ -556,12 +545,7 @@ void EnvironmentTextureNode::compile(OSLCompiler &compiler)
is_linear = metadata.is_linear;
}
- if (slot == -1) {
- compiler.parameter(this, "filename");
- }
- else {
- compiler.parameter("filename", string_printf("@i%d", slot).c_str());
- }
+ compiler.parameter_texture("filename", filename, slot);
compiler.parameter(this, "projection");
if (is_linear || color_space != NODE_COLOR_SPACE_COLOR)
compiler.parameter("color_space", "linear");
@@ -1080,7 +1064,7 @@ void IESLightNode::compile(OSLCompiler &compiler)
tex_mapping.compile(compiler);
- compiler.parameter("slot", slot);
+ compiler.parameter_texture_ies("filename", slot);
compiler.add(this, "node_ies_light");
}
@@ -1567,9 +1551,7 @@ void PointDensityTextureNode::compile(OSLCompiler &compiler)
if (use_density || use_color) {
add_image();
- if (slot != -1) {
- compiler.parameter("filename", string_printf("@i%d", slot).c_str());
- }
+ compiler.parameter_texture("filename", ustring(), slot);
if (space == NODE_TEX_VOXEL_SPACE_WORLD) {
compiler.parameter("mapping", tfm);
compiler.parameter("use_mapping", 1);
diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp
index 24c5a599c1a..5ee453275b9 100644
--- a/intern/cycles/render/osl.cpp
+++ b/intern/cycles/render/osl.cpp
@@ -145,6 +145,10 @@ void OSLShaderManager::device_update(Device *device,
/* set texture system */
scene->image_manager->set_osl_texture_system((void *)ts);
+ /* add special builtin texture types */
+ og->textures.insert(ustring("@ao"), new OSLTextureHandle(OSLTextureHandle::AO));
+ og->textures.insert(ustring("@bevel"), new OSLTextureHandle(OSLTextureHandle::BEVEL));
+
device_update_common(device, dscene, scene, progress);
{
@@ -1201,6 +1205,30 @@ void OSLCompiler::compile(Scene *scene, Shader *shader)
osl_globals->bump_state.push_back(shader->osl_surface_bump_ref);
}
+void OSLCompiler::parameter_texture(const char *name, ustring filename, int svm_slot)
+{
+ if (svm_slot != -1) {
+ /* It's not so simple to pass custom attribute to the texture() function
+ * in order to make builtin images support more clear. So we use special
+ * file name which is "@i<slot_number>" and use that for lookup in
+ * in OSLRenderServices::texture(). */
+ filename = string_printf("@i%d", svm_slot).c_str();
+ osl_globals->textures.insert(filename, new OSLTextureHandle(OSLTextureHandle::SVM, svm_slot));
+ }
+ else {
+ osl_globals->textures.insert(filename, new OSLTextureHandle(OSLTextureHandle::OIIO));
+ }
+
+ parameter(name, filename);
+}
+
+void OSLCompiler::parameter_texture_ies(const char *name, int svm_slot)
+{
+ ustring filename(string_printf("@l%d", svm_slot).c_str());
+ osl_globals->textures.insert(filename, new OSLTextureHandle(OSLTextureHandle::IES, svm_slot));
+ parameter(name, filename);
+}
+
#else
void OSLCompiler::add(ShaderNode * /*node*/, const char * /*name*/, bool /*isfilepath*/)
@@ -1255,6 +1283,16 @@ void OSLCompiler::parameter_color_array(const char * /*name*/, const array<float
{
}
+void OSLCompiler::parameter_texture(const char * /* name */,
+ ustring /* filename */,
+ int /* svm_slot */)
+{
+}
+
+void OSLCompiler::parameter_texture_ies(const char * /* name */, int /* svm_slot */)
+{
+}
+
#endif /* WITH_OSL */
CCL_NAMESPACE_END
diff --git a/intern/cycles/render/osl.h b/intern/cycles/render/osl.h
index 4d930d65e45..773252ce9dc 100644
--- a/intern/cycles/render/osl.h
+++ b/intern/cycles/render/osl.h
@@ -153,6 +153,9 @@ class OSLCompiler {
void parameter_attribute(const char *name, ustring s);
+ void parameter_texture(const char *name, ustring filename, int svm_slot);
+ void parameter_texture_ies(const char *name, int svm_slot);
+
ShaderType output_type()
{
return current_type;