Newer
Older
#shader vertex
#version 410
layout(location = 0) in vec4 position;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec2 uv;
layout(std140) uniform OK_Matrices{
Halvor Smedås
committed
mat4 projection;
mat4 view;
vec4 view_position;
mat4 rotate(float x, float y, float z) {
return mat4(
Halvor Smedås
committed
(cos(y + z) + cos(y - z)) / 2, (-sin(y + z) + sin(y - z)) / 2, -sin(y), 0,
(cos(x + y + z) - cos(x - y + z) + cos(x + y - z) - cos(x - y - z) + 2 * sin(x + z) - 2 * sin(x - z)) / 4, (2 * cos(x + z) + 2 * cos(x - z) - sin(x + y + z) + sin(x - y + z) + sin(x + y - z) - sin(x - y - z)) / 4, (-sin(x + y) - sin(x - y)) / 2, 0,
(-2 * cos(x + z) + 2 * cos(x - z) + sin(x + y + z) - sin(x - y + z) + sin(x + y - z) - sin(x - y - z)) / 4, (cos(x + y + z) - cos(x - y + z) - cos(x + y - z) + cos(x - y - z) + 2 * sin(x + z) + 2 * sin(x - z)) / 4, (cos(x + y) + cos(x - y)) / 2, 0,
0, 0, 0, 1
Halvor Smedås
committed
return projection * view * m2w * position;
Halvor Smedås
committed
float F = sqrt(position.x*position.x + position.y*position.y + position.z*position.z) * 0.01;
mat4 rot = rotate(0, time*F, 0);
Halvor Smedås
committed
vec4 rotatedNormal = rot * vec4(normal, 1);
Halvor Smedås
committed
// Pass some variables to the fragment shader
//fragNormal = vec3(rotatedNormal);
vertex_color_out = rotatedNormal;
texCoord = uv;
fragNormal = mat3(transpose(inverse(m2w))) * normal;
Halvor Smedås
committed
vec4 out_position = MVP(position);
gl_Position = out_position;
Halvor Smedås
committed
fragVert = vec3(m2w * position);
in vec2 texCoord;
in vec3 fragNormal;
in vec3 fragVert;
out vec4 out_color;
uniform float time = 0;
uniform sampler2D mainTex;
Halvor Smedås
committed
uniform float intensity = 1;
uniform float bumpiness = 1;
uniform mat4 m2w;
layout(std140) uniform OK_Matrices{
Halvor Smedås
committed
mat4 projection;
mat4 view;
vec4 view_position;
Halvor Smedås
committed
};
struct OK_Light {
vec4 position;
vec4 intensities;
Halvor Smedås
committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
OK_Light light[MAX_LIGHTS];
//float spread;
//float constant;
//float linear;
//float quadratic;
};
vec3 OK_PointLight(in vec3 position, in vec3 intensities/*, in float constant, in float linear, in float quadratic*/) {
//Ambience
float ambientStrength = 0.1;
vec3 ambient = ambientStrength * intensities;
vec3 bump = texture(bumpTex, texCoord).rgb*intensity;
// Diffussion
vec3 norm = normalize(fragNormal*bump);
vec3 lightDir = normalize(position - fragVert);
float diffusion = max(dot(norm, lightDir), 0.0);
vec3 diffuse = diffusion * intensities;
// Specularity
//float specularStrength = 0.5;
//vec3 viewDir = normalize(view_position.xyz - fragVert);
//vec3 reflectDir = reflect(-lightDir, norm);
//float specPower = pow(max(dot(viewDir, reflectDir), 0.0), 32);
//vec3 specular = specularStrength * specPower * intensities;
// Attenuation
//float distance = length(position - fragVert);
float attenuation = 1.0; // /(constant + linear * distance + quadratic * (distance * distance));
return (ambient*attenuation + diffuse * attenuation /*+ specular*specularity*attenuation*/);
Halvor Smedås
committed
vec3 diff = texture(mainTex, texCoord).rgb;
vec3 bump = texture(bumpTex, texCoord).rgb;
vec3 spec = texture(specTex, texCoord).rgb;
Halvor Smedås
committed
vec3 light0 = OK_PointLight(light[0].position.xyz, light[0].intensities.rgb /*,light[0].constant,light[0].linear, light[0].quadratic*/);
vec3 light1 = OK_PointLight(light[1].position.xyz, light[1].intensities.rgb /*,light[1].constant,light[1].linear, light[1].quadratic*/);
vec3 light2 = OK_PointLight(light[2].position.xyz, light[2].intensities.rgb /*,light[1].constant,light[1].linear, light[1].quadratic*/);
Halvor Smedås
committed
//out_color = vec4(fragNormal, 1)*0.2 + 0.8*vec4(texture(mainTex, texCoord).rgb , vertex_color_out.a);
out_color = vec4((light0+ light1+ light2) * diff, 1);
//out_color = vec4(texture(mainTexture, texCoord).rgb * vertex_color_out.rgb, vertex_color_out.a);