opengl 3.3 renderer shaders

This commit is contained in:
tmj-fstate
2020-02-21 22:50:52 +01:00
parent 7ba6383c75
commit 6b1ab6c125
47 changed files with 1620 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
in vec2 f_coord;
#texture (tex1, 0, sRGB_A)
uniform sampler2D tex1;
void main()
{
if (texture(tex1, f_coord).a < 0.5f)
discard;
}

30
shaders/apply_fog.glsl Normal file
View File

@@ -0,0 +1,30 @@
vec3 get_fog_color()
{
vec3 fog_color_v = fog_color;
if (lights_count >= 1U && lights[0].type == LIGHT_DIR) {
float sun_amount = max(dot(normalize(f_pos.xyz), normalize(-lights[0].dir)), 0.0);
fog_color_v += lights[0].color * pow(sun_amount, 30.0);
}
return fog_color_v;
}
float get_fog_amount()
{
float z = length(f_pos.xyz);
// float fog_amount_v = 1.0 - z * fog_density; // linear
// float fog_amount_v = exp( -fog_density * z ); // exp
float fog_amount_v = exp2( -fog_density * fog_density * z * z * 1.442695 ); // exp2
fog_amount_v = 1.0 - clamp(fog_amount_v, 0.0, 1.0);
return fog_amount_v;
}
vec3 apply_fog(vec3 color)
{
return mix(color, get_fog_color(), get_fog_amount());
}
vec3 add_fog(vec3 color, float amount)
{
return color + get_fog_color() * get_fog_amount() * amount;
}

25
shaders/billboard.frag Normal file
View File

@@ -0,0 +1,25 @@
in vec2 f_coord;
#texture (tex1, 0, sRGB_A)
uniform sampler2D tex1;
#include <common>
#include <tonemapping.glsl>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
void main()
{
vec4 tex_color = texture(tex1, f_coord);
#if POSTFX_ENABLED
out_color = tex_color * param[0];
#else
out_color = tonemap(tex_color * param[0]);
#endif
#if MOTIONBLUR_ENABLED
out_motion = vec4(0.0f);
#endif
}

25
shaders/celestial.frag Normal file
View File

@@ -0,0 +1,25 @@
in vec2 f_coord;
#texture (tex1, 0, sRGB_A)
uniform sampler2D tex1;
#include <common>
#include <tonemapping.glsl>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
void main()
{
vec4 tex_color = texture(tex1, f_coord);
#if POSTFX_ENABLED
out_color = tex_color * param[0];
#else
out_color = tonemap(tex_color * param[0]);
#endif
#if MOTIONBLUR_ENABLED
out_motion = vec4(0.0f);
#endif
}

28
shaders/celestial.vert Normal file
View File

@@ -0,0 +1,28 @@
const vec2 vert[4] = vec2[]
(
vec2(-1.0, 1.0),
vec2(-1.0, -1.0),
vec2( 1.0, 1.0),
vec2( 1.0, -1.0)
);
out vec2 f_coord;
#include <common>
void main()
{
gl_Position = projection * (vec4(param[1].xyz, 1.0) + vec4(vert[gl_VertexID] * param[1].w, 0.0, 0.0));
vec2 coord = param[2].xy;
float size = param[2].z;
if (gl_VertexID == 0)
f_coord = vec2(coord.x, coord.y);
if (gl_VertexID == 1)
f_coord = vec2(coord.x, coord.y - size);
if (gl_VertexID == 2)
f_coord = vec2(coord.x + size, coord.y);
if (gl_VertexID == 3)
f_coord = vec2(coord.x + size, coord.y - size);
}

23
shaders/color.frag Normal file
View File

@@ -0,0 +1,23 @@
in vec3 f_color;
in vec4 f_pos;
#include <common>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
void main()
{
#if POSTFX_ENABLED
out_color = vec4(apply_fog(f_color), 1.0f);
#else
out_color = tonemap(vec4(apply_fog(f_color), 1.0f));
#endif
#if MOTIONBLUR_ENABLED
out_motion = vec4(0.0f);
#endif
}

15
shaders/envmapping.glsl Normal file
View File

@@ -0,0 +1,15 @@
#if ENVMAP_ENABLED
uniform samplerCube envmap;
#endif
vec3 envmap_color( vec3 normal )
{
#if ENVMAP_ENABLED
vec3 refvec = reflect(f_pos.xyz, normal); // view space
refvec = vec3(inv_view * vec4(refvec, 0.0)); // world space
vec3 envcolor = texture(envmap, refvec).rgb;
#else
vec3 envcolor = vec3(0.5);
#endif
return envcolor;
}

38
shaders/freespot.frag Normal file
View File

@@ -0,0 +1,38 @@
in vec4 f_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#include <tonemapping.glsl>
#include <apply_fog.glsl>
void main()
{
float x = (gl_PointCoord.x - 0.5f) * 2.0f;
float y = (gl_PointCoord.y - 0.5f) * 2.0f;
float dist = sqrt(x * x + y * y);
if (dist > 0.5f)
discard;
// vec4 color = vec4(param[0].rgb * emission, mix(param[0].a, 0.0f, dist * 2.0f));
vec4 color = vec4(apply_fog(param[0].rgb * emission), mix(param[0].a, 0.0f, dist * 2.0f));
// vec4 color = vec4(add_fog(param[0].rgb * emission * (1.0 - get_fog_amount()), 1.0), mix(param[0].a, 0.0f, dist * 2.0f));
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

19
shaders/freespot.vert Normal file
View File

@@ -0,0 +1,19 @@
layout(location = 0) in vec3 v_vert;
layout(location = 1) in vec3 v_normal;
layout(location = 2) in vec2 v_coord;
#include <common>
out vec4 f_pos;
out vec4 f_clip_pos;
out vec4 f_clip_future_pos;
void main()
{
f_pos = modelview * vec4(v_vert, 1.0);
f_clip_pos = (projection * modelview) * vec4(v_vert, 1.0f);
f_clip_future_pos = (projection * future * modelview) * vec4(v_vert, 1.0f);
gl_Position = f_clip_pos;
gl_PointSize = param[1].x;
}

View File

@@ -0,0 +1,11 @@
in vec2 f_coords;
#texture (tex1, 0, R)
uniform sampler2D tex1;
layout(location = 0) out uvec4 out_color;
void main()
{
out_color = uvec4(uint(texture(tex1, f_coords).r * 65535.0), 0, 0, 0xFFFF);
}

162
shaders/light_common.glsl Normal file
View File

@@ -0,0 +1,162 @@
#if SHADOWMAP_ENABLED
in vec4 f_light_pos[MAX_CASCADES];
uniform sampler2DArrayShadow shadowmap;
#endif
uniform sampler2D headlightmap;
#include <envmapping.glsl>
float length2(vec3 v)
{
return dot(v, v);
}
float calc_shadow()
{
#if SHADOWMAP_ENABLED
float distance = dot(f_pos.xyz, f_pos.xyz);
uint cascade;
for (cascade = 0U; cascade < MAX_CASCADES; cascade++)
if (distance <= cascade_end[cascade])
break;
vec3 coords = f_light_pos[cascade].xyz / f_light_pos[cascade].w;
if (coords.z < 0.0f)
return 0.0f;
float shadow = 0.0;
//basic
// shadow = texture(shadowmap, coords.xyz + vec3(0.0, 0.0, bias));
//PCF
float bias = 0.00005f * (cascade + 1U);
vec2 texel = vec2(1.0) / vec2(textureSize(shadowmap, 0));
float radius = 1.0;
for (float y = -1.5; y <= 1.5; y += 1.0)
for (float x = -1.5; x <= 1.5; x += 1.0)
shadow += texture( shadowmap, vec4(coords.xy + vec2(x, y) * radius * texel, cascade, coords.z + bias) );
shadow /= 16.0;
return shadow;
#else
return 0.0;
#endif
}
// [0] - diffuse, [1] - specular
// do magic here
vec2 calc_light(vec3 light_dir, vec3 fragnormal)
{
vec3 view_dir = normalize(vec3(0.0f, 0.0f, 0.0f) - f_pos.xyz);
vec3 halfway_dir = normalize(light_dir + view_dir);
float diffuse_v = max(dot(fragnormal, light_dir), 0.0);
float specular_v = pow(max(dot(fragnormal, halfway_dir), 0.0), max(abs(param[1].w), 0.01)) * diffuse_v;
return vec2(diffuse_v, specular_v);
}
vec2 calc_point_light(light_s light, vec3 fragnormal)
{
vec3 light_dir = normalize(light.pos - f_pos.xyz);
vec2 val = calc_light(light_dir, fragnormal);
val.x += light.ambient;
val *= light.intensity;
float distance = length(light.pos - f_pos.xyz);
float atten = 1.0f / (1.0f + light.linear * distance + light.quadratic * (distance * distance));
return val * atten;
}
vec2 calc_spot_light(light_s light, vec3 fragnormal)
{
vec3 light_dir = normalize(light.pos - f_pos.xyz);
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);
vec2 point = calc_point_light(light, fragnormal);
return point * intensity;
}
vec2 calc_dir_light(light_s light, vec3 fragnormal)
{
vec3 light_dir = normalize(-light.dir);
return calc_light(light_dir, fragnormal);
}
vec2 calc_headlights(light_s light, vec3 fragnormal)
{
vec4 headlightpos = light.headlight_projection * f_pos;
vec3 coords = headlightpos.xyz / headlightpos.w;
if (coords.z > 1.0)
return vec2(0.0);
if (coords.z < 0.0)
return vec2(0.0);
vec3 light_dir = normalize(light.pos - f_pos.xyz);
vec2 part = vec2(1.0) * clamp(dot(fragnormal, light_dir) + 0.25, 0.0, 1.0);
float distance = length(light.pos - f_pos.xyz);
float atten = 1.0f / (1.0f + light.linear * distance + light.quadratic * (distance * distance));
atten *= mix(1.0, 0.0, clamp((coords.z - 0.998) * 500.0, 0.0, 1.0));
vec3 lights = textureProj(headlightmap, headlightpos).rgb * light.headlight_weights.rgb;
float lightintensity = max(max(lights.r, lights.g), lights.b);
return part * atten * lightintensity;
}
vec3 apply_lights(vec3 fragcolor, vec3 fragnormal, vec3 texturecolor, float reflectivity, float specularity, float shadowtone)
{
vec3 emissioncolor = param[0].rgb * emission;
vec3 envcolor = envmap_color(fragnormal);
if(lights_count == 0U)
return (fragcolor + emissioncolor + envcolor * reflectivity) * texturecolor;
vec2 sunlight = calc_dir_light(lights[0], fragnormal);
float diffuseamount = (sunlight.x * param[1].x) * lights[0].intensity;
// fragcolor += mix(lights[0].color * diffuseamount, envcolor, reflectivity);
fragcolor += lights[0].color * diffuseamount;
fragcolor = mix(fragcolor, envcolor, reflectivity);
for (uint i = 1U; i < lights_count; i++)
{
light_s light = lights[i];
vec2 part = vec2(0.0);
// if (light.type == LIGHT_SPOT)
// part = calc_spot_light(light, fragnormal);
// else if (light.type == LIGHT_POINT)
// part = calc_point_light(light, fragnormal);
// else if (light.type == LIGHT_DIR)
// part = calc_dir_light(light, fragnormal);
// else if (light.type == LIGHT_HEADLIGHTS)
part = calc_headlights(light, fragnormal);
fragcolor += light.color * (part.x * param[1].x + part.y * param[1].y) * light.intensity;
}
float specularamount = (sunlight.y * param[1].y * specularity) * lights[0].intensity * clamp(1.0 - shadowtone, 0.0, 1.0);
if (shadowtone < 1.0)
{
float shadow = calc_shadow();
specularamount *= clamp(1.0 - shadow, 0.0, 1.0);
fragcolor = mix(fragcolor, fragcolor * shadowtone, clamp(diffuseamount * shadow + specularamount, 0.0, 1.0));
}
fragcolor += emissioncolor;
vec3 specularcolor = specularamount * lights[0].color;
if (param[1].w >= 0.0)
{
fragcolor *= texturecolor;
fragcolor += specularcolor;
}
else
{
fragcolor += specularcolor;
fragcolor *= texturecolor;
}
return fragcolor;
}

