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

49 lines
1.5 KiB
Plaintext
Raw Normal View History

2017-07-17 15:06:27 +03: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-05 01:24:30 +03:00
in vec4 vertexTangent;
2017-07-17 15:06:27 +03:00
// Input uniform values
2017-08-25 02:43:55 +03:00
uniform mat4 mvp;
2018-05-06 01:44:59 +03:00
uniform mat4 matModel;
2017-07-17 15:06:27 +03: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-05 01:24:30 +03:00
vec3 vertexBinormal = cross(vertexNormal, vec3(vertexTangent));
2017-07-17 15:06:27 +03:00
// Calculate fragment normal based on normal transformations
2018-05-06 01:44:59 +03:00
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
2017-07-17 15:06:27 +03:00
// Calculate fragment position based on model transformations
2018-05-06 01:44:59 +03:00
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0f));
2017-07-17 15:06:27 +03:00
// Send vertex attributes to fragment shader
fragTexCoord = vertexTexCoord;
fragNormal = normalize(normalMatrix*vertexNormal);
2018-03-05 01:24:30 +03:00
fragTangent = normalize(normalMatrix*vec3(vertexTangent));
2017-07-17 15:06:27 +03:00
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal);
fragBinormal = normalize(normalMatrix*vertexBinormal);
fragBinormal = cross(fragNormal, fragTangent);
// Calculate final vertex position
2017-08-25 02:43:55 +03:00
gl_Position = mvp*vec4(vertexPosition, 1.0);
2017-07-17 15:06:27 +03:00
}