Got normal decoding working in shader.
This commit is contained in:
parent
2c916300ea
commit
224c27de50
@ -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;
|
||||
|
@ -99,7 +99,7 @@ OpenGLMeshData buildOpenGLMeshData(const PolyVox::Mesh< PolyVox::MarchingCubesVe
|
||||
// shader. This is mostly just to simplify this example code - in a real application you will know whether your
|
||||
// chosen surface extractor generates normals and can skip uploading them if not.
|
||||
glEnableVertexAttribArray(1); // Attrib '1' is the vertex normals.
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(MarchingCubesVertex< uint8_t >), (GLvoid*)(offsetof(MarchingCubesVertex< uint8_t >, normal)));
|
||||
glVertexAttribIPointer(1, 1, GL_UNSIGNED_SHORT, sizeof(MarchingCubesVertex< uint8_t >), (GLvoid*)(offsetof(MarchingCubesVertex< uint8_t >, normal)));
|
||||
|
||||
// Finally a surface extractor will probably output additional data. This is highly application dependant. For this example code
|
||||
// we're just uploading it as a set of bytes which we can read individually, but real code will want to do something specialised here.
|
||||
|
Loading…
x
Reference in New Issue
Block a user