60 lines
No EOL
1.5 KiB
Text
60 lines
No EOL
1.5 KiB
Text
include "pipelines/common.glsl"
|
|
|
|
texture_slot {
|
|
name = "Albedo",
|
|
default_texture = "textures/common/white.tga"
|
|
}
|
|
|
|
------------------
|
|
|
|
vertex_shader [[
|
|
layout(std140, binding = 4) uniform Model {
|
|
mat4 u_model;
|
|
};
|
|
layout(location = 0) in vec3 a_position;
|
|
#ifdef UV0_ATTR
|
|
layout(location = UV0_ATTR) in vec2 a_uv;
|
|
#else
|
|
const vec2 a_uv = vec2(0, 0);
|
|
#endif
|
|
#ifdef NORMAL_ATTR
|
|
layout(location = NORMAL_ATTR) in vec3 a_normal;
|
|
#else
|
|
const vec3 a_normal = vec3(0, 1, 0);
|
|
#endif
|
|
layout (location = 0) out vec2 v_uv;
|
|
layout (location = 1) out vec3 v_wpos;
|
|
layout (location = 2) out vec3 v_normal;
|
|
|
|
void main() {
|
|
v_uv = a_uv;
|
|
vec4 p = Global.view * u_model * vec4(a_position, 1);
|
|
v_wpos = p.xyz;
|
|
v_normal = a_normal;
|
|
gl_Position = Global.projection_no_jitter * p;
|
|
}
|
|
]]
|
|
|
|
---------------------
|
|
|
|
fragment_shader [[
|
|
layout (binding=0) uniform sampler2D t_albedo;
|
|
layout (binding=1) uniform sampler2D t_gbuffer_depth;
|
|
layout (location = 0) in vec2 v_uv;
|
|
layout (location = 1) in vec3 v_wpos;
|
|
layout (location = 2) in vec3 v_normal;
|
|
layout(location = 0) out vec4 o_color;
|
|
|
|
void main() {
|
|
vec2 screen_uv = gl_FragCoord.xy / Global.framebuffer_size;
|
|
vec3 wpos = getViewPosition(t_gbuffer_depth, Global.inv_view_projection, screen_uv);
|
|
vec4 albedo = texture(t_albedo, v_uv);
|
|
#ifdef ALPHA_CUTOUT
|
|
if(albedo.a < 0.5) discard;
|
|
#endif
|
|
float d = dot(Global.light_dir.xyz, v_normal);
|
|
o_color.rgb = albedo.rgb * saturate(max(0, -d) + 0.25 * max(0, d) + 0.25);
|
|
o_color.a = 1;
|
|
if(length(wpos) < length(v_wpos)) o_color.rgb *= 0.25;
|
|
}
|
|
]] |