12
$\begingroup$

I don't know much about the Open Shading Language, but I need to know if it can do a few things before I decide to spend the time to learn it.

  1. Can OSL manipulate rays that hit surfaces? Such as: change ray colors, reflect, refract, delete it

  1. Can it also get ray data? Such as: where it came from, its source, direction, and intensity.
  2. Can it emit rays from a surface? I know that the default Cycles emission shader is written in SVM, but would it be possible make a similar shader in OSL?

$\endgroup$
  • $\begingroup$ If it can't do any of these things, what do you suggest I do? Is it possible to make a SVM shader? $\endgroup$ – Daniel Pendergast Sep 5 '13 at 19:13
  • $\begingroup$ With a little programming knowledge you will find OSL very easy to pick up (it is very close to C). The OSL spec is less than 100 pages. Even if you can't get this one scenario to work, the OSL knowledge will still be useful for other tasks. If the thought of creating a new SVM shader is an option for you then I'd expect you to be able to learn and test an OSL script within an hour. This dispersion refractive shader may be a close start to what you want. $\endgroup$ – sambler Sep 6 '13 at 6:40
  • $\begingroup$ Thanks for the info. I'm supposing that it will be easier to learn than GLSL or CG? Does that dispersion/refractive shader actually emit the dispersed rays, or does it simply color the interior of the object? $\endgroup$ – Daniel Pendergast Sep 7 '13 at 11:31
  • $\begingroup$ While OSL can do an emission output, the example shader generates a dispersed colour for a camera ray and a transparent colour for other rays. Going by brecht's answer it may not have the control you want. I'm not sure if you can get the incoming colour, so while you could specify the outgoing emission colour, you probably can't alter it based off the incoming colour. $\endgroup$ – sambler Sep 9 '13 at 8:13
10
$\begingroup$

There are some restrictions on what you can do in OSL, you can't create your own BSDF or trace your own shading rays currently. There is a raytrace function for things like ambient occlusion or other tricks, but the integrator and sampling is generally outside of the control of OSL shaders.

This is part of the OSL design, the shader describes the material or light behavior but does not describe how the integrator and sampling should work specifically. For example the renderer may do multiple importance sampling, bidirectional ray tracing, photon mapping, .. and all those methods should work with the same OSL shader.

The questions you ask seem to involve specific algorithms, in a physically based render engine creating rays is generally the job of the integrator which can make smarter decisions at a global level rather than each individual shader doing their own sampling.

$\endgroup$
  • $\begingroup$ Thanks Brecht! Two years later, today, can I use OSL to describe my own mathematical BRDF formula from scratch? Or do I have to compose from shader primitives? Thanks! $\endgroup$ – Sibbs Gambling Aug 5 '17 at 20:34
  • $\begingroup$ OSL still has no support for writing custom BSDFs, you can only use the builtin closures. $\endgroup$ – brecht Aug 5 '17 at 20:44
  • $\begingroup$ Thanks for the info! I need a BRDF for research, so it needs to be exact. In this case, is it possible at all to implement my own BRDF formula in Cycles? Is there any workaround? $\endgroup$ – Sibbs Gambling Aug 5 '17 at 20:45
  • $\begingroup$ The only way to implement a custom BSDF is to do it in the Cycles source code, if it's for research maybe the quickest way is to modify/replace an existing BSDF. $\endgroup$ – brecht Aug 5 '17 at 21:05
  • $\begingroup$ I see. Would you mind pointing me to one of the built-in shaders? I looked at developer.blender.org/diffusion/B/browse/master/intern/cycles/…, but these are all implemented in OSL. Also, this is different from writing a shader in Shader Virtual Machine, right? Is that an option too? Thanks!! $\endgroup$ – Sibbs Gambling Aug 5 '17 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.