Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 330
- // Matrices
- uniform mat4 matrixProjection;
- uniform mat4 matrixView;
- uniform mat4 matrixModelView;
- uniform mat4 matrixShadow;
- // Materials
- uniform vec3 materialAmbient;
- uniform vec3 materialDiffuse;
- uniform float fogThickness;
- layout (location = 0) in vec3 aVertex;
- layout (location = 2) in vec3 aNormal;
- layout (location = 3) in vec2 aTexCoord;
- layout (location = 4) in vec3 aTangent;
- layout (location = 5) in vec3 aBiTangent;
- out vec4 color;
- out vec4 position;
- out vec3 normal;
- out float fogStrength;
- out vec2 texCoord0;
- out mat3 matrixTangent;
- out vec4 shadowCoord;
- // ambient light declaration
- struct AMBIENT
- {
- int on;
- vec3 color;
- };
- uniform AMBIENT lightAmbient;
- // ambient light function
- vec4 AmbientLight(AMBIENT light)
- {
- return vec4(materialAmbient * light.color, 1);
- }
- void main(void)
- {
- // calculate position
- position = matrixModelView * vec4(aVertex, 1.0);
- //gl_Position = vec4(aVertex, 100.0);
- //gl_Position = vec4(vec2(aVertex.x, aVertex.y), 1.0, 50.0) - vec4(20.0, 50.0, 0.0, 0.0);
- gl_Position = matrixProjection * position;
- // calculating color
- color = vec4 (0, 0, 0, 1);
- // calculating normals
- normal = normalize(mat3(matrixModelView) * aNormal);
- // calculating tangents for normal maps
- vec3 tangent = normalize(mat3(matrixModelView) * aTangent);
- vec3 biTangent = normalize(mat3(matrixModelView) * aBiTangent);
- matrixTangent = mat3(tangent, biTangent, normal);
- // calculating fog
- fogStrength = exp2(-fogThickness * length(position));
- // prepare texture vertexes to be sent to fragment shader
- texCoord0 = aTexCoord;
- // calculate shadow coordinate – using the Shadow Matrix
- mat4 matrixModel = inverse(matrixView) * matrixModelView;
- shadowCoord = matrixShadow * matrixModel * vec4(aVertex + aNormal * 2.0, 1.0);
- if (lightAmbient.on == 1) color += AmbientLight(lightAmbient);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement