LumixEngine/data/pipelines/environment.shd

60 lines
1.7 KiB
Text
Raw Normal View History

2018-10-13 00:09:34 +02:00
include "pipelines/common.glsl"
2019-08-09 09:55:19 +02:00
common [[
layout(std140, binding = 4) uniform Drawcall {
vec4 u_pos_radius;
};
]]
2018-10-13 00:09:34 +02:00
------------------
vertex_shader [[
2019-08-11 20:32:21 +02:00
layout (location = 0) in vec3 a_position;
layout (location = 0) out vec3 v_uv;
layout (location = 1) out float v_radius;
2018-10-13 00:09:34 +02:00
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 [[
2019-08-11 20:32:21 +02:00
layout (location = 0) in vec3 v_uv;
layout (location = 0) out vec4 o_color;
2018-10-13 00:09:34 +02:00
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;
2019-08-09 09:55:19 +02:00
2018-10-13 00:09:34 +02:00
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;
2019-06-23 23:55:03 +02:00
vec3 normal = gb1.rgb * 2 - 1;
2018-10-13 00:09:34 +02:00
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);
2019-10-09 21:47:32 +02:00
vec3 L = normalize(u_light_direction.xyz);
2018-10-13 00:09:34 +02:00
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;
2019-06-23 23:55:03 +02:00
o_color = vec4(indirect * alpha * u_light_indirect_intensity, alpha);
//o_color = vec4(1, 0, 0, 1);
2018-10-13 00:09:34 +02:00
//o_color = vec4(abs(u_camera_pos), 1);
//o_color = vec4(1, 0, 0, 1);
}
]]