diff options
Diffstat (limited to 'source')
3 files changed, 77 insertions, 44 deletions
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 bb4c4fe4177..2955bcb9cca 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl @@ -1,8 +1,6 @@ uniform mat4 ModelMatrix; uniform mat4 ModelMatrixInverse; -uniform mat4 ModelViewProjectionMatrix; - #ifndef HAIR_SHADER in vec3 pos; in vec3 nor; @@ -47,6 +45,18 @@ vec3 srgb_to_linear_attr(vec3 c) } #endif +vec3 workbench_hair_hair_normal(vec3 tan, vec3 binor, float rand) +{ + /* To "simulate" anisotropic shading, randomize hair normal per strand. */ + tan = normalize(tan); + vec3 nor = normalize(cross(binor, tan)); + // nor = normalize(mix(nor, -tan, rand * 0.1)); + // float cos_theta = (rand * 2.0 - 1.0) * 0.2; + // float sin_theta = sqrt(max(0.0, 1.0 - cos_theta * cos_theta)); + // nor = nor * sin_theta + binor * cos_theta; + return nor; +} + void main() { #ifdef HAIR_SHADER @@ -54,29 +64,25 @@ void main() vec2 uv = hair_get_customdata_vec2(u); # endif float time, thick_time, thickness; - vec3 pos, tan, binor; + vec3 world_pos, tan, binor; hair_get_pos_tan_binor_time((ProjectionMatrix[3][3] == 0.0), ModelMatrixInverse, ViewMatrixInverse[3].xyz, ViewMatrixInverse[2].xyz, - pos, + world_pos, tan, binor, time, thickness, thick_time); - /* To "simulate" anisotropic shading, randomize hair normal per strand. */ + hair_rand = integer_noise(hair_get_strand_id()); - tan = normalize(tan); - vec3 nor = normalize(cross(binor, tan)); - nor = normalize(mix(nor, -tan, hair_rand * 0.10)); - float cos_theta = (hair_rand * 2.0 - 1.0) * 0.20; - float sin_theta = sqrt(max(0.0, 1.0f - cos_theta * cos_theta)); - nor = nor * sin_theta + binor * cos_theta; - gl_Position = ViewProjectionMatrix * vec4(pos, 1.0); + vec3 nor = workbench_hair_hair_normal(tan, binor, hair_rand); #else - gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); + vec3 world_pos = point_object_to_world(pos); #endif + gl_Position = point_world_to_ndc(world_pos); + #ifdef V3D_SHADING_TEXTURE_COLOR uv_interp = uv; #endif @@ -95,6 +101,6 @@ void main() #endif #ifdef USE_WORLD_CLIP_PLANES - world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz); + world_clip_planes_calc_clip_distance(world_pos); #endif } diff --git a/source/blender/draw/engines/workbench/shaders/workbench_shadow_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_shadow_vert.glsl index afd704a7d3a..85145a2dcdc 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_shadow_vert.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_shadow_vert.glsl @@ -1,6 +1,6 @@ #define INFINITE 1000.0 -uniform mat4 ModelViewProjectionMatrix; +uniform mat4 ModelMatrix; uniform vec3 lightDirection = vec3(0.57, 0.57, -0.57); uniform float lightDistance = 1e4; @@ -18,6 +18,6 @@ vData; void main() { vData.pos = pos; - vData.frontPosition = ModelViewProjectionMatrix * vec4(pos, 1.0); - vData.backPosition = ModelViewProjectionMatrix * vec4(pos + lightDirection * lightDistance, 1.0); + vData.frontPosition = point_object_to_ndc(pos); + vData.backPosition = point_object_to_ndc(pos + lightDirection * lightDistance); } diff --git a/source/blender/draw/engines/workbench/workbench_deferred.c b/source/blender/draw/engines/workbench/workbench_deferred.c index e0bf8da438b..bcce507da24 100644 --- a/source/blender/draw/engines/workbench/workbench_deferred.c +++ b/source/blender/draw/engines/workbench/workbench_deferred.c @@ -385,33 +385,60 @@ void workbench_deferred_engine_init(WORKBENCH_Data *vedata) const char *shadow_frag = datatoc_gpu_shader_depth_only_frag_glsl; #endif /* TODO only compile on demand */ - e_data.shadow_pass_sh = DRW_shader_create(datatoc_workbench_shadow_vert_glsl, - datatoc_workbench_shadow_geom_glsl, - shadow_frag, - "#define SHADOW_PASS\n" - "#define DOUBLE_MANIFOLD\n"); - e_data.shadow_pass_manifold_sh = DRW_shader_create(datatoc_workbench_shadow_vert_glsl, - datatoc_workbench_shadow_geom_glsl, - shadow_frag, - "#define SHADOW_PASS\n"); - e_data.shadow_fail_sh = DRW_shader_create(datatoc_workbench_shadow_vert_glsl, - datatoc_workbench_shadow_geom_glsl, - shadow_frag, - "#define SHADOW_FAIL\n" - "#define DOUBLE_MANIFOLD\n"); - e_data.shadow_fail_manifold_sh = DRW_shader_create(datatoc_workbench_shadow_vert_glsl, - datatoc_workbench_shadow_geom_glsl, - shadow_frag, - "#define SHADOW_FAIL\n"); - e_data.shadow_caps_sh = DRW_shader_create(datatoc_workbench_shadow_vert_glsl, - datatoc_workbench_shadow_caps_geom_glsl, - shadow_frag, - "#define SHADOW_FAIL\n" - "#define DOUBLE_MANIFOLD\n"); - e_data.shadow_caps_manifold_sh = DRW_shader_create(datatoc_workbench_shadow_vert_glsl, - datatoc_workbench_shadow_caps_geom_glsl, - shadow_frag, - "#define SHADOW_FAIL\n"); + e_data.shadow_pass_sh = GPU_shader_create_from_arrays({ + .vert = (const char *[]){datatoc_common_view_lib_glsl, + datatoc_workbench_shadow_vert_glsl, + NULL}, + .geom = (const char *[]){datatoc_workbench_shadow_geom_glsl, NULL}, + .frag = (const char *[]){shadow_frag, NULL}, + .defs = (const char *[]){"#define SHADOW_PASS\n" + "#define DOUBLE_MANIFOLD\n", + NULL}, + }); + e_data.shadow_pass_manifold_sh = GPU_shader_create_from_arrays({ + .vert = (const char *[]){datatoc_common_view_lib_glsl, + datatoc_workbench_shadow_vert_glsl, + NULL}, + .geom = (const char *[]){datatoc_workbench_shadow_geom_glsl, NULL}, + .frag = (const char *[]){shadow_frag, NULL}, + .defs = (const char *[]){"#define SHADOW_PASS\n", NULL}, + }); + e_data.shadow_fail_sh = GPU_shader_create_from_arrays({ + .vert = (const char *[]){datatoc_common_view_lib_glsl, + datatoc_workbench_shadow_vert_glsl, + NULL}, + .geom = (const char *[]){datatoc_workbench_shadow_geom_glsl, NULL}, + .frag = (const char *[]){shadow_frag, NULL}, + .defs = (const char *[]){"#define SHADOW_FAIL\n" + "#define DOUBLE_MANIFOLD\n", + NULL}, + }); + e_data.shadow_fail_manifold_sh = GPU_shader_create_from_arrays({ + .vert = (const char *[]){datatoc_common_view_lib_glsl, + datatoc_workbench_shadow_vert_glsl, + NULL}, + .geom = (const char *[]){datatoc_workbench_shadow_geom_glsl, NULL}, + .frag = (const char *[]){shadow_frag, NULL}, + .defs = (const char *[]){"#define SHADOW_FAIL\n", NULL}, + }); + e_data.shadow_caps_sh = GPU_shader_create_from_arrays({ + .vert = (const char *[]){datatoc_common_view_lib_glsl, + datatoc_workbench_shadow_vert_glsl, + NULL}, + .geom = (const char *[]){datatoc_workbench_shadow_caps_geom_glsl, NULL}, + .frag = (const char *[]){shadow_frag, NULL}, + .defs = (const char *[]){"#define SHADOW_FAIL\n" + "#define DOUBLE_MANIFOLD\n", + NULL}, + }); + e_data.shadow_caps_manifold_sh = GPU_shader_create_from_arrays({ + .vert = (const char *[]){datatoc_common_view_lib_glsl, + datatoc_workbench_shadow_vert_glsl, + NULL}, + .geom = (const char *[]){datatoc_workbench_shadow_caps_geom_glsl, NULL}, + .frag = (const char *[]){shadow_frag, NULL}, + .defs = (const char *[]){"#define SHADOW_FAIL\n", NULL}, + }); e_data.ghost_resolve_sh = DRW_shader_create_fullscreen( datatoc_workbench_ghost_resolve_frag_glsl, NULL); |