8
shaders/map.frag Normal file
View File

@@ -0,0 +1,8 @@
#include <common>
layout(location = 0) out vec4 out_color;
void main()
{
out_color = vec4(scene_extra, 1.0f);
}

14
shaders/map.vert Normal file
View File

@@ -0,0 +1,14 @@
layout(location = 0) in vec3 v_vert;
layout(location = 2) in vec2 v_coords;
out vec2 g_coords;
#include <common>
void main()
{
vec4 clip_pos = projection * vec4(v_vert, 1.0f);
gl_Position = vec4(clip_pos.xz, 0.5, 1.0);
g_coords = v_coords;
}

14
shaders/map_poi.frag Normal file
View File

@@ -0,0 +1,14 @@
in vec2 f_coords;
layout(location = 0) out vec4 out_color;
#texture (tex1, 0, sRGB_A)
uniform sampler2D tex1;
void main()
{
vec2 texcoord = f_coords;
vec4 color = texture(tex1, texcoord);
out_color = color;
}

30
shaders/map_poi.geom Normal file
View File

@@ -0,0 +1,30 @@
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
in vec2 g_coords[];
out vec2 f_coords;
#include <common>
void main() {
vec4 position = gl_in[0].gl_Position;
vec2 size = vec2(0.1) * scene_extra.xy;
gl_Position = position + vec4(-size.x, -size.y, 0.0, 0.0);
f_coords = vec2(g_coords[0].s, 0.0);
EmitVertex();
gl_Position = position + vec4( size.x, -size.y, 0.0, 0.0);
f_coords = vec2(g_coords[0].t, 0.0);
EmitVertex();
gl_Position = position + vec4(-size.x, size.y, 0.0, 0.0);
f_coords = vec2(g_coords[0].s, 1.0);
EmitVertex();
gl_Position = position + vec4( size.x, size.y, 0.0, 0.0);
f_coords = vec2(g_coords[0].t, 1.0);
EmitVertex();
EndPrimitive();
}

61
shaders/mat_clouds.frag Normal file
View File

