This changes the include directive to use the standard C preprocessor `#include` directive. The regex to applied to all glsl sources is: `pragma BLENDER_REQUIRE\((\w+\.glsl)\)` `include "$1"` This allow C++ linter to parse the code and allow easier codebase traversal. However there is a small catch. While it does work like a standard include directive when the code is treated as C++, it doesn't when compiled by our shader backends. In this case, we still use our dependency concatenation approach instead of file injection. This means that included files will always be prepended when compiled to GLSL and a file cannot be appended more than once. This is why all GLSL lib file should have the `#pragma once` directive and always be included at the start of the file. These requirements are actually already enforced by our code-style in practice. On the implementation, the source needed to be mutated to comment the `#pragma once` and `#include`. This is needed to avoid GLSL compiler error out as this is an extension that not all vendor supports. Rel #127983 Pull Request: https://projects.blender.org/blender/blender/pulls/128076
71 lines
1.6 KiB
GLSL
71 lines
1.6 KiB
GLSL
/* SPDX-FileCopyrightText: 2019-2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#include "gpu_shader_common_math.glsl"
|
|
|
|
void node_attribute_color(vec4 attr, out vec4 out_attr)
|
|
{
|
|
out_attr = attr_load_color_post(attr);
|
|
}
|
|
|
|
void node_attribute_temperature(vec4 attr, out vec4 out_attr)
|
|
{
|
|
float temperature = attr_load_temperature_post(attr.x);
|
|
out_attr.x = temperature;
|
|
out_attr.y = temperature;
|
|
out_attr.z = temperature;
|
|
out_attr.w = 1.0;
|
|
}
|
|
|
|
void node_attribute_density(vec4 attr, out float out_attr)
|
|
{
|
|
out_attr = attr.x;
|
|
}
|
|
|
|
void node_attribute_flame(vec4 attr, out float out_attr)
|
|
{
|
|
out_attr = attr.x;
|
|
}
|
|
|
|
void node_attribute_uniform(vec4 attr, const float attr_hash, out vec4 out_attr)
|
|
{
|
|
/* Temporary solution to support both old UBO attributes and new SSBO loading.
|
|
* Old UBO load is already done through `attr` and will just be passed through. */
|
|
out_attr = attr_load_uniform(attr, floatBitsToUint(attr_hash));
|
|
}
|
|
|
|
vec4 attr_load_layer(const uint attr_hash)
|
|
{
|
|
#ifdef VLATTR_LIB
|
|
/* The first record of the buffer stores the length. */
|
|
uint left = 0, right = drw_layer_attrs[0].buffer_length;
|
|
|
|
while (left < right) {
|
|
uint mid = (left + right) / 2;
|
|
uint hash = drw_layer_attrs[mid].hash_code;
|
|
|
|
if (hash < attr_hash) {
|
|
left = mid + 1;
|
|
}
|
|
else if (hash > attr_hash) {
|
|
right = mid;
|
|
}
|
|
else {
|
|
return drw_layer_attrs[mid].data;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
return vec4(0.0);
|
|
}
|
|
|
|
void node_attribute(
|
|
vec4 attr, out vec4 outcol, out vec3 outvec, out float outf, out float outalpha)
|
|
{
|
|
outcol = vec4(attr.xyz, 1.0);
|
|
outvec = attr.xyz;
|
|
outf = math_average(attr.xyz);
|
|
outalpha = attr.w;
|
|
}
|