mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0024310: TKOpenGl - GLSL compatibility issues
Lights defintion clean up: - remove duplicated enumeration TLightType (equals to Visual3d_TypeOfLightSource) - remove unused fields from Graphic3d_CLight - OpenGl_Light, reuse Graphic3d_CLight definition Phong GLSL program: - move out cumulative ambient light intencity from limited list of lights - compatibility issues, replace array of structures (light sources, materials, clipping planes) with arrays of primitive types New Draw Harness command vlight to alter light sources definition. OpenGl_ShaderProgram::Initialize() - add missing Linker log
This commit is contained in:
@@ -1,192 +1,79 @@
|
||||
#define _OCC_MAX_LIGHTS_ 8
|
||||
// This files includes definition of common uniform variables in OCCT GLSL programs
|
||||
|
||||
#define _OCC_MAX_CLIP_PLANES_ 8
|
||||
|
||||
|
||||
//! OCCT ambient light source.
|
||||
const int occAmbientLight = 0;
|
||||
|
||||
//! OCCT directional light source.
|
||||
const int occDirectLight = 1;
|
||||
|
||||
//! OCCT isotropic point light source.
|
||||
const int occPointLight = 2;
|
||||
|
||||
//! OCCT spot light source.
|
||||
const int occSpotLight = 3;
|
||||
|
||||
|
||||
//! Parameters of OCCT light source.
|
||||
struct occLightSource
|
||||
{
|
||||
//! Type of light source.
|
||||
int Type;
|
||||
|
||||
//! Is light a headlight?
|
||||
int Head;
|
||||
|
||||
//! Ambient intensity.
|
||||
vec3 Ambient;
|
||||
|
||||
//! Diffuse intensity.
|
||||
vec3 Diffuse;
|
||||
|
||||
//! Specular intensity.
|
||||
vec3 Specular;
|
||||
|
||||
//! Position of light source.
|
||||
vec3 Position;
|
||||
|
||||
//! Direction of the spot light.
|
||||
vec3 SpotDirection;
|
||||
|
||||
//! Maximum spread angle of the spot light (in radians).
|
||||
float SpotCutoff;
|
||||
|
||||
//! Attenuation of the spot light intensity (from 0 to 1).
|
||||
float SpotExponent;
|
||||
|
||||
//! Const attenuation factor of positional light source.
|
||||
float ConstAttenuation;
|
||||
|
||||
//! Linear attenuation factor of positional light source.
|
||||
float LinearAttenuation;
|
||||
};
|
||||
|
||||
//! Parameters of OCCT material.
|
||||
struct occMaterialParams
|
||||
{
|
||||
//! Emission color.
|
||||
vec4 Emission;
|
||||
|
||||
//! Ambient reflection.
|
||||
vec4 Ambient;
|
||||
|
||||
//! Diffuse reflection.
|
||||
vec4 Diffuse;
|
||||
|
||||
//! Specular reflection.
|
||||
vec4 Specular;
|
||||
|
||||
//! Specular exponent.
|
||||
float Shininess;
|
||||
|
||||
//! Transparency coefficient.
|
||||
float Transparency;
|
||||
};
|
||||
|
||||
//! OCCT view-space clipping plane.
|
||||
const int occEquationCoordsView = 0;
|
||||
|
||||
//! OCCT world-space clipping plane.
|
||||
const int occEquationCoordsWorld = 1;
|
||||
|
||||
//! Parameters of OCCT clipping plane.
|
||||
struct occClipPlane
|
||||
{
|
||||
//! Plane equation.
|
||||
vec4 Equation;
|
||||
|
||||
//! Equation space.
|
||||
int Space;
|
||||
};
|
||||
|
||||
#ifdef VERTEX_SHADER
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// OCCT vertex attributes
|
||||
#define THE_MAX_LIGHTS 8
|
||||
#define THE_MAX_CLIP_PLANES 8
|
||||
|
||||
// Vertex attributes
|
||||
// Note: At the moment, we just 'rename' the default OpenGL
|
||||
// vertex attributes from compatibility profile. In the next
|
||||
// release old functionality will be removed from shader API.
|
||||
|
||||
//! Vertex color.
|
||||
#define occColor gl_Color
|
||||
|
||||
//! Normal coordinates.
|
||||
#define occNormal gl_Normal
|
||||
|
||||
//! Vertex coordinates.
|
||||
#define occVertex gl_Vertex
|
||||
|
||||
//! Texture coordinates.
|
||||
#define occTexCoord gl_MultiTexCoord0
|
||||
|
||||
#ifdef VERTEX_SHADER
|
||||
#define occColor gl_Color //!< Vertex color
|
||||
#define occNormal gl_Normal //!< Normal coordinates
|
||||
#define occVertex gl_Vertex //!< Vertex coordinates
|
||||
#define occTexCoord gl_MultiTexCoord0 //!< Texture coordinates
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// OCCT matrix state
|
||||
// Matrix state
|
||||
uniform mat4 occWorldViewMatrix; //!< World-view matrix
|
||||
uniform mat4 occProjectionMatrix; //!< Projection matrix
|
||||
uniform mat4 occModelWorldMatrix; //!< Model-world matrix
|
||||
|
||||
//! World-view matrix.
|
||||
uniform mat4 occWorldViewMatrix;
|
||||
uniform mat4 occWorldViewMatrixInverse; //!< Inverse of the world-view matrix
|
||||
uniform mat4 occProjectionMatrixInverse; //!< Inverse of the projection matrix
|
||||
uniform mat4 occModelWorldMatrixInverse; //!< Inverse of the model-world matrix
|
||||
|
||||
//! Projection matrix.
|
||||
uniform mat4 occProjectionMatrix;
|
||||
uniform mat4 occWorldViewMatrixTranspose; //!< Transpose of the world-view matrix
|
||||
uniform mat4 occProjectionMatrixTranspose; //!< Transpose of the projection matrix
|
||||
uniform mat4 occModelWorldMatrixTranspose; //!< Transpose of the model-world matrix
|
||||
|
||||
//! Model-world matrix.
|
||||
uniform mat4 occModelWorldMatrix;
|
||||
uniform mat4 occWorldViewMatrixInverseTranspose; //!< Transpose of the inverse of the world-view matrix
|
||||
uniform mat4 occProjectionMatrixInverseTranspose; //!< Transpose of the inverse of the projection matrix
|
||||
uniform mat4 occModelWorldMatrixInverseTranspose; //!< Transpose of the inverse of the model-world matrix
|
||||
|
||||
//-------------------------------------------------------
|
||||
// light type enumeration
|
||||
const int OccLightType_Direct = 1; //!< directional light source
|
||||
const int OccLightType_Point = 2; //!< isotropic point light source
|
||||
const int OccLightType_Spot = 3; //!< spot light source
|
||||
|
||||
//! Inverse of the world-view matrix.
|
||||
uniform mat4 occWorldViewMatrixInverse;
|
||||
// Light sources
|
||||
uniform vec4 occLightAmbient; //!< Cumulative ambient color
|
||||
uniform int occLightSourcesCount; //!< Total number of light sources
|
||||
int occLight_Type (in int theId); //!< Type of light source
|
||||
int occLight_IsHeadlight (in int theId); //!< Is light a headlight?
|
||||
vec4 occLight_Diffuse (in int theId); //!< Diffuse intensity for specified light source
|
||||
vec4 occLight_Specular (in int theId); //!< Specular intensity (currently - equals to diffuse intencity)
|
||||
vec4 occLight_Position (in int theId); //!< Position of specified light source
|
||||
vec4 occLight_SpotDirection (in int theId); //!< Direction of specified spot light source
|
||||
float occLight_ConstAttenuation (in int theId); //!< Const attenuation factor of positional light source
|
||||
float occLight_LinearAttenuation (in int theId); //!< Linear attenuation factor of positional light source
|
||||
float occLight_SpotCutOff (in int theId); //!< Maximum spread angle of the spot light (in radians)
|
||||
float occLight_SpotExponent (in int theId); //!< Attenuation of the spot light intensity (from 0 to 1)
|
||||
|
||||
//! Inverse of the projection matrix.
|
||||
uniform mat4 occProjectionMatrixInverse;
|
||||
// Front material properties accessors
|
||||
vec4 occFrontMaterial_Emission(void); //!< Emission color
|
||||
vec4 occFrontMaterial_Ambient(void); //!< Ambient reflection
|
||||
vec4 occFrontMaterial_Diffuse(void); //!< Diffuse reflection
|
||||
vec4 occFrontMaterial_Specular(void); //!< Specular reflection
|
||||
float occFrontMaterial_Shininess(void); //!< Specular exponent
|
||||
float occFrontMaterial_Transparency(void); //!< Transparency coefficient
|
||||
|
||||
//! Inverse of the model-world matrix.
|
||||
uniform mat4 occModelWorldMatrixInverse;
|
||||
// Front material properties accessors
|
||||
vec4 occBackMaterial_Emission(void); //!< Emission color
|
||||
vec4 occBackMaterial_Ambient(void); //!< Ambient reflection
|
||||
vec4 occBackMaterial_Diffuse(void); //!< Diffuse reflection
|
||||
vec4 occBackMaterial_Specular(void); //!< Specular reflection
|
||||
float occBackMaterial_Shininess(void); //!< Specular exponent
|
||||
float occBackMaterial_Transparency(void); //!< Transparency coefficient
|
||||
|
||||
//-------------------------------------------------------
|
||||
uniform int occDistinguishingMode; //!< Are front and back faces distinguished?
|
||||
uniform int occTextureEnable; //!< Is texture enabled?
|
||||
uniform sampler2D occActiveSampler; //!< Current active sampler
|
||||
|
||||
//! Transpose of the world-view matrix.
|
||||
uniform mat4 occWorldViewMatrixTranspose;
|
||||
// clipping planes state
|
||||
const int OccEquationCoords_View = 0; //!< view-space clipping plane
|
||||
const int OccEquationCoords_World = 1; //!< world-space clipping plane
|
||||
|
||||
//! Transpose of the projection matrix.
|
||||
uniform mat4 occProjectionMatrixTranspose;
|
||||
|
||||
//! Transpose of the model-world matrix.
|
||||
uniform mat4 occModelWorldMatrixTranspose;
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
//! Transpose of the inverse of the world-view matrix.
|
||||
uniform mat4 occWorldViewMatrixInverseTranspose;
|
||||
|
||||
//! Transpose of the inverse of the projection matrix.
|
||||
uniform mat4 occProjectionMatrixInverseTranspose;
|
||||
|
||||
//! Transpose of the inverse of the model-world matrix.
|
||||
uniform mat4 occModelWorldMatrixInverseTranspose;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// OCCT light source state
|
||||
|
||||
//! Array of OCCT light sources.
|
||||
uniform occLightSource occLightSources[_OCC_MAX_LIGHTS_];
|
||||
|
||||
//! Total number of OCCT light sources.
|
||||
uniform int occLightSourcesCount;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// OCCT material state
|
||||
|
||||
//! Parameters of OCCT back material.
|
||||
uniform occMaterialParams occBackMaterial;
|
||||
|
||||
//! Parameters of OCCT front material.
|
||||
uniform occMaterialParams occFrontMaterial;
|
||||
|
||||
//! Are front and back faces distinguished?
|
||||
uniform int occDistinguishingMode;
|
||||
|
||||
//! Is texture enabled?
|
||||
uniform int occTextureEnable;
|
||||
|
||||
//! Current active sampler.
|
||||
uniform sampler2D occActiveSampler;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// OCCT clipping planes state
|
||||
|
||||
uniform occClipPlane occClipPlanes[_OCC_MAX_CLIP_PLANES_];
|
||||
//! Parameters of clipping planes
|
||||
uniform vec4 occClipPlaneEquations[THE_MAX_CLIP_PLANES];
|
||||
uniform int occClipPlaneSpaces [THE_MAX_CLIP_PLANES];
|
||||
|
37
src/Shaders/DeclarationsImpl.glsl
Normal file
37
src/Shaders/DeclarationsImpl.glsl
Normal file
@@ -0,0 +1,37 @@
|
||||
// This file includes implementation of common functions and properties accessors
|
||||
|
||||
// arrays of light sources
|
||||
uniform ivec2 occLightSourcesTypes[THE_MAX_LIGHTS]; //!< packed light sources types
|
||||
uniform vec4 occLightSources[THE_MAX_LIGHTS * 4]; //!< packed light sources parameters
|
||||
|
||||
// light source properties accessors
|
||||
int occLight_Type (in int theId) { return occLightSourcesTypes[theId].x; }
|
||||
int occLight_IsHeadlight (in int theId) { return occLightSourcesTypes[theId].y; }
|
||||
vec4 occLight_Diffuse (in int theId) { return occLightSources[theId * 4 + 0]; }
|
||||
vec4 occLight_Specular (in int theId) { return occLightSources[theId * 4 + 0]; }
|
||||
vec4 occLight_Position (in int theId) { return occLightSources[theId * 4 + 1]; }
|
||||
vec4 occLight_SpotDirection (in int theId) { return occLightSources[theId * 4 + 2]; }
|
||||
float occLight_ConstAttenuation (in int theId) { return occLightSources[theId * 4 + 3].x; }
|
||||
float occLight_LinearAttenuation (in int theId) { return occLightSources[theId * 4 + 3].y; }
|
||||
float occLight_SpotCutOff (in int theId) { return occLightSources[theId * 4 + 3].z; }
|
||||
float occLight_SpotExponent (in int theId) { return occLightSources[theId * 4 + 3].w; }
|
||||
|
||||
// material state
|
||||
uniform vec4 occFrontMaterial[5];
|
||||
uniform vec4 occBackMaterial[5];
|
||||
|
||||
// front material properties accessors
|
||||
vec4 occFrontMaterial_Emission(void) { return occFrontMaterial[0]; }
|
||||
vec4 occFrontMaterial_Ambient(void) { return occFrontMaterial[1]; }
|
||||
vec4 occFrontMaterial_Diffuse(void) { return occFrontMaterial[2]; }
|
||||
vec4 occFrontMaterial_Specular(void) { return occFrontMaterial[3]; }
|
||||
float occFrontMaterial_Shininess(void) { return occFrontMaterial[4].x; }
|
||||
float occFrontMaterial_Transparency(void) { return occFrontMaterial[4].y; }
|
||||
|
||||
// back material properties accessors
|
||||
vec4 occBackMaterial_Emission(void) { return occBackMaterial[0]; }
|
||||
vec4 occBackMaterial_Ambient(void) { return occBackMaterial[1]; }
|
||||
vec4 occBackMaterial_Diffuse(void) { return occBackMaterial[2]; }
|
||||
vec4 occBackMaterial_Specular(void) { return occBackMaterial[3]; }
|
||||
float occBackMaterial_Shininess(void) { return occBackMaterial[4].x; }
|
||||
float occBackMaterial_Transparency(void) { return occBackMaterial[4].y; }
|
@@ -17,46 +17,22 @@
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
//! Direction to the viewer.
|
||||
varying vec3 View;
|
||||
varying vec3 View; //!< Direction to the viewer
|
||||
varying vec3 Normal; //!< Vertex normal in view space
|
||||
varying vec4 Position; //!< Vertex position in view space.
|
||||
|
||||
//! Vertex normal in view space.
|
||||
varying vec3 Normal;
|
||||
vec3 Ambient; //!< Ambient contribution of light sources
|
||||
vec3 Diffuse; //!< Diffuse contribution of light sources
|
||||
vec3 Specular; //!< Specular contribution of light sources
|
||||
|
||||
//! Vertex position in view space.
|
||||
varying vec4 Position;
|
||||
|
||||
|
||||
//! Ambient contribution of light sources.
|
||||
vec3 Ambient;
|
||||
|
||||
//! Diffuse contribution of light sources.
|
||||
vec3 Diffuse;
|
||||
|
||||
//! Specular contribution of light sources.
|
||||
vec3 Specular;
|
||||
|
||||
|
||||
// =======================================================================
|
||||
// function : AmbientLight
|
||||
// purpose : Computes contribution of OCCT pure ambient light source
|
||||
// =======================================================================
|
||||
void AmbientLight (in int theIndex)
|
||||
{
|
||||
Ambient += occLightSources[theIndex].Ambient;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : PointLight
|
||||
// purpose : Computes contribution of OCCT isotropic point light source
|
||||
// =======================================================================
|
||||
void PointLight (in int theIndex,
|
||||
//! Computes contribution of isotropic point light source
|
||||
void pointLight (in int theId,
|
||||
in vec3 theNormal,
|
||||
in vec3 theView,
|
||||
in vec3 thePoint)
|
||||
{
|
||||
vec3 aLight = occLightSources[theIndex].Position;
|
||||
if (occLightSources[theIndex].Head == 0)
|
||||
vec3 aLight = occLight_Position (theId).xyz;
|
||||
if (occLight_IsHeadlight (theId) == 0)
|
||||
{
|
||||
aLight = vec3 (occWorldViewMatrix * occModelWorldMatrix * vec4 (aLight, 1.0));
|
||||
}
|
||||
@@ -64,107 +40,86 @@ void PointLight (in int theIndex,
|
||||
|
||||
float aDist = length (aLight);
|
||||
aLight = aLight * (1.0 / aDist);
|
||||
|
||||
float anAttenuation = 1.0 / (occLightSources[theIndex].ConstAttenuation +
|
||||
occLightSources[theIndex].LinearAttenuation * aDist);
|
||||
|
||||
float anAtten = 1.0 / (occLight_ConstAttenuation (theId)
|
||||
+ occLight_LinearAttenuation (theId) * aDist);
|
||||
|
||||
vec3 aHalf = normalize (aLight + theView);
|
||||
|
||||
float aNdotL = max (0.0, dot (theNormal, aLight));
|
||||
float aNdotH = max (0.0, dot (theNormal, aHalf));
|
||||
float aNdotH = max (0.0, dot (theNormal, aHalf ));
|
||||
|
||||
float aSpecl = 0.0;
|
||||
if (aNdotL > 0.0)
|
||||
{
|
||||
aSpecl = pow (aNdotH, occFrontMaterial.Shininess);
|
||||
aSpecl = pow (aNdotH, occFrontMaterial_Shininess());
|
||||
}
|
||||
|
||||
Ambient += occLightSources[theIndex].Ambient * anAttenuation;
|
||||
Diffuse += occLightSources[theIndex].Diffuse * aNdotL * anAttenuation;
|
||||
Specular += occLightSources[theIndex].Specular * aSpecl * anAttenuation;
|
||||
|
||||
Diffuse += occLight_Diffuse (theId).rgb * aNdotL * anAtten;
|
||||
Specular += occLight_Specular (theId).rgb * aSpecl * anAtten;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : DirectionalLight
|
||||
// purpose : Computes contribution of OCCT directional light source
|
||||
// =======================================================================
|
||||
void DirectionalLight (in int theIndex,
|
||||
//! Computes contribution of directional light source
|
||||
void directionalLight (in int theId,
|
||||
in vec3 theNormal,
|
||||
in vec3 theView)
|
||||
{
|
||||
vec3 aLight = normalize (occLightSources[theIndex].Position);
|
||||
|
||||
if (occLightSources[theIndex].Head == 0)
|
||||
vec3 aLight = normalize (occLight_Position (theId).xyz);
|
||||
if (occLight_IsHeadlight (theId) == 0)
|
||||
{
|
||||
aLight = vec3 (occWorldViewMatrix * occModelWorldMatrix * vec4 (aLight, 0.0));
|
||||
}
|
||||
|
||||
|
||||
vec3 aHalf = normalize (aLight + theView);
|
||||
|
||||
float aNdotL = max (0.0, dot (theNormal, aLight));
|
||||
float aNdotH = max (0.0, dot (theNormal, aHalf));
|
||||
float aNdotH = max (0.0, dot (theNormal, aHalf ));
|
||||
|
||||
float aSpecl = 0.0;
|
||||
|
||||
if (aNdotL > 0.0)
|
||||
{
|
||||
aSpecl = pow (aNdotH, occFrontMaterial.Shininess);
|
||||
aSpecl = pow (aNdotH, occFrontMaterial_Shininess());
|
||||
}
|
||||
|
||||
Ambient += occLightSources[theIndex].Ambient;
|
||||
Diffuse += occLightSources[theIndex].Diffuse * aNdotL;
|
||||
Specular += occLightSources[theIndex].Specular * aSpecl;
|
||||
Diffuse += occLight_Diffuse (theId).rgb * aNdotL;
|
||||
Specular += occLight_Specular (theId).rgb * aSpecl;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ComputeLighting
|
||||
// purpose : Computes illumination from OCCT light sources
|
||||
// =======================================================================
|
||||
vec4 ComputeLighting (in vec3 theNormal,
|
||||
//! Computes illumination from light sources
|
||||
vec4 computeLighting (in vec3 theNormal,
|
||||
in vec3 theView,
|
||||
in vec4 thePoint)
|
||||
{
|
||||
// Clear the light intensity accumulators
|
||||
Ambient = vec3 (0.0);
|
||||
Ambient = occLightAmbient.rgb;
|
||||
Diffuse = vec3 (0.0);
|
||||
Specular = vec3 (0.0);
|
||||
|
||||
vec3 aPoint = thePoint.xyz / thePoint.w;
|
||||
|
||||
for (int anIndex = 0; anIndex < occLightSourcesCount; ++anIndex)
|
||||
{
|
||||
occLightSource light = occLightSources[anIndex];
|
||||
|
||||
if (light.Type == occAmbientLight)
|
||||
int aType = occLight_Type (anIndex);
|
||||
if (aType == OccLightType_Direct)
|
||||
{
|
||||
AmbientLight (anIndex);
|
||||
directionalLight (anIndex, theNormal, theView);
|
||||
}
|
||||
else if (aType == OccLightType_Point)
|
||||
{
|
||||
pointLight (anIndex, theNormal, theView, aPoint);
|
||||
}
|
||||
else if (aType == OccLightType_Spot)
|
||||
{
|
||||
// Not implemented
|
||||
}
|
||||
else if (light.Type == occDirectLight)
|
||||
{
|
||||
DirectionalLight (anIndex, theNormal, theView);
|
||||
}
|
||||
else if (light.Type == occPointLight)
|
||||
{
|
||||
PointLight (anIndex, theNormal, theView, aPoint);
|
||||
}
|
||||
else if (light.Type == occSpotLight)
|
||||
{
|
||||
/* Not implemented */
|
||||
}
|
||||
}
|
||||
|
||||
return vec4 (Ambient, 1.0) * occFrontMaterial.Ambient +
|
||||
vec4 (Diffuse, 1.0) * occFrontMaterial.Diffuse +
|
||||
vec4 (Specular, 1.0) * occFrontMaterial.Specular;
|
||||
|
||||
return vec4 (Ambient, 1.0) * occFrontMaterial_Ambient()
|
||||
+ vec4 (Diffuse, 1.0) * occFrontMaterial_Diffuse()
|
||||
+ vec4 (Specular, 1.0) * occFrontMaterial_Specular();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : main
|
||||
// purpose : Entry point to the fragment shader
|
||||
// =======================================================================
|
||||
//! Entry point to the Fragment Shader
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = ComputeLighting (normalize (Normal),
|
||||
gl_FragColor = computeLighting (normalize (Normal),
|
||||
normalize (View),
|
||||
Position);
|
||||
}
|
||||
|
@@ -17,42 +17,27 @@
|
||||
// purpose or non-infringement. Please see the License for the specific terms
|
||||
// and conditions governing the rights and limitations under the License.
|
||||
|
||||
//! Direction to the viewer.
|
||||
varying vec3 View;
|
||||
varying vec3 View; //!< Direction to the viewer
|
||||
varying vec3 Normal; //!< Vertex normal in view space
|
||||
varying vec4 Position; //!< Vertex position in view space
|
||||
|
||||
//! Vertex normal in view space.
|
||||
varying vec3 Normal;
|
||||
|
||||
//! Vertex position in view space.
|
||||
varying vec4 Position;
|
||||
|
||||
// =======================================================================
|
||||
// function : TransformNormal
|
||||
// purpose : Computes the normal in view space
|
||||
// =======================================================================
|
||||
//! Computes the normal in view space
|
||||
vec3 TransformNormal (in vec3 theNormal)
|
||||
{
|
||||
vec4 aResult = occWorldViewMatrixInverseTranspose *
|
||||
occModelWorldMatrixInverseTranspose * vec4 (theNormal, 0.0);
|
||||
|
||||
vec4 aResult = occWorldViewMatrixInverseTranspose
|
||||
* occModelWorldMatrixInverseTranspose
|
||||
* vec4 (theNormal, 0.0);
|
||||
return normalize (aResult.xyz);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : main
|
||||
// purpose : Entry point to the vertex shader
|
||||
// =======================================================================
|
||||
//! Entry point to the Vertex Shader
|
||||
void main()
|
||||
{
|
||||
// Compute vertex position in the view space
|
||||
Position = occWorldViewMatrix * occModelWorldMatrix * occVertex;
|
||||
|
||||
// Compute vertex normal in the view space
|
||||
Normal = TransformNormal (occNormal);
|
||||
|
||||
// Note: The specified view vector is absolutely correct only for the orthogonal
|
||||
// projection. For perspective projection it will be approximate, but it is in
|
||||
// good agreement with the OpenGL calculations
|
||||
Position = occWorldViewMatrix * occModelWorldMatrix * occVertex; // position in the view space
|
||||
Normal = TransformNormal (occNormal); // normal in the view space
|
||||
|
||||
// Note: The specified view vector is absolutely correct only for the orthogonal projection.
|
||||
// For perspective projection it will be approximate, but it is in good agreement with the OpenGL calculations.
|
||||
View = vec3 (0.0, 0.0, 1.0);
|
||||
|
||||
// Do fixed functionality vertex transform
|
||||
|
Reference in New Issue
Block a user