@@ -0,0 +1,61 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
#param (diffuse, 1, 0, 1, diffuse)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#include <apply_fog.glsl>
#include <tonemapping.glsl>
vec3 apply_lights_clouds(vec3 fragcolor, vec3 fragnormal, vec3 texturecolor)
{
if(lights_count == 0U)
return fragcolor * texturecolor;
vec3 light_dir = normalize(-lights[0].dir);
vec3 view_dir = normalize(vec3(0.0) - f_pos.xyz);
vec3 halfway_dir = normalize(light_dir + view_dir);
float diffuse_v = max(dot(fragnormal, light_dir), 0.0);
float diffuseamount = (diffuse_v * param[1].x) * lights[0].intensity;
fragcolor += lights[0].color * diffuseamount;
fragcolor *= texturecolor;
return fragcolor;
}
void main()
{
vec4 tex_color = texture(diffuse, f_coord);
tex_color.a = clamp(tex_color.a * 1.25, 0.0, 1.0);
if(tex_color.a < 0.01)
discard;
vec3 fragcolor = param[0].rgb;
vec3 fragnormal = normalize(f_normal);
fragcolor = apply_lights_clouds(fragcolor, fragnormal, tex_color.rgb);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
out_motion = vec4(0.0f);
#endif
}

53
shaders/mat_colored.frag Normal file
View File

@@ -0,0 +1,53 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, zero)
#param (glossiness, 1, 3, 1, glossiness)
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
void main()
{
vec4 tex_color = vec4(pow(param[0].rgb, vec3(2.2)), param[0].a);
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 fragnormal = normalize(f_normal);
float reflectivity = param[1].z;
float specularity = (tex_color.r + tex_color.g + tex_color.b) * 0.5;
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

65
shaders/mat_default.frag Normal file
View File

@@ -0,0 +1,65 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, zero)
#param (glossiness, 1, 3, 1, glossiness)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
void main()
{
vec4 tex_color = texture(diffuse, f_coord);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 fragnormal = normalize(f_normal);
float reflectivity = param[1].z;
float specularity = (tex_color.r + tex_color.g + tex_color.b) * 0.5;
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
/*
float distance = dot(f_pos.xyz, f_pos.xyz);
if( distance <= cascade_end.x ) { color.r += 0.25; }
else if( distance <= cascade_end.y ) { color.g += 0.25; }
else if( distance <= cascade_end.z ) { color.b += 0.25; }
*/
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, tex_color.a * alpha_mult);
}
#endif
}

View File

@@ -0,0 +1 @@
#include <mat_colored.frag>

View File

@@ -0,0 +1 @@
#include <mat_default.frag>

View File

@@ -0,0 +1 @@
#include <mat_reflmap.frag>

20
shaders/mat_invalid.frag Normal file
View File

@@ -0,0 +1,20 @@
#include <common>
#include <tonemapping.glsl>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
void main()
{
vec4 color = vec4(1.0, 0.0, 1.0, 1.0);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
out_motion = vec4(0.0f);
#endif
}

View File

@@ -0,0 +1,68 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, one)
#param (glossiness, 1, 3, 1, glossiness)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (normalmap, 1, RGBA)
uniform sampler2D normalmap;
#define NORMALMAP
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
void main()
{
vec4 tex_color = texture(diffuse, f_coord);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 normal;
normal.xy = (texture(normalmap, f_coord).rg * 2.0 - 1.0);
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(normal.xyz));
float reflectivity = param[1].z * texture(normalmap, f_coord).a;
float specularity = (tex_color.r + tex_color.g + tex_color.b) * 0.5;
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

121
shaders/mat_parallax.frag Normal file
View File

@@ -0,0 +1,121 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn; //tangent matrix nietransponowany; mnożyć przez f_tbn dla TangentLightPos; TangentViewPos; TangentFragPos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
in vec3 TangentFragPos;
#include <common>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, one)
#param (glossiness, 1, 3, 1, glossiness)
#param (height_scale, 2, 1, 1, zero)
#param (height_offset, 2, 2, 1, zero)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (normalmap, 1, RGBA)
uniform sampler2D normalmap;
#define PARALLAX
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir);
void main()
{
//parallax mapping
vec3 viewDir = normalize(vec3(0.0f, 0.0f, 0.0f) - TangentFragPos); //tangent view pos - tangent frag pos
vec2 f_coord_p = ParallaxMapping(f_coord, viewDir);
vec4 tex_color = texture(diffuse, f_coord_p);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 normal;
normal.xy = (texture(normalmap, f_coord_p).rg * 2.0 - 1.0);
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(normal.xyz));
float reflectivity = param[1].z * texture(normalmap, f_coord_p).a;
float specularity = (tex_color.r + tex_color.g + tex_color.b) * 0.5;
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}
vec2 ParallaxMapping(vec2 f_coord, vec3 viewDir)
{
float pos_len = length(f_pos.xyz);
if (pos_len > 100.0) {
return f_coord;
}
#if EXTRAEFFECTS_ENABLED
const float minLayers = 8.0;
const float maxLayers = 32.0;
float LayersWeight = pos_len / 20.0;
vec2 currentTexCoords = f_coord;
float currentDepthMapValue = texture(normalmap, currentTexCoords).b;
LayersWeight = min(abs(dot(vec3(0.0, 0.0, 1.0), viewDir)),LayersWeight);
float numLayers = mix(maxLayers, minLayers, clamp(LayersWeight, 0.0, 1.0)); // number of depth layers
float layerDepth = 1.0 / numLayers; // calculate the size of each layer
float currentLayerDepth = 0.0; // depth of current layer
vec2 P = viewDir.xy * param[2].y; // the amount to shift the texture coordinates per layer (from vector P)
vec2 deltaTexCoords = P / numLayers;
while(currentLayerDepth < currentDepthMapValue)
{
currentTexCoords -= deltaTexCoords; // shift texture coordinates along direction of P
currentDepthMapValue = texture(normalmap, currentTexCoords).b; // get depthmap value at current texture coordinates
currentLayerDepth += layerDepth; // get depth of next layer
}
vec2 prevTexCoords = currentTexCoords + deltaTexCoords; // get texture coordinates before collision (reverse operations)
float afterDepth = currentDepthMapValue - currentLayerDepth; // get depth after and before collision for linear interpolation
float beforeDepth = texture(normalmap, prevTexCoords).b - currentLayerDepth + layerDepth;
float weight = afterDepth / (afterDepth - beforeDepth); // interpolation of texture coordinates
vec2 finalTexCoords = prevTexCoords * weight + currentTexCoords * (1.0 - weight);
return finalTexCoords;
#else
float height = texture(normalmap, f_coord).b;
vec2 p = viewDir.xy / viewDir.z * (height * (param[2].y - param[2].z) * 0.2);
return f_coord - p;
#endif
}

