Custom shaders

Defining a custom shader

Before a custom shader can be used, it needs to be defined through a call to HC_Define_Shader. HC_Define_Shader will return the shader definition key upon success, or -1 if an error occurred. In order to define a shader, three things are needed:

  • a name – this field is not used by Visualize, and is only available to allow developers to associate the shader definition with a string.
  • a stage – this field determines which stage of the graphics pipeline the shader will be bound to. Currently the only two options available are vertex and pixel.
  • the shader source – this is a string containing the source which will be injected in the Visualize shaders. Either GLSL or HLSL source is allowed. If you wish to run your code using different graphics driver, the source you provide should compile on all of them. The shader source must be contained in a function called custom_main with the following signature:
// For vertex shaders
void custom_main(inout VertexShaderContext ctx)
// For pixel shaders
void custom_main(inout PixelShaderContext ctx)

The VertexShaderContext and PixelShaderContext are the two structures which will be used to interact with Visualize shader code. They are defined as follows:

struct VertexShaderContext {
vertex_input vinput; //Input vertex data, unchanged by Visualize
vertex_output voutput; //Output vertex data, already processed by Visualize vertex shader. Will be passed to the pixel shader.
};
struct PixelShaderContext {
pixel_input pinput; //Input pixel data, unchanged by Visualize
pixel_output poutput; //Output pixel data, already processed by Visualize pixel shader. Will be passed to Output Merger pipeline stage.
};

Using custom shaders

Once a custom shader has been defined it needs to be set on a segment, like any other attribute, in order for it to take effect during drawing. This can be done through the HC_Set_Shader function. The function allows to set both a vertex and a pixel shader at the same time, but only one of the two is required.

The target parameter for the function determines which kind of geometry will be affected by the shader, with the possible choices being triangles, lines, points.

There is no one-to-one mapping between HOOPS geometry types and the target used by the Set_Shader function. For example, text might be rendered as triangles, lines or points, depending on the rendering options which are selected.

Since custom shaders are attributes, they will inherit down the scene graph.

Limitations

Using a custom vertex shader to change the output vertex position will cause issues when using highlight and selection features.

Example

This example shows how to define and set a custom shader which will always draw triangles and lines in red:

static const char ps_source[] = {
"void custom_main(inout PixelShaderContext ctx) { \n"
"\tctx.poutput.FinalColor = float4(1.0, 0.0, 0.0, 0.0);\n"
"}\n\n"
};
HC_KEY shader_key = HC_Define_Shader("red_shader", "pixel", ps_source);
HC_Set_Shader("triangles, lines", HC_ERROR_KEY, shader_key);

Passing custom data between shaders

By default, the pixel shader has access to the contents of the vertex_output / pixel_input structures (the two structures are always identical). It is possible to add custom fields to this structure and to assign a value to them in the vertex shader, so that they can be optionally interpolated by the graphics pipeline before becoming available as an input to the pixel shader.

The Set_Shader_Outputs function is used to define new vertex output fields. Three things are needed in order to define a new output field:

  • its name – in order to avoid conflict with other variables defined by the Visualize shaders, user_ will be automatically prepended to the name selected
  • its type
  • whether or not the value of the field should be interpolated

Note that Set_Shader_Outputs can only be called on a custom vertex shader.

Example

// The custom field can be accessed in the vertex shader as
// ctx.voutput.user_customField
static const char vs_source[] = {
"void custom_main(inout VertexShaderContext ctx) { \n"
"\tctx.voutput.user_customField = float3(1.0, 0.0, 0.0);\n"
"}\n\n"
};
// The custom field can be accessed in the pixel shader as
// ctx.pinput.user_customField
static const char ps_source[] = {
"void custom_main(inout PixelShaderContext ctx) { \n"
"\tfloat calculation = dot(ctx.pinput.user_customField, float3(ctx.pinput.position.xyz));\n"
"\tcalculation = saturate(calculation);\n"
"\tctx.poutput.FinalColor.x = calculation;\n"
"}\n\n"
};
HC_KEY vertex_shader_key = HC_Define_Shader("v_shader", "vertex", vs_source);
HC_KEY pixel_shader_key = HC_Define_Shader("p_shader", "pixel", ps_source);
HC_Set_Shader("triangles, lines", vertex_shader_key, pixel_shader_key);
HC_Set_Shader_Outputs(vertex_shader_key, "customField = (type = float3, interpolation)");

Limitations

