69 lines
No EOL
1.6 KiB
Text
69 lines
No EOL
1.6 KiB
Text
include "pipelines/common.glsl"
|
|
|
|
|
|
common [[
|
|
layout(std140, binding = 4) uniform Drawcall {
|
|
vec4 u_pos;
|
|
vec4 u_rot;
|
|
vec4 u_half_extents;
|
|
};
|
|
]]
|
|
|
|
------------------
|
|
|
|
vertex_shader [[
|
|
layout(location = 0) in vec3 a_position;
|
|
|
|
void main()
|
|
{
|
|
vec3 pos = rotateByQuat(u_rot, u_half_extents.xyz * a_position);
|
|
pos += u_pos.xyz;
|
|
gl_Position = u_camera_projection * u_camera_view * vec4(pos, 1);
|
|
}
|
|
]]
|
|
|
|
---------------------
|
|
|
|
|
|
fragment_shader [[
|
|
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 samplerCube u_radiancemap;
|
|
|
|
void main()
|
|
{
|
|
vec2 screen_uv = gl_FragCoord.xy / u_framebuffer_size;
|
|
vec3 wpos = getViewPosition(u_gbuffer_depth, u_camera_inv_view_projection, screen_uv);
|
|
|
|
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;
|
|
|
|
vec3 V = normalize(-wpos);
|
|
|
|
o_color.rgb = PBR_ComputeIndirectSpecular(u_radiancemap, albedo, metallic, roughness, normal, V);
|
|
|
|
vec4 inv_rot = u_rot;
|
|
inv_rot.w = -inv_rot.w;
|
|
vec3 lpos = abs(rotateByQuat(inv_rot, wpos - u_pos.xyz) / u_half_extents.xyz);
|
|
|
|
//if (any(greaterThan(abs(lpos), u_half_extents))) discard;
|
|
float m = saturate(max(max(lpos.x, lpos.y), lpos.z) * 2 - 0.5);
|
|
m = 1 - m * m;
|
|
|
|
o_color.rgb *= m;
|
|
|
|
o_color.a = m;
|
|
}
|
|
]] |