66
shaders/mat_reflmap.frag Normal file
View File

@@ -0,0 +1,66 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, one)
#param (glossiness, 1, 3, 1, glossiness)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (reflmap, 1, RGBA)
uniform sampler2D reflmap;
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
void main()
{
vec4 tex_color = texture(diffuse, f_coord);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 fragnormal = normalize(f_normal);
float reflectivity = param[1].z * texture(reflmap, f_coord).a;
float specularity = (tex_color.r + tex_color.g + tex_color.b) * 0.5;
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
if(alphatestfail)
fragcolor.r = 1.0;
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

View File

@@ -0,0 +1,67 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, zero)
#param (glossiness, 1, 3, 1, glossiness)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (normalmap, 1, RGBA)
uniform sampler2D normalmap;
#define NORMALMAP
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
void main()
{
vec4 tex_color = texture(diffuse, f_coord);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 normal;
normal.xy = (texture(normalmap, f_coord).rg * 2.0 - 1.0);
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(normal.xyz));
float reflectivity = param[1].z * texture(normalmap, f_coord).a;
float specularity = (tex_color.r + tex_color.g + tex_color.b) * 0.5;
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, 1.0);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

28
shaders/mat_stars.frag Normal file
View File

@@ -0,0 +1,28 @@
#include <common>
#include <tonemapping.glsl>
flat in vec3 f_normal_raw;
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
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;
// color data space is shared with normals, ugh
vec4 color = vec4(pow(f_normal_raw.rgb, vec3(2.2)), 1.0f);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
out_motion = vec4(0.0f);
#endif
}

View File

