16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 01:59:19 +02:00
This commit is contained in:
milek7
2018-07-08 21:33:26 +02:00
parent 1c26096c5c
commit 13ba3fcd13
40 changed files with 917 additions and 506 deletions

View File

@@ -2,6 +2,8 @@
in vec3 f_color;
#include <common>
void main()
{
gl_FragColor = vec4(f_color, 1.0f);

13
shaders/freespot.frag Normal file
View File

@@ -0,0 +1,13 @@
#version 330
#include <common>
void main()
{
float x = (gl_PointCoord.x - 0.5f) * 2.0f;
float y = (gl_PointCoord.y - 0.5f) * 2.0f;
float dist2 = abs(x * x + y * y);
if (dist2 > 0.5f * 0.5f)
discard;
gl_FragColor = param[0] * emission;
}

12
shaders/freespot.vert Normal file
View File

@@ -0,0 +1,12 @@
#version 330
in vec3 v_vert;
in vec3 v_normal;
in vec2 v_coord;
#include <common>
void main()
{
gl_Position = (projection * modelview) * vec4(v_vert, 1.0f);
}

83
shaders/mat_default.frag Normal file
View File

@@ -0,0 +1,83 @@
#version 330
in vec3 f_normal;
in vec2 f_coord;
in vec3 f_pos;
#include <common>
uniform sampler2D tex1;
vec3 apply_fog(vec3 color)
{
float sun_amount = 0.0;
if (lights_count >= 1U && lights[0].type == LIGHT_DIR)
sun_amount = max(dot(normalize(f_pos), normalize(-lights[0].dir)), 0.0);
vec3 fog_color_v = mix(fog_color, lights[0].color, pow(sun_amount, 30.0));
float fog_amount_v = 1.0 - min(1.0, exp(-length(f_pos) * fog_density));
return mix(color, fog_color_v, fog_amount_v);
}
float calc_light(vec3 light_dir)
{
vec3 normal = normalize(f_normal);
vec3 view_dir = normalize(vec3(0.0f, 0.0f, 0.0f) - f_pos);
vec3 halfway_dir = normalize(light_dir + view_dir);
float diffuse_v = max(dot(normal, light_dir), 0.0);
float specular_v = pow(max(dot(normal, halfway_dir), 0.0), 15.0);
return specular_v + diffuse_v;
}
float calc_point_light(light_s light)
{
vec3 light_dir = normalize(light.pos - f_pos);
float val = calc_light(light_dir);
float distance = length(light.pos - f_pos);
float atten = 1.0f / (1.0f + light.linear * distance + light.quadratic * (distance * distance));
return val * atten;
}
float calc_spot_light(light_s light)
{
vec3 light_dir = normalize(light.pos - f_pos);
float theta = dot(light_dir, normalize(-light.dir));
float epsilon = light.in_cutoff - light.out_cutoff;
float intensity = clamp((theta - light.out_cutoff) / epsilon, 0.0, 1.0);
float point = calc_point_light(light);
return point * intensity;
}
float calc_dir_light(light_s light)
{
vec3 light_dir = normalize(-light.dir);
return calc_light(light_dir);
}
void main()
{
vec3 result = ambient * 0.3 + param[0].rgb * emission;
for (uint i = 0U; i < lights_count; i++)
{
light_s light = lights[i];
float part = 0.0;
if (light.type == LIGHT_SPOT)
part = calc_spot_light(light);
else if (light.type == LIGHT_POINT)
part = calc_point_light(light);
else if (light.type == LIGHT_DIR)
part = calc_dir_light(light);
result += light.color * part;
}
vec4 tex_color = texture(tex1, f_coord);
vec3 c = apply_fog(result * tex_color.xyz);
gl_FragColor = vec4(c, tex_color.w);
}

8
shaders/mat_invalid.frag Normal file
View File

@@ -0,0 +1,8 @@
#version 330
#include <common>
void main()
{
gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);
}

15
shaders/mat_nolight.frag Normal file
View File

@@ -0,0 +1,15 @@
#version 330
in vec3 f_normal;
in vec2 f_coord;
in vec3 f_pos;
uniform sampler2D tex1;
#include <common>
void main()
{
vec4 tex_color = texture(tex1, f_coord);
gl_FragColor = vec4(tex_color.xyz * ambient, tex_color.a);
}

91
shaders/mat_normal.frag Normal file
View File

@@ -0,0 +1,91 @@
#version 330
in vec3 f_normal;
in vec2 f_coord;
in vec3 f_pos;
in mat3 f_tbn;
in vec4 f_tangent;
uniform sampler2D tex1;
uniform sampler2D tex2;
#include <common>
vec3 apply_fog(vec3 color)
{
float sun_amount = 0.0;
if (lights_count >= 1U && lights[0].type == LIGHT_DIR)
sun_amount = max(dot(normalize(f_pos), normalize(-lights[0].dir)), 0.0);
vec3 fog_color_v = mix(fog_color, lights[0].color, pow(sun_amount, 30.0));
float fog_amount_v = 1.0 - min(1.0, exp(-length(f_pos) * fog_density));
return mix(color, fog_color_v, fog_amount_v);
}
float calc_light(vec3 light_dir)
{
//vec3 normal = normalize(f_normal);
vec3 normal = f_tbn * normalize(texture(tex2, f_coord).rgb * 2.0 - 1.0);
vec3 view_dir = normalize(vec3(0.0f, 0.0f, 0.0f) - f_pos);
vec3 halfway_dir = normalize(light_dir + view_dir);
float diffuse_v = max(dot(normal, light_dir), 0.0);
float specular_v = pow(max(dot(normal, halfway_dir), 0.0), 15.0) * 0.2;
return specular_v + diffuse_v;
}
float calc_point_light(light_s light)
{
vec3 light_dir = normalize(light.pos - f_pos);
float val = calc_light(light_dir);
float distance = length(light.pos - f_pos);
float atten = 1.0f / (1.0f + light.linear * distance + light.quadratic * (distance * distance));
return val * atten;
}
float calc_spot_light(light_s light)
{
vec3 light_dir = normalize(light.pos - f_pos);
float theta = dot(light_dir, normalize(-light.dir));
float epsilon = light.in_cutoff - light.out_cutoff;
float intensity = clamp((theta - light.out_cutoff) / epsilon, 0.0, 1.0);
float point = calc_point_light(light);
return point * intensity;
}
float calc_dir_light(light_s light)
{
vec3 light_dir = normalize(-light.dir);
return calc_light(light_dir);
}
void main()
{
vec3 result = ambient * 0.3 + param[0].rgb * emission;
for (uint i = 0U; i < lights_count; i++)
{
light_s light = lights[i];
float part = 0.0;
if (light.type == LIGHT_SPOT)
part = calc_spot_light(light);
else if (light.type == LIGHT_POINT)
part = calc_point_light(light);
else if (light.type == LIGHT_DIR)
part = calc_dir_light(light);
result += light.color * part;
}
vec4 tex_color = texture(tex1, f_coord);
vec3 c = apply_fog(result * tex_color.xyz);
gl_FragColor = vec4(c, tex_color.w);
// gl_FragColor = vec4(f_tangent.xyz, 1.0f);
}

8
shaders/mat_notex.frag Normal file
View File

@@ -0,0 +1,8 @@
#version 330
#include <common>
void main()
{
gl_FragColor = param[0];
}

28
shaders/simple.vert Normal file
View File

@@ -0,0 +1,28 @@
#version 330
in vec3 v_vert;
in vec3 v_normal;
in vec2 v_coord;
in vec4 v_tangent;
out vec3 f_normal;
out vec2 f_coord;
out vec3 f_pos;
out mat3 f_tbn;
out vec4 f_tangent;
#include <common>
void main()
{
gl_Position = (projection * modelview) * vec4(v_vert, 1.0f);
f_normal = modelviewnormal * v_normal;
f_coord = v_coord;
f_tangent = v_tangent;
f_pos = vec3(modelview * vec4(v_vert, 1.0f));
vec3 T = normalize(modelviewnormal * v_tangent.xyz);
vec3 B = normalize(modelviewnormal * cross(v_normal, v_tangent.xyz) * v_tangent.w);
vec3 N = normalize(modelviewnormal * v_normal);
f_tbn = mat3(T, B, N);
}

8
shaders/traction.frag Normal file
View File

@@ -0,0 +1,8 @@
#version 330
#include <common>
void main()
{
gl_FragColor = param[0];
}

12
shaders/traction.vert Normal file
View File

@@ -0,0 +1,12 @@
#version 330
in vec3 v_vert;
in vec3 v_normal;
in vec2 v_coord;
#include <common>
void main()
{
gl_Position = (projection * modelview) * vec4(v_vert, 1.0f);
}

View File

@@ -5,8 +5,7 @@ in vec3 v_color;
out vec3 f_color;
uniform mat4 modelview;
uniform mat4 projection;
#include <common>
void main()
{