They are actually already some literals with the `f` suffix that are in our shader codebase and we never had problem in the past 5 years (or even 8 years). So I think it is safe to do and improves convergence of codestyles. Pull Request: https://projects.blender.org/blender/blender/pulls/137352
52 lines
1.2 KiB
GLSL
52 lines
1.2 KiB
GLSL
/* SPDX-FileCopyrightText: 2019-2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
void differentiate_texco(vec3 v, out vec3 df)
|
|
{
|
|
/* Implementation defined. */
|
|
df = v + dF_impl(v);
|
|
}
|
|
|
|
/* Overload for UVs which are loaded as generic attributes. */
|
|
void differentiate_texco(vec4 v, out vec3 df)
|
|
{
|
|
/* Implementation defined. */
|
|
df = v.xyz + dF_impl(v.xyz);
|
|
}
|
|
|
|
void node_bump(float strength,
|
|
float dist,
|
|
float filter_width,
|
|
float height,
|
|
vec3 N,
|
|
vec2 height_xy,
|
|
float invert,
|
|
out vec3 result)
|
|
{
|
|
N = normalize(N);
|
|
dist *= FrontFacing ? invert : -invert;
|
|
|
|
#ifdef GPU_FRAGMENT_SHADER
|
|
vec3 dPdx = dFdx(g_data.P);
|
|
vec3 dPdy = dFdy(g_data.P);
|
|
|
|
/* Get surface tangents from normal. */
|
|
vec3 Rx = cross(dPdy, N);
|
|
vec3 Ry = cross(N, dPdx);
|
|
|
|
/* Compute surface gradient and determinant. */
|
|
float det = dot(dPdx, Rx);
|
|
|
|
vec2 dHd = height_xy - vec2(height);
|
|
vec3 surfgrad = dHd.x * Rx + dHd.y * Ry;
|
|
|
|
strength = max(strength, 0.0f);
|
|
|
|
result = normalize(filter_width * abs(det) * N - dist * sign(det) * surfgrad);
|
|
result = normalize(mix(N, result, strength));
|
|
#else
|
|
result = N;
|
|
#endif
|
|
}
|