@@ -0,0 +1,110 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, zero)
#param (glossiness, 1, 3, 1, glossiness)
#texture (diffuse, 0, sRGB_A)
uniform sampler2D diffuse;
#texture (normalmap, 1, RGBA)
uniform sampler2D normalmap;
#define NORMALMAP
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
vec3 apply_lights_sunless(vec3 fragcolor, vec3 fragnormal, vec3 texturecolor, float reflectivity, float specularity, float shadowtone)
{
vec3 emissioncolor = param[0].rgb * emission;
vec3 envcolor = envmap_color(fragnormal);
if(lights_count == 0U)
return (fragcolor + emissioncolor + envcolor * reflectivity) * texturecolor;
vec2 sunlight = calc_dir_light(lights[0], fragnormal);
float diffuseamount = (sunlight.x * param[1].x) * lights[0].intensity;
fragcolor += envcolor * reflectivity;
float specularamount = (sunlight.y * param[1].y * specularity) * lights[0].intensity;
for (uint i = 1U; i < lights_count; i++)
{
light_s light = lights[i];
vec2 part = vec2(0.0);
// if (light.type == LIGHT_SPOT)
// part = calc_spot_light(light, fragnormal);
// else if (light.type == LIGHT_POINT)
// part = calc_point_light(light, fragnormal);
// else if (light.type == LIGHT_DIR)
// part = calc_dir_light(light, fragnormal);
// else if (light.type == LIGHT_HEADLIGHTS)
part = calc_headlights(light, fragnormal);
fragcolor += light.color * (part.x * param[1].x + part.y * param[1].y) * light.intensity;
}
if (shadowtone < 1.0)
{
float shadow = calc_shadow();
specularamount *= clamp(1.0 - shadow, 0.0, 1.0);
fragcolor = mix(fragcolor, fragcolor * shadowtone, clamp(diffuseamount * shadow + specularamount, 0.0, 1.0));
}
fragcolor += emissioncolor;
fragcolor *= texturecolor;
return fragcolor;
}
void main()
{
vec4 tex_color = texture(diffuse, f_coord);
bool alphatestfail = ( opacity >= 0.0 ? (tex_color.a < opacity) : (tex_color.a >= -opacity) );
if(alphatestfail)
discard;
// if (tex_color.a < opacity)
// discard;
vec3 fragcolor = ambient;
vec3 normal;
normal.xy = (texture(normalmap, f_coord).rg * 2.0 - 1.0);
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(normal.xyz));
float reflectivity = param[1].z * texture(normalmap, f_coord).a;
float specularity = (tex_color.r + tex_color.g + tex_color.b) * 0.5;
fragcolor = apply_lights_sunless(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
vec4 color = vec4(apply_fog(fragcolor), tex_color.a * alpha_mult);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

89
shaders/mat_water.frag Normal file
View File

@@ -0,0 +1,89 @@
in vec3 f_normal;
in vec2 f_coord;
in vec4 f_pos;
in mat3 f_tbn;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <common>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#param (color, 0, 0, 4, diffuse)
#param (diffuse, 1, 0, 1, diffuse)
#param (specular, 1, 1, 1, specular)
#param (reflection, 1, 2, 1, one)
#param (glossiness, 1, 3, 1, glossiness)
#param (wave_strength, 2, 1, 1, one)
#param (wave_speed, 2, 2, 1, one)
#texture (normalmap, 0, RGBA)
uniform sampler2D normalmap;
#texture (dudvmap, 1, RGB)
uniform sampler2D dudvmap;
#texture (diffuse, 2, sRGB_A)
uniform sampler2D diffuse;
//wave distortion variables
float move_factor = 0.0;
#define WATER
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
void main()
{
//wave distortion
move_factor += (param[2].z * time);
move_factor = mod(move_factor, 1.0);
vec2 texture_coords = f_coord;
vec2 distorted_tex_coord = texture(dudvmap, vec2(texture_coords.x + move_factor, texture_coords.y)).rg * 0.1;
distorted_tex_coord = texture_coords + vec2(distorted_tex_coord.x , distorted_tex_coord.y + move_factor);
vec2 total_distorted_tex_coord = (texture(dudvmap, distorted_tex_coord).rg * 2.0 - 1.0 ) * param[2].y;
texture_coords += total_distorted_tex_coord;
vec4 tex_color = texture(diffuse, texture_coords);
vec3 fragcolor = ambient * 0.25;
vec3 normal;
normal.xy = (texture(normalmap, texture_coords).rg * 2.0 - 1.0);
normal.z = sqrt(1.0 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0));
vec3 fragnormal = normalize(f_tbn * normalize(normal.xyz));
float reflectivity = param[1].z * texture(normalmap, texture_coords ).a;
float specularity = 1.0;
fragcolor = apply_lights(fragcolor, fragnormal, tex_color.rgb, reflectivity, specularity, shadow_tone);
//fragcolor = mix(fragcolor, param[0].rgb, param[1].z);
// fragcolor = (fragcolor * tex_color.rgb * param[1].z) + (fragcolor * (1.0 - param[1].z)); //multiply
//fragcolor = ( max(fragcolor + param[0].rgb -1.0,0.0) * param[1].z + fragcolor * (1.0 - param[1].z)); //linear burn
//fragcolor = ( min(param[0].rgb,fragcolor) * param[1].z + fragcolor * (1.0 - param[1].z)); //darken
// fresnel effect
vec3 view_dir = normalize(vec3(0.0f, 0.0f, 0.0f) - f_pos.xyz);
float fresnel = pow ( dot (f_normal, view_dir), 0.2 );
float fresnel_inv = ((fresnel - 1.0 ) * -1.0 );
vec4 color = vec4(apply_fog(clamp(fragcolor, 0.0, 1.0)), clamp((fresnel_inv + param[0].a), 0.0, 1.0));
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

8
shaders/pick.frag Normal file
View File

@@ -0,0 +1,8 @@
#include <common>
layout(location = 0) out vec4 out_color;
void main()
{
out_color = vec4(param[0].rgb, 1.0);
}

View File

@@ -0,0 +1,29 @@
in vec2 f_coords;
layout(location = 0) out vec4 out_color;
#texture (color_tex, 0, RGB)
uniform sampler2D color_tex;
#texture (velocity_tex, 1, RG)
uniform sampler2D velocity_tex;
#include <common>
void main()
{
vec2 texelSize = 1.0 / vec2(textureSize(color_tex, 0));
vec2 velocity = texture(velocity_tex, f_coords).rg * param[0].r;
float speed = length(velocity / texelSize);
int nSamples = clamp(int(speed), 1, 64);
vec4 oResult = texture(color_tex, f_coords);
for (int i = 1; i < nSamples; ++i)
{
vec2 offset = velocity * (float(i) / float(nSamples - 1) - 0.5);
oResult += texture(color_tex, f_coords + offset);
}
oResult /= float(nSamples);
out_color = oResult;
}

View File

@@ -0,0 +1,15 @@
in vec2 f_coords;
layout(location = 0) out vec4 out_color;
#texture (tex1, 0, RGB)
uniform sampler2D tex1;
#include <tonemapping.glsl>
void main()
{
vec2 texcoord = f_coords;
vec3 hdr_color = texture(tex1, texcoord).xyz;
out_color = tonemap(vec4(hdr_color, 1.0));
}

View File

@@ -0,0 +1,35 @@
in vec2 f_coord;
#texture (tex1, 0, sRGB_A)
uniform sampler2D tex1;
#include <common>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#include <tonemapping.glsl>
void main()
{
vec4 tex_color = texture(tex1, vec2(f_coord.x, f_coord.y + param[1].x));
vec4 color = tex_color * param[0];
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;
out_motion = vec4(a - b, 0.0f, tex_color.a * alpha_mult);
}
#endif
}

