[Bf-blender-cvs] [349affe] master: Cycles: Implement proper texture derivatives evaluation for OSL

Sergey Sharybin noreply at git.blender.org
Fri Dec 18 17:51:03 CET 2015


Commit: 349affe3707b5b383cc6652bdaba1679a692a101
Author: Sergey Sharybin
Date:   Fri Dec 18 21:42:04 2015 +0500
Branches: master
https://developer.blender.org/rB349affe3707b5b383cc6652bdaba1679a692a101

Cycles: Implement proper texture derivatives evaluation for OSL

This was an oldie TODO since initial work on newer OSL/OIIO support.
Now we should be ready for the libraries bump.

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

M	intern/cycles/kernel/osl/osl_services.cpp
M	intern/cycles/kernel/osl/osl_services.h

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

diff --git a/intern/cycles/kernel/osl/osl_services.cpp b/intern/cycles/kernel/osl/osl_services.cpp
index b0609ad..db53f2d 100644
--- a/intern/cycles/kernel/osl/osl_services.cpp
+++ b/intern/cycles/kernel/osl/osl_services.cpp
@@ -840,14 +840,85 @@ bool OSLRenderServices::has_userdata(ustring name, TypeDesc type, OSL::ShaderGlo
 	return false; /* never called by OSL */
 }
 
