Skip to content
Murilo Polese edited this page Feb 15, 2024 · 17 revisions

Beside the defines you can pass as an argument using -D[define] you can relay on the following native defines automatically generated for you. Remember you can always use the defines commands to have a sense of all the active define flags, their values on each shader/subshader

  • GLSLVIEWER <GLSLVIEWER_VERSION_WOUT_DOTS>: you can use it to tell your shader it's being render in GlslViewer.

Platform defines

  • PLATFORM_OSX: added only on MacOS/OSX platforms.

  • PLATFORM_RPI: added only on RaspberryPi devices.

  • PLATFORM_LINUX: added only in i86 and 64bit Linux platforms.

  • PLATFORM_WEBGL: added only on WASM or WebGL platforms.

Buffers and DoubleBuffers

The following defines fork and reuse the same shader program in different buffers

  • BUFFER_[NUMBER]: added extra buffer passes through branching subshader. Each time you add a uniform sampler2D u_buffer[NUMBER];, glslViewer will run another version of the same shader code but with the #define BUFFER_[NUMBER] on top and save the content into u_buffer[NUMBER] texture buffer. This way you can code different passes with a single source file. Please take a look to this examples to see how this works. B_Mt

  • DOUBLE_BUFFER_[NUMBER]: added extra double buffer (for PingPong passes) through branching subshader. Each time you add a uniform sampler2D u_doubleBuffer[NUMBER];, glslViewer will run another version of the same shader code but with the #define DOUBLE_BUFFER_[NUMBER] on top and save the content into u_buffer[NUMBER] texture buffer. This way you can code different Ping-Pong passes with a single source file. Please take a look to this examples to see how this works. D_Mt

  • PYRAMID_[NUMBER]: perform Convolution Pyramids to the content of a buffer where the result will be stored as uniform sampler2D u_pyramid[NUMBER]. Please take a look to this examples to see how this works. For advance use is possible to overwrite the up/down scaling shaders using #ifdef PYRAMID_ALGORITHM and the uniforms:

uniform sampler2D   u_pyramidTex0;
uniform sampler2D   u_pyramidTex1;
uniform bool        u_pyramidUpscaling;

Render Passes on 3D scenes

The following defines fork and reuse the same shader program in different passes Fork

  • BACKGROUND: added a background subshader when rendering a 3D geometry. Bg_Mt

  • FLOOR: add a floor geometry and fork the behavior of the shader to render the floor using it Mt_Fl

  • POSTPROCESSING: added a post-processing pass where the main scene have been render to uniform sampler2D u_scene; and uniform sampler2D u_sceneDepth;. Bg_Mt_Pp

Geometry defines

  • MODEL_NAME_<NAME>: only OBJ file import a name. Default is MODEL_NAME_MESH

  • MODEL_VERTEX_COLOR: if the model have a vertex color attribute will be follow by the name of the attribute (Default: a_color)

  • MODEL_VERTEX_NORMAL: if the model have a vertex normal attribute will be follow by the name of the attribute (Default: a_normal`)

  • MODEL_VERTEX_TEXCOORD: if the model have a vertex normal attribute will be follow by the name of the attribute (Default: a_texcoord)

  • MODEL_VERTEX_TANGENT: if the model have a vertex normal attribute will be follow by the name of the attribute (Default: a_tangent)

Material defines

  • MATERIAL_NAME_[NAME]: only OBJ file import a name. Default is MATERIAL_NAME_DEFAULT

  • MATERIAL_ILLUM: integer between 0 to 10. Specs from here

    0 Color on and Ambient off
    1 Color on and Ambient on
    2 Highlight on
    3 Reflection on and Ray trace on
    4 Transparency: Glass on

    Reflection: Ray trace on
    5 Reflection: Fresnel on and Ray trace on
    6 Transparency: Refraction on

    Reflection: Fresnel off and Ray trace on
    7 Transparency: Refraction on

    Reflection: Fresnel on and Ray trace on
    8 Reflection on and Ray trace off
    9 Transparency: Glass on

    Reflection: Ray trace off
    10 Casts shadows onto invisible surfaces
  • MATERIAL_AMBIENT: the color as vec3

  • MATERIAL_AMBIENTMAP: the name of a sampler2D

  • MATERIAL_BASECOLOR: a color as vec3

  • MATERIAL_BASECOLORMAP: the name of a sampler2D

  • MATERIAL_SPECULAR: a color as vec3

  • MATERIAL_SPECULARMAP: the name of a sampler2D

  • MATERIAL_ROUGHNESS: a normalize float value

  • MATERIAL_ROUGHNESSMAP: the name of a sampler2D

  • MATERIAL_METALLIC: a normalize float value

  • MATERIAL_METALLICMAP: the name of a sampler2D

  • MATERIAL_SHININESS: a scallar factor for speculars

  • MATERIAL_SHEEN: a normalize float value

  • MATERIAL_SHEENMAP: the name of a sampler2D

  • MATERIAL_SPECULAR_HIGHLIGHTMAP: the name of a sampler2D

  • MATERIAL_REFLECTIONMAP: the name of a sampler2D

  • MATERIAL_CLEARCOAT_THICKNESS: a normalize float value

  • MATERIAL_CLEARCOAT_ROUGHNESS: a normalize float value

  • MATERIAL_ANISOTROPY: a normalize float value

  • MATERIAL_ANISOTROPY_ROTATION: float value

  • MATERIAL_EMISSIVE: a color as vec3

  • MATERIAL_EMISSIVEMAP: the name of a sampler2D

  • MATERIAL_NORMALMAP: the name of a sampler2D

  • MATERIAL_BUMPMAP: the name of a sampler2D

  • MATERIAL_DISPLACEMENTMAP: the name of a sampler2D

  • MATERIAL_ALPHAMAP: the name of a sampler2D

  • MATERIAL_TRANSMITTANCE: a color as vec3

  • MATERIAL_DISSOLVE: a normalize float value

  • MATERIAL_IOR: a normalize float value