View File

@@ -0,0 +1,18 @@
layout(location = 0) in vec3 v_vert;
layout(location = 1) in vec2 v_coord;
out vec2 f_coord;
out vec4 f_clip_pos;
out vec4 f_clip_future_pos;
#include <common>
void main()
{
f_clip_pos = (projection * modelview) * vec4(v_vert, 1.0f);
f_clip_future_pos = (projection * future * modelview) * vec4(v_vert, 1.0f);
gl_Position = f_clip_pos;
f_coord = v_coord;
}

23
shaders/quad.vert Normal file
View File

@@ -0,0 +1,23 @@
const vec2 vert[4] = vec2[]
(
vec2(-1.0, 1.0),
vec2(-1.0, -1.0),
vec2( 1.0, 1.0),
vec2( 1.0, -1.0)
);
const vec2 uv[4] = vec2[]
(
vec2(0.0, 1.0),
vec2(0.0, 0.0),
vec2(1.0, 1.0),
vec2(1.0, 0.0)
);
out vec2 f_coords;
void main()
{
gl_Position = vec4(vert[gl_VertexID], 0.0, 1.0);
f_coords = uv[gl_VertexID];
}

5
shaders/shadowmap.frag Normal file
View File

@@ -0,0 +1,5 @@
in vec2 f_coord;
void main()
{
}

12
shaders/simpleuv.vert Normal file
View File

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

36
shaders/smoke.frag Normal file
View File

@@ -0,0 +1,36 @@
in vec4 f_color;
in vec2 f_coord;
in vec4 f_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
#texture (tex1, 0, sRGB_A)
uniform sampler2D tex1;
#include <common>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
void main()
{
vec4 tex_color = texture(tex1, f_coord) * f_color;
#if POSTFX_ENABLED
out_color = vec4(apply_fog(tex_color.rgb), tex_color.a);
#else
out_color = tonemap(vec4(apply_fog(tex_color.rgb), tex_color.a));
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, tex_color.a * alpha_mult);
}
#endif
}

23
shaders/smoke.vert Normal file
View File

@@ -0,0 +1,23 @@
layout(location = 0) in vec3 v_vert;
layout(location = 1) in vec4 v_color;
layout(location = 2) in vec2 v_coord;
out vec4 f_pos;
out vec4 f_color;
out vec2 f_coord;
out vec4 f_clip_pos;
out vec4 f_clip_future_pos;
#include <common>
void main()
{
f_pos = modelview * vec4(v_vert, 1.0f);
f_clip_pos = (projection * modelview) * vec4(v_vert, 1.0f);
f_clip_future_pos = (projection * future * modelview) * vec4(v_vert, 1.0f);
gl_Position = f_clip_pos;
f_coord = v_coord;
f_color = v_color;
}

View File

@@ -0,0 +1,14 @@
in vec2 f_coords;
layout(location = 0) out vec4 out_color;
#texture (tex1, 0, sRGB)
uniform sampler2D tex1;
void main()
{
vec2 texcoord = f_coords;
vec3 color = texture(tex1, texcoord).rgb;
out_color = FBOUT(vec4(color, 1.0));
}

View File

@@ -0,0 +1,31 @@
layout (std140) uniform scene_ubo
{
mat4 projection;
mat4 lightview;
float time;
};
const vec2 vert[4] = vec2[]
(
vec2(-1.0, 1.0),
vec2(-1.0, -1.0),
vec2( 1.0, 1.0),
vec2( 1.0, -1.0)
);
const vec2 uv[4] = vec2[]
(
vec2(0.0, 1.0),
vec2(0.0, 0.0),
vec2(1.0, 1.0),
vec2(1.0, 0.0)
);
out vec2 f_coords;
void main()
{
gl_Position = vec4(vert[gl_VertexID], 0.0, 1.0);
f_coords = vec2(mat3(projection) * vec3(uv[gl_VertexID], 1.0));
}

47
shaders/tonemapping.glsl Normal file
View File

