217 lines
No EOL
5.7 KiB
Text
217 lines
No EOL
5.7 KiB
Text
texture_slot {
|
|
name = "Albedo",
|
|
default_texture = "textures/common/white.tga"
|
|
}
|
|
|
|
texture_slot {
|
|
name = "Normal",
|
|
default_texture = "textures/common/default_normal.tga"
|
|
}
|
|
|
|
texture_slot {
|
|
name = "Roughness",
|
|
default_texture = "textures/common/white.tga"
|
|
}
|
|
|
|
texture_slot {
|
|
name = "Metallic",
|
|
default_texture = "textures/common/white.tga"
|
|
}
|
|
|
|
include "pipelines/common.glsl"
|
|
|
|
define "ALPHA_CUTOUT"
|
|
define "VEGETATION"
|
|
|
|
------------------
|
|
|
|
vertex_shader [[
|
|
layout(location = 0) in vec3 a_position;
|
|
layout(location = 1) in vec2 a_uv;
|
|
layout(location = 2) in vec3 a_normal;
|
|
#ifdef _HAS_ATTR3
|
|
layout(location = 3) in vec3 a_tangent;
|
|
#else
|
|
const vec3 a_tangent = vec3(0, 1, 0);
|
|
#endif
|
|
#ifdef GRASS
|
|
layout(location = 4) in vec4 i_rot_quat;
|
|
layout(location = 5) in vec4 i_pos_scale;
|
|
layout(location = 6) in vec4 i_grass_normal;
|
|
layout(std140, binding = 4) uniform Model {
|
|
mat4 u_model;
|
|
float u_max_dist;
|
|
};
|
|
#elif defined SKINNED
|
|
layout(location = 4) in vec4 a_indices;
|
|
layout(location = 5) in vec4 a_weights;
|
|
layout(std140, binding = 4) uniform Model {
|
|
mat4 u_model;
|
|
mat4 u_bones[256];
|
|
};
|
|
#elif defined INSTANCED
|
|
layout(location = 4) in vec4 i_rot_quat;
|
|
layout(location = 5) in vec4 i_pos_scale;
|
|
#else
|
|
layout(std140, binding = 4) uniform Model {
|
|
mat4 u_model;
|
|
};
|
|
#endif
|
|
layout (location = 0) out vec2 v_uv;
|
|
layout (location = 1) out vec3 v_normal;
|
|
layout (location = 2) out vec3 v_tangent;
|
|
layout (location = 3) out vec4 v_wpos;
|
|
#ifdef GRASS
|
|
layout (location = 4) out float v_darken;
|
|
#endif
|
|
|
|
void main() {
|
|
v_uv = a_uv;
|
|
#ifdef GRASS
|
|
v_normal = rotateByQuat(i_rot_quat, a_normal * 2 - 1);
|
|
v_tangent = rotateByQuat(i_rot_quat, a_tangent * 2 - 1);
|
|
vec3 p = a_position;
|
|
vec3 v = (u_model * vec4(i_pos_scale.xyz, 1)).xyz;
|
|
const float scale_dist = 10;
|
|
const float dist = length(v) - (u_max_dist - scale_dist);
|
|
p *= 1 - saturate(dist / scale_dist);
|
|
v_wpos = u_model * vec4(i_pos_scale.xyz + rotateByQuat(i_rot_quat, p * i_pos_scale.w), 1);
|
|
v_wpos.x += p.y > 0.1 ? cos((i_pos_scale.x + i_pos_scale.y + i_pos_scale.z + i_rot_quat.w * 5) * 0.3 + u_time * 2) * p.y * 0.1 : 0;
|
|
v_darken = a_position.y > 0.1 ? 1 : 0.0;
|
|
#elif defined INSTANCED
|
|
v_normal = rotateByQuat(i_rot_quat, a_normal * 2 - 1);
|
|
v_tangent = rotateByQuat(i_rot_quat, a_tangent * 2 - 1);
|
|
vec3 p = a_position * i_pos_scale.w;
|
|
#ifdef VEGETATION
|
|
p = vegetationAnim(i_pos_scale.xyz, p);
|
|
#endif
|
|
v_wpos = vec4(i_pos_scale.xyz + rotateByQuat(i_rot_quat, p), 1);
|
|
#elif defined SKINNED
|
|
mat4 model_mtx = u_model * (a_weights.x * u_bones[int(a_indices.x)] +
|
|
a_weights.y * u_bones[int(a_indices.y)] +
|
|
a_weights.z * u_bones[int(a_indices.z)] +
|
|
a_weights.w * u_bones[int(a_indices.w)]);
|
|
v_normal = mat3(model_mtx) * (a_normal * 2 - 1);
|
|
v_tangent = mat3(model_mtx) * (a_tangent * 2 - 1);
|
|
v_wpos = model_mtx * vec4(a_position, 1);
|
|
#else
|
|
mat4 model_mtx = u_model;
|
|
v_normal = mat3(model_mtx) * (a_normal * 2 - 1);
|
|
v_tangent = mat3(model_mtx) * (a_tangent * 2 - 1);
|
|
|
|
vec3 p = a_position;
|
|
#ifdef VEGETATION
|
|
p = vegetationAnim(u_model[3].xyz, p);
|
|
#endif
|
|
|
|
v_wpos = model_mtx * vec4(p, 1);
|
|
#endif
|
|
|
|
gl_Position = u_pass_view_projection * v_wpos;
|
|
}
|
|
]]
|
|
|
|
---------------------
|
|
|
|
fragment_shader [[
|
|
layout (binding=0) uniform sampler2D u_albedomap;
|
|
layout (binding=1) uniform sampler2D u_normalmap;
|
|
layout (binding=2) uniform sampler2D u_roughnessmap;
|
|
layout (binding=3) uniform sampler2D u_metallicmap;
|
|
layout (binding=4) uniform sampler2D u_shadowmap;
|
|
layout (location = 0) in vec2 v_uv;
|
|
layout (location = 1) in vec3 v_normal;
|
|
layout (location = 2) in vec3 v_tangent;
|
|
layout (location = 3) in vec4 v_wpos;
|
|
#ifdef GRASS
|
|
layout (location = 4) in float v_darken;
|
|
#endif
|
|
|
|
#ifdef DEFERRED
|
|
layout(location = 0) out vec4 o_gbuffer0;
|
|
layout(location = 1) out vec4 o_gbuffer1;
|
|
layout(location = 2) out vec4 o_gbuffer2;
|
|
#else
|
|
layout(location = 0) out vec4 o_color;
|
|
#endif
|
|
|
|
void getData()
|
|
{
|
|
data.albedo = texture(u_albedomap, v_uv) * u_material_color;
|
|
#ifdef ALPHA_CUTOUT
|
|
if(data.albedo.a < 0.5) discard;
|
|
#endif
|
|
|
|
vec3 N = v_normal;
|
|
vec3 tangent = v_tangent;
|
|
#ifdef VEGETATION
|
|
if (!gl_FrontFacing) {
|
|
N = -N;
|
|
tangent = -tangent;
|
|
}
|
|
#endif
|
|
|
|
mat3 tbn = mat3(
|
|
normalize(tangent),
|
|
normalize(N),
|
|
normalize(cross(N, tangent))
|
|
);
|
|
|
|
data.wpos = v_wpos.xyz;
|
|
data.roughness = texture(u_roughnessmap, v_uv).r * u_roughness;
|
|
data.metallic = texture(u_metallicmap, v_uv).r * u_metallic;
|
|
data.normal.xz = texture(u_normalmap, v_uv).xy * 2 - 1;
|
|
data.normal.y = sqrt(clamp(1 - dot(data.normal.xz, data.normal.xz), 0, 1));
|
|
data.normal = tbn * data.normal;
|
|
data.emission = packEmission(u_emission);
|
|
}
|
|
|
|
#ifdef DEPTH
|
|
void main()
|
|
{
|
|
#ifdef ALPHA_CUTOUT
|
|
data.albedo = texture(u_albedomap, v_uv);
|
|
if(data.albedo.a < 0.5) discard;
|
|
#endif
|
|
o_color = vec4(shadowmapValue(gl_FragCoord.z));
|
|
}
|
|
#elif defined DEFERRED
|
|
void main()
|
|
{
|
|
getData();
|
|
o_gbuffer0 = vec4(data.albedo.rgb, data.roughness);
|
|
#ifdef GRASS
|
|
o_gbuffer0.rgb *= v_darken;
|
|
#endif
|
|
o_gbuffer1 = vec4(data.normal * 0.5 + 0.5, data.metallic);
|
|
float translucency = 0;
|
|
#if defined(VEGETATION) && defined(ALPHA_CUTOUT)
|
|
translucency = 1;
|
|
#endif
|
|
o_gbuffer2 = vec4(data.emission, translucency, 0, 1);
|
|
}
|
|
#else
|
|
void main()
|
|
{
|
|
getData();
|
|
|
|
vec3 V = normalize(-data.wpos);
|
|
vec3 L = normalize(u_light_direction);
|
|
|
|
float shadow = getShadow(u_shadowmap, data.wpos);
|
|
|
|
o_color.rgb = pbr(data.albedo.rgb
|
|
, data.roughness
|
|
, data.metallic
|
|
, data.emission
|
|
, data.normal
|
|
, V
|
|
, L
|
|
, shadow
|
|
, u_light_color * u_light_intensity
|
|
, u_light_indirect_intensity);
|
|
|
|
o_color.w = data.albedo.a;
|
|
}
|
|
#endif
|
|
]] |