diff options
Diffstat (limited to 'source/blender/draw/intern/shaders')
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 */ |