This avoid having to guards functions that are only available in fragment shader stage. Calling the function inside another stage is still invalid and will yield a compile error on Metal. The vulkan and opengl glsl patch need to be modified per stage to allow the fragment specific function to be defined. This is not yet widely used, but a good example is the change in `film_display_depth_amend`. Rel #137261 Pull Request: https://projects.blender.org/blender/blender/pulls/138280
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(float3 v, out float3 df)
|
|
{
|
|
/* Implementation defined. */
|
|
df = v + dF_impl(v);
|
|
}
|
|
|
|
/* Overload for UVs which are loaded as generic attributes. */
|
|
void differentiate_texco(float4 v, out float3 df)
|
|
{
|
|
/* Implementation defined. */
|
|
df = v.xyz + dF_impl(v.xyz);
|
|
}
|
|
|
|
void node_bump(float strength,
|
|
float dist,
|
|
float filter_width,
|
|
float height,
|
|
float3 N,
|
|
float2 height_xy,
|
|
float invert,
|
|
out float3 result)
|
|
{
|
|
N = normalize(N);
|
|
dist *= FrontFacing ? invert : -invert;
|
|
|
|
#ifdef GPU_FRAGMENT_SHADER
|
|
float3 dPdx = gpu_dfdx(g_data.P);
|
|
float3 dPdy = gpu_dfdy(g_data.P);
|
|
|
|
/* Get surface tangents from normal. */
|
|
float3 Rx = cross(dPdy, N);
|
|
float3 Ry = cross(N, dPdx);
|
|
|
|
/* Compute surface gradient and determinant. */
|
|
float det = dot(dPdx, Rx);
|
|
|
|
float2 dHd = height_xy - float2(height);
|
|
float3 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
|
|
}
|