20 n[0] += (v_prev[1] - v_curr[1]) * (v_prev[2] + v_curr[2]);
21 n[1] += (v_prev[2] - v_curr[2]) * (v_prev[0] + v_curr[0]);
22 n[2] += (v_prev[0] - v_curr[0]) * (v_prev[1] + v_curr[1]);
29 bool q = (
dot(v1, v2) >= 0.0f);
30 float3 v = (q) ? (v1 - v2) : (v1 + v2);
32 return (q) ? a :
M_PI - a;
52 uint face_index, uint vertex_index, uint &curr, uint &next, uint &prev)
54 uint start_loop_index = face_index * 4;
56 for (uint i = 0; i < 4; i++) {
59 if (subdiv_vert_index == vertex_index) {
62 prev = (i + 4 - 1) % 4;
75 uint vertex_index = srt.get_global_invocation_index(global_id,
num_work_groups);
76 if (vertex_index >= srt.shader_data.total_dispatch_size) {
80 uint first_adjacent_face_offset = accum.face_adjacency_offsets[vertex_index];
81 uint number_of_adjacent_faces = accum.face_adjacency_offsets[vertex_index + 1] -
82 first_adjacent_face_offset;
87 for (uint i = 0; i < number_of_adjacent_faces; i++) {
88 uint adjacent_face = accum.face_adjacency_lists[first_adjacent_face_offset + i];
89 uint start_loop_index = adjacent_face * 4;
93 for (uint j = 0; j < 4; j++) [[
unroll]] {
94 StoredFloat3 data = accum.positions[start_loop_index + j];
108 accum.find_prev_and_next_vertex_on_face(
109 adjacent_face, vertex_index, curr_vert, next_vert, prev_vert);
111 float3 curr_co = verts[curr_vert];
112 float3 prev_co = verts[next_vert];
113 float3 next_co = verts[prev_vert];
118 float fac =
acos(-
dot(edvec_prev, edvec_next));
120 accumulated_normal += face_normal * fac;
135 float cosine =
dot(fa_no, fb_no);
137 float fac = (200 * (cosine - 1.0f)) + 1.0f;
139 return clamp(fac, 0.0f, 1.0f) * (254.0f / 255.0f);
155 if (quad_other == -1) {
160 const uint start_corner_index_other = uint(quad_other * 4);
180 const uint quad_index = srt.get_global_invocation_index(global_id,
num_work_groups);
181 if (quad_index >= srt.shader_data.total_dispatch_size) {
186 const uint start_loop_index = quad_index * 4;
189 StoredFloat3 f0 = edges.positions[start_loop_index + 0];
190 StoredFloat3 f1 = edges.positions[start_loop_index + 1];
191 StoredFloat3 f2 = edges.positions[start_loop_index + 2];
197 for (uint i = 0; i < 4; i++) {
198 edges.output_edge_fac[start_loop_index + i] = edges.compute_line_factor(start_loop_index + i,
222 const uint quad_index = srt.get_global_invocation_index(global_id,
num_work_groups);
223 if (quad_index >= srt.shader_data.total_dispatch_size) {
228 uint start_loop_index = quad_index * 4;
230 uint coarse_quad_index = poly_ofs.coarse_face_index_from_subdiv_quad_index(
231 quad_index, uint(srt.shader_data.coarse_face_count));
233 for (uint i = 0; i < 4; i++) [[
unroll]] {
234 edit.subdiv_stretch_area[start_loop_index + i] = edit.coarse_stretch_area[coarse_quad_index];
251 const uint quad_index = srt.get_global_invocation_index(global_id,
num_work_groups);
252 if (quad_index >= srt.shader_data.total_dispatch_size) {
256 uint start_loop_index = quad_index * 4;
258 for (uint i = 0; i < 4; i++) {
259 uint cur_loop_index = start_loop_index + i;
260 uint next_loop_index = start_loop_index + (i + 1) % 4;
261 uint prev_loop_index = start_loop_index + (i + 3) % 4;
264 float2 cur_uv = edit.uvs[uint(srt.shader_data.src_offset) + cur_loop_index];
265 float2 next_uv = edit.uvs[uint(srt.shader_data.src_offset) + next_loop_index];
266 float2 prev_uv = edit.uvs[uint(srt.shader_data.src_offset) + prev_loop_index];
272 StoredFloat3 curr_data = edit.positions[cur_loop_index];
273 StoredFloat3 next_data = edit.positions[next_loop_index];
274 StoredFloat3 prev_data = edit.positions[prev_loop_index];
289 edit.uv_stretches[cur_loop_index] = stretch;
315 const uint quad_index = srt.get_global_invocation_index(global_id,
num_work_groups);
316 if (quad_index >= srt.shader_data.total_dispatch_size) {
321 const uint start_loop_index = quad_index * 4;
323 const uint coarse_quad_index = poly_ofs.coarse_face_index_from_subdiv_quad_index(
324 quad_index, uint(srt.shader_data.coarse_face_count));
326 if ((lnors.extra_coarse_face_data[coarse_quad_index] &
327 srt.shader_data.coarse_face_smooth_mask) != 0)
330 for (uint i = 0; i < 4u; i++) [[
unroll]] {
331 const uint subdiv_vert_index = lnors.vert_loop_map[start_loop_index + i];
332 lnors.output_lnor[start_loop_index + i] = lnors.vert_normals[subdiv_vert_index];
336 StoredFloat3 f0 = lnors.positions[start_loop_index + 0];
337 StoredFloat3 f1 = lnors.positions[start_loop_index + 1];
338 StoredFloat3 f2 = lnors.positions[start_loop_index + 2];
339 StoredFloat3 f3 = lnors.positions[start_loop_index + 3];
353 for (uint i = 0; i < 4; i++) [[
unroll]] {
354 lnors.output_lnor[start_loop_index + i] = normal;
408 const uint quad_index = srt.get_global_invocation_index(global_id,
num_work_groups);
409 if (quad_index >= srt.shader_data.total_dispatch_size) {
414 const uint start_loop_index = quad_index * 4;
416 const uint coarse_quad_index = poly_ofs.coarse_face_index_from_subdiv_quad_index(
417 quad_index, uint(srt.shader_data.coarse_face_count));
418 for (uint i = 0; i < 4; i++) [[
unroll]] {
419 int origindex = paint.input_vert_origindex[start_loop_index + i];
420 int flag = paint.get_loop_flag(coarse_quad_index, origindex);
422 paint.flags[start_loop_index + i] = flag;
445 const uint quad_index = srt.get_global_invocation_index(global_id,
num_work_groups);
446 if (quad_index >= srt.shader_data.total_dispatch_size) {
450 const uint start_loop_index = quad_index * 4;
452 for (uint loop_index = start_loop_index; loop_index < start_loop_index + 4; loop_index++) {
454 .face_set_color = sculpt.face_set_color[loop_index],
458 if (srt.shader_data.has_sculpt_mask) {
459 data.mask = sculpt.mask[loop_index];
462 sculpt.data_buf[loop_index] = data;
StoredFloat4 as_data(float4 interp)
float4 load_data(StoredFloat4 data)
#define LOOP_NORMALS_POS_SLOT
#define LOOP_NORMALS_VERT_NORMALS_BUF_SLOT
#define EDGE_FAC_EDGE_FAC_BUF_SLOT
#define NORMALS_ACCUMULATE_POS_BUF_SLOT
#define PAINT_OVERLAY_EXTRA_INPUT_VERT_ORIG_INDEX_SLOT
#define LOOP_NORMALS_OUTPUT_LNOR_BUF_SLOT
#define SCULPT_DATA_SCULPT_DATA_BUF_SLOT
#define STRETCH_ANGLE_UV_STRETCHES_BUF_SLOT
#define NORMALS_ACCUMULATE_FACE_ADJACENCY_LISTS_BUF_SLOT
#define EDGE_FAC_POS_BUF_SLOT
#define EDGE_FAC_POLY_OTHER_MAP_BUF_SLOT
#define SUBDIV_GROUP_SIZE
#define NORMALS_ACCUMULATE_NORMALS_BUF_SLOT
#define SCULPT_DATA_SCULPT_FACE_SET_COLOR_BUF_SLOT
#define LOOP_NORMALS_EXTRA_COARSE_FACE_DATA_BUF_SLOT
#define SCULPT_DATA_SCULPT_MASK_BUF_SLOT
#define PAINT_OVERLAY_EXTRA_COARSE_FACE_DATA_BUF_SLOT
#define EDGE_FAC_EDGE_DRAW_FLAG_BUF_SLOT
#define STRETCH_ANGLE_POS_BUF_SLOT
#define STRETCH_AREA_COARSE_STRETCH_AREA_BUF_SLOT
#define NORMALS_ACCUMULATE_VERTEX_LOOP_MAP_BUF_SLOT
#define STRETCH_AREA_SUBDIV_STRETCH_AREA_BUF_SLOT
#define NORMALS_ACCUMULATE_FACE_ADJACENCY_OFFSETS_BUF_SLOT
#define LOOP_NORMALS_VERTEX_LOOP_MAP_BUF_SLOT
#define PAINT_OVERLAY_OUTPUT_FLAG_SLOT
#define STRETCH_ANGLE_UVS_BUF_SLOT
#define storage(slot, qualifiers)
#define global_invocation_id
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
constexpr T clamp(T, U, U) RET
float length(VecOp< float, D >) RET
float loop_edge_factor_get(float3 fa_no, float3 fb_no)
void sculpt_data_main(const SubdivResources &srt, SculptResources &sculpt, const uint3 global_id, const uint3 num_work_groups)
void normals_accumulate_main(const SubdivResources &srt, NormalAccumulate &accum, const uint3 global_id, const uint3 num_work_groups)
void edituv_stretch_area_main(const SubdivResources &srt, const PolygonOffsetBase &poly_ofs, EditUVStretchArea &edit, const uint3 global_id, const uint3 num_work_groups)
void edituv_stretch_angle_main(const SubdivResources &srt, EditUVStretchAngle &edit, const uint3 global_id, const uint3 num_work_groups)
void paint_overlay_flag_main(const SubdivResources &srt, const PolygonOffsetBase &poly_ofs, PaintResource &paint, const uint3 global_id, const uint3 num_work_groups)
PipelineCompute loop_normals(loop_normals_main)
PipelineCompute edge_fac(edge_fac_main)
void write(AttribInterp &res, uint dst_offset, uint index, const T value)
T read(const AttribInterp &res, uint index)
void loop_normals_main(const SubdivResources &srt, const PolygonOffsetBase &poly_ofs, LoopNormalsResource &lnors, const uint3 global_id, const uint3 num_work_groups)
void add_newell_cross_v3_v3v3(float3 &n, float3 v_prev, float3 v_curr)
float angle_normalized_v3v3(float3 v1, float3 v2)
PipelineCompute sculpt_data(sculpt_data_main)
PipelineCompute normals_accumulate(normals_accumulate_main)
PipelineCompute edituv_stretch_area(edituv_stretch_area_main)
PipelineCompute edituv_stretch_angle(edituv_stretch_angle_main)
void edge_fac_main(const SubdivResources &srt, EdgeFac &edges, const uint3 global_id, const uint3 num_work_groups)
PipelineCompute paint_overlay_flag(paint_overlay_flag_main)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
uint coarse_face_select_mask
uint coarse_face_hidden_mask
const DRWSubdivUboStorage shader_data
int(& input_poly_other_map)[]
uint(& input_edge_draw_flag)[]
float compute_line_factor(uint corner_index, float3 face_normal)
float(& output_edge_fac)[]
StoredFloat3(& positions)[]
UVStretchAngle(& uv_stretches)[]
StoredFloat3(& positions)[]
float(& subdiv_stretch_area)[]
float(& coarse_stretch_area)[]
StoredFloat3(& vert_normals)[]
StoredFloat3(& positions)[]
uint(& extra_coarse_face_data)[]
StoredFloat3(& output_lnor)[]
StoredFloat3(& vert_normals)[]
void find_prev_and_next_vertex_on_face(uint face_index, uint vertex_index, uint &curr, uint &next, uint &prev)
StoredFloat3(& positions)[]
uint(& face_adjacency_offsets)[]
uint(& face_adjacency_lists)[]
int get_loop_flag(uint coarse_quad_index, int vert_origindex)
const SubdivResources & srt
uint(& extra_coarse_face_data)[]
int(& input_vert_origindex)[]
bool is_face_hidden(uint coarse_quad_index)
bool is_face_selected(uint coarse_quad_index)