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

60 lines
No EOL
1.7 KiB
Text

include "pipelines/common.glsl"
common [[
layout(std140, binding = 4) uniform Drawcall {
vec4 u_pos_radius;
};
]]
------------------
vertex_shader [[
layout (location = 0) in vec3 a_position;
layout (location = 0) out vec3 v_uv;
layout (location = 1) out float v_radius;
void main()
{
v_uv = a_position;
gl_Position = u_camera_projection * u_camera_view * vec4(a_position * u_pos_radius.w + u_pos_radius.xyz, 1);
}
]]
---------------------
fragment_shader [[
layout (location = 0) in vec3 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;
void main()
{
vec2 screen_uv = gl_FragCoord.xy / u_framebuffer_size;
vec4 gb0 = texture(u_gbuffer0, screen_uv);
vec4 gb1 = texture(u_gbuffer1, screen_uv);
vec4 gb2 = texture(u_gbuffer2, screen_uv);
float depth = texture(u_gbuffer_depth, screen_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, screen_uv);
vec3 V = normalize(-wpos);
vec3 L = normalize(u_light_direction.xyz);
vec3 indirect = PBR_ComputeIndirectLight(albedo, roughness, metallic, normal, V);
float alpha = 1 - saturate(length(wpos - u_pos_radius.xyz) / u_pos_radius.w);
//alpha *= alpha;
o_color = vec4(indirect * alpha * u_light_indirect_intensity, alpha);
//o_color = vec4(1, 0, 0, 1);
//o_color = vec4(abs(u_camera_pos), 1);
//o_color = vec4(1, 0, 0, 1);
}
]]