This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/gpu/shaders/material/gpu_shader_material_bump.glsl
Kévin Dietrich d86d7c935e Fix T97827: material preview not displaying textures
Caused by rB281bcc1c1dd6 which did not properly made use
of `vec4` for UVs which are now loaded as attributes.
2022-05-04 14:30:52 +02:00

42 lines
948 B
GLSL

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 height, vec3 N, vec2 dHd, 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);
vec3 surfgrad = dHd.x * Rx + dHd.y * Ry;
strength = max(strength, 0.0);
result = normalize(abs(det) * N - dist * sign(det) * surfgrad);
result = normalize(mix(N, result, strength));
#else
result = N;
#endif
}