-bool OSLRenderServices::texture(ustring filename, TextureOpt &options,
+#if OSL_LIBRARY_VERSION_CODE < 10600
+bool OSLRenderServices::texture(ustring filename,
+                                TextureOpt &options,
                                 OSL::ShaderGlobals *sg,
-                                float s, float t, float dsdx, float dtdx,
-                                float dsdy, float dtdy, int nchannels, float *result)
+                                float s, float t,
+                                float dsdx, float dtdx,
+                                float dsdy, float dtdy,
+                                float *result)
 {
 	OSL::TextureSystem *ts = osl_ts;
 	ShaderData *sd = (ShaderData *)(sg->renderstate);
 	KernelGlobals *kg = sd->osl_globals;
+	OSLThreadData *tdata = kg->osl_tdata;
+	OIIO::TextureSystem::Perthread *texture_thread_info =
+	       tdata->oiio_thread_info;
+	OIIO::TextureSystem::TextureHandle *texture_handle =
+	       ts->get_texture_handle(filename, texture_thread_info);
+	return texture(filename,
+	               texture_handle,
+	               texture_thread_info,
+	               options,
+	               sg,
+	               s, t,
+	               dsdx, dtdx, dsdy, dtdy,
+	               options.nchannels,
+	               result,
+	               NULL, NULL);
+}
+
+bool OSLRenderServices::texture3d(ustring filename,
+                                  TextureOpt &options,
+                                  OSL::ShaderGlobals *sg,
+                                  const OSL::Vec3 &P,
+                                  const OSL::Vec3 &dPdx,
+                                  const OSL::Vec3 &dPdy,
+                                  const OSL::Vec3 &dPdz,
+                                  float *result)
+{
+	OSL::TextureSystem *ts = osl_ts;
+	ShaderData *sd = (ShaderData *)(sg->renderstate);
+	KernelGlobals *kg = sd->osl_globals;
+	OSLThreadData *tdata = kg->osl_tdata;
+	OIIO::TextureSystem::Perthread *texture_thread_info =
+	       tdata->oiio_thread_info;
+	OIIO::TextureSystem::TextureHandle *texture_handle =
+	       ts->get_texture_handle(filename, texture_thread_info);
+	return texture3d(filename,
+	                 texture_handle,
+	                 texture_thread_info,
+	                 options,
+	                 sg,
+	                 P,
+	                 dPdx, dPdy, dPdz,
+	                 options.nchannels,
+	                 result,
+	                 NULL, NULL, NULL);
+}
+#endif  /* OSL_LIBRARY_VERSION_CODE < 10600 */
+
+bool OSLRenderServices::texture(ustring filename,
+                                TextureHandle *texture_handle,
+                                TexturePerthread *texture_thread_info,
+                                TextureOpt &options,
+                                OSL::ShaderGlobals *sg,
+                                float s, float t,
+                                float dsdx, float dtdx, float dsdy, float dtdy,
+                                int nchannels,
+                                float *result,
+                                float *dresultds,
+                                float *dresultdt)
+{
+	OSL::TextureSystem *ts = osl_ts;
+	ShaderData *sd = (ShaderData *)(sg->renderstate);
+	KernelGlobals *kg = sd->osl_globals;
+
+	if(texture_thread_info == NULL) {
+		OSLThreadData *tdata = kg->osl_tdata;
+		texture_thread_info = tdata->oiio_thread_info;
+	}
 
 #ifdef WITH_PTEX
 	/* todo: this is just a quick hack, only works with particular files and options */
@@ -902,19 +973,38 @@ bool OSLRenderServices::texture(ustring filename, TextureOpt &options,
 		status = true;
 	}
 	else {
-		OSLThreadData *tdata = kg->osl_tdata;
-		OIIO::TextureSystem::Perthread *thread_info = tdata->oiio_thread_info;
-
-		OIIO::TextureSystem::TextureHandle *th = ts->get_texture_handle(filename, thread_info);
-
 #if OIIO_VERSION < 10500
-		status = ts->texture(th, thread_info,
-		                     options, s, t, dsdx, dtdx, dsdy, dtdy,
+		(void) dresultds;  /* Ignored. */
+		(void) dresultdt;  /* Ignored. */
+		status = ts->texture(texture_handle,
+		                     texture_thread_info,
+		                     options,
+		                     s, t,
+		                     dsdx, dtdx,
+		                     dsdy, dtdy,
 		                     result);
 #else
-		status = ts->texture(th, thread_info,
-		                     options, s, t, dsdx, dtdx, dsdy, dtdy,
-		                     nchannels, result);
+		if(texture_handle != NULL) {
+			status = ts->texture(texture_handle,
+			                     texture_thread_info,
+			                     options,
+			                     s, t,
+			                     dsdx, dtdx,
+			                     dsdy, dtdy,
+			                     nchannels,
+			                     result,
+			                     dresultds, dresultdt);
+		}
+		else {
+			status = ts->texture(filename,
+			                     options,
+			                     s, t,
+			                     dsdx, dtdx,
+			                     dsdy, dtdy,
+			                     nchannels,
+			                     result,
+			                     dresultds, dresultdt);
+		}
 #endif
 	}
 
@@ -932,14 +1022,30 @@ bool OSLRenderServices::texture(ustring filename, TextureOpt &options,
 	return status;
 }
 
-bool OSLRenderServices::texture3d(ustring filename, TextureOpt &options,
-                                  OSL::ShaderGlobals *sg, const OSL::Vec3 &P,
-                                  const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy,
-                                  const OSL::Vec3 &dPdz, int nchannels, float *result)
+bool OSLRenderServices::texture3d(ustring filename,
+                                  TextureHandle *texture_handle,
+                                  TexturePerthread *texture_thread_info,
+                                  TextureOpt &options,
+                                  OSL::ShaderGlobals *sg,
+                                  const OSL::Vec3 &P,
+                                  const OSL::Vec3 &dPdx,
+                                  const OSL::Vec3 &dPdy,
+                                  const OSL::Vec3 &dPdz,
+                                  int nchannels,
+                                  float *result,
+                                  float *dresultds,
+                                  float *dresultdt,
+                                  float *dresultdr)
 {
 	OSL::TextureSystem *ts = osl_ts;
 	ShaderData *sd = (ShaderData *)(sg->renderstate);
 	KernelGlobals *kg = sd->osl_globals;
+
+	if(texture_thread_info == NULL) {
+		OSLThreadData *tdata = kg->osl_tdata;
+		texture_thread_info = tdata->oiio_thread_info;
+	}
+
 	bool status;
 	if(filename[0] == '@') {
 		int slot = atoi(filename.c_str() + 1);
@@ -955,16 +1061,36 @@ bool OSLRenderServices::texture3d(ustring filename, TextureOpt &options,
 		status = true;
 	}
 	else {
-		OSLThreadData *tdata = kg->osl_tdata;
-		OIIO::TextureSystem::Perthread *thread_info = tdata->oiio_thread_info;
-		OIIO::TextureSystem::TextureHandle *th = ts->get_texture_handle(filename, thread_info);
 #if OIIO_VERSION < 10500
-		status = ts->texture3d(th, thread_info,
-		                       options, P, dPdx, dPdy, dPdz, result);
+		(void) dresultds;  /* Ignored. */
+		(void) dresultdt;  /* Ignored. */
+		(void) dresultdr;  /* Ignored. */
+		status = ts->texture3d(texture_handle,
+		                       texture_thread_info,
+		                       options,
+		                       P,
+		                       dPdx, dPdy, dPdz,
+		                       result);
 #else
-		status = ts->texture3d(th, thread_info,
-		                       options, P, dPdx, dPdy, dPdz,
-		                       nchannels, result);
+		if(texture_handle != NULL) {
+			status = ts->texture3d(texture_handle,
+			                       texture_thread_info,
+			                       options,
+			                       P,
+			                       dPdx, dPdy, dPdz,
+			                       nchannels,
+			                       result,
+			                       dresultds, dresultdt, dresultdr);
+		}
+		else {
+			status = ts->texture3d(filename,
+			                       options,
+			                       P,
+			                       dPdx, dPdy, dPdz,
+			                       nchannels,
+			                       result,
+			                       dresultds, dresultdt, dresultdr);
+		}
 #endif
 	}
 
diff --git a/intern/cycles/kernel/osl/osl_services.h b/intern/cycles/kernel/osl/osl_services.h
index aa2befd..f35ddca 100644
--- a/intern/cycles/kernel/osl/osl_services.h
+++ b/intern/cycles/kernel/osl/osl_services.h
@@ -40,7 +40,6 @@ class Shader;
 struct ShaderData;
 struct float3;
 struct KernelGlobals;
-
 class OSLRenderServices : public OSL::RendererServices
 {
 public:
@@ -94,42 +93,26 @@ public:
 	bool getmessage(OSL::ShaderGlobals *sg, ustring source, ustring name,
 	                TypeDesc type, void *val, bool derivatives);
 
-	bool texture(ustring filename, TextureOpt &options,
-	             OSL::ShaderGlobals *sg,
-	             float s, float t, float dsdx, float dtdx,
-	             float dsdy, float dtdy, int nchannels, float *result);
-
-	bool texture3d(ustring filename, TextureOpt &options,
-	               OSL::ShaderGlobals *sg, const OSL::Vec3 &P,
-	               const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy,
-	               const OSL::Vec3 &dPdz, int nchannels, float *result);
+#if OSL_LIBRARY_VERSION_CODE < 10600
+	typedef TextureSystem::TextureHandle TextureHandle;
+	typedef TextureSystem::Perthread TexturePerthread;
+#endif
 
-#if OSL_LIBRARY_VERSION_CODE >= 10600
 	bool texture(ustring filename,
-	             TextureHandle * /*texture_handle*/,
-	             TexturePerthread * /*texture_thread_info*/,
+	             TextureSystem::TextureHandle *texture_handle,
+	             TexturePerthread *texture_thread_info,
 	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list