A WIP 3D game engine in C++ using OpenGL
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

49 lines
1.1 KiB

#version 330 core
layout (location = 0) in vec3 LVertexPos2D;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTexCoords;
layout (location = 3) in vec3 offset;
layout (location = 4) in vec3 aTangent;
layout (location = 5) in mat4 modelInst;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
out vec3 Normal;
out vec3 FragPos;
out vec3 theTexCoord;
out mat3 TBN;
void main()
{
vec4 pos = (vec4( LVertexPos2D, 1.0) + vec4(offset, 0));
vec4 ppos = projection * view * model * pos;
// ps1 jiggle
vec2 resolution = vec2(100,75);
vec4 snapped = ppos;
snapped.xyz = ppos.xyz / ppos.w;
snapped.xy = floor(resolution * snapped.xy) / resolution;
snapped.xyz *= ppos.w;
// use gl_Position = ppos; to disable jiggle
gl_Position = snapped;
theTexCoord = vec3(aTexCoords, 1.0);
Normal = mat3(transpose(inverse(model))) * aNormal;
FragPos = vec3((model) * pos);
// calculating TBN
vec3 T = normalize(vec3(model * vec4(aTangent, 0.0)));
vec3 N = normalize(vec3(model * vec4(aNormal, 0.0)));
T = normalize(T - dot(T, N) * N);
vec3 B = cross(N,T);
TBN = mat3(T, B, N);
}