mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
Merge branch 'gfx-work' of github.com:Milek7/maszyna into gfx-work
This commit is contained in:
9
shaders/apply_fog.glsl
Normal file
9
shaders/apply_fog.glsl
Normal file
@@ -0,0 +1,9 @@
|
||||
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.xyz), 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.xyz) * fog_density));
|
||||
return mix(color, fog_color_v, fog_amount_v);
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <apply_fog.glsl>
|
||||
|
||||
float calc_shadow()
|
||||
{
|
||||
#if SHADOWMAP_ENABLED
|
||||
@@ -23,22 +25,14 @@ float calc_shadow()
|
||||
#endif
|
||||
}
|
||||
|
||||
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.xyz), 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.xyz) * fog_density));
|
||||
return mix(color, fog_color_v, fog_amount_v);
|
||||
}
|
||||
|
||||
// [0] - diffuse, [1] - specular
|
||||
// do magic here
|
||||
vec2 calc_light(vec3 light_dir)
|
||||
{
|
||||
#ifdef NORMALMAP
|
||||
vec3 normal = normalize(f_tbn * normalize(texture(normalmap, f_coord).rgb * 2.0 - 1.0));
|
||||
#elif defined(WATER)
|
||||
vec3 normal = normal_d;
|
||||
#else
|
||||
vec3 normal = normalize(f_normal);
|
||||
#endif
|
||||
|
||||
@@ -22,7 +22,7 @@ layout(location = 1) out vec4 out_motion;
|
||||
#texture (diffuse, 0, sRGB_A)
|
||||
uniform sampler2D diffuse;
|
||||
|
||||
#texture (normalmap, 1, RGB)
|
||||
#texture (normalmap, 1, RGBA)
|
||||
uniform sampler2D normalmap;
|
||||
|
||||
#if SHADOWMAP_ENABLED
|
||||
@@ -58,7 +58,7 @@ void main()
|
||||
{
|
||||
vec2 part = calc_dir_light(lights[0]);
|
||||
vec3 c = (part.x * param[1].x + part.y * param[1].y) * calc_shadow() * lights[0].color;
|
||||
result += mix(c, envcolor, param[1].z);
|
||||
result += mix(c, envcolor, param[1].z * texture(normalmap, f_coord).a);
|
||||
}
|
||||
|
||||
for (uint i = 1U; i < lights_count; i++)
|
||||
|
||||
@@ -21,7 +21,7 @@ layout(location = 1) out vec4 out_motion;
|
||||
#texture (diffuse, 0, sRGB_A)
|
||||
uniform sampler2D diffuse;
|
||||
|
||||
#texture (reflmap, 1, R)
|
||||
#texture (reflmap, 1, RGBA)
|
||||
uniform sampler2D reflmap;
|
||||
|
||||
#if SHADOWMAP_ENABLED
|
||||
@@ -56,7 +56,7 @@ void main()
|
||||
{
|
||||
vec2 part = calc_dir_light(lights[0]);
|
||||
vec3 c = (part.x * param[1].x + part.y * param[1].y) * calc_shadow() * lights[0].color;
|
||||
result += mix(c, envcolor, param[1].z * texture(reflmap, f_coord).r);
|
||||
result += mix(c, envcolor, param[1].z * texture(reflmap, f_coord).a);
|
||||
}
|
||||
|
||||
for (uint i = 1U; i < lights_count; i++)
|
||||
|
||||
@@ -17,7 +17,7 @@ void main()
|
||||
discard;
|
||||
|
||||
// color data space is shared with normals, ugh
|
||||
vec4 color = vec4(pow(f_normal_raw.bgr, vec3(2.2)), 1.0f);
|
||||
vec4 color = vec4(pow(f_normal_raw.rgb, vec3(2.2)), 1.0f);
|
||||
#if POSTFX_ENABLED
|
||||
out_color = color;
|
||||
#else
|
||||
|
||||
114
shaders/mat_water.frag
Normal file
114
shaders/mat_water.frag
Normal file
@@ -0,0 +1,114 @@
|
||||
in vec3 f_normal;
|
||||
in vec2 f_coord;
|
||||
in vec4 f_pos;
|
||||
in mat3 f_tbn;
|
||||
in vec4 f_light_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 (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;
|
||||
|
||||
#if SHADOWMAP_ENABLED
|
||||
uniform sampler2DShadow shadowmap;
|
||||
#endif
|
||||
#if ENVMAP_ENABLED
|
||||
uniform samplerCube envmap;
|
||||
#endif
|
||||
|
||||
//wave distortion variables
|
||||
float move_factor = 0;
|
||||
vec3 normal_d;
|
||||
|
||||
#define WATER
|
||||
#include <light_common.glsl>
|
||||
#include <tonemapping.glsl>
|
||||
|
||||
void main()
|
||||
{
|
||||
//wave distortion
|
||||
move_factor += (param[2].z * time);
|
||||
move_factor = mod(move_factor, 1);
|
||||
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;
|
||||
|
||||
normal_d = f_tbn * normalize(texture(normalmap, texture_coords).rgb * 2.0 - 1.0);
|
||||
vec3 refvec = reflect(f_pos.xyz, normal_d);
|
||||
#if ENVMAP_ENABLED
|
||||
vec3 envcolor = texture(envmap, refvec).rgb;
|
||||
#else
|
||||
vec3 envcolor = vec3(0.5);
|
||||
#endif
|
||||
vec4 tex_color = texture(diffuse, texture_coords);
|
||||
//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 );
|
||||
|
||||
vec3 result = ambient * 0.5 + param[0].rgb * emission;
|
||||
|
||||
if (lights_count > 0U)
|
||||
{
|
||||
vec2 part = calc_dir_light(lights[0]);
|
||||
vec3 c = (part.x * param[1].x + part.y * param[1].y) * calc_shadow() * lights[0].color;
|
||||
result += mix(c, envcolor, param[1].z * texture(normalmap, texture_coords ).a);
|
||||
}
|
||||
//result = mix(result, param[0].rgb, param[1].z);
|
||||
result = (result * tex_color.rgb * param[1].z) + (result * (1.0 - param[1].z)); //multiply
|
||||
//result = ( max(result + param[0].rgb -1.0,0.0) * param[1].z + result * (1.0 - param[1].z)); //linear burn
|
||||
//result = ( min(param[0].rgb,result) * param[1].z + result * (1.0 - param[1].z)); //darken
|
||||
|
||||
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);
|
||||
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.x * param[1].x + part.y * param[1].y);
|
||||
}
|
||||
|
||||
vec4 color = vec4(apply_fog(clamp(result,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
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <common>
|
||||
|
||||
in vec4 f_pos;
|
||||
in vec4 f_clip_pos;
|
||||
in vec4 f_clip_future_pos;
|
||||
|
||||
@@ -9,10 +10,11 @@ layout(location = 1) out vec4 out_motion;
|
||||
#endif
|
||||
|
||||
#include <tonemapping.glsl>
|
||||
#include <apply_fog.glsl>
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = vec4(pow(param[0].rgb, vec3(2.2)), param[0].a);
|
||||
vec4 color = vec4(apply_fog(pow(param[0].rgb, vec3(2.2))), param[0].a);
|
||||
#if POSTFX_ENABLED
|
||||
out_color = color;
|
||||
#else
|
||||
|
||||
@@ -6,9 +6,11 @@ layout(location = 2) in vec2 v_coord;
|
||||
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user