diff options
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/GPU_buffers.h | 2 | ||||
-rw-r--r-- | source/blender/gpu/GPU_material.h | 4 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_buffers.c | 10 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_extensions.c | 8 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 4 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl | 52 | ||||
-rw-r--r-- | source/blender/gpu/shaders/material/gpu_shader_material_tex_sky.glsl | 148 |
7 files changed, 191 insertions, 37 deletions
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h index 41a29a4d45d..c7e74040568 100644 --- a/source/blender/gpu/GPU_buffers.h +++ b/source/blender/gpu/GPU_buffers.h @@ -67,7 +67,7 @@ GPU_PBVH_Buffers *GPU_pbvh_bmesh_buffers_build(bool smooth_shading); void GPU_pbvh_bmesh_buffers_update_free(GPU_PBVH_Buffers *buffers); void GPU_pbvh_grid_buffers_update_free(GPU_PBVH_Buffers *buffers, const struct DMFlagMat *grid_flag_mats, - int *grid_indices); + const int *grid_indices); /* Update mesh buffers without topology changes. Threaded. */ enum { diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index eeb2d2caef2..c372bfaf218 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -169,8 +169,8 @@ void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link); void GPU_material_sss_profile_create(GPUMaterial *material, float radii[3], - short *falloff_type, - float *sharpness); + const short *falloff_type, + const float *sharpness); struct GPUUniformBuffer *GPU_material_sss_profile_get(GPUMaterial *material, int sample_len, struct GPUTexture **tex_profile); diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c index 9c21f9040da..10d5a860f6a 100644 --- a/source/blender/gpu/intern/gpu_buffers.c +++ b/source/blender/gpu/intern/gpu_buffers.c @@ -38,6 +38,7 @@ #include "BLI_utildefines.h" #include "DNA_meshdata_types.h" +#include "DNA_userdef_types.h" #include "BKE_DerivedMesh.h" #include "BKE_ccg.h" @@ -234,7 +235,8 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers, const bool show_mask = vmask && (update_flags & GPU_PBVH_BUFFERS_SHOW_MASK) != 0; const bool show_face_sets = sculpt_face_sets && (update_flags & GPU_PBVH_BUFFERS_SHOW_SCULPT_FACE_SETS) != 0; - const bool show_vcol = (vcol || vtcol) && (update_flags & GPU_PBVH_BUFFERS_SHOW_VCOL) != 0; + const bool show_vcol = (vcol || (vtcol && U.experimental.use_sculpt_vertex_colors)) && + (update_flags & GPU_PBVH_BUFFERS_SHOW_VCOL) != 0; bool empty_mask = true; bool default_face_set = true; @@ -317,7 +319,7 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers, /* Vertex Colors. */ if (show_vcol) { ushort scol[4] = {USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX}; - if (vtcol) { + if (vtcol && U.experimental.use_sculpt_vertex_colors) { scol[0] = unit_float_to_ushort_clamp(vtcol[vtri[j]].color[0]); scol[1] = unit_float_to_ushort_clamp(vtcol[vtri[j]].color[1]); scol[2] = unit_float_to_ushort_clamp(vtcol[vtri[j]].color[2]); @@ -450,7 +452,7 @@ GPU_PBVH_Buffers *GPU_pbvh_mesh_buffers_build(const MPoly *mpoly, static void gpu_pbvh_grid_fill_index_buffers(GPU_PBVH_Buffers *buffers, SubdivCCG *UNUSED(subdiv_ccg), const int *UNUSED(face_sets), - int *grid_indices, + const int *grid_indices, uint visible_quad_len, int totgrid, int gridsize) @@ -581,7 +583,7 @@ static void gpu_pbvh_grid_fill_index_buffers(GPU_PBVH_Buffers *buffers, void GPU_pbvh_grid_buffers_update_free(GPU_PBVH_Buffers *buffers, const struct DMFlagMat *grid_flag_mats, - int *grid_indices) + const int *grid_indices) { const bool smooth = grid_flag_mats[grid_indices[0]].flag & ME_SMOOTH; diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index fbeb2edc266..d1c7aba37df 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -339,7 +339,6 @@ void gpu_extensions_init(void) GG.depth_blitting_workaround = true; GG.unused_fb_slot_workaround = true; GG.texture_copy_workaround = true; - GG.context_local_shaders_workaround = GLEW_ARB_get_program_binary; } /* Special fix for theses specific GPUs. @@ -347,7 +346,12 @@ void gpu_extensions_init(void) if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_WIN, GPU_DRIVER_OFFICIAL) && (strstr(renderer, "HD Graphics 620") || strstr(renderer, "HD Graphics 630"))) { GG.mip_render_workaround = true; - GG.context_local_shaders_workaround = GLEW_ARB_get_program_binary; + } + + /* Intel Ivy Bridge GPU's seems to have buggy cube-map array support. (see T75943) */ + if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_WIN, GPU_DRIVER_OFFICIAL) && + (strstr(renderer, "HD Graphics 4000") || strstr(renderer, "HD Graphics 2500"))) { + GG.glew_arb_texture_cube_map_array_is_supported = false; } /* df/dy calculation factors, those are dependent on driver */ diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index d2384b9c065..c65c1046b8f 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -497,8 +497,8 @@ static void compute_sss_translucence_kernel(const GPUSssKernelData *kd, void GPU_material_sss_profile_create(GPUMaterial *material, float radii[3], - short *falloff_type, - float *sharpness) + const short *falloff_type, + const float *sharpness) { copy_v3_v3(material->sss_radii, radii); material->sss_falloff = (falloff_type) ? *falloff_type : 0.0; diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl index 7309549062c..d15f48c8f8a 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl @@ -9,25 +9,33 @@ uniform vec4 parameters[MAX_PARAM * MAX_INSTANCE]; uniform vec4 parameters[MAX_PARAM]; #endif -/* gl_InstanceID is 0 if not drawing instances. */ -#define recti parameters[gl_InstanceID * MAX_PARAM + 0] -#define rect parameters[gl_InstanceID * MAX_PARAM + 1] -#define radsi parameters[gl_InstanceID * MAX_PARAM + 2].x -#define rads parameters[gl_InstanceID * MAX_PARAM + 2].y -#define faci parameters[gl_InstanceID * MAX_PARAM + 2].zw -#define roundCorners parameters[gl_InstanceID * MAX_PARAM + 3] -#define colorInner1 parameters[gl_InstanceID * MAX_PARAM + 4] -#define colorInner2 parameters[gl_InstanceID * MAX_PARAM + 5] -#define colorEdge parameters[gl_InstanceID * MAX_PARAM + 6] -#define colorEmboss parameters[gl_InstanceID * MAX_PARAM + 7] -#define colorTria parameters[gl_InstanceID * MAX_PARAM + 8] -#define tria1Center parameters[gl_InstanceID * MAX_PARAM + 9].xy -#define tria2Center parameters[gl_InstanceID * MAX_PARAM + 9].zw -#define tria1Size parameters[gl_InstanceID * MAX_PARAM + 10].x -#define tria2Size parameters[gl_InstanceID * MAX_PARAM + 10].y -#define shadeDir parameters[gl_InstanceID * MAX_PARAM + 10].z -#define alphaDiscard parameters[gl_InstanceID * MAX_PARAM + 10].w -#define triaType parameters[gl_InstanceID * MAX_PARAM + 11].x +/* gl_InstanceID is supposed to be 0 if not drawing instances, but this seems + * to be violated in some drivers. For example, macOS 10.15.4 and Intel Iris + * causes T78307 when using gl_InstanceID outside of instance. */ +#ifdef USE_INSTANCE +# define widgetID gl_InstanceID +#else +# define widgetID 0 +#endif + +#define recti parameters[widgetID * MAX_PARAM + 0] +#define rect parameters[widgetID * MAX_PARAM + 1] +#define radsi parameters[widgetID * MAX_PARAM + 2].x +#define rads parameters[widgetID * MAX_PARAM + 2].y +#define faci parameters[widgetID * MAX_PARAM + 2].zw +#define roundCorners parameters[widgetID * MAX_PARAM + 3] +#define colorInner1 parameters[widgetID * MAX_PARAM + 4] +#define colorInner2 parameters[widgetID * MAX_PARAM + 5] +#define colorEdge parameters[widgetID * MAX_PARAM + 6] +#define colorEmboss parameters[widgetID * MAX_PARAM + 7] +#define colorTria parameters[widgetID * MAX_PARAM + 8] +#define tria1Center parameters[widgetID * MAX_PARAM + 9].xy +#define tria2Center parameters[widgetID * MAX_PARAM + 9].zw +#define tria1Size parameters[widgetID * MAX_PARAM + 10].x +#define tria2Size parameters[widgetID * MAX_PARAM + 10].y +#define shadeDir parameters[widgetID * MAX_PARAM + 10].z +#define alphaDiscard parameters[widgetID * MAX_PARAM + 10].w +#define triaType parameters[widgetID * MAX_PARAM + 11].x /* We encode alpha check and discard factor together. */ #define doAlphaCheck (alphaDiscard < 0.0) @@ -179,10 +187,4 @@ void main() vec2 pos = (is_tria) ? do_tria() : do_widget(); gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0); - -#ifdef OS_MAC - /* Generate a dummy read to avoid the driver bug with shaders having no - * vertex reads on macOS (T78307) */ - gl_Position.x += dummy * 0.0; -#endif } diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_tex_sky.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_tex_sky.glsl index 981d17b4283..b6aad5904ff 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_tex_sky.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_tex_sky.glsl @@ -1,4 +1,150 @@ -void node_tex_sky(vec3 co, out vec4 color) +float sky_angle_between(float thetav, float phiv, float theta, float phi) +{ + float cospsi = sin(thetav) * sin(theta) * cos(phi - phiv) + cos(thetav) * cos(theta); + + if (cospsi > 1.0) { + return 0.0; + } + if (cospsi < -1.0) { + return M_PI; + } + + return acos(cospsi); +} + +vec3 sky_spherical_coordinates(vec3 dir) +{ + return vec3(M_PI_2 - atan(dir.z, length(dir.xy)), atan(dir.x, dir.y), 0); +} + +/* Preetham */ +/* lam03+lam4: 5 floats passed as vec4+float */ +float sky_perez_function(vec4 lam03, float lam4, float theta, float gamma) +{ + float ctheta = cos(theta); + float cgamma = cos(gamma); + + return (1.0 + lam03[0] * exp(lam03[1] / ctheta)) * + (1.0 + lam03[2] * exp(lam03[3] * gamma) + lam4 * cgamma * cgamma); +} + +vec3 xyY_to_xyz(float x, float y, float Y) +{ + float X, Z; + + if (y != 0.0) { + X = (x / y) * Y; + } + else { + X = 0.0; + } + + if (y != 0.0 && Y != 0.0) { + Z = ((1.0 - x - y) / y) * Y; + } + else { + Z = 0.0; + } + + return vec3(X, Y, Z); +} + +void node_tex_sky_preetham(vec3 co, + vec4 config_Y03, + float config_Y4, + vec4 config_x03, + float config_x4, + vec4 config_y03, + float config_y4, + vec2 sun_angles, + vec3 radiance, + vec3 xyz_to_r, + vec3 xyz_to_g, + vec3 xyz_to_b, + out vec4 color) +{ + /* convert vector to spherical coordinates */ + vec3 spherical = sky_spherical_coordinates(co); + float theta = spherical[0]; + float phi = spherical[1]; + + float suntheta = sun_angles[0]; + float sunphi = sun_angles[1]; + + /* angle between sun direction and dir */ + float gamma = sky_angle_between(theta, phi, suntheta, sunphi); + + /* clamp theta to horizon */ + theta = min(theta, M_PI_2 - 0.001); + + /* compute xyY color space values */ + float Y = radiance[0] * sky_perez_function(config_Y03, config_Y4, theta, gamma); + float x = radiance[1] * sky_perez_function(config_x03, config_x4, theta, gamma); + float y = radiance[2] * sky_perez_function(config_y03, config_y4, theta, gamma); + + /* convert to RGB */ + vec3 xyz = xyY_to_xyz(x, y, Y); + color = vec4(dot(xyz_to_r, xyz), dot(xyz_to_g, xyz), dot(xyz_to_b, xyz), 1); +} + +/* Hosek / Wilkie */ +float sky_radiance_hosekwilkie( + vec4 config03, vec4 config47, float config8, float theta, float gamma) +{ + float ctheta = cos(theta); + float cgamma = cos(gamma); + + float expM = exp(config47[0] * gamma); + float rayM = cgamma * cgamma; + float mieM = (1.0 + rayM) / pow((1.0 + config8 * config8 - 2.0 * config8 * cgamma), 1.5); + float zenith = sqrt(ctheta); + + return (1.0 + config03[0] * exp(config03[1] / (ctheta + 0.01))) * + (config03[2] + config03[3] * expM + config47[1] * rayM + config47[2] * mieM + + config47[3] * zenith); +} + +void node_tex_sky_hosekwilkie(vec3 co, + vec4 config_x03, + vec4 config_x47, + vec4 config_y03, + vec4 config_y47, + vec4 config_z03, + vec4 config_z47, + vec3 config_xyz8, + vec2 sun_angles, + vec3 radiance, + vec3 xyz_to_r, + vec3 xyz_to_g, + vec3 xyz_to_b, + out vec4 color) +{ + /* convert vector to spherical coordinates */ + vec3 spherical = sky_spherical_coordinates(co); + float theta = spherical[0]; + float phi = spherical[1]; + + float suntheta = sun_angles[0]; + float sunphi = sun_angles[1]; + + /* angle between sun direction and dir */ + float gamma = sky_angle_between(theta, phi, suntheta, sunphi); + + /* clamp theta to horizon */ + theta = min(theta, M_PI_2 - 0.001); + + vec3 xyz; + xyz.x = sky_radiance_hosekwilkie(config_x03, config_x47, config_xyz8[0], theta, gamma) * + radiance.x; + xyz.y = sky_radiance_hosekwilkie(config_y03, config_y47, config_xyz8[1], theta, gamma) * + radiance.y; + xyz.z = sky_radiance_hosekwilkie(config_z03, config_z47, config_xyz8[2], theta, gamma) * + radiance.z; + + color = vec4(dot(xyz_to_r, xyz), dot(xyz_to_g, xyz), dot(xyz_to_b, xyz), 1); +} + +void node_tex_sky_nishita(vec3 co, out vec4 color) { color = vec4(1.0); } |