This commit removes all EEVEE specific code from the `gpu_shader_material*.glsl` files. It defines a clear interface to evaluate the closure nodes leaving more flexibility to the render engine. Some of the long standing workaround are fixed: - bump mapping support is no longer duplicating a lot of node and is instead compiled into a function call. - bump rewiring to Normal socket is no longer needed as we now use a global `g_data.N` for that. Closure sampling with upstread weight eval is now supported if the engine needs it. This also makes all the material GLSL sources use `GPUSource` for better debugging experience. The `GPUFunction` parsing now happens in `GPUSource` creation. The whole `GPUCodegen` now uses the `ShaderCreateInfo` and is object type agnostic. Is has also been rewritten in C++. This patch changes a view behavior for EEVEE: - Mix shader node factor imput is now clamped. - Tangent Vector displacement behavior is now matching cycles. - The chosen BSDF used for SSR might change. - Hair shading may have very small changes on very large hairs when using hair polygon stripes. - ShaderToRGB node will remove any SSR and SSS form a shader. - SSS radius input now is no longer a scaling factor but defines an average radius. The SSS kernel "shape" (radii) are still defined by the socket default values. Appart from the listed changes no other regressions are expected.
222 lines
4.3 KiB
GLSL
222 lines
4.3 KiB
GLSL
#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
|
|
|
|
void math_add(float a, float b, float c, out float result)
|
|
{
|
|
result = a + b;
|
|
}
|
|
|
|
void math_subtract(float a, float b, float c, out float result)
|
|
{
|
|
result = a - b;
|
|
}
|
|
|
|
void math_multiply(float a, float b, float c, out float result)
|
|
{
|
|
result = a * b;
|
|
}
|
|
|
|
void math_divide(float a, float b, float c, out float result)
|
|
{
|
|
result = safe_divide(a, b);
|
|
}
|
|
|
|
void math_power(float a, float b, float c, out float result)
|
|
{
|
|
if (a >= 0.0) {
|
|
result = compatible_pow(a, b);
|
|
}
|
|
else {
|
|
float fraction = mod(abs(b), 1.0);
|
|
if (fraction > 0.999 || fraction < 0.001) {
|
|
result = compatible_pow(a, floor(b + 0.5));
|
|
}
|
|
else {
|
|
result = 0.0;
|
|
}
|
|
}
|
|
}
|
|
|
|
void math_logarithm(float a, float b, float c, out float result)
|
|
{
|
|
result = (a > 0.0 && b > 0.0) ? log2(a) / log2(b) : 0.0;
|
|
}
|
|
|
|
void math_sqrt(float a, float b, float c, out float result)
|
|
{
|
|
result = (a > 0.0) ? sqrt(a) : 0.0;
|
|
}
|
|
|
|
void math_inversesqrt(float a, float b, float c, out float result)
|
|
{
|
|
result = inversesqrt(a);
|
|
}
|
|
|
|
void math_absolute(float a, float b, float c, out float result)
|
|
{
|
|
result = abs(a);
|
|
}
|
|
|
|
void math_radians(float a, float b, float c, out float result)
|
|
{
|
|
result = radians(a);
|
|
}
|
|
|
|
void math_degrees(float a, float b, float c, out float result)
|
|
{
|
|
result = degrees(a);
|
|
}
|
|
|
|
void math_minimum(float a, float b, float c, out float result)
|
|
{
|
|
result = min(a, b);
|
|
}
|
|
|
|
void math_maximum(float a, float b, float c, out float result)
|
|
{
|
|
result = max(a, b);
|
|
}
|
|
|
|
void math_less_than(float a, float b, float c, out float result)
|
|
{
|
|
result = (a < b) ? 1.0 : 0.0;
|
|
}
|
|
|
|
void math_greater_than(float a, float b, float c, out float result)
|
|
{
|
|
result = (a > b) ? 1.0 : 0.0;
|
|
}
|
|
|
|
void math_round(float a, float b, float c, out float result)
|
|
{
|
|
result = floor(a + 0.5);
|
|
}
|
|
|
|
void math_floor(float a, float b, float c, out float result)
|
|
{
|
|
result = floor(a);
|
|
}
|
|
|
|
void math_ceil(float a, float b, float c, out float result)
|
|
{
|
|
result = ceil(a);
|
|
}
|
|
|
|
void math_fraction(float a, float b, float c, out float result)
|
|
{
|
|
result = a - floor(a);
|
|
}
|
|
|
|
void math_modulo(float a, float b, float c, out float result)
|
|
{
|
|
result = compatible_fmod(a, b);
|
|
}
|
|
|
|
void math_trunc(float a, float b, float c, out float result)
|
|
{
|
|
result = trunc(a);
|
|
}
|
|
|
|
void math_snap(float a, float b, float c, out float result)
|
|
{
|
|
result = floor(safe_divide(a, b)) * b;
|
|
}
|
|
|
|
void math_pingpong(float a, float b, float c, out float result)
|
|
{
|
|
result = (b != 0.0) ? abs(fract((a - b) / (b * 2.0)) * b * 2.0 - b) : 0.0;
|
|
}
|
|
|
|
/* Adapted from godotengine math_funcs.h. */
|
|
void math_wrap(float a, float b, float c, out float result)
|
|
{
|
|
result = wrap(a, b, c);
|
|
}
|
|
|
|
void math_sine(float a, float b, float c, out float result)
|
|
{
|
|
result = sin(a);
|
|
}
|
|
|
|
void math_cosine(float a, float b, float c, out float result)
|
|
{
|
|
result = cos(a);
|
|
}
|
|
|
|
void math_tangent(float a, float b, float c, out float result)
|
|
{
|
|
result = tan(a);
|
|
}
|
|
|
|
void math_sinh(float a, float b, float c, out float result)
|
|
{
|
|
result = sinh(a);
|
|
}
|
|
|
|
void math_cosh(float a, float b, float c, out float result)
|
|
{
|
|
result = cosh(a);
|
|
}
|
|
|
|
void math_tanh(float a, float b, float c, out float result)
|
|
{
|
|
result = tanh(a);
|
|
}
|
|
|
|
void math_arcsine(float a, float b, float c, out float result)
|
|
{
|
|
result = (a <= 1.0 && a >= -1.0) ? asin(a) : 0.0;
|
|
}
|
|
|
|
void math_arccosine(float a, float b, float c, out float result)
|
|
{
|
|
result = (a <= 1.0 && a >= -1.0) ? acos(a) : 0.0;
|
|
}
|
|
|
|
void math_arctangent(float a, float b, float c, out float result)
|
|
{
|
|
result = atan(a);
|
|
}
|
|
|
|
void math_arctan2(float a, float b, float c, out float result)
|
|
{
|
|
result = atan(a, b);
|
|
}
|
|
|
|
void math_sign(float a, float b, float c, out float result)
|
|
{
|
|
result = sign(a);
|
|
}
|
|
|
|
void math_exponent(float a, float b, float c, out float result)
|
|
{
|
|
result = exp(a);
|
|
}
|
|
|
|
void math_compare(float a, float b, float c, out float result)
|
|
{
|
|
result = (abs(a - b) <= max(c, 1e-5)) ? 1.0 : 0.0;
|
|
}
|
|
|
|
void math_multiply_add(float a, float b, float c, out float result)
|
|
{
|
|
result = a * b + c;
|
|
}
|
|
|
|
/* See: https://www.iquilezles.org/www/articles/smin/smin.htm. */
|
|
void math_smoothmin(float a, float b, float c, out float result)
|
|
{
|
|
if (c != 0.0) {
|
|
float h = max(c - abs(a - b), 0.0) / c;
|
|
result = min(a, b) - h * h * h * c * (1.0 / 6.0);
|
|
}
|
|
else {
|
|
result = min(a, b);
|
|
}
|
|
}
|
|
|
|
void math_smoothmax(float a, float b, float c, out float result)
|
|
{
|
|
math_smoothmin(-a, -b, c, result);
|
|
result = -result;
|
|
}
|