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-13 18:32:18 +0300 |
commit | ce34a6b0d727bbde6ae373afa8ec6c42bc8980ce (patch) | |
tree | f8cc84f7e2038f2a81ac0141d79205f1df649e4e /source/blender/draw/engines/workbench/shaders | |
parent | f7e8b580989ec70d1cf8f15a11d4f09e6b36f407 (diff) |
DRW: Refactor to support draw call batching
Reviewers: brecht
Differential Revision: D4997
Diffstat (limited to 'source/blender/draw/engines/workbench/shaders')
6 files changed, 46 insertions, 29 deletions
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_forward_depth_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_forward_depth_frag.glsl index 505b4822ad6..abd8c1f6579 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_forward_depth_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_forward_depth_frag.glsl @@ -1,5 +1,6 @@ -uniform int object_id = 0; + layout(location = 0) out uint objectId; + uniform float ImageTransparencyCutoff = 0.1; #ifdef V3D_SHADING_TEXTURE_COLOR uniform sampler2D image; @@ -10,11 +11,10 @@ in vec2 uv_interp; void main() { #ifdef V3D_SHADING_TEXTURE_COLOR - vec4 diffuse_color = texture(image, uv_interp); - if (diffuse_color.a < ImageTransparencyCutoff) { + if (texture(image, uv_interp).a < ImageTransparencyCutoff) { discard; } #endif - objectId = uint(object_id); + objectId = uint(resource_id + 1) & 0xFFu; } diff --git a/source/blender/draw/engines/workbench/shaders/workbench_forward_transparent_accum_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_forward_transparent_accum_frag.glsl index 3333dfeff38..f799ce41cb2 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_forward_transparent_accum_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_forward_transparent_accum_frag.glsl @@ -8,8 +8,7 @@ uniform float alpha = 0.5; uniform vec2 invertedViewportSize; uniform vec4 viewvecs[3]; -uniform vec3 materialDiffuseColor; -uniform vec3 materialSpecularColor; +uniform vec4 materialColorAndMetal; uniform float materialRoughness; uniform float shadowMultiplier = 0.5; @@ -42,17 +41,17 @@ layout(location = 1) out void main() { - vec4 diffuse_color; + vec4 base_color; #if defined(V3D_SHADING_TEXTURE_COLOR) - diffuse_color = workbench_sample_texture(image, uv_interp, imageNearest, imagePremultiplied); - if (diffuse_color.a < ImageTransparencyCutoff) { + base_color = workbench_sample_texture(image, uv_interp, imageNearest, imagePremultiplied); + if (base_color.a < ImageTransparencyCutoff) { discard; } #elif defined(V3D_SHADING_VERTEX_COLOR) - diffuse_color = vec4(vertexColor, 1.0); + base_color.rgb = vertexColor; #else - diffuse_color = vec4(materialDiffuseColor, 1.0); + base_color.rgb = materialColorAndMetal.rgb; #endif /* V3D_SHADING_TEXTURE_COLOR */ vec2 uv_viewport = gl_FragCoord.xy * invertedViewportSize; @@ -64,7 +63,7 @@ void main() /* -------- SHADING --------- */ #ifdef V3D_LIGHTING_FLAT - vec3 shaded_color = diffuse_color.rgb; + vec3 shaded_color = base_color.rgb; #elif defined(V3D_LIGHTING_MATCAP) bool flipped = world_data.matcap_orientation != 0; @@ -75,11 +74,20 @@ void main() # else vec3 matcap_specular = vec3(0.0); # endif - vec3 shaded_color = matcap_diffuse * diffuse_color.rgb + matcap_specular; + vec3 shaded_color = matcap_diffuse * base_color.rgb + matcap_specular; #elif defined(V3D_LIGHTING_STUDIO) +# ifdef V3D_SHADING_SPECULAR_HIGHLIGHT + float metallic = materialColorAndMetal.a; + vec3 specular_color = mix(vec3(0.05), base_color.rgb, metallic); + vec3 diffuse_color = mix(base_color.rgb, vec3(0.0), metallic); +# else + vec3 specular_color = vec3(0.0); + vec3 diffuse_color = base_color.rgb; +# endif + vec3 shaded_color = get_world_lighting( - world_data, diffuse_color.rgb, materialSpecularColor, materialRoughness, nor, I_vs); + world_data, diffuse_color, specular_color, materialRoughness, nor, I_vs); #endif #ifdef V3D_SHADING_SHADOW diff --git a/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl index c673b2484de..b5f95f2dcf8 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl @@ -1,7 +1,5 @@ -uniform int object_id = 0; -uniform vec3 materialDiffuseColor; -uniform float materialMetallic; +uniform vec4 materialColorAndMetal; uniform float materialRoughness; uniform sampler2D image; @@ -48,7 +46,7 @@ void main() # elif defined(V3D_SHADING_VERTEX_COLOR) color.rgb = vertexColor; # else - color.rgb = materialDiffuseColor; + color.rgb = materialColorAndMetal.rgb; # endif # ifdef V3D_LIGHTING_MATCAP @@ -56,7 +54,7 @@ void main() metallic = float(gl_FrontFacing); roughness = 0.0; # else - metallic = materialMetallic; + metallic = materialColorAndMetal.a; roughness = materialRoughness; # endif @@ -64,7 +62,7 @@ void main() /* Add some variation to the hairs to avoid uniform look. */ float hair_variation = hair_rand * 0.1; color = clamp(color - hair_variation, 0.0, 1.0); - metallic = clamp(materialMetallic - hair_variation, 0.0, 1.0); + metallic = clamp(materialColorAndMetal.a - hair_variation, 0.0, 1.0); roughness = clamp(materialRoughness - hair_variation, 0.0, 1.0); # endif @@ -73,7 +71,7 @@ void main() #endif /* MATDATA_PASS_ENABLED */ #ifdef OBJECT_ID_PASS_ENABLED - objectId = uint(object_id); + objectId = uint(resource_id + 1) & 0xFFu; #endif #ifdef NORMAL_VIEWPORT_PASS_ENABLED diff --git a/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl index 7eb12dbdeb9..04dd9ab85bb 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl @@ -25,6 +25,10 @@ out vec2 uv_interp; out vec3 vertexColor; #endif +#ifdef OBJECT_ID_PASS_ENABLED +RESOURCE_ID_VARYING +#endif + /* From http://libnoise.sourceforge.net/noisegen/index.html */ float integer_noise(int n) { @@ -91,12 +95,18 @@ void main() #endif #ifdef NORMAL_VIEWPORT_PASS_ENABLED - normal_viewport = normal_object_to_view(nor); # ifndef HAIR_SHADER + normal_viewport = normal_object_to_view(nor); normal_viewport = normalize(normal_viewport); +# else + normal_viewport = normal_world_to_view(nor); # endif #endif +#ifdef OBJECT_ID_PASS_ENABLED + PASS_RESOURCE_ID +#endif + #ifdef USE_WORLD_CLIP_PLANES world_clip_planes_calc_clip_distance(world_pos); #endif 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 4a9b0ae3b7d..c24c335189e 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl @@ -1,6 +1,4 @@ -uniform vec3 OrcoTexCoFactors[2]; - uniform sampler2D depthBuffer; uniform sampler3D densityTexture; @@ -216,13 +214,13 @@ void main() vs_ray_dir /= abs(vs_ray_dir.z); /* TODO(fclem) Precompute the matrix/ */ - vec3 ls_ray_dir = mat3(ViewMatrixInverse) * vs_ray_dir * OrcoTexCoFactors[1] * 2.0; + vec3 ls_ray_dir = mat3(ViewMatrixInverse) * vs_ray_dir * OrcoTexCoFactors[1].xyz * 2.0; ls_ray_dir = mat3(ModelMatrixInverse) * 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; + ls_ray_ori = (OrcoTexCoFactors[0].xyz + ls_ray_ori * OrcoTexCoFactors[1].xyz) * 2.0 - 1.0; + ls_ray_end = (OrcoTexCoFactors[0].xyz + ls_ray_end * OrcoTexCoFactors[1].xyz) * 2.0 - 1.0; /* TODO: Align rays to volume center so that it mimics old behaviour of slicing the volume. */ 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 6f0bb56fafd..3542a1a91fc 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_volume_vert.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_volume_vert.glsl @@ -1,10 +1,11 @@ -uniform vec3 OrcoTexCoFactors[2]; uniform float slicePosition; uniform int sliceAxis; /* -1 is no slice, 0 is X, 1 is Y, 2 is Z. */ in vec3 pos; +RESOURCE_ID_VARYING + #ifdef VOLUME_SLICE in vec3 uvs; @@ -27,6 +28,8 @@ void main() #else vec3 final_pos = pos; #endif - final_pos = ((final_pos * 0.5 + 0.5) - OrcoTexCoFactors[0]) / OrcoTexCoFactors[1]; + final_pos = ((final_pos * 0.5 + 0.5) - OrcoTexCoFactors[0].xyz) / OrcoTexCoFactors[1].xyz; gl_Position = point_object_to_ndc(final_pos); + + PASS_RESOURCE_ID } |