diff --git a/client/shaders/common.glsl.inc b/client/shaders/common.glsl.inc index ea0c249a..b19183fd 100644 --- a/client/shaders/common.glsl.inc +++ b/client/shaders/common.glsl.inc @@ -131,4 +131,8 @@ layout(location = 0) VS_TO_FS vec3 normal; layout(location = 1) VS_TO_FS vec4 tangent; layout(location = 2) VS_TO_FS vec4 frag_pos; layout(location = 3) VS_TO_FS vec4 light_pos; -layout(location = 4) VS_TO_FS vec2 texcoord[nb_texcoords]; +layout(location = 4) VS_TO_FS vec2 texcoord_base_color; +layout(location = 5) VS_TO_FS vec2 texcoord_metallic_roughness; +layout(location = 6) VS_TO_FS vec2 texcoord_occlusion; +layout(location = 7) VS_TO_FS vec2 texcoord_emissive; +layout(location = 8) VS_TO_FS vec2 texcoord_normal; diff --git a/client/shaders/lit.frag.glsl b/client/shaders/lit.frag.glsl index 06f48228..8e7b5811 100644 --- a/client/shaders/lit.frag.glsl +++ b/client/shaders/lit.frag.glsl @@ -30,14 +30,14 @@ layout(early_fragment_tests) in; void main() { - vec4 albedo = material.base_color_factor * texture(base_color_texture, texcoord[0]); - vec3 emissive_color = (material.base_emissive_factor * texture(emissive_texture, texcoord[0])).rgb; + vec4 albedo = material.base_color_factor * texture(base_color_texture, texcoord_base_color); + vec3 emissive_color = (material.base_emissive_factor * texture(emissive_texture, texcoord_emissive)).rgb; vec3 normal_unit; if (use_normal_maps) { - vec3 sampled_normal = normalize(vec3(material.normal_scale, material.normal_scale, 1) * (texture(normal_map_texture, texcoord[0]).xyz * 2 - 1)); + vec3 sampled_normal = normalize(vec3(material.normal_scale, material.normal_scale, 1) * (texture(normal_map_texture, texcoord_normal).xyz * 2 - 1)); // glTF spec §3.7.2.1 vec3 bitangent = cross(normal, tangent.xyz) * tangent.w; @@ -54,8 +54,8 @@ void main() if (use_pbr) { - float ao = 1 + material.occlusion_strength * (texture(occlusion_texture, texcoord[0]).r - 1); - vec4 mr = texture(metallic_roughness_texture, texcoord[0]); + float ao = 1 + material.occlusion_strength * (texture(occlusion_texture, texcoord_occlusion).r - 1); + vec4 mr = texture(metallic_roughness_texture, texcoord_metallic_roughness); vec3 half_vec = normalize(light_dir + view_dir); diff --git a/client/shaders/lit.vert.glsl b/client/shaders/lit.vert.glsl index a0b9e8df..a612d7c9 100644 --- a/client/shaders/lit.vert.glsl +++ b/client/shaders/lit.vert.glsl @@ -39,10 +39,11 @@ out gl_PerVertex void main() { - // TODO use base_color_texcoord et al instead of always using texcoord 0 - // TODO use the correct transform - texcoord[0] = compute_texcoord(material.base_color, in_texcoord[material.base_color.texcoord]); - + texcoord_base_color = compute_texcoord(material.base_color, in_texcoord[material.base_color.texcoord]); + texcoord_metallic_roughness = compute_texcoord(material.metallic_roughness, in_texcoord[material.metallic_roughness.texcoord]); + texcoord_occlusion = compute_texcoord(material.occlusion, in_texcoord[material.occlusion.texcoord]); + texcoord_emissive = compute_texcoord(material.emissive, in_texcoord[material.emissive.texcoord]); + texcoord_normal = compute_texcoord(material.normal, in_texcoord[material.normal.texcoord]); // TODO on CPU? mat3 mv = inverse(transpose(mat3(mesh.modelview[gl_ViewIndex]))); diff --git a/client/shaders/lit_mask.frag.glsl b/client/shaders/lit_mask.frag.glsl index 3f2217b0..a802bee3 100644 --- a/client/shaders/lit_mask.frag.glsl +++ b/client/shaders/lit_mask.frag.glsl @@ -30,14 +30,14 @@ layout(location = 0) out vec4 out_color; void main() { - vec4 albedo = material.base_color_factor * texture(base_color_texture, texcoord[0]); - vec3 emissive_color = (material.base_emissive_factor * texture(emissive_texture, texcoord[0])).rgb; + vec4 albedo = material.base_color_factor * texture(base_color_texture, texcoord_base_color); + vec3 emissive_color = (material.base_emissive_factor * texture(emissive_texture, texcoord_emissive)).rgb; vec3 normal_unit; if (use_normal_maps) { - vec3 sampled_normal = normalize(vec3(material.normal_scale, material.normal_scale, 1) * (texture(normal_map_texture, texcoord[0]).xyz * 2 - 1)); + vec3 sampled_normal = normalize(vec3(material.normal_scale, material.normal_scale, 1) * (texture(normal_map_texture, texcoord_normal).xyz * 2 - 1)); // glTF spec §3.7.2.1 vec3 bitangent = cross(normal, tangent.xyz) * tangent.w; @@ -54,8 +54,8 @@ void main() if (use_pbr) { - float ao = 1 + material.occlusion_strength * (texture(occlusion_texture, texcoord[0]).r - 1); - vec4 mr = texture(metallic_roughness_texture, texcoord[0]); + float ao = 1 + material.occlusion_strength * (texture(occlusion_texture, texcoord_occlusion).r - 1); + vec4 mr = texture(metallic_roughness_texture, texcoord_metallic_roughness); vec3 half_vec = normalize(light_dir + view_dir); @@ -65,8 +65,8 @@ void main() vec3 light_colour = scene.light_color.rgb; float attenuation = 1; vec3 radiance = - per_light_radiance(albedo.rgb, metallic, roughness, light_colour, light_dir, normal_unit, view_dir, half_vec, attenuation) + - vec3(scene.ambient_color) * albedo.rgb * ao; + per_light_radiance(albedo.rgb, metallic, roughness, light_colour, light_dir, normal_unit, view_dir, half_vec, attenuation) + + vec3(scene.ambient_color) * albedo.rgb * ao; vec3 tmp = radiance + emissive_color; diff --git a/client/shaders/lit_skinned.vert.glsl b/client/shaders/lit_skinned.vert.glsl index 4be67996..5c8e7261 100644 --- a/client/shaders/lit_skinned.vert.glsl +++ b/client/shaders/lit_skinned.vert.glsl @@ -41,9 +41,11 @@ out gl_PerVertex void main() { - // TODO use base_color_texcoord et al instead of always using texcoord 0 - // TODO use the correct transform - texcoord[0] = compute_texcoord(material.base_color, in_texcoord[material.base_color.texcoord]); + texcoord_base_color = compute_texcoord(material.base_color, in_texcoord[material.base_color.texcoord]); + texcoord_metallic_roughness = compute_texcoord(material.metallic_roughness, in_texcoord[material.metallic_roughness.texcoord]); + texcoord_occlusion = compute_texcoord(material.occlusion, in_texcoord[material.occlusion.texcoord]); + texcoord_emissive = compute_texcoord(material.emissive, in_texcoord[material.emissive.texcoord]); + texcoord_normal = compute_texcoord(material.normal, in_texcoord[material.normal.texcoord]); mat4 skinMatrix = in_weights.x * joints.joint_matrices[int(in_joints.x)] +