Files
raylib/examples/models/resources/shaders/pbr.vs

49 lines
1.5 KiB
Plaintext
Raw Normal View History

2017-07-17 14:06:27 +02:00
/*******************************************************************************************
*
* rPBR [shader] - Physically based rendering vertex shader
*
* Copyright (c) 2017 Victor Fisac
*
**********************************************************************************************/
#version 330
// Input vertex attributes
in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec3 vertexNormal;
2018-03-04 23:24:30 +01:00
in vec4 vertexTangent;
2017-07-17 14:06:27 +02:00
// Input uniform values
2017-08-25 01:43:55 +02:00
uniform mat4 mvp;
2018-05-06 00:44:59 +02:00
uniform mat4 matModel;
2017-07-17 14:06:27 +02:00
// Output vertex attributes (to fragment shader)
out vec3 fragPosition;
out vec2 fragTexCoord;
out vec3 fragNormal;
out vec3 fragTangent;
out vec3 fragBinormal;
void main()
{
// Calculate binormal from vertex normal and tangent
2018-03-04 23:24:30 +01:00
vec3 vertexBinormal = cross(vertexNormal, vec3(vertexTangent));
2017-07-17 14:06:27 +02:00
// Calculate fragment normal based on normal transformations
2018-05-06 00:44:59 +02:00
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
2017-07-17 14:06:27 +02:00
// Calculate fragment position based on model transformations
2018-05-06 00:44:59 +02:00
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0f));
2017-07-17 14:06:27 +02:00
// Send vertex attributes to fragment shader
fragTexCoord = vertexTexCoord;
fragNormal = normalize(normalMatrix*vertexNormal);
2018-03-04 23:24:30 +01:00
fragTangent = normalize(normalMatrix*vec3(vertexTangent));
2017-07-17 14:06:27 +02:00
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal);
fragBinormal = normalize(normalMatrix*vertexBinormal);
fragBinormal = cross(fragNormal, fragTangent);
// Calculate final vertex position
2017-08-25 01:43:55 +02:00
gl_Position = mvp*vec4(vertexPosition, 1.0);
2017-07-17 14:06:27 +02:00
}