Use the correct texcoord

This commit is contained in:
Guillaume Meunier
2025-12-02 19:57:11 +01:00
parent f99fb8fa18
commit 6f50ba3979
5 changed files with 27 additions and 20 deletions
+5 -1
View File
@@ -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;
+5 -5
View File
@@ -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);
+5 -4
View File
@@ -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])));
+7 -7
View File
@@ -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;
+5 -3
View File
@@ -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)] +