diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-05-09 23:10:38 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-05-10 13:14:41 +0300 |
commit | 0d8ab0eac6045c0e4e3d175d0f7fc70d80072a71 (patch) | |
tree | 17bc32617524d7390b7197bcd62a06b20427059c /source/blender/draw/engines/workbench | |
parent | a298dde5d799bd41dd571cda9c91b62a6b78562a (diff) |
DRW: Remove ModelViewMatrix Usage
Diffstat (limited to 'source/blender/draw/engines/workbench')
3 files changed, 16 insertions, 10 deletions
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl index a1c269d5a65..cef405d12d3 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl @@ -1,8 +1,7 @@ -uniform mat4 ProjectionMatrix; -uniform mat4 ModelMatrixInverse; -uniform mat4 ModelViewMatrixInverse; uniform mat4 ModelMatrix; +uniform mat4 ModelMatrixInverse; + uniform vec3 OrcoTexCoFactors[2]; uniform sampler2D depthBuffer; @@ -219,9 +218,11 @@ void main() vec3 vs_ray_dir = (is_persp) ? (vs_ray_end - vs_ray_ori) : vec3(0.0, 0.0, -1.0); vs_ray_dir /= abs(vs_ray_dir.z); - vec3 ls_ray_dir = mat3(ModelViewMatrixInverse) * vs_ray_dir * OrcoTexCoFactors[1] * 2.0; - vec3 ls_ray_ori = (ModelViewMatrixInverse * vec4(vs_ray_ori, 1.0)).xyz; - vec3 ls_ray_end = (ModelViewMatrixInverse * vec4(vs_ray_end, 1.0)).xyz; + /* TODO(fclem) Precompute the matrix/ */ + vec3 ls_ray_dir = vs_ray_dir * OrcoTexCoFactors[1] * 2.0; + ls_ray_dir = mat3(ModelMatrixInverse) * (mat3(ViewMatrixInverse) * ls_ray_dir); + vec3 ls_ray_ori = point_view_to_object(vs_ray_ori); + vec3 ls_ray_end = point_view_to_object(vs_ray_end); ls_ray_ori = (OrcoTexCoFactors[0] + ls_ray_ori * OrcoTexCoFactors[1]) * 2.0 - 1.0; ls_ray_end = (OrcoTexCoFactors[0] + ls_ray_end * OrcoTexCoFactors[1]) * 2.0 - 1.0; diff --git a/source/blender/draw/engines/workbench/shaders/workbench_volume_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_volume_vert.glsl index 7a418243fd3..1834173fee9 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_volume_vert.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_volume_vert.glsl @@ -1,5 +1,6 @@ -uniform mat4 ModelViewProjectionMatrix; +uniform mat4 ModelMatrix; + uniform vec3 OrcoTexCoFactors[2]; uniform float slicePosition; uniform int sliceAxis; /* -1 is no slice, 0 is X, 1 is Y, 2 is Z. */ @@ -29,5 +30,5 @@ void main() vec3 final_pos = pos; #endif final_pos = ((final_pos * 0.5 + 0.5) - OrcoTexCoFactors[0]) / OrcoTexCoFactors[1]; - gl_Position = ModelViewProjectionMatrix * vec4(final_pos, 1.0); + gl_Position = point_object_to_ndc(final_pos); } diff --git a/source/blender/draw/engines/workbench/workbench_volume.c b/source/blender/draw/engines/workbench/workbench_volume.c index accc7e91576..d2f19f57dcf 100644 --- a/source/blender/draw/engines/workbench/workbench_volume.c +++ b/source/blender/draw/engines/workbench/workbench_volume.c @@ -53,6 +53,7 @@ static struct { extern char datatoc_workbench_volume_vert_glsl[]; extern char datatoc_workbench_volume_frag_glsl[]; +extern char datatoc_common_view_lib_glsl[]; static GPUShader *volume_shader_get(bool slice, bool coba, bool cubic) { @@ -77,8 +78,11 @@ static GPUShader *volume_shader_get(bool slice, bool coba, bool cubic) char *defines = BLI_dynstr_get_cstring(ds); BLI_dynstr_free(ds); - e_data.volume_sh[id] = DRW_shader_create( - datatoc_workbench_volume_vert_glsl, NULL, datatoc_workbench_volume_frag_glsl, defines); + e_data.volume_sh[id] = DRW_shader_create_with_lib(datatoc_workbench_volume_vert_glsl, + NULL, + datatoc_workbench_volume_frag_glsl, + datatoc_common_view_lib_glsl, + defines); MEM_freeN(defines); } |