GPU: Move common shaders into a common directory

This patch moves some of the utility library shaders into a common
directory and makes the necessary renames across shaders. Additionally,
material-specific transform functions were moved outside of math utils
into a separate transform_utils.glsl file.

This is needed in preparation for the viewport compositor, which will
make use of some of those utilities and will require all material
specific bit to be removed out of those files.

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D14688
This commit is contained in:
Omar Emara 2022-05-06 12:58:14 +02:00
parent f5428736a7
commit 8f6f28a0dc
30 changed files with 107 additions and 104 deletions

View File

@ -303,6 +303,13 @@ set(GLSL_SRC
shaders/gpu_shader_geometry.glsl
shaders/common/gpu_shader_common_color_ramp.glsl
shaders/common/gpu_shader_common_color_utils.glsl
shaders/common/gpu_shader_common_hash.glsl
shaders/common/gpu_shader_common_math.glsl
shaders/common/gpu_shader_common_math_utils.glsl
shaders/common/gpu_shader_common_mix_rgb.glsl
shaders/material/gpu_shader_material_add_shader.glsl
shaders/material/gpu_shader_material_ambient_occlusion.glsl
shaders/material/gpu_shader_material_anisotropic.glsl
@ -315,8 +322,6 @@ set(GLSL_SRC
shaders/material/gpu_shader_material_bump.glsl
shaders/material/gpu_shader_material_camera.glsl
shaders/material/gpu_shader_material_clamp.glsl
shaders/material/gpu_shader_material_color_ramp.glsl
shaders/material/gpu_shader_material_color_util.glsl
shaders/material/gpu_shader_material_combine_color.glsl
shaders/material/gpu_shader_material_combine_hsv.glsl
shaders/material/gpu_shader_material_combine_rgb.glsl
@ -334,7 +339,6 @@ set(GLSL_SRC
shaders/material/gpu_shader_material_glossy.glsl
shaders/material/gpu_shader_material_hair_info.glsl
shaders/material/gpu_shader_material_hair.glsl
shaders/material/gpu_shader_material_hash.glsl
shaders/material/gpu_shader_material_holdout.glsl
shaders/material/gpu_shader_material_hue_sat_val.glsl
shaders/material/gpu_shader_material_invert.glsl
@ -343,9 +347,6 @@ set(GLSL_SRC
shaders/material/gpu_shader_material_light_path.glsl
shaders/material/gpu_shader_material_mapping.glsl
shaders/material/gpu_shader_material_map_range.glsl
shaders/material/gpu_shader_material_math.glsl
shaders/material/gpu_shader_material_math_util.glsl
shaders/material/gpu_shader_material_mix_rgb.glsl
shaders/material/gpu_shader_material_mix_shader.glsl
shaders/material/gpu_shader_material_noise.glsl
shaders/material/gpu_shader_material_normal.glsl
@ -383,6 +384,7 @@ set(GLSL_SRC
shaders/material/gpu_shader_material_tex_wave.glsl
shaders/material/gpu_shader_material_tex_white_noise.glsl
shaders/material/gpu_shader_material_toon.glsl
shaders/material/gpu_shader_material_transform_utils.glsl
shaders/material/gpu_shader_material_translucent.glsl
shaders/material/gpu_shader_material_transparent.glsl
shaders/material/gpu_shader_material_uv_map.glsl

View File

@ -549,7 +549,9 @@ struct GPUSource {
bool is_from_material_library() const
{
return filename.startswith("gpu_shader_material_") && filename.endswith(".glsl");
return (filename.startswith("gpu_shader_material_") ||
filename.startswith("gpu_shader_common_")) &&
filename.endswith(".glsl");
}
};

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
void math_add(float a, float b, float c, out float result)
{

View File

@ -139,75 +139,3 @@ mat3 euler_to_mat3(vec3 euler)
mat[2][2] = cy * cx;
return mat;
}
void normal_transform_object_to_world(vec3 vin, out vec3 vout)
{
vout = normal_object_to_world(vin);
}
void normal_transform_world_to_object(vec3 vin, out vec3 vout)
{
vout = normal_world_to_object(vin);
}
void direction_transform_object_to_world(vec3 vin, out vec3 vout)
{
vout = transform_direction(ModelMatrix, vin);
}
void direction_transform_object_to_view(vec3 vin, out vec3 vout)
{
vout = transform_direction(ModelMatrix, vin);
vout = transform_direction(ViewMatrix, vout);
}
void direction_transform_view_to_world(vec3 vin, out vec3 vout)
{
vout = transform_direction(ViewMatrixInverse, vin);
}
void direction_transform_view_to_object(vec3 vin, out vec3 vout)
{
vout = transform_direction(ViewMatrixInverse, vin);
vout = transform_direction(ModelMatrixInverse, vout);
}
void direction_transform_world_to_view(vec3 vin, out vec3 vout)
{
vout = transform_direction(ViewMatrix, vin);
}
void direction_transform_world_to_object(vec3 vin, out vec3 vout)
{
vout = transform_direction(ModelMatrixInverse, vin);
}
void point_transform_object_to_world(vec3 vin, out vec3 vout)
{
vout = point_object_to_world(vin);
}
void point_transform_object_to_view(vec3 vin, out vec3 vout)
{
vout = point_object_to_view(vin);
}
void point_transform_view_to_world(vec3 vin, out vec3 vout)
{
vout = point_view_to_world(vin);
}
void point_transform_view_to_object(vec3 vin, out vec3 vout)
{
vout = point_view_to_object(vin);
}
void point_transform_world_to_view(vec3 vin, out vec3 vout)
{
vout = point_world_to_view(vin);
}
void point_transform_world_to_object(vec3 vin, out vec3 vout)
{
vout = point_world_to_object(vin);
}

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_color_util.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_color_utils.glsl)
void mix_blend(float fac, vec4 col1, vec4 col2, out vec4 outcol)
{

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_color_util.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_color_utils.glsl)
void combine_color_rgb(float r, float g, float b, out vec4 col)
{

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_color_util.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_color_utils.glsl)
void combine_hsv(float h, float s, float v, out vec4 col)
{

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_material_noise.glsl)
/* The fractal_noise functions are all exactly the same except for the input type. */

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
void node_gamma(vec4 col, float gamma, out vec4 outcol)
{

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
void node_hair_info(float hair_length,
out float is_strand,

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_color_util.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_color_utils.glsl)
void hue_sat(float hue, float sat, float value, float fac, vec4 col, out vec4 outcol)
{

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
float smootherstep(float edge0, float edge1, float x)
{

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
void mapping_mat4(
vec3 vec, vec4 m0, vec4 m1, vec4 m2, vec4 m3, vec3 minvec, vec3 maxvec, out vec3 outvec)

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
/* clang-format off */
#define FLOORFRAC(x, x_int, x_fract) { float x_floor = floor(x); x_int = int(x_floor); x_fract = x - x_floor; }

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
void node_point_info(out vec3 position, out float radius, out float random)
{

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_color_util.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_color_utils.glsl)
void separate_color_rgb(vec4 col, out float r, out float g, out float b)
{

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_color_util.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_color_utils.glsl)
void separate_hsv(vec4 col, out float h, out float s, out float v)
{

View File

@ -1,5 +1,5 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
vec2 calc_brick_texture(vec3 p,
float mortar_size,

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
void node_tex_environment_equirectangular(vec3 co, out vec3 uv)
{

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_material_noise.glsl)
/* 1D Musgrave fBm

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_material_noise.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_material_fractal_noise.glsl)

View File

@ -1,5 +1,5 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
/*
* Original code is under the MIT License, Copyright (c) 2013 Inigo Quilez.

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_material_noise.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_material_fractal_noise.glsl)

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
/* White Noise */

View File

@ -0,0 +1,71 @@
void normal_transform_object_to_world(vec3 vin, out vec3 vout)
{
vout = normal_object_to_world(vin);
}
void normal_transform_world_to_object(vec3 vin, out vec3 vout)
{
vout = normal_world_to_object(vin);
}
void direction_transform_object_to_world(vec3 vin, out vec3 vout)
{
vout = transform_direction(ModelMatrix, vin);
}
void direction_transform_object_to_view(vec3 vin, out vec3 vout)
{
vout = transform_direction(ModelMatrix, vin);
vout = transform_direction(ViewMatrix, vout);
}
void direction_transform_view_to_world(vec3 vin, out vec3 vout)
{
vout = transform_direction(ViewMatrixInverse, vin);
}
void direction_transform_view_to_object(vec3 vin, out vec3 vout)
{
vout = transform_direction(ViewMatrixInverse, vin);
vout = transform_direction(ModelMatrixInverse, vout);
}
void direction_transform_world_to_view(vec3 vin, out vec3 vout)
{
vout = transform_direction(ViewMatrix, vin);
}
void direction_transform_world_to_object(vec3 vin, out vec3 vout)
{
vout = transform_direction(ModelMatrixInverse, vin);
}
void point_transform_object_to_world(vec3 vin, out vec3 vout)
{
vout = point_object_to_world(vin);
}
void point_transform_object_to_view(vec3 vin, out vec3 vout)
{
vout = point_object_to_view(vin);
}
void point_transform_view_to_world(vec3 vin, out vec3 vout)
{
vout = point_view_to_world(vin);
}
void point_transform_view_to_object(vec3 vin, out vec3 vout)
{
vout = point_view_to_object(vin);
}
void point_transform_world_to_view(vec3 vin, out vec3 vout)
{
vout = point_world_to_view(vin);
}
void point_transform_world_to_object(vec3 vin, out vec3 vout)
{
vout = point_world_to_object(vin);
}

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
void vector_math_add(vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue)
{

View File

@ -1,4 +1,4 @@
#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
vec3 rotate_around_axis(vec3 p, vec3 axis, float angle)
{