Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Default.vert
- #version 330 core
- uniform mat4 matModelView;
- uniform mat4 matProjection;
- uniform mat4 matWorld;
- uniform mat4 matModelWorld;
- uniform mat4 matFullTransform;
- uniform mat3 matNormal;
- uniform vec3 uniLight0Position;
- uniform vec3 uniLight0Color;
- in vec3 inPosition;
- in vec2 inTexCoord;
- in vec3 inNormal;
- out mat3 vertObjectTransform;
- out vec4 vertPosition;
- out vec2 vertTexCoord;
- out vec3 vertNormal;
- out vec3 vertEye;
- out vec3 vertLight;
- void main()
- {
- vec4 vertex = vec4(inPosition, 1.0);
- vertNormal = normalize(matNormal * inNormal);
- //vertLight = uniLight0Position.xyz;
- vertLight = vec3(0.0, 0.0, 1.0);
- vertEye = (matModelWorld * vertex).xyz;
- vertTexCoord = inTexCoord;
- gl_Position = matFullTransform * vertex;
- }
- // Default.frag
- #version 330 core
- in mat3 vertObjectTransform;
- in vec4 vertPosition;
- in vec2 vertTexCoord;
- in vec3 vertNormal;
- in vec3 vertEye;
- in vec3 vertLight;
- uniform vec4 u_ColorAmbient;
- uniform vec4 u_ColorDiffuse;
- uniform vec4 u_ColorSpecular;
- uniform vec4 u_Specular;
- uniform sampler2D uniTexDiffuse;
- uniform sampler2D uniTexNormal;
- out vec4 fragColor;
- vec4 Lighting(vec3 a_Normal, vec3 a_LightPos, vec3 a_Eye, vec3 a_Attenuation, float a_LightIntensity, float a_Shininess)
- {
- vec3 N = normalize(a_Normal);
- vec3 L = normalize(a_LightPos - a_Eye);
- vec3 E = normalize(-a_Eye);
- vec3 R = normalize(-reflect(L, N));
- float diffuse = max(dot(N, L), 0.0);
- float specular = pow(max(dot(R, E), 0.0), a_Shininess);
- float attenuation = a_LightIntensity;
- return (vec4(1.0, 1.0, 1.0, 1.0) * diffuse) + (vec4(1.0, 1.0, 1.0, 1.0) * specular * attenuation);
- }
- vec4 NormalToColor(vec3 a_Normal)
- {
- return vec4((a_Normal / 2.0) + 0.5, 1.0);
- }
- vec3 ColorToNormal(vec4 a_Color)
- {
- return (((a_Color - 0.5) * 2.0).xyz);
- }
- void main()
- {
- vec4 texel_diff = texture2D(uniTexDiffuse, vertTexCoord);
- vec4 texel_normal = texture2D(uniTexNormal, vertTexCoord);
- //vec3 N = vertObjectTransform * vertNormal;
- vec3 N = vertNormal;
- vec4 Final = Lighting(
- N,
- vertLight,
- vertEye,
- vec3(0.1, 0.1, 0.0),
- 1.0,
- 10.0
- );
- fragColor = Final * texel_diff;
- //fragColor = texel_diff;
- }
Add Comment
Please, Sign In to add comment