Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2022-04-14 19:47:58 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-04-14 19:47:58 +0300
commit80859a6cb2726a39fb22cb49f06e0355dc9390a7 (patch)
treefd3f8ead5a247a79ea11e4aacc720843bbc5e2c2 /source/blender/draw/intern/shaders
parent66dc4d4efb88ecf2d18bfa08ab9c43b024ebd2fb (diff)
GPU: Make nodetree GLSL Codegen render engine agnostic
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.
Diffstat (limited to 'source/blender/draw/intern/shaders')
-rw-r--r--source/blender/draw/intern/shaders/common_attribute_lib.glsl21
-rw-r--r--source/blender/draw/intern/shaders/common_math_lib.glsl6
-rw-r--r--source/blender/draw/intern/shaders/common_view_lib.glsl54
3 files changed, 65 insertions, 16 deletions
diff --git a/source/blender/draw/intern/shaders/common_attribute_lib.glsl b/source/blender/draw/intern/shaders/common_attribute_lib.glsl
new file mode 100644
index 00000000000..99db2929a13
--- /dev/null
+++ b/source/blender/draw/intern/shaders/common_attribute_lib.glsl
@@ -0,0 +1,21 @@
+
+/* Prototype of functions to implement to load attributes data.
+ * Implementation changes based on object data type. */
+
+vec3 attr_load_orco(vec4 orco);
+vec4 attr_load_tangent(vec4 tangent);
+vec3 attr_load_uv(vec3 uv);
+vec4 attr_load_color(vec4 color);
+vec4 attr_load_vec4(vec4 attr);
+vec3 attr_load_vec3(vec3 attr);
+vec2 attr_load_vec2(vec2 attr);
+float attr_load_float(float attr);
+
+vec3 attr_load_orco(samplerBuffer orco);
+vec4 attr_load_tangent(samplerBuffer tangent);
+vec3 attr_load_uv(samplerBuffer uv);
+vec4 attr_load_color(samplerBuffer color);
+vec4 attr_load_vec4(samplerBuffer attr);
+vec3 attr_load_vec3(samplerBuffer attr);
+vec2 attr_load_vec2(samplerBuffer attr);
+float attr_load_float(samplerBuffer attr);
diff --git a/source/blender/draw/intern/shaders/common_math_lib.glsl b/source/blender/draw/intern/shaders/common_math_lib.glsl
index 4d0ffaeb40f..1ac26c91b93 100644
--- a/source/blender/draw/intern/shaders/common_math_lib.glsl
+++ b/source/blender/draw/intern/shaders/common_math_lib.glsl
@@ -1,4 +1,8 @@
+/* WORKAROUND: to guard against double include in EEVEE. */
+#ifndef COMMON_MATH_LIB_GLSL
+#define COMMON_MATH_LIB_GLSL
+
/* ---------------------------------------------------------------------- */
/** \name Common Math Utilities
* \{ */
@@ -276,3 +280,5 @@ vec3 hue_gradient(float t)
vec3 p = abs(fract(t + vec3(1.0, 2.0 / 3.0, 1.0 / 3.0)) * 6.0 - 3.0);
return (clamp(p - 1.0, 0.0, 1.0));
}
+
+#endif /* COMMON_MATH_LIB_GLSL */
diff --git a/source/blender/draw/intern/shaders/common_view_lib.glsl b/source/blender/draw/intern/shaders/common_view_lib.glsl
index a2b8cb4bbd6..4086162a530 100644
--- a/source/blender/draw/intern/shaders/common_view_lib.glsl
+++ b/source/blender/draw/intern/shaders/common_view_lib.glsl
@@ -1,5 +1,10 @@
+
+/* WORKAROUND: to guard against double include in EEVEE. */
+#ifndef COMMON_VIEW_LIB_GLSL
+#define COMMON_VIEW_LIB_GLSL
+
/* Temporary until we fully make the switch. */
-#ifndef USE_GPU_SHADER_CREATE_INFO
+#if !defined(USE_GPU_SHADER_CREATE_INFO)
# define DRW_RESOURCE_CHUNK_LEN 512
@@ -37,7 +42,10 @@ layout(std140) uniform viewBlock
#define cameraForward ViewMatrixInverse[2].xyz
#define cameraPos ViewMatrixInverse[3].xyz
-#define cameraVec(P) ((ProjectionMatrix[3][3] == 0.0) ? normalize(cameraPos - P) : cameraForward)
+vec3 cameraVec(vec3 P)
+{
+ return ((ProjectionMatrix[3][3] == 0.0) ? normalize(cameraPos - P) : cameraForward);
+}
#define viewCameraVec(vP) ((ProjectionMatrix[3][3] == 0.0) ? normalize(-vP) : vec3(0.0, 0.0, 1.0))
#ifdef world_clip_planes_calc_clip_distance
@@ -92,14 +100,14 @@ vec4 pack_line_data(vec2 frag_co, vec2 edge_start, vec2 edge_pos)
}
/* Temporary until we fully make the switch. */
-#ifndef DRW_SHADER_SHARED_H
+#ifndef USE_GPU_SHADER_CREATE_INFO
uniform int drw_resourceChunk;
-#endif /* DRW_SHADER_SHARED_H */
+#endif /* USE_GPU_SHADER_CREATE_INFO */
#ifdef GPU_VERTEX_SHADER
/* Temporary until we fully make the switch. */
-# ifndef DRW_SHADER_SHARED_H
+# ifndef USE_GPU_SHADER_CREATE_INFO
/* clang-format off */
# if defined(IN_PLACE_INSTANCES) || defined(INSTANCED_ATTR) || defined(DRW_LEGACY_MODEL_MATRIX) || defined(GPU_DEPRECATED_AMD_DRIVER)
@@ -121,7 +129,10 @@ uniform int drw_ResourceID;
/* Use this to declare and pass the value if
* the fragment shader uses the resource_id. */
-# ifdef USE_GEOMETRY_SHADER
+# if defined(EEVEE_GENERATED_INTERFACE)
+# define RESOURCE_ID_VARYING
+# define PASS_RESOURCE_ID resourceIDFrag = resource_id;
+# elif defined(USE_GEOMETRY_SHADER)
# define RESOURCE_ID_VARYING flat out int resourceIDGeom;
# define PASS_RESOURCE_ID resourceIDGeom = resource_id;
# else
@@ -129,12 +140,12 @@ uniform int drw_ResourceID;
# define PASS_RESOURCE_ID resourceIDFrag = resource_id;
# endif
-# endif /* DRW_SHADER_SHARED_H */
+# endif /* USE_GPU_SHADER_CREATE_INFO */
#endif /* GPU_VERTEX_SHADER */
/* Temporary until we fully make the switch. */
-#ifdef DRW_SHADER_SHARED_H
+#ifdef USE_GPU_SHADER_CREATE_INFO
/* TODO(fclem): Rename PASS_RESOURCE_ID to DRW_RESOURCE_ID_VARYING_SET */
# if defined(UNIFORM_RESOURCE_ID)
# define resource_id drw_ResourceID
@@ -159,16 +170,23 @@ uniform int drw_ResourceID;
/* If used in a fragment / geometry shader, we pass
* resource_id as varying. */
# ifdef GPU_GEOMETRY_SHADER
-# define RESOURCE_ID_VARYING \
- flat out int resourceIDFrag; \
- flat in int resourceIDGeom[];
+/* TODO(fclem): Remove. This is getting ridiculous. */
+# if !defined(EEVEE_GENERATED_INTERFACE)
+# define RESOURCE_ID_VARYING \
+ flat out int resourceIDFrag; \
+ flat in int resourceIDGeom[];
+# else
+# define RESOURCE_ID_VARYING
+# endif
# define resource_id resourceIDGeom
# define PASS_RESOURCE_ID resourceIDFrag = resource_id[0];
# endif
-# ifdef GPU_FRAGMENT_SHADER
+# if defined(GPU_FRAGMENT_SHADER)
+# if !defined(EEVEE_GENERATED_INTERFACE)
flat in int resourceIDFrag;
+# endif
# define resource_id resourceIDFrag
# endif
#endif
@@ -185,7 +203,9 @@ struct ObjectMatrices {
mat4 drw_modelMatrix;
mat4 drw_modelMatrixInverse;
};
+# endif /* DRW_SHADER_SHARED_H */
+# ifndef USE_GPU_SHADER_CREATE_INFO
layout(std140) uniform modelBlock
{
ObjectMatrices drw_matrices[DRW_RESOURCE_CHUNK_LEN];
@@ -193,24 +213,24 @@ layout(std140) uniform modelBlock
# define ModelMatrix (drw_matrices[resource_id].drw_modelMatrix)
# define ModelMatrixInverse (drw_matrices[resource_id].drw_modelMatrixInverse)
-# endif /* DRW_SHADER_SHARED_H */
+# endif /* USE_GPU_SHADER_CREATE_INFO */
#else /* GPU_INTEL */
/* Temporary until we fully make the switch. */
-# ifndef DRW_SHADER_SHARED_H
+# ifndef USE_GPU_SHADER_CREATE_INFO
/* Intel GPU seems to suffer performance impact when the model matrix is in UBO storage.
* So for now we just force using the legacy path. */
/* Note that this is also a workaround of a problem on osx (amd or nvidia)
* and older amd driver on windows. */
uniform mat4 ModelMatrix;
uniform mat4 ModelMatrixInverse;
-# endif /* DRW_SHADER_SHARED_H */
+# endif /* USE_GPU_SHADER_CREATE_INFO */
#endif
/* Temporary until we fully make the switch. */
-#ifndef DRW_SHADER_SHARED_H
+#ifndef USE_GPU_SHADER_CREATE_INFO
# define resource_handle (drw_resourceChunk * DRW_RESOURCE_CHUNK_LEN + resource_id)
#endif
@@ -337,3 +357,5 @@ vec3 get_view_vector_from_screen_uv(vec2 uv)
return vec3(0.0, 0.0, 1.0);
}
}
+
+#endif /* COMMON_VIEW_LIB_GLSL */