<div dir="ltr">A fix for this issue is now in master. Please see the commit message for explanation:<div><a href="https://developer.blender.org/rBd59f53f7b7dac5eff66fcf182f2cdc7dfabd6f87">https://developer.blender.org/rBd59f53f7b7dac5eff66fcf182f2cdc7dfabd6f87</a><br>
</div><div><br></div><div>This does not include OSL query support yet and the way input/output declaration is separate from input value specification is a bit awkward, but at least this should make OSL shaders fully functional with Cycles standalone.</div>
<div><br></div><div>Cheers,</div><div>Lukas</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Feb 13, 2014 at 4:03 PM, Brecht Van Lommel <span dir="ltr">&lt;<a href="mailto:brechtvanlommel@pandora.be" target="_blank">brechtvanlommel@pandora.be</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
The situation is currently that the there isn&#39;t any stable API or<br>
complete file format, so integrating Cycles in another application is<br>
going to be tricky right now.<br>
<br>
About OSL parameters I agree with Lukas, I think the node inputs and<br>
outputs could be created from the XML file / API without doing an OSL<br>
query. This should fit what Blender does, and postponing that kind of<br>
work is better for multithreading or lazy loading in the future.<br>
<span class="HOEnZb"><font color="#888888"><br>
Brecht.<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
On Thu, Feb 13, 2014 at 1:14 PM, Lukas Tönne &lt;<a href="mailto:lukas.toenne@gmail.com">lukas.toenne@gmail.com</a>&gt; wrote:<br>
&gt; Hi John,<br>
&gt;<br>
&gt; Great to see Cycles being used outside of Blender context, really promising.<br>
&gt;<br>
&gt; Thomas Dinges and i have been discussing the issue of OSL scripts and<br>
&gt; parameters a while ago.<br>
&gt;<br>
&gt; Cycles handles OSL script nodes roughly like so:<br>
&gt;<br>
&gt; 1) Internal node instance of &quot;OSLScriptNode&quot; type is generated, either from<br>
&gt; Blender DNA data (regular Blender nodes) or the XML file description<br>
&gt;     This stores a file path to the script source (in case of DNA nodes can<br>
&gt; also use cached .oso bytecode to avoid recompiling)<br>
&gt;<br>
&gt; 2) The script node is converted into OSL shader instances using the filepath<br>
&gt; or bytecode<br>
&gt;     OSL input/output parameter defaults and connections are set at this<br>
&gt; point.<br>
&gt;     For DNA nodes it uses links and default values from the editor.<br>
&gt;     For XML we don&#39;t have a complete equivalent system in place yet, which<br>
&gt; is what you experienced.<br>
&gt;<br>
&gt; The output/output_type thing is basically a placeholder at this point, which<br>
&gt; allows only the most basic shaders to run using only default input param<br>
&gt; values and a single output value.<br>
&gt;<br>
&gt; The main idea for standalone Cycles to support arbitrary OSL scripts is to<br>
&gt; make a flexible input/output XML attribute, so you can assign connections<br>
&gt; and values to any possible parameter. This would be based purely on<br>
&gt; parameter names, which is the main way of identifying parameters in OSL<br>
&gt; anyway. This means you don&#39;t have to define ALL the parameters for a script<br>
&gt; node, and you don&#39;t have to worry about non-existent parameters either. As<br>
&gt; long as you know what sort of input/output parameters a script has this<br>
&gt; would be perfectly fine and sufficient to get you going.<br>
&gt;<br>
&gt; As a feature *on top of that* we might support OSL queries via Cycles. That<br>
&gt; would be entirely optional and wouldn&#39;t have to be connected to XML or<br>
&gt; rendering even. All it would do is parse a given shader script and return<br>
&gt; info about the parameters and metadata, so you don&#39;t have to link OSL<br>
&gt; yourself if you already work with Cycles.<br>
&gt;<br>
&gt; As for closures:<br>
&gt; Yes, you can use the full range of closures provided by OSL directly (e.g.<br>
&gt; diffuse() ), all of these builtin functions/closures are available.<br>
&gt; In addition to that you can also create the equivalent Cycles nodes in the<br>
&gt; XML. Many nodes are just thin wrappers around the basic OSL closures to<br>
&gt; define them in the Cycles universe as nodes.<br>
&gt;<br>
&gt; If you want to import entire existing shader networks into Cycles it&#39;s<br>
&gt; probably best to make a script node for each of them (provided the<br>
&gt; limitations you found are sorted out).<br>
&gt;<br>
&gt; The only thing that should be avoided in OSL scripts for Cycles is use of<br>
&gt; the Ci global variable, which defines the final output closure. This<br>
&gt; variable is set by the Cycles Output node and doing this in script nodes<br>
&gt; could mess up the expected shader:<br>
&gt; <a href="https://developer.blender.org/diffusion/B/browse/master/intern/cycles/kernel/shaders/node_output_surface.osl" target="_blank">https://developer.blender.org/diffusion/B/browse/master/intern/cycles/kernel/shaders/node_output_surface.osl</a><br>

