diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-05-31 02:45:41 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-09-17 16:16:43 +0300 |
commit | 3a08153d7a842b7ab1e40a9048730e1a3ddab5f7 (patch) | |
tree | 37e7c902ceb35c5626644ccbbc7e0376e169e56c /source/blender/gpu/shaders | |
parent | 41299bce936afb5e7da9c332d1140c5a77d49317 (diff) |
DRW: Refactor to support draw call batching
Reviewers: brecht
Differential Revision: D4997
Diffstat (limited to 'source/blender/gpu/shaders')
6 files changed, 34 insertions, 19 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_common_obinfos_lib.glsl b/source/blender/gpu/shaders/gpu_shader_common_obinfos_lib.glsl new file mode 100644 index 00000000000..aa1d437c307 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_common_obinfos_lib.glsl @@ -0,0 +1,19 @@ + +/* Need to be included after common_view_lib.glsl for resource_id. */ +#ifndef GPU_OBINFOS_UBO +#define GPU_OBINFOS_UBO +struct ObjectInfos { + vec4 drw_OrcoTexCoFactors[2]; + vec4 drw_ObjectColor; + vec4 drw_Infos; +}; + +layout(std140) uniform infoBlock +{ + /* DRW_RESOURCE_CHUNK_LEN = 512 */ + ObjectInfos drw_infos[512]; +}; +#define OrcoTexCoFactors (drw_infos[resource_id].drw_OrcoTexCoFactors) +#define ObjectInfo (drw_infos[resource_id].drw_Infos) +#define ObjectColor (drw_infos[resource_id].drw_ObjectColor) +#endif diff --git a/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl index 31b359dbe6d..f32c47bcec3 100644 --- a/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl @@ -1,8 +1,5 @@ uniform mat4 ViewProjectionMatrix; -#ifdef USE_WORLD_CLIP_PLANES -uniform mat4 ModelMatrix; -#endif /* ---- Instantiated Attrs ---- */ in float pos; @@ -47,11 +44,12 @@ void main() pPos = vec3(0.0); } - gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pPos, 1.0); + vec4 wPos = InstanceModelMatrix * vec4(pPos, 1.0); + gl_Position = ViewProjectionMatrix * wPos; finalColor = vec4(color, 1.0); #ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance((ModelMatrix * InstanceModelMatrix * vec4(pPos, 1.0)).xyz); + world_clip_planes_calc_clip_distance(wPos.xyz); #endif } diff --git a/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl index d9a0ffbbdac..5bd29c55e42 100644 --- a/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl @@ -18,13 +18,14 @@ void main() { float len = end - start; vec3 sta = vec3(0.0, 0.0, -start); - vec4 pos_4d = vec4(pos * -len + sta, 1.0); - gl_Position = ViewProjectionMatrix * InstanceModelMatrix * pos_4d; + vec4 wPos = InstanceModelMatrix * vec4(pos * -len + sta, 1.0); + + gl_Position = ViewProjectionMatrix * wPos; gl_PointSize = size; finalColor = vec4(color, 1.0); #ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance((InstanceModelMatrix * pos_4d).xyz); + world_clip_planes_calc_clip_distance(wPos.xyz); #endif } diff --git a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl index 3e52e43beae..10228a1e985 100644 --- a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl @@ -1,6 +1,5 @@ uniform mat4 ViewProjectionMatrix; -uniform mat4 ModelMatrix; /* ---- Instantiated Attrs ---- */ in vec3 pos; @@ -20,10 +19,10 @@ void main() { finalColor = color; - vec4 pos_4d = vec4(pos * size, 1.0); - gl_Position = ViewProjectionMatrix * InstanceModelMatrix * pos_4d; + vec4 wPos = InstanceModelMatrix * vec4(pos * size, 1.0); + gl_Position = ViewProjectionMatrix * wPos; #ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance((ModelMatrix * InstanceModelMatrix * pos_4d).xyz); + world_clip_planes_calc_clip_distance(wPos.xyz); #endif } diff --git a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl index 130f46e1e33..32db8d17572 100644 --- a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl @@ -1,8 +1,6 @@ uniform mat4 ViewProjectionMatrix; -#ifdef USE_WORLD_CLIP_PLANES -uniform mat4 ModelMatrix; -#endif + uniform int baseId; /* ---- Instantiated Attrs ---- */ @@ -21,11 +19,11 @@ flat out uint finalId; void main() { - vec4 pos_4d = vec4(pos * size, 1.0); - gl_Position = ViewProjectionMatrix * InstanceModelMatrix * pos_4d; + vec4 wPos = InstanceModelMatrix * vec4(pos * size, 1.0); + gl_Position = ViewProjectionMatrix * wPos; finalId = uint(baseId + callId); #ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance((ModelMatrix * InstanceModelMatrix * pos_4d).xyz); + world_clip_planes_calc_clip_distance(wPos.xyz); #endif } diff --git a/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl index eeca6e972fa..b8d31f5540a 100644 --- a/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl @@ -9,5 +9,5 @@ in mat4 InstanceModelMatrix; void main() { - gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pos, 1.0); + gl_Position = ViewProjectionMatrix * (InstanceModelMatrix * vec4(pos, 1.0)); } |