OSLMap: textureMap
OSLMap - superclass: textureMap; super-superclass:material - 11:2 - classID: #(2140830621L, 1875767309L)
The OSLMap texturemap provides a container object to hold Open Shader Language shaders. Available in 3ds Max 2019 and higher. All OSL shaders shipped with 3ds Max are instances of this class .
The OSLMap container has some constant properties that are common to all instances of OSLMaps. Other properties, such as input and output ports, and shader options, are created dynamically by the shader code, and will vary depending on the instance.
Constructor
OSLMap...
Example
This example illustrates how to create an OSLMap from a bitmap file.
function CreateOSLBitmap bitmapfilename =
(
local string_OSLShaderFilename = (getdir #maxroot) + "OSL/OSLBitmap.osl"
assert_true (doesfileexist string_OSLShaderFilename) message:("The file "+string_OSLShaderFilename+" should exist")
-- Create the OSL Map with the OSL Bitmap shader in it
theOSLBitmap = OSLMap OSLPath:string_OSLShaderFilename
-- We should have a property named "Filename"
local bool_IsProp = (IsProperty theOSLBitmap "Filename")
assert_true (bool_IsProp) message:("The file "+bitmapFilename+" should exist")
theOSLBitmap.Filename = bitmapfilename -- Assign the bitmap filename
theOSLBitmap -- return the OSLBitmap
)
-- Example of using this function:
-- Set viewport to high quality to see the bump mapping
actionMan.executeAction -844228238 "12"
-- Create a Physical Material
physMat = PhysicalMaterial()
-- Create a Box node and assign the physical material to it
bx = box width:50 height:50 length:50 backfacecull:true mapcoords:on wirecolor:(color 88 144 225)
bx.material = physMat
-- Set an OSL Bitmap into the base_color_map of the physical material
-- bitmapFilename should be a bitmap path for a bitmap with an alpha layer as it's also being assigned to the cut_out map!
bitmapFilename = @"C:\My Documents\Materials\resources\textures\ananas.png"
assert_true (doesfileexist bitmapFilename) message:("The bitmap file "+bitmapFilename+" should exist")
bumpBitmapFilename = @"C:\My Documents\Materials\resources\textures\brick_bump.jpg"
assert_true (doesfileexist bumpBitmapFilename) message:("The bitmap file "+bumpBitmapFilename+" should exist")
physMat.base_color_map = CreateOSLBitmap bitmapFilename
-- Assign an OSLBitmap in the cutout_map of the Physical Material to use transparency
theSecondOSLBitmapTex = CreateOSLBitmap bitmapFilename
-- We need to connect an MultiOutputChannelTexmapToTexmap in between the OSLMap and the physical material
-- as the OSLMap has multiple outputs, it uses under the hood an MultiOutputChannelTexmapToTexmap instance
-- which helps choosing which output is connected. By default MultiOutputChannelTexmapToTexmap conencts the first output
-- which is RGB for the OSLMap
theMultiOutputChannelTexmapToTexmap = MultiOutputChannelTexmapToTexmap sourceMap:theSecondOSLBitmapTex
theMultiOutputChannelTexmapToTexmap.outputChannelIndex = 5 -- 5 is the index of the alpha output of the OSLMap (see in the SME the outputs)
physMat.cutout_map = theMultiOutputChannelTexmapToTexmap
-- Assign an OSLBitmap in the bump_map of the Physical Material to use bump mapping
the3rdOSLBitmapTex = CreateOSLBitmap bumpBitmapFilename
physMat.bump_map = the3rdOSLBitmapTex
Properties
These properties are common to all OSLMap instances.
<OSLMap>.OSLAutoUpdate BooleanClass default: false -- boolean; OSL_Auto_Update
Specifies whether the OSL shader code is linked to the file on disk (true), or is held independently by the OSL Map in the scene. This parameter corresponds to the link icon next to the file name in the OSLMap UI.
<OSLMap>.OSLCode String -- string; OSL_Code
A string that contains the OSL shader code. The default is a simple shader that can be used as a starting point for creating a new shader.
The default shader mixes two input colors (or maps) and produces a single output color:
// Simple Example Shader with three inputs two outputs, to demo the syntax.
// For more information read the OSL Language Specifictaion:
// https://github.com/imageworks/OpenShadingLanguage/blob/master/src/doc/osl-languagespec.pdf
shader Example
[[ string help="Example shader with three inputs and two outputs<br>" ]]
(
// Inputs
color Input_A = 0.5 [[ string label = "A"]],
color Input_B = 0.5 [[ string label = "B"]],
float Mixer = 0.5 [[ float min = 0.0, float max = 1.0 ]],
// Outputs
output color Out = 0.0,
output color Mix = 0.0)
{
Out = Input_A + Input_B; // Sum
Mix = mix(Input_A, Input_B, Mixer); // Mix
}
<OSLMap>.OSLPath String default: "" -- filename; OSL_Path
If the OSL code is loaded from a file, this parameter holds the path to that file. This parameter is maintained even if the file is unlinked (by setting .OSLAutoUpdate
to false).
<OSLMap>.numIMultipleOutputChannels Integer default: 2 -- integer; Read-only
Specifies the number of output ports for the shader.
<OSLMap>.numInputs
Specifies the number of input ports.
OSLMap Example Properties
These properties exist on the default example OSLMap, and are defined by the example .OSLCode
string.
<OSLMap>.Input_A Color default: (color 127.5 127.5 127.5) -- animatable; fRGBA color; Controller Scaling: ([1,1,1,1] : (color 255 255 255)); WeirdScaled ([1,1,1,1])
<OSLMap>.Input_A_map UndefinedClass default: undefined -- texturemap
<OSLMap>.Input_B Color default: (color 127.5 127.5 127.5) -- animatable; fRGBA color; Controller Scaling: ([1,1,1,1] : (color 255 255 255)); WeirdScaled ([1,1,1,1])
<OSLMap>.Input_B_map UndefinedClass default: undefined -- texturemap
<OSLMap>.Mixer Float default: 0.5 -- animatable; float
<OSLMap>.Mixer_map UndefinedClass default: undefined -- texturemap
OSLMap interfaces
Interface: IMtlRender_Compability_MtlBase
Properties:
Methods:
Actions:
Interface: iMultipleOutputChannelsWithValues
Properties:
.numIMultipleOutputChannels : integer : Read
Gets the number of output ports for the OSLMap.
Methods:
<string>getIMultipleOutputChannelLocalizedName <index>index
getIMultipleOutputChannelLocalizedName - no automatic redraw after invoked
Returns the localized name string for the specified output channel.
<string>getIMultipleOutputChannelName <index>index
getIMultipleOutputChannelName - no automatic redraw after invoked
Returns the name string for the specified output channel.
<enum>getIMultipleOutputChannelType <index>index
getIMultipleOutputChannelType enums: {#float|#integer|#rgb|#point3|#string|#filename|#material|#texturemap|#bitmap|#node|#maxObject|#matrix3|#paramblock2|#point4|#frgba
getIMultipleOutputChannelType - no automatic redraw after invoked
Returns the type of the specified output channel.
<value>getIMultipleOutputChannelValue <index>index time:<time>
getIMultipleOutputChannelValue - no automatic redraw after invoked
time default value: 0f
Returns the value of the specified output channel at the specified time.
Actions:
Interface: iMultiOutputConsumer
This interfaces is exposed to MAXScript, but the properties and methods listed here are not implemented and cannot be used.
Properties:
.numInputs : integer : Read
Methods:
<boolean>SetOutputToInput <index>input_index <maxObject>output_rtarg <index>output_index
<maxObject>GetOutputRefTargetFromInput <index>input_index
<index>GetOutputIndexFromInput <index>input_index
<boolean>CanAssignOutputToInput <index>input_index <maxObject>output_rtarg <index>output_index
<string>GetInputName <index>input_index
GetInputName - no automatic redraw after invoked
<string>GetInputLocalizedName <index>input_index
GetInputLocalizedName - no automatic redraw after invoked
Actions: