Got normal decoding working in shader.

This commit is contained in:
David Williams
2014-05-29 23:31:36 +02:00
parent 2c916300ea
commit 224c27de50
2 changed files with 9 additions and 3 deletions

View File

@ -1,7 +1,7 @@
#version 140
in uvec4 position; // This will be the position of the vertex in model-space
in vec4 normal;
in uint normal;
// The usual matrices are provided
uniform mat4 cameraToClipMatrix;
@ -18,7 +18,13 @@ void main()
vec4 decodedPosition = position;
decodedPosition.xyz = decodedPosition.xyz * (1.0 / 256.0);
worldNormal = normal;
uint encodedX = (normal >> 10u) & 0x1Fu;
uint encodedY = (normal >> 5u) & 0x1Fu;
uint encodedZ = (normal) & 0x1Fu;
worldNormal.xyz = vec3(encodedX, encodedY, encodedZ);
worldNormal.xyz = worldNormal.xyz / 15.5;
worldNormal.xyz = worldNormal.xyz - vec3(1.0, 1.0, 1.0);
worldNormal.w = 1.0;
// Standard sequence of OpenGL transformations.
worldPosition = modelToWorldMatrix * decodedPosition;