There is a finite amount of fields that can be output from the vertex shader. This number changes from driver to driver and sometimes also based on the GPU running the code. Additionally, Visualize will use a variable number of outputs based on the complexity of the scene that needs to be rendered.

This means that you should use the minimum amount of outputs possible in order to avoid encountering this limitation

Guaranteeing data availability

The contents of the vertex_input and pixel_input structs change from one draw call to the next, based on what Visualize determines is necessary for rendering the geometry being drawn. This means that a custom shader that uses a vertex's normal to complete some calculation might fail to compile in the case where Visualize determined that a scene did not need normals in order to be rendered.

To work around this issue it is possible to request that some inputs to the vertex and pixel shader be always made available through a call to Set_Shader_Inputs. Different shader types have different fields that can be requested:

InputAvailable stages

Available field

normalvertexvinput.normal
eye positionpixelpinput.eye_position
eye normalpixelpinput.eye_normal
object viewpixelpinput.object_view
object normalpixelpinput.object_normal
texcoord[0-7]vertex, pixelvinput.texcoord[0-7], pinput.texcoord[0-7]

Example

// My custom shader uses the vertex normal for calculations, therefore I need to make sure
// it is available to the shader
static const char vs_source[] = {
"void custom_main(inout VertexShaderContext ctx) { \n"
"\tctx.voutput.user_customField = normalize(mul(ctx.vinput.normal, GetNormalizedModelMatrix(ctx.vinput)));\n"
"}\n\n"
};
static const char ps_source[] = {
"void custom_main(inout PixelShaderContext ctx) { \n"
"\tfloat calculation = dot(ctx.pinput.user_customField, float3(ctx.pinput.position.xyz));\n"
"\tcalculation = saturate(calculation);\n"
"\tctx.poutput.FinalColor.x = calculation;\n"
"}\n\n"
};
HC_KEY vertex_shader_key = HC_Define_Shader("v_shader", "vertex", vs_source);
HC_KEY pixel_shader_key = HC_Define_Shader("p_shader", "pixel", ps_source);
HC_Set_Shader("triangles, lines", vertex_shader, shader_key);
HC_Set_Shader_Outputs(vertex_shader_key, "customField = (type = float3, interpolation)");
HC_Set_Shader_Inputs(vertex_shader_key, "normal");

Limitations

  • Texture coordinates can only be requested in order: HC_Set_Shader_Inputs(key, "texcoord2, texcoord0, texcoord1") is a valid call because it requests texture coordinates 0 through 2, while HC_Set_Shader_Inputs(key, "texcoord2, texcoord0") is not a valid call because it requests texture coordinates 0 and 2 while omitting 1.

  • Certain options will only provide the requested input at runtime if the geometry being drawn supports that option. For example, texture coordinates will only be available when drawing geometry that can be textured: shells and meshes.

  • If texture coordinates are requested as inputs, any kind of texturing will be disabled (this includes bump mapping, diffuse texturing, etc…) and Visualize will expect that 4 vertex parameters will be available for each vertex of triangles drawn under such a shader.

Structs

Only struct members which are deemed of interest to our partners are explained here.

The description for the availability column is an approximation. To find out exactly when every field is available it is always best to refer to the code directly, since the circumstances can change.

What follows is a description of the fields in the structs which are used in the vertex and pixel shader.

The contents of the structs change from one draw call to the other based on what is needed to render the draw call. As such, when writing custom shaders, customers are only allowed to refer to a field if the conditions in the Availability column for that field are satisfied.

When the Availability value of a field is listed as Needs to be requested, the user should request the field through a call to Set_Shader_Input.

vertex_input

The type of the position field is POS_TYPE.

POS_TYPE can be either a float3 or a float4 depending on how transform data is bound to the shader.

When POS_TYPE is a float4 its w component is an index into a structured buffer.

If the geometry was inserted with double precision and the underlying graphics API supports passing doubles as vertex attributes (presently only true for OpenGL2), POS_TYPE will be either double3 or double4.

TypeInterpolatedNameAvailability

Description

