Getting ready to decode normal.
This commit is contained in:
parent
e40eb6d762
commit
a6a1c4dbb7
@ -11,9 +11,9 @@ void main()
|
|||||||
{
|
{
|
||||||
// Again, for the purposes of these examples we cannot be sure that per-vertex normals are provided. A sensible fallback
|
// Again, for the purposes of these examples we cannot be sure that per-vertex normals are provided. A sensible fallback
|
||||||
// is to use this little trick to compute per-fragment flat-shaded normals from the world positions using derivative operations.
|
// is to use this little trick to compute per-fragment flat-shaded normals from the world positions using derivative operations.
|
||||||
vec3 normal = normalize(cross(dFdy(worldPosition.xyz), dFdx(worldPosition.xyz)));
|
//vec3 normal = normalize(cross(dFdy(worldPosition.xyz), dFdx(worldPosition.xyz)));
|
||||||
|
|
||||||
// We are just using the normal as the output color, and making it lighter so it looks a bit nicer.
|
// We are just using the normal as the output color, and making it lighter so it looks a bit nicer.
|
||||||
// Obviously a real shader would also do texuring, lighting, or whatever is required for the application.
|
// Obviously a real shader would also do texuring, lighting, or whatever is required for the application.
|
||||||
outputColor = vec4(abs(normal) * 0.5 + vec3(0.5, 0.5, 0.5), 1.0);
|
outputColor = vec4(abs(worldNormal.xyz) * 0.5 + vec3(0.5, 0.5, 0.5), 1.0);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#version 140
|
#version 140
|
||||||
|
|
||||||
in uvec4 position; // This will be the position of the vertex in model-space
|
in uvec4 position; // This will be the position of the vertex in model-space
|
||||||
|
in vec4 normal;
|
||||||
|
|
||||||
// The usual matrices are provided
|
// The usual matrices are provided
|
||||||
uniform mat4 cameraToClipMatrix;
|
uniform mat4 cameraToClipMatrix;
|
||||||
@ -10,12 +11,15 @@ uniform mat4 modelToWorldMatrix;
|
|||||||
// This will be used by the fragment shader to calculate flat-shaded normals. This is an unconventional approach
|
// 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.
|
// but we use it in this example framework because not all surface extractor generate surface normals.
|
||||||
out vec4 worldPosition;
|
out vec4 worldPosition;
|
||||||
|
out vec4 worldNormal;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 decodedPosition = position;
|
vec4 decodedPosition = position;
|
||||||
decodedPosition.xyz = decodedPosition.xyz * (1.0 / 256.0);
|
decodedPosition.xyz = decodedPosition.xyz * (1.0 / 256.0);
|
||||||
|
|
||||||
|
worldNormal = normal;
|
||||||
|
|
||||||
// Standard sequence of OpenGL transformations.
|
// Standard sequence of OpenGL transformations.
|
||||||
worldPosition = modelToWorldMatrix * decodedPosition;
|
worldPosition = modelToWorldMatrix * decodedPosition;
|
||||||
vec4 cameraPosition = worldToCameraMatrix * worldPosition;
|
vec4 cameraPosition = worldToCameraMatrix * worldPosition;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user