This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/gpu/shaders/material/gpu_shader_material_math.glsl
OmarSquircleArt 8cd0da88e5 GPU: Split gpu_shader_material into multiple files.
This patch continue the efforts to split the `gpu_shader_material` file
started in D5569.

Dependency resolution is now recursive. Each shading node gets its own
file. Additionally, some utility files are added to be shared between
files, like `math_util`, `color_util`, and `hash`. Some files are always
included because they may be used in the execution function, like
`world_normals`.

Some glsl functions appeared to be unused, so they were removed, like
`output_node`, `bits_to_01`, and `exp_blender`. Other functions have
been renamed to be more general and get used as utils, like `texco_norm`
which became `vector_normalize`.

A lot of the opengl tests fails, but those same tests also fail in
master, so this is probably unrelated to this patch.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D5616
2019-08-30 17:28:57 +02:00

131 lines
2.2 KiB
GLSL

void math_add(float a, float b, out float result)
{
result = a + b;
}
void math_subtract(float a, float b, out float result)
{
result = a - b;
}
void math_multiply(float a, float b, out float result)
{
result = a * b;
}
void math_divide(float a, float b, out float result)
{
result = safe_divide(a, b);
}
void math_power(float a, float b, 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, out float result)
{
result = (a > 0.0 && b > 0.0) ? log2(a) / log2(b) : 0.0;
}
void math_sqrt(float a, float b, out float result)
{
result = (a > 0.0) ? sqrt(a) : 0.0;
}
void math_absolute(float a, float b, out float result)
{
result = abs(a);
}
void math_minimum(float a, float b, out float result)
{
result = min(a, b);
}
void math_maximum(float a, float b, out float result)
{
result = max(a, b);
}
void math_less_than(float a, float b, out float result)
{
result = (a < b) ? 1.0 : 0.0;
}
void math_greater_than(float a, float b, out float result)
{
result = (a > b) ? 1.0 : 0.0;
}
void math_round(float a, float b, out float result)
{
result = floor(a + 0.5);
}
void math_floor(float a, float b, out float result)
{
result = floor(a);
}
void math_ceil(float a, float b, out float result)
{
result = ceil(a);
}
void math_fraction(float a, float b, out float result)
{
result = a - floor(a);
}
void math_modulo(float a, float b, out float result)
{
result = c_mod(a, b);
}
void math_sine(float a, float b, out float result)
{
result = sin(a);
}
void math_cosine(float a, float b, out float result)
{
result = cos(a);
}
void math_tangent(float a, float b, out float result)
{
result = tan(a);
}
void math_arcsine(float a, float b, out float result)
{
result = (a <= 1.0 && a >= -1.0) ? asin(a) : 0.0;
}
void math_arccosine(float a, float b, out float result)
{
result = (a <= 1.0 && a >= -1.0) ? acos(a) : 0.0;
}
void math_arctangent(float a, float b, out float result)
{
result = atan(a);
}
void math_arctan2(float a, float b, out float result)
{
result = atan(a, b);
}