POS_TYPEyespositionAlways availableVertex position in object space
float3yesnormalNeeds to be requestedVertex normal in object space
float4yestangentOnly available for triangles when bump textures are activeVertex tangent in object space
float2yesfindexOnly available when color is assigned by fractional index (example: because of a call to HC_Set_Color_By_FIndex)UV coordinates used to lookup color of geometry colored by FIndex
float4yestexcoord0Only defined if there is at least one diffuse texture bound to the shader or if requested by the userContains the UVW coordinates for the texture. The alpha component is not used
float4yestexcoord1Only defined if there are at least two diffuse textures bound to the shader or if requested by the userContains the UVW coordinates for the texture. The alpha component is not used
float4yestexcoord2Only defined if there are at least three diffuse textures bound to the shader or if requested by the userContains the UVW coordinates for the texture. The alpha component is not used
float4yestexcoord3Only defined if there are at least four diffuse textures bound to the shader or if requested by the userContains the UVW coordinates for the texture. The alpha component is not used
float4yestexcoord4Only defined if there are at least five diffuse textures bound to the shader or if requested by the userContains the UVW coordinates for the texture. The alpha component is not used
float4yestexcoord5Only defined if there are at least six diffuse textures bound to the shader or if requested by the userContains the UVW coordinates for the texture. The alpha component is not used
float4yestexcoord6Only defined if there are at least seven diffuse textures bound to the shader or if requested by the userContains the UVW coordinates for the texture. The alpha component is not used
float4yestexcoord7Only defined if there are at least eight diffuse textures bound to the shader or if requested by the userContains the UVW coordinates for the texture. The alpha component is not used
float4yesbacktexcoord0Only defined if there is at least one back face diffuse texture bound to the shaderContains the UVW coordinates for the texture. The alpha component is not used
float4yesbacktexcoord1Only defined if there are at least two back face diffuse textures bound to the shaderContains the UVW coordinates for the texture. The alpha component is not used
float4yesbacktexcoord2Only defined if there are at least three back face diffuse textures bound to the shaderContains the UVW coordinates for the texture. The alpha component is not used
float4yesbacktexcoord3Only defined if there are at least four back face diffuse textures bound to the shaderContains the UVW coordinates for the texture. The alpha component is not used
float4yesbacktexcoord4Only defined if there are at least five back face diffuse textures bound to the shaderContains the UVW coordinates for the texture. The alpha component is not used
float4yesbacktexcoord5Only defined if there are at least six back face diffuse textures bound to the shaderContains the UVW coordinates for the texture. The alpha component is not used
float4yesbacktexcoord6Only defined if there are at least seven back face diffuse textures bound to the shaderContains the UVW coordinates for the texture. The alpha component is not used
float4yesbacktexcoord7Only defined if there are at least eight back face diffuse textures bound to the shaderContains the UVW coordinates for the texture. The alpha component is not used
float3yesuvsmirrorOnly available if a mirror texture is bound to the shaderWhen using spherical parameterization source it contains a non-normalized vector pointing in the direction to be sampled. Otherwise it contains the UV coordinates for sampling the mirror texture
float3yesuvsspecOnly available if a specular texture is bound to the shaderWhen using spherical parameterization source it contains a non-normalized vector pointing in the direction to be sampled. Otherwise it contains the UV coordinates for sampling the specular texture
float3yesuvsbumpOnly available if a bump texture is bound to the shaderWhen using spherical parameterization source it contains a non-normalized vector pointing in the direction to be sampled. Otherwise it contains the UV coordinates for sampling the bump texture
float3yesuvsemissionOnly available if an emission texture is bound to the shaderWhen using spherical parameterization source it contains a non-normalized vector pointing in the direction to be sampled. Otherwise it contains the UV coordinates for sampling the emission texture

vertex_output / pixel_input

TypeInterpolatedNameAvailability

Description

