glsl_programs - ryzom/ryzomcore GitHub Wiki


title: GLSL Programs description: published: true date: 2023-03-01T05:18:46.867Z tags: editor: markdown dateCreated: 2022-03-08T22:26:02.216Z

For custom glsl programs at NL3D level, define several preprocessor pragmas for replacement in the driver.

glsl330v

#pragma nel vertexformat <number>

Used in vertex shader. Pragma is replaced with the necessary vertex inputs. Program only support one vertex format.

number: Decimal representation of the vertex format flags as specified in CVertexBuffer

#pragma nel vertexprogram

Defines that the driver will automatically generate the header, inputs and main function for the program.

#pragma nel vertexpostposition <function> (requires nel vertexprogram)

Used in vertex shader. Specifies a function name to use to transform a vertex position.

function: void function(inout vec3 position) { ... }

Is called after vertices have been transformed by their matrices.

May be used multiple times.

#pragma nel vertexcolor <on/off> (requires nel vertexprogram)

Enables or disables the builtin usage of the PrimaryColor and SecondaryColor vertex format attributes. Default is on.

#pragma nel lighting <pixel/vertex/off> (requires nel vertexprogram)

Enables or disables lighting. Default is off.

Note: User program ignores driver lighting enabled state.

#pragma nel lightspecular <on/off> (requires nel vertexprogram)

Enables or disables calculation of specular for lights. This can be used for optimization. Default is on.

#pragma nel light <idx> <directional/point/off> (requires nel vertexprogram)

Enables or disables a specific light. Default is off.

Note: User program ignores driver light state. It does use the diffuse etc parameters from the setup light configuration.

#pragma nel fog <on/of> (requires nel vertexprogram)

Enables or disables fog. Default is off

Note: User program ignores driver fog enabled state.

Implementation: compileVertexProgram (when called by the user) will go through the pragmas and handle them all, do replacements where needed. If vertexprogram has been specified, it will call the vp generator with an additional pointer to a userdesc structure. The userdesc structure contains the preprocessed string of the user program, which will be inserted between the header and the main function. It also contains a vector of the postposition functions, and the vertexcolor bool, and a bool specifying whether vertexformat was already added by the user.


Misc

setLighting will be modified to allow instead of only enable/disable to switch between Pixel, Vertex and in the future Defered. The setupMaterial of the ogl3 driver will internally simply override the Vertex with Pixel when using one of the perpixel materials (and additionally handle the shader using the per pixel material specific main procedure).

This will allow to globally enable per pixel lighting.

⚠️ **GitHub.com Fallback** ⚠️