&gt;<br>
&gt; You can construct a complex closure entirely inside your own custom script,<br>
&gt; and then only pass this out as a single parameter and connect it to the<br>
&gt; standard Cycles output node.<br>
&gt;<br>
&gt; Best regards,<br>
&gt; Lukas Tönne<br>
&gt;<br>
&gt;<br>
&gt; On Thu, Feb 13, 2014 at 9:50 AM, John Haddon &lt;<a href="mailto:thehaddonyoof@gmail.com">thehaddonyoof@gmail.com</a>&gt;<br>
&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hi,<br>
&gt;&gt;<br>
&gt;&gt; Thanks very much for your work towards making Cycles into a standalone<br>
&gt;&gt; renderer. I&#39;ve made a small start on an experimental exporter for it<br>
&gt;&gt; in Gaffer, a procedural scene assembly tool I&#39;ve been working on. So<br>
&gt;&gt; far it&#39;s been very straightforward, and basic mesh and camera export<br>
&gt;&gt; seems to be working fine.<br>
&gt;&gt;<br>
&gt;&gt; <a href="https://github.com/johnhaddon/gafferCycles" target="_blank">https://github.com/johnhaddon/gafferCycles</a><br>
&gt;&gt;<br>
&gt;&gt; I&#39;m now looking at exporting shaders and I&#39;m hitting a few hurdles.<br>
&gt;&gt; Gaffer already loads OSL shaders and can build networks from them, so<br>
&gt;&gt; I had hoped it would be fairly straightforward to export them to<br>
&gt;&gt; Cycles. Unfortunately as far as I can tell, OSL shaders aren&#39;t really<br>
&gt;&gt; properly supported in Cycles XML. As I understand it, the problem is<br>
&gt;&gt; that OSLScriptNodes start out with no input or output sockets, so the<br>
&gt;&gt; code to transfer parameter values from the XML to the shader has<br>
&gt;&gt; nothing to transfer them onto. The output socket seems to be specified<br>
&gt;&gt; manually with the &quot;output&quot; and &quot;output_type&quot; XML attributes, but there<br>
&gt;&gt; is no equivalent for input sockets.<br>
&gt;&gt;<br>
&gt;&gt; Assuming that is correct, I wonder what you think is the best approach<br>
&gt;&gt; to fixing this? Perhaps the OSLScriptNode could be extended with a<br>
&gt;&gt; load_shader() method which uses OSL::OSLQuery to build the sockets<br>
&gt;&gt; automatically, and then the existing parameter loading code in the XML<br>
&gt;&gt; loader would work? Or do you think it would be best to support<br>
&gt;&gt; additional arbitrary XML attributes to manually describe the sockets<br>
&gt;&gt; using some sort of in_* in_type_* syntax? My preference would be for<br>
&gt;&gt; the former, but I have no real understanding of the codebase on which<br>
&gt;&gt; to base my opinion.<br>
&gt;&gt;<br>
&gt;&gt; &gt;From the examples, I&#39;m also not clear as to how full the OSL support<br>
&gt;&gt; is in terms of using OSL surface shaders (rather than just pattern<br>
&gt;&gt; generators). Am I right in thinking that the scene_osl_stripes.xml<br>
&gt;&gt; example file connects an OSL pattern generator into a built-in shader<br>
&gt;&gt; node rather than using an OSL closure to perform the final shading? If<br>
&gt;&gt; so, is it possible to actually use an OSL surface shader with closures<br>
&gt;&gt; to do the entire render? My main interest in Cycles at present is for<br>
&gt;&gt; the OSL support, so before I go any further it&#39;d be great to know if<br>
&gt;&gt; there are any other gotchas awaiting...<br>
&gt;&gt;<br>
&gt;&gt; Thanks once again for your work on Cycles, and for any assistance you<br>
&gt;&gt; might be able to offer...<br>
&gt;&gt;<br>
&gt;&gt; Cheers...<br>
&gt;&gt; John<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Bf-cycles mailing list<br>
&gt;&gt; <a href="mailto:Bf-cycles@blender.org">Bf-cycles@blender.org</a><br>
&gt;&gt; <a href="http://lists.blender.org/mailman/listinfo/bf-cycles" target="_blank">http://lists.blender.org/mailman/listinfo/bf-cycles</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Bf-cycles mailing list<br>
&gt; <a href="mailto:Bf-cycles@blender.org">Bf-cycles@blender.org</a><br>
&gt; <a href="http://lists.blender.org/mailman/listinfo/bf-cycles" target="_blank">http://lists.blender.org/mailman/listinfo/bf-cycles</a><br>
&gt;<br>
_______________________________________________<br>
Bf-cycles mailing list<br>
<a href="mailto:Bf-cycles@blender.org">Bf-cycles@blender.org</a><br>
<a href="http://lists.blender.org/mailman/listinfo/bf-cycles" target="_blank">http://lists.blender.org/mailman/listinfo/bf-cycles</a><br>
</div></div></blockquote></div><br></div>