LumixEngine/data/pipelines/deferred.shd
Mikulas Florek 2b56f75f30 fog
2019-10-14 22:28:06 +02:00

56 lines
No EOL
1.5 KiB
Text

include "pipelines/common.glsl"
------------------
vertex_shader [[
layout (location = 0) out vec2 v_uv;
void main()
{
gl_Position = fullscreenQuad(gl_VertexID, v_uv);
}
]]
---------------------
fragment_shader [[
layout (location = 0) in vec2 v_uv;
layout (location = 0) out vec4 o_color;
layout (binding=0) uniform sampler2D u_gbuffer0;
layout (binding=1) uniform sampler2D u_gbuffer1;
layout (binding=2) uniform sampler2D u_gbuffer2;
layout (binding=3) uniform sampler2D u_gbuffer_depth;
layout (binding=4) uniform sampler2D u_shadowmap;
void main()
{
vec4 gb0 = texture(u_gbuffer0, v_uv);
vec4 gb1 = texture(u_gbuffer1, v_uv);
vec4 gb2 = texture(u_gbuffer2, v_uv);
float depth = texture(u_gbuffer_depth, v_uv).x;
vec3 albedo = gb0.rgb;
vec3 normal = gb1.rgb * 2 - 1;
float roughness = gb0.w;
float metallic = gb1.w;
float emission = unpackEmission(gb2.x);
vec3 wpos = getViewPosition(u_gbuffer_depth, u_camera_inv_view_projection, v_uv);
vec3 V = normalize(-wpos);
vec3 L = normalize(u_light_direction.xyz);
float shadow = getShadow(u_shadowmap, wpos);
vec3 direct = PBR_ComputeDirectLight(albedo
, normal
, L
, V
, u_light_color.rgb * u_light_intensity * shadow
, roughness
, metallic);
float fog_factor = getFogFactor(u_camera_world_pos.y, u_camera_world_pos.y + wpos.y, wpos, u_fog_params.x, u_fog_params.y, u_fog_params.z);
o_color.rgb = mix(direct, u_fog_color.rgb, fog_factor);
o_color.w = 1;
}
]]