@@ -0,0 +1,47 @@
const float pureWhite = 1.0;
vec3 reinhard(vec3 x)
{
// return x / (x + vec3(1.0));
// Reinhard tonemapping operator.
// see: "Photographic Tone Reproduction for Digital Images", eq. 4
float luminance = dot(x, vec3(0.2126, 0.7152, 0.0722));
float mappedLuminance = (luminance * (1.0 + luminance/(pureWhite*pureWhite))) / (1.0 + luminance);
// Scale color by ratio of average luminances.
return (mappedLuminance / luminance) * x;
}
// https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/
vec3 ACESFilm(vec3 x)
{
float a = 2.51f;
float b = 0.03f;
float c = 2.43f;
float d = 0.59f;
float e = 0.14f;
return (x*(a*x+b))/(x*(c*x+d)+e);
}
// https://www.slideshare.net/ozlael/hable-john-uncharted2-hdr-lighting
vec3 filmicF(vec3 x)
{
float A = 0.22f;
float B = 0.30f;
float C = 0.10f;
float D = 0.20f;
float E = 0.01f;
float F = 0.30f;
return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F)) - E/F;
}
vec3 filmic(vec3 x)
{
return filmicF(x) / filmicF(vec3(11.2f));
}
vec4 tonemap(vec4 x)
{
// return FBOUT(vec4(ACESFilm(x.rgb), x.a));
return FBOUT(vec4(reinhard(x.rgb), x.a));
}

32
shaders/traction.frag Normal file
View File

@@ -0,0 +1,32 @@
#include <common>
in vec4 f_pos;
in vec4 f_clip_pos;
in vec4 f_clip_future_pos;
layout(location = 0) out vec4 out_color;
#if MOTIONBLUR_ENABLED
layout(location = 1) out vec4 out_motion;
#endif
#include <tonemapping.glsl>
#include <apply_fog.glsl>
void main()
{
vec4 color = vec4(apply_fog(pow(param[0].rgb, vec3(2.2))), param[0].a);
#if POSTFX_ENABLED
out_color = color;
#else
out_color = tonemap(color);
#endif
#if MOTIONBLUR_ENABLED
{
vec2 a = (f_clip_future_pos.xy / f_clip_future_pos.w) * 0.5 + 0.5;;
vec2 b = (f_clip_pos.xy / f_clip_pos.w) * 0.5 + 0.5;;
out_motion = vec4(a - b, 0.0f, 0.0f);
}
#endif
}

18
shaders/traction.vert Normal file
View File

@@ -0,0 +1,18 @@
layout(location = 0) in vec3 v_vert;
layout(location = 1) in vec3 v_normal;
layout(location = 2) in vec2 v_coord;
#include <common>
out vec4 f_clip_pos;
out vec4 f_clip_future_pos;
out vec4 f_pos;
void main()
{
f_pos = modelview * vec4(v_vert, 1.0f);
f_clip_pos = (projection * modelview) * vec4(v_vert, 1.0f);
f_clip_future_pos = (projection * future * modelview) * vec4(v_vert, 1.0f);
gl_Position = f_clip_pos;
}

17
shaders/vbocolor.vert Normal file
View File

@@ -0,0 +1,17 @@
layout(location = 0) in vec3 v_vert;
layout(location = 1) in vec3 v_color;
out vec3 f_color;
out vec4 f_pos;
out vec4 f_clip_pos;
#include <common>
void main()
{
f_pos = modelview * vec4(v_vert, 1.0);
f_clip_pos = (projection * modelview) * vec4(v_vert, 1.0);
f_color = v_color;
gl_Position = f_clip_pos;
}

46
shaders/vertex.vert Normal file
View File

@@ -0,0 +1,46 @@
layout(location = 0) in vec3 v_vert;
layout(location = 1) in vec3 v_normal;
layout(location = 2) in vec2 v_coord;
layout(location = 3) in vec4 v_tangent;
#include <common>
out vec3 f_normal;
flat out vec3 f_normal_raw;
out vec2 f_coord;
out vec4 f_pos;
out mat3 f_tbn;
out vec4 f_light_pos[MAX_CASCADES];
out vec4 f_clip_pos;
out vec4 f_clip_future_pos;
//out vec3 TangentLightPos;
//out vec3 TangentViewPos;
out vec3 TangentFragPos;
void main()
{
f_normal = normalize(modelviewnormal * v_normal);
f_normal_raw = v_normal;
f_coord = v_coord;
f_pos = modelview * vec4(v_vert, 1.0);
for (uint idx = 0U ; idx < MAX_CASCADES ; ++idx) {
f_light_pos[idx] = lightview[idx] * f_pos;
}
f_clip_pos = (projection * modelview) * vec4(v_vert, 1.0);
f_clip_future_pos = (projection * future * modelview) * vec4(v_vert, 1.0);
gl_Position = f_clip_pos;
gl_PointSize = param[1].x;
vec3 T = normalize(modelviewnormal * v_tangent.xyz);
vec3 N = f_normal;
vec3 B = normalize(cross(N, T));
f_tbn = mat3(T, B, N);
mat3 TBN = transpose(f_tbn);
// TangentLightPos = TBN * f_light_pos.xyz;
// TangentViewPos = TBN * vec3(0.0, 0.0, 0.0);
TangentFragPos = TBN * f_pos.xyz;
}

8
shaders/vertexonly.vert Normal file
View File

@@ -0,0 +1,8 @@
layout(location = 0) in vec3 v_vert;
#include <common>
void main()
{
gl_Position = (projection * modelview) * vec4(v_vert, 1.0);
}