MCPcopy Create free account
hub / github.com/MrNeRF/LichtFeld-Studio / shadeMeshPixel

Function shadeMeshPixel

src/rendering/raster_rendering_engine.cpp:1329–1419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1327 }
1328
1329 [[nodiscard]] glm::vec3 shadeMeshPixel(const lfs::core::MeshData& mesh,
1330 const size_t material_index,
1331 const MeshRenderOptions& options,
1332 const glm::vec3& world_position,
1333 glm::vec3 normal,
1334 const glm::vec3& tangent,
1335 const float tangent_handedness,
1336 const glm::vec2& texcoord,
1337 const glm::vec4& vertex_color,
1338 const glm::vec3& camera_position,
1339 const glm::vec3& light_dir,
1340 const SoftwareShadowMap& shadow_map) {
1341 const auto& material = meshMaterialOrDefault(mesh, material_index);
1342
1343 glm::vec4 albedo = material.base_color;
1344 if (mesh.has_texcoords() &&
1345 material.has_albedo_texture() &&
1346 material.albedo_tex > 0 &&
1347 material.albedo_tex <= mesh.texture_images.size()) {
1348 const auto sample = sampleTextureBilinear(mesh.texture_images[material.albedo_tex - 1u],
1349 texcoord.x, texcoord.y);
1350 albedo *= glm::vec4(srgbToLinear(glm::vec3(sample)), sample.a);
1351 }
1352 albedo *= vertex_color;
1353
1354 float metallic = material.metallic;
1355 float roughness = material.roughness;
1356 float ao = material.ao;
1357 if (mesh.has_texcoords() &&
1358 material.has_metallic_roughness_texture() &&
1359 material.metallic_roughness_tex > 0 &&
1360 material.metallic_roughness_tex <= mesh.texture_images.size()) {
1361 const glm::vec3 orm = glm::vec3(sampleTextureBilinear(
1362 mesh.texture_images[material.metallic_roughness_tex - 1u],
1363 texcoord.x, texcoord.y));
1364 ao *= orm.r;
1365 roughness *= orm.g;
1366 metallic *= orm.b;
1367 }
1368 roughness = std::max(roughness, 0.04f);
1369
1370 normal = safeNormalize(normal, glm::vec3(0.0f, 1.0f, 0.0f));
1371 if (mesh.has_texcoords() &&
1372 material.has_normal_texture() &&
1373 material.normal_tex > 0 &&
1374 material.normal_tex <= mesh.texture_images.size()) {
1375 const glm::vec3 normal_sample = glm::vec3(sampleTextureBilinear(
1376 mesh.texture_images[material.normal_tex - 1u],
1377 texcoord.x, texcoord.y)) *
1378 2.0f -
1379 glm::vec3(1.0f);
1380 const glm::vec3 t = safeNormalize(tangent, glm::vec3(1.0f, 0.0f, 0.0f));
1381 const glm::vec3 b = safeNormalize(glm::cross(normal, t) * tangent_handedness,
1382 glm::vec3(0.0f, 1.0f, 0.0f));
1383 normal = safeNormalize(glm::mat3(t, b, normal) * normal_sample, normal);
1384 }
1385
1386 const glm::vec3 view_dir = safeNormalize(camera_position - world_position, glm::vec3(0.0f, 0.0f, 1.0f));

Callers 1

rasterizeMeshTriangleFunction · 0.85

Calls 15

sampleTextureBilinearFunction · 0.85
srgbToLinearFunction · 0.85
sampleShadowFunction · 0.85
distributionGGXFunction · 0.85
geometrySmithFunction · 0.85
fresnelSchlickFunction · 0.85
powFunction · 0.85
has_albedo_textureMethod · 0.80
has_normal_textureMethod · 0.80
safeNormalizeFunction · 0.70
maxFunction · 0.50

Tested by

no test coverage detected