float4yespositionAlways availableAs a vertex output, vertex position in homogeneous coordinates. As a pixel input, interpolated vertex position in device coordinates
float4nomaterial_color_and_specular_intensityAlways availableThe xyz component contains the diffuse color, the alpha component contains the specular intensity. The color contained in this variable was passed in either as a vertex attribute or as a uniform value.
float4yeseye_positionNeeds to be requestedVertex position in camera coordinates
float3noeye_normalNeeds to be requestedVertex normal in camera coordinates. Not guaranteed to be normalized.
float4nodiffuse_light_and_ambient_blendOnly available when eye_normal has not been requested, or when lighting is calculated per-vertex rather than per-pixelthe xyz component contains the diffuse color, the alpha component contains an ambient blend factor between 0 and 1. The color contained in this variable was calculated based on the surface and lighting characteristics of the scene.
float4yeseye_tangentOnly available for triangles when bump textures are activeVertex tangent in camera coordinates. Not guaranteed to be normalized.
float2yesfindexOnly available when color is assigned by fractional index (example: because of a call to HC_Set_Color_By_FIndex)When drawing geometry with color specified by findex a texture containing all the possible colors is created. findex contains the UV coordinates necessary to index the color texture.
float4yestexcoord0Only defined if there is at least one diffuse texture bound to the shader or if requested by the userContains the UVW coordinates for the texture. The alpha component is not used.
float4yestexcoord1Only defined if there are at least two diffuse textures bound to the shader or if requested by the userContains the UVW coordinates for the texture. The alpha component is not used.
float4yestexcoord2Only defined if there are at least three diffuse textures bound to the shader or if requested by the userContains the UVW coordinates for the texture. The alpha component is not used.
float4yestexcoord3Only defined if there are at least four diffuse textures bound to the shader or if requested by the userContains the UVW coordinates for the texture. The alpha component is not used.
float4yestexcoord4Only defined if there are at least five diffuse textures bound to the shader or if requested by the userContains the UVW coordinates for the texture. The alpha component is not used.
float4yestexcoord5Only defined if there are at least six diffuse textures bound to the shader or if requested by the userContains the UVW coordinates for the texture. The alpha component is not used.
float4yestexcoord6Only defined if there are at least seven diffuse textures bound to the shader or if requested by the userContains the UVW coordinates for the texture. The alpha component is not used.
float4yestexcoord7Only defined if there are at least eight diffuse textures bound to the shader or if requested by the userContains the UVW coordinates for the texture. The alpha component is not used.
float4yesbacktexcoord0Only defined if there is at least one back face diffuse texture bound to the shaderContains the UVW coordinates for the texture. The alpha component is not used.
float4yesbacktexcoord1Only defined if there are at least two back face diffuse textures bound to the shaderContains the UVW coordinates for the texture. The alpha component is not used.
float4yesbacktexcoord2Only defined if there are at least three back face diffuse textures bound to the shaderContains the UVW coordinates for the texture. The alpha component is not used.
float4yesbacktexcoord3Only defined if there are at least four back face diffuse textures bound to the shaderContains the UVW coordinates for the texture. The alpha component is not used.
float4yesbacktexcoord4Only defined if there are at least five back face diffuse textures bound to the shaderContains the UVW coordinates for the texture. The alpha component is not used.
float4yesbacktexcoord5Only defined if there are at least six back face diffuse textures bound to the shaderContains the UVW coordinates for the texture. The alpha component is not used.
float4yesbacktexcoord6Only defined if there are at least seven back face diffuse textures bound to the shaderContains the UVW coordinates for the texture. The alpha component is not used.
float4yesbacktexcoord7Only defined if there are at least eight back face diffuse textures bound to the shaderContains the UVW coordinates for the texture. The alpha component is not used.
float3yesobject_viewNeeds to be requestedVector from the vertex position to the camera eye position.
float3yesobject_normalNeeds to be requestedVertex normal in world coordinates. Nor guaranteed to be normalized.
float3yesuvenvOnly available if an environment texture is bound to the shader.When using a cube map, uvenv contains the reflection vector used to sample the environment texture cube. Otherwise it contains the UV coordinates for sampling the environment texture.
float4yesuvstmirrorOnly available if a mirror texture is bound to the shaderWhen using spherical parameterization source it contains a non-normalized vector pointing in the direction to be sampled. Otherwise it contains the UV coordinates for sampling the mirror texture
float4yes`uvstspecOnly available if a specular texture is bound to the shaderWhen using spherical parameterization source it contains a non-normalized vector pointing in the direction to be sampled. Otherwise it contains the UV coordinates for sampling the specular texture
float4yesuvstbumpOnly available if a bump texture is bound to the shaderWhen using spherical parameterization source it contains a non-normalized vector pointing in the direction to be sampled. Otherwise it contains the UV coordinates for sampling the bump texture
float4yesuvstemissionOnly available if an emission texture is bound to the shaderWhen using spherical parameterization source it contains a non-normalized vector pointing in the direction to be sampled. Otherwise it contains the UV coordinates for sampling the emission texture

pixel_output

TypeNameAvailability

Description

float4FinalColorAlways availableThe output color for the pixel

Uniforms

Common uniform

The common uniform is accessible from both the vertex and pixel shader. Its fields can be accessed as follows: uniformCommon.fieldName.

All matrices contained in this uniform are declared row major for use in HLSL.

TypeName

Description

float3EyeCameraPositionThe camera's eye position in camera space
float3DistantLightsDirection[]The size of the array is number of distant lights + 1. Directions of distant lights in camera space
float4DistantLightsDiffuse[]The size of the array is number of distant lights + 1. Diffuse color of distant lights
float3DistantLightsSpecular[]The size of the array is number of distant lights + 1. Diffuse color of distant lights modulated by the specular component
float3DistantLightsHalfway[]The size of the array is number of distant lights + 1. Normalized halfway vector between distant light direction and camera position
float3PointLightsPosition[]The size of the array is number of point lights + 1. Position of point lights in camera space
float4PointLightsDiffuse[]The size of the array is number of point lights + 1. Diffuse color of point lights
float3PointLightsSpecular[]The size of the array is number of point lights + 1. Diffuse color of point lights modulated by the specular component
float3SpotLightsPosition[]The size of the array is number of spot lights + 1. Position of spot lights in camera space
float3SpotLightsDirection[]The size of the array is number of spot lights + 1. Direction of spot lights in camera space
float2SpotLightsAngles[]The size of the array is number of spot lights + 1. Values used for spot light attenuation
float4SpotLightsDiffuse[]The size of the array is number of spot lights + 1. Diffuse color of spot lights
float3SpotLightsSpecular[]The size of the array is number of spot lights + 1. Diffuse color of spot lights modulated by the specular component
float4x4IndexTextureMatrixTexture transform used for geometry colored by FIndex
float4x4TextureMatrix0Transform for diffuse texture 0
float4x4TextureMatrix1Transform for diffuse texture 1
float4x4TextureMatrix2Transform for diffuse texture 2
float4x4TextureMatrix3Transform for diffuse texture 3
float4x4TextureMatrix4Transform for diffuse texture 4
float4x4TextureMatrix5Transform for diffuse texture 5
float4x4TextureMatrix6Transform for diffuse texture 6
float4x4TextureMatrix7Transform for diffuse texture 7
float4x4BumpTextureMatrixTransform for bump texture
float4x4SpecularTextureMatrixTransform for specular texture
float4x4MirrorTextureMatrixTransform for mirror texture
float4x4EnvironmentTextureMatrixTransform for environment texture
float4x4TransmissionTextureMatrixTransform for transmission texture
float4x4EmissionTextureMatrixTransform for emission texture

Vertex uniform

The vertex uniform is accessible from the vertex shader. Its fields can be accessed as follows: uniformVertex.fieldName.

TypeName

Description

float3CameraPositionCamera position in object space
float4MaterialColorDiffuseMaterial diffuse value
float4MaterialColorSpecularMaterial specular value
floatColormapSizeSize of the colormap used when coloring geometry by FIndex
float2InvViewportInverse of the viewport width and height, in pixels

Fragment uniform

The fragment uniform is accessible from the pixel shader. Its fields can be accessed as follows: uniformFragment.fieldName.

TypeName

Description

float4MaterialColorDiffuseMaterial diffuse value
float4MaterialColorSpecularMaterial specular value
intAlphaTestWhether alpha test is active

Utility functions

Compatibility macros

The following macros are defined in Visualize shaders and can be used to make it easier to write shader code which compiles on all our supported drivers. The following table indicates the macro and its equivalent evaluation in the various drivers:

MacroOpenGLDirectX

Metal (GLSL / MSL)

float2vec2float2vec2 / float2
float3vec3float3vec3 / float3
float4vec4float4vec4 / float4
float2x2mat2float2x2mat2 / float2x2
float3x3mat3float3x3mat3 / float3x3
float4x4mat4float4x4mat4 / float4x4
double2dvec2double2Unsupported
double3dvec3double3Unsupported
double4dvec4double4Unsupported
int2ivec2int2ivec2 / int2
int3ivec3int3ivec3 / int3
int4ivec4int4ivec4 / int4
uint2uvec2uint2uvec2 / uint2
uint3uvec3uint3uvec3 / uint3
uint4uvec4uint4uvec4 / uint4
bool2bvec2bool2bvec2 / bool2
bool3bvec3bool3bvec3 / bool3
bool4bvec4bool4bvec4 / bool4
ddxdFdxddxdFdx / dfdx
ddydFdyddydFdy / dfdy
mul(a, b)((b) * (a))mul(a, b)((b) * (a)) / ((b) * (a))
saturate(a)clamp((a), 0.0, 1.0)saturate(a)clamp((a), 0.0, 1.0) / saturate(a)
lerp(x, y, s)mix(x, y, s)lerp(x, y, s)mix(x, y, s) / mix(x, y, s)
frac(x)fract(x)frac(x)fract(x) / fract(x)
atan2(y, x)atan(y, x)atan2(y, x)atan(y, x) / atan2(y, x)
equal(a, b)equal(a, b)((a) == (b))equal(a, b) / ((a) == (b))
notEqual(a, b)notEqual(a, b)((a) != (b))notEqual(a, b) / ((a) != (b))
greaterThan(a, b)greaterThan(a, b)((a) > (b))greaterThan(a, b) / ((a) > (b))
lessThan(a, b)lessThan(a, b)((a) < (b))lessThan(a, b) / ((a) < (b))
not(a)not(a)(!(a))not(a) / (!(a))

Vertex shader

The way transform matrices are passed to the shader changes based on how the scene will be rendered. In order to access the correct values regardless of how the shader is organized, the following utility functions should be used.

The following utility functions are only available when the geometry is not being drawn in display coordinates.

GetProjectionMatrix

float4x4 GetProjectionMatrix(const vertex_input vertex)

vertexthe vinput component of the VertexShaderContext
resultthe projection matrix

GetModelMatrix

float4x4 GetModelMatrix(const vertex_input vertex)

vertexthe vinput component of the VertexShaderContext
resultthe world matrix

GetViewMatrix

float4x4 GetViewMatrix(const vertex_input vertex)

vertexthe vinput component of the VertexShaderContext
resultthe view (camera) matrix

GetModelViewMatrix

float4x4 GetModelViewMatrix(const vertex_input vertex)

vertexthe vinput component of the VertexShaderContext
resultthe product of the model and view (camera) matrices

GetNormalizedModelMatrix

float3x3 GetNormalizedModelMatrix(const vertex_input vertex)

vertexthe vinput component of the VertexShaderContext
resultthe normalized 3x3 adjoint of the world matrix

GetNormalizedModelViewMatrix

float3x3 GetNormalizedModelViewMatrix(const vertex_input vertex)

vertexthe vinput component of the VertexShaderContext
resultthe product of the normalized world matrix and the view (camera) matrices

Internal implementation

There are three main parts to how the modern custom shaders are implemented internally:

  • Custom shader definition
  • Custom shader attribute
  • Usage of the attribute and definition by each graphics API

Custom shader definition

The custom shader definition is an object that exists to hold onto all the relevant data for a shader so that we can refer to it elsewhere. Defining a custom shader doesn't actually use it, it simply defines it. Much like we can define a line style, but never use it as a line pattern when drawing, or define a glyph, but never use it as a marker symbol when drawing.

This is represented internally by a Custom_Shader_Definition object, and is created when HC_Define_Shader is used to define a modern custom shader.

This object will be stored globally on a linked list hanging off of HOOPS::WORLD.

It is the object which contains all the relevant settings that were used to define the shader, basically, the name, what stage it applies to, and the source for the custom_main function.

Additionally, it will hold onto any settings which operate directly on an HC_KEY representing a custom shader. In particular, this is where the following functions will also store, query, or remove any data they set:

  • HC_Set_Shader_Inputs
  • HC_Set_Shader_Outputs
  • HC_Set_Shader_Samplers
  • HC_Set_Shader_Textures
  • HC_Set_Shader_Uniform

All of these functions merely store the necessary data on the definition which will get referred to later when we need to actually start creating our shaders when rendering.

Samplers and textures behave slightly differently than the other settings here in that they also need to get defined (though they are immutable) and are referred to by HC_KEY, so there are some additional definition functions for those types:

  • HC_Define_Shader_Sampler - creates a Custom_Shader_Sampler internally
  • HC_Define_Shader_Texture - creates a Custom_Shader_Texture internally

Sampler and texture definitions are also global objects and are stored as linked lists hanging off HOOPS::WORLD as well.

Custom shader attribute

To actually tell the scene graph we want to use a custom shader, we need to set an attribute on a segment. We do this by calling HC_Set_Shader on the segment where we want our previously defined shader to get used, and this will create a Custom_Shader attribute object which will be associated with the segment.

The Custom_Shader attribute will store the Custom_Shader_Definition pointers we want to use as vertex or pixel shaders for a particular type of primitive.

Additionally it will need to store any uniform data that needs to be set for a particular usage of a custom shader if that custom shader had a uniform added to it. This is because we could use the same custom shader in a different segment, but we may want to have the custom shader use different uniform data. For example, we may have different modelling matrices in two different segments, so it should be possible to specify each of those modelling matrices separately, but otherwise use the same shader.

top_level:1 prog_guide:0 prog_guide/3DGS:5