Fix: Cycles: Wrong differentials of Wireframe nodes for bump mapping

Bump map differentials are computed in `svm_node_set_bump()`, other
shader nodes should just evaluate at shifted locations.

Pull Request: https://projects.blender.org/blender/blender/pulls/133876
This commit is contained in:
Weizhen Huang
2025-02-03 10:57:34 +01:00
committed by Weizhen Huang
parent ae23bcdc1a
commit e9c39a6dcd
2 changed files with 9 additions and 17 deletions

View File

@@ -10,19 +10,12 @@ shader node_wireframe(string bump_offset = "center",
float Size = 0.01,
output float Fac = 0.0)
{
Fac = wireframe("triangles", Size, use_pixel_size);
/* TODO(sergey): Since we can't use autodiff here we do algebraic
* calculation of derivatives by definition. We could probably
* optimize this a bit by doing some extra calculation in wireframe().
*/
if (bump_offset == "dx") {
point dx = Dx(P);
P -= dx;
Fac += (Fac - wireframe("triangles", Size, use_pixel_size)) / length(dx);
P += Dx(P);
}
else if (bump_offset == "dy") {
point dy = Dy(P);
P -= dy;
Fac += (Fac - wireframe("triangles", Size, use_pixel_size)) / length(dy);
P += Dy(P);
}
Fac = wireframe("triangles", Size, use_pixel_size);
}

View File

@@ -95,18 +95,17 @@ ccl_device_noinline void svm_node_wireframe(KernelGlobals kg,
/* Calculate wireframe */
const differential3 dP = differential_from_compact(sd->Ng, sd->dP);
float f = wireframe(kg, sd, dP, size, pixel_size, &sd->P);
/* TODO(sergey): Think of faster way to calculate derivatives. */
float3 P = sd->P;
if (bump_offset == NODE_BUMP_OFFSET_DX) {
float3 Px = sd->P - dP.dx;
f += (f - wireframe(kg, sd, dP, size, pixel_size, &Px)) / len(dP.dx);
P += dP.dx;
}
else if (bump_offset == NODE_BUMP_OFFSET_DY) {
float3 Py = sd->P - dP.dy;
f += (f - wireframe(kg, sd, dP, size, pixel_size, &Py)) / len(dP.dy);
P += dP.dy;
}
const float f = wireframe(kg, sd, dP, size, pixel_size, &P);
if (stack_valid(out_fac)) {
stack_store_float(stack, out_fac, f);
}