134 lines
No EOL
4 KiB
Text
134 lines
No EOL
4 KiB
Text
include "pipelines/common.glsl"
|
|
|
|
|
|
------------------
|
|
|
|
vertex_shader [[
|
|
layout(location = 0) in vec3 a_position;
|
|
layout(location = 1) in vec4 i_rot;
|
|
layout(location = 2) in vec3 i_pos;
|
|
layout(location = 3) in float i_radius;
|
|
layout(location = 4) in float i_attn;
|
|
layout(location = 5) in vec3 i_color;
|
|
layout(location = 6) in vec3 i_dir;
|
|
layout(location = 7) in float i_fov;
|
|
|
|
layout(location = 0) out float v_radius;
|
|
layout(location = 1) out vec3 v_center;
|
|
layout(location = 2) out vec4 v_rot;
|
|
layout(location = 3) out float v_attn;
|
|
layout(location = 4) out vec3 v_color;
|
|
layout(location = 5) out vec3 v_dir;
|
|
layout(location = 6) out float v_fov;
|
|
|
|
void main()
|
|
{
|
|
v_center = i_pos;
|
|
v_rot = i_rot;
|
|
v_radius = i_radius;
|
|
v_attn = i_attn;
|
|
v_color = i_color;
|
|
v_dir = i_dir;
|
|
v_fov = i_fov;
|
|
vec3 pos = rotateByQuat(i_rot, a_position * i_radius);
|
|
pos += i_pos;
|
|
gl_Position = u_camera_projection * u_camera_view * vec4(pos, 1);
|
|
}
|
|
]]
|
|
|
|
---------------------
|
|
|
|
|
|
fragment_shader [[
|
|
layout(location = 0) out vec4 o_color;
|
|
|
|
layout(location = 0) in float v_radius;
|
|
layout(location = 1) in vec3 v_center;
|
|
layout(location = 2) in vec4 v_rot;
|
|
layout(location = 3) in float v_attn;
|
|
layout(location = 4) in vec3 v_color;
|
|
layout(location = 5) in vec3 v_dir;
|
|
layout(location = 6) in float v_fov;
|
|
|
|
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()
|
|
{
|
|
/*float f0 = 0.04;
|
|
|
|
vec2 screen_uv = gl_FragCoord.xy / u_framebuffer_size;
|
|
vec3 wpos = getViewPosition(u_gbuffer_depth, u_camera_inv_view_projection, screen_uv);
|
|
|
|
vec4 gbuffer1_val = texture(u_gbuffer1, screen_uv * 0.5 + 0.5);
|
|
vec4 gbuffer2_val = texture(u_gbuffer2, screen_uv * 0.5 + 0.5);
|
|
vec3 normal = normalize(gbuffer1_val.xyz * 2 - 1);
|
|
vec4 albedo = texture(u_gbuffer0, screen_uv * 0.5 + 0.5);
|
|
float roughness = albedo.w;
|
|
float metallic = gbuffer1_val.w;
|
|
|
|
vec3 light_dir = normalize(v_center - wpos);
|
|
|
|
PBR_ComputeDirectLight(normal, light_dir, view, v_color_attn.rgb, f0, roughness, diff, spec);
|
|
|
|
vec4 r = v_rot;
|
|
r.w = -r.w;
|
|
vec3 lpos = rotateByQuat(r, wpos - v_center);
|
|
|
|
float dist = length(lpos);
|
|
float attn = pow(max(0, 1 - dist / v_radius), v_attn);
|
|
if (dist > v_radius) discard;
|
|
|
|
o_color = vec4(attn, attn, attn, 1);*/
|
|
float f0 = 0.04;
|
|
|
|
vec2 screen_uv = gl_FragCoord.xy / u_framebuffer_size;
|
|
vec4 gbuffer1_val = texture(u_gbuffer1, screen_uv);
|
|
vec4 gbuffer2_val = texture(u_gbuffer2, screen_uv);
|
|
vec3 N = normalize(gbuffer1_val.xyz * 2 - 1);
|
|
vec4 albedo = texture(u_gbuffer0, screen_uv);
|
|
float roughness = albedo.w;
|
|
float metallic = gbuffer1_val.w;
|
|
|
|
vec3 wpos = getViewPosition(u_gbuffer_depth, u_camera_inv_view_projection, screen_uv);
|
|
|
|
vec3 diff;
|
|
vec3 spec;
|
|
vec3 V = normalize(-wpos);
|
|
vec3 lpos = v_center - wpos.xyz;
|
|
vec3 L = normalize(lpos);
|
|
vec3 direct_light = PBR_ComputeDirectLight(albedo.rgb, N, L, V, v_color.rgb, roughness, metallic);
|
|
float dist = length(lpos);
|
|
float attn = pow(max(0, 1 - dist / v_radius), v_attn);
|
|
if(v_fov < 3.14159) {
|
|
float cosDir = dot(normalize(v_dir), normalize(L));
|
|
float cosCone = cos(v_fov * 0.5);
|
|
|
|
if(cosDir < cosCone) discard;
|
|
attn *= (cosDir - cosCone) / (1 - cosCone);
|
|
}/**/
|
|
/*vec3 lp = v_pos_radius.xyz - wpos;
|
|
float dist = length(lp);
|
|
float attn = pow(max(0, 1 - dist / v_pos_radius.w), v_color_attn.w);
|
|
if(v_dir_fov.w < 3.14159)
|
|
{
|
|
float cosDir = dot(normalize(v_dir_fov.xyz), normalize(light_dir));
|
|
float cosCone = cos(v_dir_fov.w * 0.5);
|
|
|
|
if(cosDir < cosCone)
|
|
discard;
|
|
attn *= (cosDir - cosCone) / (1 - cosCone);
|
|
}
|
|
vec4 specular_color = (f0 - f0 * metallic) + albedo * metallic;
|
|
vec4 diffuse_color = albedo - albedo * metallic;
|
|
|
|
o_color.xyz = attn * (diff * diffuse_color.rgb + spec * specular_color.rgb);
|
|
o_color.w = 1;*/
|
|
|
|
o_color.rgb = direct_light * attn;
|
|
//o_color.rgb = vec3(saturate(wpos));
|
|
o_color.a = 1;
|
|
}
|
|
]] |