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.
This commit is contained in:
Brecht Van Lommel
2019-05-02 12:40:24 +02:00
parent 08a44d2981
commit fadb6f3466
8 changed files with 309 additions and 202 deletions

View File

@@ -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