Added functions to perform 'octahedral' encoding and decoding of normals.

See http://jcgt.org/published/0003/02/01/paper-lowres.pdf
This commit is contained in:
David Williams
2014-07-23 23:35:46 +02:00
parent dd5e34bc92
commit 4a42535f13
4 changed files with 135 additions and 52 deletions

View File

@ -1,20 +1,25 @@
#version 140
in vec4 position; // This will be the position of the vertex in model-space
// The usual matrices are provided
uniform mat4 cameraToClipMatrix;
uniform mat4 worldToCameraMatrix;
uniform mat4 modelToWorldMatrix;
// This will be used by the fragment shader to calculate flat-shaded normals. This is an unconventional approach
// but we use it in this example framework because not all surface extractor generate surface normals.
out vec4 worldPosition;
void main()
{
// Standard sequence of OpenGL transformations.
worldPosition = modelToWorldMatrix * position;
vec4 cameraPosition = worldToCameraMatrix * worldPosition;
gl_Position = cameraToClipMatrix * cameraPosition;
}
#version 140
in vec4 position; // This will be the position of the vertex in model-space
in vec3 normal;
// The usual matrices are provided
uniform mat4 cameraToClipMatrix;
uniform mat4 worldToCameraMatrix;
uniform mat4 modelToWorldMatrix;
// This will be used by the fragment shader to calculate flat-shaded normals. This is an unconventional approach
// but we use it in this example framework because not all surface extractor generate surface normals.
out vec4 worldPosition;
out vec3 worldNormal;
void main()
{
// Standard sequence of OpenGL transformations.
worldPosition = modelToWorldMatrix * position;
vec4 cameraPosition = worldToCameraMatrix * worldPosition;
worldNormal = normal;
gl_Position = cameraToClipMatrix * cameraPosition;
}