From the course: 3ds Max: Tips, Tricks and Techniques
Basic syntax of Open Shading Language - 3ds Max Tutorial
From the course: 3ds Max: Tips, Tricks and Techniques
Basic syntax of Open Shading Language
- [Instructor] Over the next few weeks, we will explore coding a procedural map in the Open Shading Language, or OSL. OSL is a very exciting development. It allows us to author our own maps. It was introduced in 3ds Max 2019. And we're gonna spend the next few weeks learning how to author a procedural fractal noise map. OSL really has no limits. You could write your own functions, and go crazy. We're going to start simply by using one of the built-in noise pattern generators, which is a simplex noise. It's an updated version of the familiar Perlin noise, or fractal pattern. The first thing we want to do is simply get acquainted with the syntax, or the overall structure of an OSL map. I got a empty scene here. The only thing I've done is assign the Production Renderer to Arnold. Let's open up the Material Editor from its button on the main tool bar. I don't need the Navigator, so I'm gonna close that. And let's create an OSL map. If you look in the map section, you'll see a subsection labeled OSL, and within these are many maps created by Autodesk, specifically Mr. Zap Andersson authored all of these. We could take one of these, and modify it, but we want to start fresh from a blank OSL document. And to do that, we would use this OSL map which is found in the General section. So drag OSL map over, and then double-click it to load its parameters. Double-click its preview, or sample swatch in order to make it larger. And I'm not going to be using the Material Map Browser again, so I can close that. If I want to get the Material Map Browser, or the Navigator open again, I can do that from the Tools Menu here. Let's take a look at the sample code provided with this example map. That's done by clicking on the icon that looks like a pencil. And we click on that, we get the OSL code editor opening up. You notice by the way that in this example map, the icons indicate link to a file is grayed out, or darkened. So in other words, we're not currently linked to a file. Anything we do inside this code editor window is going to be local to the current map instance. And additionally of course local to the current 3ds Max scene. So anything we do in here is not going to affect anything outside of this particular map in this particular scene. We will look at how to set up the linking later. For now we just want to get familiar with the overall structure of an OSL shader. In the code editor window, we can see that it's basically divided into a few sections. At the top are some comments. Anything that follows two forward slashes is a comment. At the top we usually provide some information to describe what this shader is. In this case there's also a link to the OSL language specification document which is a must if you're going to be authoring any OSL shaders, you'll definitely want to go, and download that. Below those comments, we see the shader declaration. The word shader followed by the name of a shader, in this case, the map, which is called Example. We can have exactly one shader per OSL document. Below the shader declaration, we see some stuff here in double angle brackets. And these are metadata strings. We've got a help string, that prints out some text here, so that the user has some idea of what this particular map or shader is going to do. We've also got a URL here, which links to the 3ds Max shader repository on GitHub, and that's what this more button is here. Alright, so that is the metadata for the shader declaration. Below that we have the input, and output parameters declarations enclosed in parenthesis. There's an open parenthesis here, and then we have input declarations, output declarations, and a closed parenthesis. And just for clarity here, I'm going to insert a carriage return, and delete that tab, and then add another carriage return just to space things out. Everything within these parenthesis is an input, or output parameter. The inputs are of course the user values, that you can plug in. And those values can be numeric, or they can be other maps, or other shaders. And the we have the outputs, and those of course are what feed into materials, or other map notes. Below the input, and output parameter declarations, is a section enclosed by curly braces, and this is the statements area. The actual mathematical operations of the shader are enclosed in these curly braces. Also notice that the lines are separated by separator characters within the input, and output parameters, the separator character is a comma, but within the statement section, the separator is a semicolon. Notice also, in the statements, the last line of the statements has a semicolon after it. And that seems to be a requirement. If I remove that, if I delete that, and click the compile shader button down here, then I get a syntax error, and we get this line lighting up in red. So that's a little bit of an idiosyncrasy here, we have to have a semicolon at the end of the last line of statements, but we don't need to have a comma at the end of the last line of input, and output parameter declarations. So that is the overall structure. I can go ahead, and click compile shader here again, and it says compilation okay. Now that we know how the shader is structured, we can make some simple changes here. First thing I would do is just change the description at the top. I'll select everything after those first two forward slashes, and give this a description. I'm going to call it a basic iterated simplex noise pattern generator. That will only bee seen by someone opening up this editor window. But if we want to, we can also copy that into the string help, so I can just select that, right click, and copy. I can paste it over this line here, which is enclosed in double quotes. I'll paste that in with control V. So the string that will be displayed to the user will be basic iterated simplex noise pattern generator, and I don't want the string URL here. So I can just delete everything after that, including the comma, because we don't need a separator. So I'll just delete that with the backspace key. And we'll rename this shader as well. We'll call it simplex noise. Capital S i m p l e x. No space, capital N o i s e, and then click the compile shader button again, and we don't see any errors. We haven't changed the input, and output. We haven't changed the statements at all. All we've done is change the name, and the metadata here. So now that we can see that that's been adjusted. We've got some metadata printed out, and we've also got a new name for the OSL noise map. So we wanna save our scene at this point. Next week we will look at plugging in some input, and output declarations, and our journey to creating our own procedural noise map. So check in next week as the exercise continues.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
- Ex_Files_3DSMax_Q1_2018.zip
- Ex_Files_3DSMax_Q1_2019.zip
- Ex_Files_3DSMax_Q2_2018.zip
- Ex_Files_3DSMax_Q2_2019.zip
- Ex_Files_3DSMax_Q3_2017.zip
- Ex_Files_3DSMax_Q3_2018.zip
- Ex_Files_3DSMax_Q4_2017.zip
- Ex_Files_3DSMax_Q4_2018.zip
- Ex_Files_3DSMax_Q3_2019.zip
- Ex_Files_3DSMax_Q4_2019.zip
- Ex_Files_3DSMax_Q1_2020.zip
- Ex_Files_3DSMax_Q2_2020.zip
- Ex_Files_3DSMax_Q3_2020.zip
- Ex_Files_3DSMax_Q4_2020.zip
Contents
-
-
-
Modeling a floor plan from a 2D drafting document13m 36s
-
(Locked)
Modeling terrain with Displace space warp11m 18s
-
(Locked)
Projecting UVs with the Camera Map world-space modifier7m 46s
-
(Locked)
Capturing shadows with Arnold Shadow Matte map10m 43s
-
(Locked)
Rendering compositing passes with Arnold AOVs9m 6s
-
(Locked)
Mechanical rigging with IK and the LookAt controller9m 16s
-
(Locked)
Modulating animation with Multiply and Ease Curves13m 9s
-
(Locked)
Working with audio and the AudioFloat controller12m 8s
-
(Locked)
Automating with Expression controllers10m 13s
-
(Locked)
Real-time animation with the Motion Capture utility10m 17s
-
(Locked)
Stylized rendering with Scanline Ink 'n Paint8m 16s
-
(Locked)
Getting started with the Max Creation Graph13m 25s
-
(Locked)
Modifying a Max Creation Graph tool12m 27s
-
(Locked)
Sculpting a terrain with Texture Object Mask9m 33s
-
(Locked)
Building a road with Conform space warp11m 12s
-
(Locked)
Shading a landscape with Arnold Curvature14m 59s
-
(Locked)
Creating custom attributes with the Parameter Editor9m 1s
-
Driving animation curves with the Reaction controller6m 56s
-
(Locked)
Rigging a camera-facing matte painting10m 41s
-
(Locked)
Aligning a camera to a background with Perspective Match10m 32s
-
(Locked)
Projecting a photo to proxy geometry with Camera Map11m 49s
-
(Locked)
Automation with wire parameters and manipulators8m 18s
-
Converting scenes for different renderers10m 52s
-
(Locked)
Rendering light groups with Arnold AOVs10m 11s
-
(Locked)
Graphing scene conditions with State Sets Compositor9m 34s
-
Introduction to 3ds Max Fluids10m 18s
-
(Locked)
Modeling with the Motion Field Space Warp9m 55s
-
(Locked)
Non-destructive model adjustment with Linked Xform9m 23s
-
(Locked)
Animating sub-objects with Linked Xform10m 11s
-
(Locked)
Customize and cycle Path Constraint animation5m 54s
-
(Locked)
Generate complex motion with Waveform Controllers10m 56s
-
(Locked)
Illuminate a scene with an Arnold Mesh Light5m 49s
-
Shading with Maya maps in 3ds Max4m 32s
-
(Locked)
Varying shader properties by object with Arnold Color Jitter5m 26s
-
Render a mesh object with Arnold Standard Volume9m 47s
-
Render a Point Cloud object8m 21s
-
(Locked)
Setting track value boundaries with a limit controller4m 5s
-
(Locked)
Drawing curves with Freehand Spline8m 41s
-
(Locked)
Correcting intersections with Spline Overlap4m 38s
-
Reducing curve detail with Optimize Spline6m 42s
-
Resampling curves with Normalize Spline8m 44s
-
(Locked)
Soft-selecting curves with Spline Influence7m 42s
-
(Locked)
Blending curves with Spline Morph12m 15s
-
Combining splines with shape Booleans10m 51s
-
(Locked)
Approximating global illumination in Arnold13m 10s
-
(Locked)
Rendering proxies with Arnold procedurals10m 25s
-
(Locked)
Introduction to the Open Shading Language map11m 16s
-
Basic syntax of Open Shading Language8m 24s
-
(Locked)
Declaring OSL input and output parameters12m 53s
-
(Locked)
Generating a fractal noise pattern in OSL9m 25s
-
(Locked)
Iterating a for loop in OSL10m 16s
-
(Locked)
Using the if… else conditional statement in OSL10m 9s
-
(Locked)
Managing OSL file assets and paths10m 8s
-
(Locked)
Accelerate Arnold rendering with adaptive sampling5m 59s
-
(Locked)
Texturing with the Advanced Wood procedural map11m 2s
-
(Locked)
Art directing the Advanced Wood texture map5m 16s
-
(Locked)
Setting a fluid initial state9m 19s
-
(Locked)
In-camera compositing with Camera Map modifier7m 8s
-
(Locked)
Creating animation layers14m 33s
-
(Locked)
Collaborate online with shared views6m 14s
-
(Locked)
Rendering iridescence with Arnold Thin Film8m 17s
-
(Locked)
Loading and saving fluid presets7m 36s
-
(Locked)
Introduction to 3ds Max Interactive9m 15s
-
(Locked)
Building a motion graphics rig with Data Channel10m 18s
-
(Locked)
Creating custom project folder structures8m 28s
-
(Locked)
Open Shading Language code editor tips and tricks8m 21s
-
(Locked)
Spawning particles from a 3D map11m 18s
-
(Locked)
Rendering a starfield10m 21s
-
Faking GI with an Arnold ambient occlusion filter9m 4s
-
(Locked)
Modeling with the animation Snapshot tool6m 30s
-
(Locked)
Rendering particles with Arnold Standard Volume11m 23s
-
(Locked)
Render Arnold volume with physical values6m 38s
-
(Locked)
Volume indirect global illumination in Arnold7m 56s
-
(Locked)
Removing polygon detail with Freeform Optimize6m 26s
-
Transform and retime a cache with Fluid Loader7m 25s
-
Rendering motion blur in Arnold10m 46s
-
Drawing splines on an editable poly2m 48s
-
(Locked)
Sketching freeform topology over a polygon mesh6m 17s
-
(Locked)
Animating effects with Data Channel Decay6m 54s
-
(Locked)
Animating controllers in the Material Editor7m 17s
-
(Locked)
Painting a vertex color mask with VertexPaint9m 25s
-
(Locked)
Drawing polygon freeform strips5m 17s
-
(Locked)
Extruding polygon freeform branches2m 41s
-
(Locked)
Interactive ActiveShade in a viewport4m 35s
-
(Locked)
Fluid data channels5m 50s
-
(Locked)
Displaying fluid data channels9m 56s
-
(Locked)
Assigning UVW coordinates in an OSL network8m 52s
-
(Locked)
Using named coordinate spaces in Open Shading Language (OSL)11m 27s
-
(Locked)
Shadow group exclusion with Arnold properties5m 59s
-
(Locked)
Erasing materials with MAXScript or UVW Remove3m 3s
-
(Locked)
Understanding Fluid Churn and Vorticity channels6m 13s
-
(Locked)
Rendering Fluid channels with Arnold User Data5m 56s
-
(Locked)
Keyframe quantization and sub-frame editing with Snap Keys8m 37s
-
(Locked)
Importing a CAD solid model as a Body Object8m 38s
-
(Locked)
Solid model subtraction and intersection with Body Cutter4m 58s
-
(Locked)
Solid model union with Join Bodies6m 54s
-
(Locked)
Denoising an Arnold rendering7m 50s
-
(Locked)
Interactive Update in the animation Curve Editor2m 54s
-
(Locked)
Curve Editor view menu: Tips and tricks5m 33s
-
(Locked)
Editing animation curves with the Region Keys tool4m 56s
-
(Locked)
Combining data channels of Fluids7m 13s
-
(Locked)
Shading per object with OSL Random by Index7m 15s
-
(Locked)
Layering materials of Fluids6m 51s
-
(Locked)
Render particles as Arnold primitives3m 37s
-
(Locked)
Render PFlow particles with Arnold Shape4m 34s
-
(Locked)
Remapping colors with Arnold Ramp RGB7m 36s
-
(Locked)
Rendering contours with Arnold Toon7m 31s
-
(Locked)
Mapping Arnold Toon base color8m 55s
-
(Locked)
Controlling preview quality6m 2s
-
(Locked)
Adding information overlays to a preview with MAXScript7m 49s
-
(Locked)
Modeling with the updated Chamfer modifier9m 7s
-
(Locked)
Applying a chamfer using edge weight and depth5m 4s
-
(Locked)
Baking a map to a mesh with Assign Vertex Color9m 59s
-
(Locked)
Generating cavity and occlusion maps with Render Surface Map6m 48s
-
(Locked)
Baking multiple vertex color channels with VertexPaint9m 4s
-
(Locked)
Compositing vertex color in a shading network7m 29s
-
(Locked)
Optimizing geometry with the MultiRes modifier8m 33s
-
(Locked)
Improving viewport performance with the Substitute modifier2m 57s
-
(Locked)
Constructing a lighting assembly5m 24s
-
(Locked)
Wiring parameters in a lighting assembly8m 24s
-
(Locked)
Measuring with tape helper, the Measure Distance tool, and the Measure utility6m 39s
-
(Locked)
Display panel tips and tricks5m 12s
-
(Locked)
Quickly adjusting transforms and pivot point with the Transform Toolbox8m 39s
-
(Locked)
Stacking objects with Select and Place5m 13s
-
(Locked)
Managing objects and sub-objects with selection sets8m 17s
-
(Locked)
Referencing scenes with containers8m 51s
-
(Locked)
Changing inherited container content with Edit in Place8m 13s
-
(Locked)
Locking and unlocking container parameters9m 14s
-
(Locked)
Editing unlocked container parameters7m 16s
-
(Locked)
Projecting splines onto surfaces with ShapeMerge6m 31s
-
(Locked)
Analyzing and correcting mesh geometry with xView7m 29s
-
(Locked)
Keyframing sub-objects with the Master Point controller9m 38s
-
(Locked)
Managing scene materials with Material Explorer8m 36s
-
(Locked)
Defining a temporary transform center with working pivot8m 23s
-
(Locked)
Customizing keyboard shortcuts with Hotkey editor6m 56s
-
(Locked)
Stylized rendering with OSL Halftone Dots map4m 44s
-
(Locked)
Incorporating scene lighting in a shading network5m 20s
-
(Locked)
Incorporating render resolution in a shading network7m 32s
-
(Locked)
Situating geometry within an OSL HDRI environment6m 9s
-
(Locked)
Studio lighting with HDRI lights map8m 9s
-
(Locked)
White balance and exposure with an Arnold camera filtermap5m 11s
-
(Locked)
Rasterizing maps with bake to texture9m 45s
-
(Locked)
Advanced baking with bake to texture8m 26s
-
(Locked)
Baking to physically based renderer (PBR) materials for export7m 35s
-
(Locked)
Production rendering with Quicksilver hardware12m 11s
-
(Locked)
Varying textures with OSL Randomized Bitmaps11m 29s
-
(Locked)
Deforming a particle system with the Mesher compound object4m 49s
-
(Locked)
Set up Arnold render passes with AOV Manager8m 19s
-
(Locked)
Animating multiple tracks with Parameter Collector6m 45s
-
(Locked)
Improving edge smoothing with Weighted Normals modifier7m 35s
-
(Locked)
Rendering a cutaway with the Arnold Clip Geo material4m 14s
-
(Locked)
Advanced procedural noise with Uber Noise map13m 14s
-
(Locked)
Rendering polygon edges with OSL Wireframe map7m 32s
-
(Locked)
Art directing the OSL Wireframe map5m 55s
-
(Locked)
Introduction to MassFX Rigid Body dynamics7m 30s
-
(Locked)
Setting up a MassFX Rigid Body simulation5m 14s
-
(Locked)
Controlling a MassFX Rigid Body simulation7m 40s
-
(Locked)
Fine-tuning a MassFX Rigid Body simulation7m 42s
-
(Locked)
Automating secondary animation with the Flex modifier7m 2s
-
(Locked)
Keyframing modeling commands with the Edit Poly Animate mode4m 44s
-
(Locked)
Generating UVs with OSL projection maps5m 33s
-
(Locked)
Retiming all keyframes in a scene with the world track6m 53s
-
(Locked)
Snapping surfaces dynamically with MCG Ray Constraint6m 1s
-
(Locked)
Complex sub-object selections with the Selection ribbon7m 30s
-
(Locked)
Adding polygon edges with Paint Connect4m 33s
-
(Locked)
Manipulating sub-objects without changing mapping with Preserve UVs3m 41s
-
(Locked)
Hiding geometry based on distance with Viewport Clipping2m 53s
-
(Locked)
Navigating a scene with walkthrough mode3m 55s
-
(Locked)
Parametric soft transforms with Affect Region4m 1s
-