Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/shaders/common_hair_lib.glsl
| Show First 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | float hair_shaperadius(float shape, float root, float tip, float time) | ||||
| return (radius * (root - tip)) + tip; | return (radius * (root - tip)) + tip; | ||||
| } | } | ||||
| # if defined(OS_MAC) && defined(GPU_OPENGL) | # if defined(OS_MAC) && defined(GPU_OPENGL) | ||||
| in float dummy; | in float dummy; | ||||
| # endif | # endif | ||||
| void hair_get_pos_tan_binor_time(bool is_persp, | void hair_get_center_pos_tan_binor_time(bool is_persp, | ||||
| mat4 invmodel_mat, | mat4 invmodel_mat, | ||||
| vec3 camera_pos, | vec3 camera_pos, | ||||
| vec3 camera_z, | vec3 camera_z, | ||||
| out vec3 wpos, | out vec3 wpos, | ||||
| out vec3 wtan, | out vec3 wtan, | ||||
| out vec3 wbinor, | out vec3 wbinor, | ||||
| out float time, | out float time, | ||||
| out float thickness, | out float thickness) | ||||
| out float thick_time) | |||||
| { | { | ||||
| int id = hair_get_base_id(); | int id = hair_get_base_id(); | ||||
| vec4 data = texelFetch(hairPointBuffer, id); | vec4 data = texelFetch(hairPointBuffer, id); | ||||
| wpos = data.point_position; | wpos = data.point_position; | ||||
| time = data.point_time; | time = data.point_time; | ||||
| # if defined(OS_MAC) && defined(GPU_OPENGL) | # if defined(OS_MAC) && defined(GPU_OPENGL) | ||||
| /* Generate a dummy read to avoid the driver bug with shaders having no | /* Generate a dummy read to avoid the driver bug with shaders having no | ||||
| Show All 12 Lines | # endif | ||||
| mat4 obmat = hairDupliMatrix; | mat4 obmat = hairDupliMatrix; | ||||
| wpos = (obmat * vec4(wpos, 1.0)).xyz; | wpos = (obmat * vec4(wpos, 1.0)).xyz; | ||||
| wtan = -normalize(mat3(obmat) * wtan); | wtan = -normalize(mat3(obmat) * wtan); | ||||
| vec3 camera_vec = (is_persp) ? camera_pos - wpos : camera_z; | vec3 camera_vec = (is_persp) ? camera_pos - wpos : camera_z; | ||||
| wbinor = normalize(cross(camera_vec, wtan)); | wbinor = normalize(cross(camera_vec, wtan)); | ||||
| thickness = hair_shaperadius(hairRadShape, hairRadRoot, hairRadTip, time); | thickness = hair_shaperadius(hairRadShape, hairRadRoot, hairRadTip, time); | ||||
| } | |||||
| void hair_get_pos_tan_binor_time(bool is_persp, | |||||
| mat4 invmodel_mat, | |||||
| vec3 camera_pos, | |||||
| vec3 camera_z, | |||||
| out vec3 wpos, | |||||
| out vec3 wtan, | |||||
| out vec3 wbinor, | |||||
| out float time, | |||||
| out float thickness, | |||||
| out float thick_time) | |||||
| { | |||||
| hair_get_center_pos_tan_binor_time( | |||||
| is_persp, invmodel_mat, camera_pos, camera_z, wpos, wtan, wbinor, time, thickness); | |||||
| if (hairThicknessRes > 1) { | if (hairThicknessRes > 1) { | ||||
| thick_time = float(gl_VertexID % hairThicknessRes) / float(hairThicknessRes - 1); | thick_time = float(gl_VertexID % hairThicknessRes) / float(hairThicknessRes - 1); | ||||
| thick_time = thickness * (thick_time * 2.0 - 1.0); | thick_time = thickness * (thick_time * 2.0 - 1.0); | ||||
| /* Take object scale into account. | /* Take object scale into account. | ||||
| * NOTE: This only works fine with uniform scaling. */ | * NOTE: This only works fine with uniform scaling. */ | ||||
| float scale = 1.0 / length(mat3(invmodel_mat) * wbinor); | float scale = 1.0 / length(mat3(invmodel_mat) * wbinor); | ||||
| wpos += wbinor * thick_time * scale; | wpos += wbinor * thick_time * scale; | ||||
| } | } | ||||
| else { | else { | ||||
| /* NOTE: Ensures 'hairThickTime' is initialized - | /* NOTE: Ensures 'hairThickTime' is initialized - | ||||
| * avoids undefined behavior on certain macOS configurations. */ | * avoids undefined behavior on certain macOS configurations. */ | ||||
| thick_time = 0.0; | thick_time = 0.0; | ||||
| } | } | ||||
| } | } | ||||
fclem: I would rename the function `hair_get_pos_tan_binor_time_no_expand` and move this block to… | |||||
| float hair_get_customdata_float(const samplerBuffer cd_buf) | float hair_get_customdata_float(const samplerBuffer cd_buf) | ||||
| { | { | ||||
| int id = hair_get_strand_id(); | int id = hair_get_strand_id(); | ||||
| return texelFetch(cd_buf, id).r; | return texelFetch(cd_buf, id).r; | ||||
| } | } | ||||
| vec2 hair_get_customdata_vec2(const samplerBuffer cd_buf) | vec2 hair_get_customdata_vec2(const samplerBuffer cd_buf) | ||||
| ▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines | |||||
I would rename the function hair_get_pos_tan_binor_time_no_expand and move this block to hair_get_pos_tan_binor_time. This would remove the need to rename wpos to orig_wpos.