Eyeon:Script/Reference/Applications/Fuse/Classes/ViewShader/SetParam
From VFXPedia
Contents |
Summary
The SetParam function is used to set the value of exposed run-time parameters in the shader.
In addition to the 'ViewShader source' data member, the struct derived from the ViewShader baseclass in the shader string may also contain other data members, which can be exposed as run-time parameters. To do this, call AddParam(name), where name is the name of the data member to be exposed. This is typically done when the ViewShader object is created, in ScriptViewShader:SetupShader().
Once exposed, the value of the run-time parameter can be set with SetParam(), typically when ScriptViewShader:SetupParams() is called. Various data types are supported, including numbers, booleans, vectors, 4x4 matrices and images.
Usage
SetParam(number index, boolean bool)
SetParam(number index, number value [, number value [, number value [, number value]]])
SetParam(number index, Vector2 vec2)
SetParam(number index, Vector3f vec3)
SetParam(number index, Vector4 vec4)
SetParam(number index, Matrix4 mat4)
SetParam(number index, Image image [, table channels [, table tags]])
index (number, required)
- The index of the run-time parameter to be set
image (Image, required)
- An Image object.
channels (table, optional)
- A table containing the string "Color", to upload RGBA, or containing four channel identifier strings from the following table:
R | Red |
G | Green |
B | Blue |
A | Alpha |
Z | Depth |
U | U texcoord |
V | V texcoord |
Coverage | Z Coverage |
ObjectID | Object ID |
MaterialID | Material ID |
NX | X surface normal |
NY | Y surface normal |
NZ | Z surface normal |
BgR | Red background color |
BgG | Green background color |
BgB | Blue background color |
BgA | Alpha background color |
VectX | X motion vector |
VectY | Y motion vector |
BackVectX | X back motion vector |
BackVectY | Y back motion vector |
tags (table, optional)
- A table containing a series of tag and value strings, from the following table:
TR_GLTexTarget | Type of texture sample; "RECT" (default, pixel coords) or "2D" (normalized coords) |
TR_F3DTexDataType | Depth of texture; "int8", "int16", "float16", "float32", "ChooseSmallest" (default) |
TR_WrapModeS, TR_WrapModeT | Texture edge sampling; "Black", "Clamp" (default), "Black", and (not for RECTs) "Wrap", "Mirror" |
TR_GLMinFilter | Texture minification filter; "Linear" (default), "Nearest" |
TR_GLMagFilter | Texture magnification filter; "Linear" (default), "Nearest" |
Returns
SetParam() has no returns.
Example
This example fetches a shaded pixel from the source and applies a simple gamma.
-- Here's the Cg shader itself: shader = [[ struct GammaFuse : ViewShader { ViewShader source; // need this line float gamma; // run-time parameter void ShadePixel(inout FuPixel f) { source.ShadePixel(f); // get source pixel f.Color.rgb = pow(f.Color.rgb, gamma); // apply simple gamma } }; ]] -- This is called every display refresh -- img may be nil function SetupParams(req, vs, img) local gamma = InGamma:GetValue(req).Value; -- retrieve our current control value if gamma ~= 0.0 then gamma = 1.0 / gamma; else gamma = 1000000.0; end vs:SetParam(gammaparam, gamma); -- use the gammaparam index we got from AddParam() earlier return true; end
Example of setting a point parameter:
function SetupParams(req, vs, img) local centerx = InCenter:GetValue(req).X; -- retrieve control values local centery = InCenter:GetValue(req).Y; vs:SetParam(centerindex, centerx * imgw, centery * imgh); end
Example of uploading an Image to a texture sampler:
-- load our img only when the filename changes, not every redraw! function NotifyChanged(inp, param, time) if param then if inp == InFilename then local filename = tostring(param.Value); -- get filename as a string local clip = Clip(filename); -- make a Clip out of it (defaults to read-only) uploadimg = clip:GetFrame(0); -- get the first frame only end end end -- upload the image (table args are optional) function SetupParams(req, vs, img) vs:SetParam(imgindex, uploadimg, {"Color"}, { -- {"Color"}, {"R","G","B","A"}, {"Z","Z","Z","A"} etc TR_GLTexTarget = "2D", -- RECT (default, pixel coords), 2D (normalized coords) TR_F3DTexDataType = "int8", -- int8, int16, float16, float32, ChooseSmallest (default) TR_WrapModeS = "Black", -- Clamp (default), Black, and (not for RECTs) Wrap, Mirror TR_WrapModeT = "Black", TR_GLMinFilter = "Linear", -- Linear (default), Nearest TR_GLMagFilter = "Linear", }); end
See Also
Tips for SetParam (edit)
EyeonTips:Script/Reference/Applications/Fuse/Classes/ViewShader/SetParam