Blender V5.3
gpu_shader_material_bump.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include "gpu_shader_codegen_lib.glsl"
9
10[[node]]
12{
13 /* Implementation defined. */
14 df = v + dF_impl(v);
15}
16
17/* Overload for UVs which are loaded as generic attributes. */
18[[node]]
20{
21 /* Implementation defined. */
22 df = v.xyz + dF_impl(v.xyz);
23}
24
25[[node]]
26void node_bump(float strength,
27 float dist,
28 float filter_width,
29 float height,
30 float3 N,
31 float2 height_xy,
32 float invert,
34 const ShadingData &sd,
35 float3 &result)
36{
37 N = normalize(N);
38#if defined(GPU_FRAGMENT_SHADER) || defined(GLSL_CPP_STUBS)
39 dist *= FrontFacing ? invert : -invert;
40
43
44 /* Get surface tangents from normal. */
45 float3 Rx = cross(dPdy, N);
46 float3 Ry = cross(N, dPdx);
47
48 /* Compute surface gradient and determinant. */
49 float det = dot(dPdx, Rx);
50
51 float2 dHd = height_xy - float2(height);
52 float3 surfgrad = dHd.x * Rx + dHd.y * Ry;
53
54 strength = max(strength, 0.0f);
55
56 result = normalize(filter_width * abs(det) * N - dist * sign(det) * surfgrad);
57 result = normalize(mix(N, result, strength));
58#else
59 result = N;
60#endif
61}
btScalar max
ccl_device_forceinline float3 dPdx(const ccl_private ShaderData *sd)
ccl_device_forceinline float3 dPdy(const ccl_private ShaderData *sd)
float derivative_scale_get(KernelGlobals &kg)
#define resource_table
T gpu_dfdx(T) RET
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
constexpr T sign(T) RET
#define abs
T gpu_dfdy(T) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
void node_bump(float strength, float dist, float filter_width, float height, float3 N, float2 height_xy, float invert, KernelGlobals &kg, const ShadingData &sd, float3 &result)
void differentiate_texco(float3 v, float3 &df)
float2x2 invert(float2x2 mat)
#define N
#define mix
float x
float y