Use sub-pixel differentials for bump mapping helps with reducing artifacts when objects are moving or when textures have high frequency details. Currently we scale it by 0.1 because it seems to work good in practice, we can adjust the value in the future if it turns out to be impractical. Ref: #122892 Pull Request: https://projects.blender.org/blender/blender/pulls/133991
34 lines
954 B
Plaintext
34 lines
954 B
Plaintext
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
|
|
|
#include "stdcycles.h"
|
|
|
|
shader node_attribute(string bump_offset = "center",
|
|
string name = "",
|
|
output point Vector = point(0.0, 0.0, 0.0),
|
|
output color Color = 0.0,
|
|
output float Fac = 0.0,
|
|
output float Alpha = 0.0)
|
|
{
|
|
float data[4] = {0.0, 0.0, 0.0, 0.0};
|
|
getattribute(name, data);
|
|
Color = color(data[0], data[1], data[2]);
|
|
Vector = point(Color);
|
|
getattribute(name, Fac);
|
|
Alpha = data[3];
|
|
|
|
if (bump_offset == "dx") {
|
|
Color += Dx(Color) * BUMP_DX;
|
|
Vector += Dx(Vector) * BUMP_DX;
|
|
Fac += Dx(Fac) * BUMP_DX;
|
|
Alpha += Dx(Alpha) * BUMP_DX;
|
|
}
|
|
else if (bump_offset == "dy") {
|
|
Color += Dy(Color) * BUMP_DY;
|
|
Vector += Dy(Vector) * BUMP_DY;
|
|
Fac += Dy(Fac) * BUMP_DY;
|
|
Alpha += Dy(Alpha) * BUMP_DY;
|
|
}
|
|
}
|