0028912: Visualization, TKOpenGl - multi-texture support
[occt.git] / src / Shaders / Declarations.glsl
CommitLineData
d5f74e42 1// Created on: 2013-10-10
2// Created by: Denis BOGOLEPOV
3// Copyright (c) 2013-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
12381341 16// This files includes definition of common uniform variables in OCCT GLSL programs
30f0ad28 17
12381341 18#define THE_MAX_LIGHTS 8
19#define THE_MAX_CLIP_PLANES 8
30f0ad28 20
b86bb3df 21// compatibility macros
22#if (__VERSION__ >= 130)
23 #define THE_ATTRIBUTE in
24 #define THE_SHADER_IN in
25 #define THE_SHADER_OUT out
26 #define THE_OUT out
ff6665dc 27 #define occTexture1D texture
b86bb3df 28 #define occTexture2D texture
ff6665dc 29 #define occTexture3D texture
b86bb3df 30#else
31 #define THE_ATTRIBUTE attribute
32 #define THE_SHADER_IN varying
33 #define THE_SHADER_OUT varying
34 #define THE_OUT
ff6665dc 35 #define occTexture1D texture1D
b86bb3df 36 #define occTexture2D texture2D
ff6665dc 37 #define occTexture3D texture3D
b86bb3df 38#endif
39
8a53d1c4 40#ifdef GL_ES
41 #define THE_PREC_ENUM lowp // enumerations should fit into lowp range
42#else
43 #define THE_PREC_ENUM
44#endif
45
12381341 46// Vertex attributes
12381341 47#ifdef VERTEX_SHADER
b86bb3df 48 THE_ATTRIBUTE vec4 occVertex;
49 THE_ATTRIBUTE vec3 occNormal;
50 THE_ATTRIBUTE vec4 occTexCoord;
51 THE_ATTRIBUTE vec4 occVertColor;
52#elif (__VERSION__ >= 130)
a1073ae2 53 #ifdef OCC_ENABLE_draw_buffers
177781da 54 out vec4 occFragColorArray[2];
55 #define occFragColor occFragColorArray[0]
56 #define occFragCoverage occFragColorArray[1]
57 #else
58 out vec4 occFragColor;
a1073ae2 59 #endif
b86bb3df 60#else
a1073ae2 61 #ifdef OCC_ENABLE_draw_buffers
62 #define occFragColor gl_FragData[0]
63 #define occFragCoverage gl_FragData[1]
64 #else
65 #define occFragColor gl_FragColor
66 #endif
30f0ad28 67#endif
68
12381341 69// Matrix state
70uniform mat4 occWorldViewMatrix; //!< World-view matrix
71uniform mat4 occProjectionMatrix; //!< Projection matrix
72uniform mat4 occModelWorldMatrix; //!< Model-world matrix
73
74uniform mat4 occWorldViewMatrixInverse; //!< Inverse of the world-view matrix
75uniform mat4 occProjectionMatrixInverse; //!< Inverse of the projection matrix
76uniform mat4 occModelWorldMatrixInverse; //!< Inverse of the model-world matrix
77
78uniform mat4 occWorldViewMatrixTranspose; //!< Transpose of the world-view matrix
79uniform mat4 occProjectionMatrixTranspose; //!< Transpose of the projection matrix
80uniform mat4 occModelWorldMatrixTranspose; //!< Transpose of the model-world matrix
81
82uniform mat4 occWorldViewMatrixInverseTranspose; //!< Transpose of the inverse of the world-view matrix
83uniform mat4 occProjectionMatrixInverseTranspose; //!< Transpose of the inverse of the projection matrix
84uniform mat4 occModelWorldMatrixInverseTranspose; //!< Transpose of the inverse of the model-world matrix
85
86// light type enumeration
87const int OccLightType_Direct = 1; //!< directional light source
88const int OccLightType_Point = 2; //!< isotropic point light source
89const int OccLightType_Spot = 3; //!< spot light source
90
91// Light sources
8a53d1c4 92uniform vec4 occLightAmbient; //!< Cumulative ambient color
93uniform THE_PREC_ENUM int occLightSourcesCount; //!< Total number of light sources
12381341 94int occLight_Type (in int theId); //!< Type of light source
95int occLight_IsHeadlight (in int theId); //!< Is light a headlight?
96vec4 occLight_Diffuse (in int theId); //!< Diffuse intensity for specified light source
97vec4 occLight_Specular (in int theId); //!< Specular intensity (currently - equals to diffuse intencity)
98vec4 occLight_Position (in int theId); //!< Position of specified light source
99vec4 occLight_SpotDirection (in int theId); //!< Direction of specified spot light source
100float occLight_ConstAttenuation (in int theId); //!< Const attenuation factor of positional light source
101float occLight_LinearAttenuation (in int theId); //!< Linear attenuation factor of positional light source
102float occLight_SpotCutOff (in int theId); //!< Maximum spread angle of the spot light (in radians)
103float occLight_SpotExponent (in int theId); //!< Attenuation of the spot light intensity (from 0 to 1)
104
105// Front material properties accessors
106vec4 occFrontMaterial_Emission(void); //!< Emission color
107vec4 occFrontMaterial_Ambient(void); //!< Ambient reflection
108vec4 occFrontMaterial_Diffuse(void); //!< Diffuse reflection
109vec4 occFrontMaterial_Specular(void); //!< Specular reflection
110float occFrontMaterial_Shininess(void); //!< Specular exponent
111float occFrontMaterial_Transparency(void); //!< Transparency coefficient
112
8625ef7e 113// Back material properties accessors
12381341 114vec4 occBackMaterial_Emission(void); //!< Emission color
115vec4 occBackMaterial_Ambient(void); //!< Ambient reflection
116vec4 occBackMaterial_Diffuse(void); //!< Diffuse reflection
117vec4 occBackMaterial_Specular(void); //!< Specular reflection
118float occBackMaterial_Shininess(void); //!< Specular exponent
119float occBackMaterial_Transparency(void); //!< Transparency coefficient
120
cc8cbabe 121#define occActiveSampler occSampler0 //!< alias for backward compatibility
122#define occSamplerBaseColor occSampler0 //!< alias to a base color texture
123uniform sampler2D occSampler0; //!< current active sampler;
124 //! occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing
8a53d1c4 125uniform vec4 occColor; //!< color value (in case of disabled lighting)
126uniform THE_PREC_ENUM int occDistinguishingMode; //!< Are front and back faces distinguished?
127uniform THE_PREC_ENUM int occTextureEnable; //!< Is texture enabled?
79f4f036 128uniform vec4 occTexTrsf2d[2]; //!< 2D texture transformation parameters
8a53d1c4 129uniform float occPointSize; //!< point size
12381341 130
a1073ae2 131//! Parameters of blended order-independent transparency rendering algorithm
132uniform int occOitOutput; //!< Enable bit for writing output color buffers for OIT (occFragColor, occFragCoverage)
133uniform float occOitDepthFactor; //!< Influence of the depth component to the coverage of the accumulated fragment
134
12381341 135//! Parameters of clipping planes
8a53d1c4 136uniform vec4 occClipPlaneEquations[THE_MAX_CLIP_PLANES];
8a53d1c4 137uniform THE_PREC_ENUM int occClipPlaneCount; //!< Total number of clip planes