diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-09-14 00:02:45 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-09-14 00:03:10 +0300 |
commit | fd5c1972cd5c8a826c0d40effb0e2d367389666a (patch) | |
tree | 6a093944267ff888e9fb4323bac22d52468ab7ec /source/blender/draw/modes/shaders | |
parent | c80564ef9f557fadd235b87533b24d126e2138c9 (diff) |
Revert "DRW: Refactor to support draw call batching"
This reverts commit ce34a6b0d727bbde6ae373afa8ec6c42bc8980ce.
Diffstat (limited to 'source/blender/draw/modes/shaders')
6 files changed, 39 insertions, 118 deletions
diff --git a/source/blender/draw/modes/shaders/common_view_lib.glsl b/source/blender/draw/modes/shaders/common_view_lib.glsl index a554db7d4a4..20a54947db7 100644 --- a/source/blender/draw/modes/shaders/common_view_lib.glsl +++ b/source/blender/draw/modes/shaders/common_view_lib.glsl @@ -1,5 +1,4 @@ #define COMMON_VIEW_LIB -#define DRW_RESOURCE_CHUNK_LEN 512 /* keep in sync with DRWManager.view_data */ layout(std140) uniform viewBlock @@ -24,74 +23,8 @@ layout(std140) uniform viewBlock _world_clip_planes_calc_clip_distance(p, clipPlanes) #endif -uniform int resourceChunk; - -#ifdef GPU_VERTEX_SHADER -# ifdef GL_ARB_shader_draw_parameters -# define baseInstance gl_BaseInstanceARB -# else /* no ARB_shader_draw_parameters */ -uniform int baseInstance; -# endif - -# ifdef IN_PLACE_INSTANCES -/* When drawing instances of an object at the same position. */ -# define instanceId 0 -# elif defined(GPU_CRAPPY_AMD_DRIVER) -/* NOTE: This does contain the baseInstance ofset */ -in int _instanceId; -# define instanceId (_instanceId - baseInstance) -# else -# define instanceId gl_InstanceID -# endif - -# define resource_id (baseInstance + instanceId) - -/* Use this to declare and pass the value if - * the fragment shader uses the resource_id. */ -# define RESOURCE_ID_VARYING flat out int resourceIDFrag; -# define RESOURCE_ID_VARYING_GEOM flat out int resourceIDGeom; -# define PASS_RESOURCE_ID resourceIDFrag = resource_id; -# define PASS_RESOURCE_ID_GEOM resourceIDGeom = resource_id; -#endif - -/* 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[]; - -# define resource_id resourceIDGeom -# define PASS_RESOURCE_ID(i) resourceIDFrag = resource_id[i]; -#endif - -#ifdef GPU_FRAGMENT_SHADER -flat in int resourceIDFrag; -# define resource_id resourceIDFrag -#endif - -#ifndef GPU_INTEL -struct ObjectMatrices { - mat4 drw_modelMatrix; - mat4 drw_modelMatrixInverse; -}; - -layout(std140) uniform modelBlock -{ - ObjectMatrices drw_matrices[DRW_RESOURCE_CHUNK_LEN]; -}; - -# define ModelMatrix (drw_matrices[resource_id].drw_modelMatrix) -# define ModelMatrixInverse (drw_matrices[resource_id].drw_modelMatrixInverse) - -#else /* GPU_INTEL */ -/* 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. */ uniform mat4 ModelMatrix; uniform mat4 ModelMatrixInverse; -#endif - -#define resource_handle (resourceChunk * DRW_RESOURCE_CHUNK_LEN + resource_id) /** Transform shortcuts. */ /* Rule of thumb: Try to reuse world positions and normals because converting though viewspace diff --git a/source/blender/draw/modes/shaders/object_lightprobe_grid_vert.glsl b/source/blender/draw/modes/shaders/object_lightprobe_grid_vert.glsl index 144024a7d5d..d27d55c3fd6 100644 --- a/source/blender/draw/modes/shaders/object_lightprobe_grid_vert.glsl +++ b/source/blender/draw/modes/shaders/object_lightprobe_grid_vert.glsl @@ -1,11 +1,18 @@ +uniform mat4 ViewProjectionMatrix; + +uniform float sphere_size; uniform ivec3 grid_resolution; uniform vec3 corner; uniform vec3 increment_x; uniform vec3 increment_y; uniform vec3 increment_z; +uniform vec3 screen_vecs[2]; + +uniform int call_id; /* we don't want the builtin callId which would be 0. */ +uniform int baseId; -flat out int objectId; +flat out uint finalId; void main() { @@ -22,8 +29,7 @@ void main() gl_Position = ViewProjectionMatrix * vec4(ws_cell_location, 1.0); gl_PointSize = 2.0f; - /* ID 0 is nothing (background) */ - objectId = resource_handle + 1; + finalId = uint(baseId + call_id); #ifdef USE_WORLD_CLIP_PLANES world_clip_planes_calc_clip_distance(ws_cell_location); diff --git a/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl b/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl index 7b86d477a39..7668a0c2c94 100644 --- a/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl +++ b/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl @@ -7,9 +7,30 @@ uniform usampler2D outlineId; uniform sampler2D outlineDepth; uniform sampler2D sceneDepth; +uniform int idOffsets[4]; + uniform float alphaOcclu; uniform vec2 viewportSize; +vec4 convert_id_to_color(int id) +{ + if (id == 0) { + return vec4(0.0); + } + if (id < idOffsets[1]) { + return colorActive; + } + else if (id < idOffsets[2]) { + return colorSelect; + } + else if (id < idOffsets[3]) { + return colorDupliSelect; + } + else { + return colorTransform; + } +} + void main() { ivec2 texel = ivec2(gl_FragCoord.xy); @@ -64,24 +85,7 @@ void main() const float epsilon = 3.0 / 8388608.0; bool occluded = (ref_depth > scene_depth + epsilon); - /* WATCH: Keep in sync with outlineId of the prepass. */ - uint color_id = ref_id >> 14u; - if (ref_id == 0u) { - FragColor = vec4(0.0); - } - else if (color_id == 1u) { - FragColor = colorSelect; - } - else if (color_id == 2u) { - FragColor = colorDupliSelect; - } - else if (color_id == 3u) { - FragColor = colorActive; - } - else { - FragColor = colorTransform; - } - + FragColor = convert_id_to_color(int(ref_id)); FragColor.a *= (occluded) ? alphaOcclu : 1.0; FragColor.a = (outline) ? FragColor.a : 0.0; } diff --git a/source/blender/draw/modes/shaders/object_outline_prepass_frag.glsl b/source/blender/draw/modes/shaders/object_outline_prepass_frag.glsl index 5d6c4881b5b..c3447456ea6 100644 --- a/source/blender/draw/modes/shaders/object_outline_prepass_frag.glsl +++ b/source/blender/draw/modes/shaders/object_outline_prepass_frag.glsl @@ -1,18 +1,10 @@ - -/* Should be 2 bits only [0..3]. */ -uniform int outlineId; - -flat in int objectId; +uniform int callId; +uniform int baseId; /* using uint because 16bit uint can contain more ids than int. */ out uint outId; -/* Replace top 2 bits (of the 16bit output) by outlineId. - * This leaves 16K different IDs to create outlines between objects. - * SHIFT = (32 - (16 - 2)) */ -#define SHIFT 18u - void main() { - outId = (uint(outlineId) << 14u) | ((uint(objectId) << SHIFT) >> SHIFT); + outId = uint(baseId + callId); } diff --git a/source/blender/draw/modes/shaders/object_outline_prepass_geom.glsl b/source/blender/draw/modes/shaders/object_outline_prepass_geom.glsl index b32913dcd60..5a3eb38fb6b 100644 --- a/source/blender/draw/modes/shaders/object_outline_prepass_geom.glsl +++ b/source/blender/draw/modes/shaders/object_outline_prepass_geom.glsl @@ -2,15 +2,12 @@ layout(lines_adjacency) in; layout(line_strip, max_vertices = 2) out; +in vec4 pPos[]; in vec3 vPos[]; -in int objectId_g[]; - -flat out int objectId; void vert_from_gl_in(int v) { - gl_Position = gl_in[v].gl_Position; - objectId = objectId_g[v]; + gl_Position = pPos[v]; #ifdef USE_WORLD_CLIP_PLANES world_clip_planes_set_clip_distance(gl_in[v].gl_ClipDistance); #endif diff --git a/source/blender/draw/modes/shaders/object_outline_prepass_vert.glsl b/source/blender/draw/modes/shaders/object_outline_prepass_vert.glsl index 7740f9a4af2..e34afe95b5e 100644 --- a/source/blender/draw/modes/shaders/object_outline_prepass_vert.glsl +++ b/source/blender/draw/modes/shaders/object_outline_prepass_vert.glsl @@ -1,27 +1,16 @@ in vec3 pos; -#ifdef USE_GEOM +out vec4 pPos; out vec3 vPos; -out int objectId_g; -# define objectId objectId_g -#else - -flat out int objectId; -#endif void main() { vec3 world_pos = point_object_to_world(pos); -#ifdef USE_GEOM vPos = point_world_to_view(world_pos); -#endif - gl_Position = point_world_to_ndc(world_pos); + pPos = point_world_to_ndc(world_pos); /* Small bias to always be on top of the geom. */ - gl_Position.z -= 1e-3; - - /* ID 0 is nothing (background) */ - objectId = resource_handle + 1; + pPos.z -= 1e-3; #ifdef USE_WORLD_CLIP_PLANES world_clip_planes_calc_clip_distance(world_pos); |