HC_Define_Shader
-
Key
HC_Define_Shader(char const *name, char const *options, char const *shader_source) - Key HC_Define_Shader(char const name, char const options, char const shader_source)
Defines a section of code that will be injected into HOOPS 3DF shaders.
There are two types of shaders that can be defined through this function call: legacy and modern. Legacy custom shaders can only be bound to the pixel shader. Modern custom shaders can be bound to both the vertex and pixel stages and allow users to define custom input and output fields as well as uniforms. This function will return a Key when used to define a modern custom shaders. All shader functions that require a Key are only valid with modern custom shaders and vice-versa. In order to define a modern custom shader the options field should just contain a string describing the stage of the pipeline where the shader will bind. Example: stage = pixel will create a legacy custom shader pixel will create a modern custom shader The main function in the source code of modern shader has to be called custom_main.
The following paragraphs only apply to legacy custom shaders
With Define_Shader, you can specify a section of code to be injected into the pixel shader instead of replacing the entire shader. The shader source can be a snippet of glsl or hlsl code that has access to lights, textures, and coordinates to use as inputs, and can override or modify values for material relating to colors and local surface normals.
Note that if your shader code uses hlsl specific calls, the driver type for your model at render time must be DX11 while shaders that use glsl specific calls will only work with OpenGL2.
All shader definitions are considered local to the current segment and below.
The options parameter to Define_Shader is a comma-separated list of settings which can include the following:
[no] multitexture = on/off
If set, any diffuse textures present in channels greater than 0 will be layered on top of the material properties that are specified in the shader. Normally, all diffuse texture input is assumed to be handled in the shader while remaining textures would be skipped. The default value is “no multitexture”.
parameterization source = source
Like textures, shaders will require some form of parameterization source to be considered active. The possible settings are as described in the Define_Texture()’s description of parameterization source. The default value for this option is “world”.
stage = xxx
This option specifies where the shader code should be injected. Currently, “material” is the only acceptable value, but future versions, HOOPS may allow other stages of the pipeline to be overridden. The default value is, of course, “material”.
[no] transform = segment
The possible settings for this option are as described in the Define_Texture()’s description of transform.
This interface is used both for defining legacy custom shader and modern custom shaders introduced with v27. Modern custom shaders allow users to define custom input / outputs as well as uniforms and use a new hlsl/glsl interface to make writing custom shaders easier and more powerful.
In order to define a modern custom shader, the option field must contain just ‘vertex’ or ‘pixel’ based on the stage of the graphics pipeline the custom shader will bind to. When defining a modern custom shader a Key to it is returned by this function. When defining a legacy custom shader this function will return -1.
Modern custom shader definitions can be deleted using Delete_By_Key.
HC_Delete_By_Key, HC_Show_Shader_By_KeyParameters
name: A name to associate with the shader code.
options: A quoted string or a string variable containing a list of the desired option settings.
shader_source: A section of shader code that be injected into the HOOPS shader.
Returns
The key to the defined shader. This value is only valid when defining modern custom shaders.