Permalink
Browse files

Fix show 'some' edges when in smooth proxy

  • Loading branch information...
1 parent 1b293b7 commit 223d86248e2a6da59ca7fd0df84d2f230fd3c3be @dgud committed Mar 17, 2011
Showing with 98 additions and 30 deletions.
  1. +47 −2 shaders/cc_subdiv.cl
  2. +1 −0 src/wings.hrl
  3. +30 −16 src/wings_cc.erl
  4. +20 −12 src/wings_proxy.erl
View
@@ -217,7 +217,7 @@ __kernel void gen_edges(__global float4 *VsIn,
int F11=-1,F12=-1,F21=-1,F22=-1, CCW1,CCW2;
const int oe_id = edge_id*4;
// Be sure to create faces with the correct order
- if(edge.z >= 0) { // Edge is in a hole
+ if(edge.z >= 0) { // Edge is not in a hole
FaceIndex IF1 = FiIn[edge.z];
find_faces(edge.x,edge.y,IF1,FsIn,&F11,&F12,&CCW1);
e.x = ov_id; e.y = noVs+edge.z; e.z = F11; e.w = F12;
@@ -232,7 +232,7 @@ __kernel void gen_edges(__global float4 *VsIn,
} else {
EsOut[oe_id+0] = hole_edge;
}
- if(edge.w >= 0) { // Edge is in a hole
+ if(edge.w >= 0) { // Edge is not in a hole
FaceIndex IF2 = FiIn[edge.w];
find_faces(edge.x,edge.y,IF2,FsIn,&F21,&F22,&CCW2);
e.x = ov_id; e.y = noVs+edge.w; e.z = F21; e.w = F22;
@@ -630,6 +630,51 @@ __kernel void get_sel_col_uv(
}
}
+// ---------------- Gen Edges ----------------------------
+__kernel void gen_some_edges(__global int4 *EsIn,
+ __global float4 *VsIn,
+ __global ccfloat3 *VsOut,
+ uint level,
+ const uint noEs)
+{
+ const int edge_id = get_global_id(0);
+ if (edge_id >= noEs)
+ return;
+ ccfloat3 v1, v2;
+ float4 temp;
+ int4 edge;
+ float p;
+ uint in;
+
+ // The edges we want are at 2,3, 6,7, 10,11 ... at level = 1
+ // and at 10,11, 14,15, 26,27 ... at level = 2
+ // and at 42,43, 46,47, 58,59 ... at level = 3
+
+ p = edge_id/pown(2.0f, level);
+ in = convert_uint_rtz(p);
+ while(level > 0) {
+ p *= 2.0f;
+ in = in*4 + 2 + (convert_uint_rtz(p) % 2);
+ level--;
+ }
+ edge = EsIn[in];
+ if(edge.y < 0 || edge.w < 0 || edge.z < 0) {
+ // Indicates hole edge hide it far away
+ v1.x = MAXFLOAT;
+ v1.y = MAXFLOAT;
+ v1.z = MAXFLOAT;
+ v2 = v1;
+ } else {
+ temp = VsIn[edge.x];
+ float4_to_ccfloat3(temp, &v1);
+ temp = VsIn[edge.y];
+ float4_to_ccfloat3(temp, &v2);
+ }
+ VsOut[edge_id*2+0] = v1;
+ VsOut[edge_id*2+1] = v2;
+}
+
+// ---------------- Normal calculation --------------------
__kernel void clearf(__global float *mem,
const int isz,
const int sz)
View
@@ -312,6 +312,7 @@
face_sn = none :: wings_vtx_buffer(), %Face Normals (smooth)
face_uv = none :: wings_vtx_buffer(), %UV coords
face_vc = none :: wings_vtx_buffer(), %Vertex Colors coords
+ face_es = none :: wings_vtx_buffer(), %Edges 2*Vertex coords
face_map = none, %FaceId -> {BinPos,TriCount}
mat_map = none %Face per Material draw info
}).
View
@@ -147,7 +147,7 @@ gen_vab_1(Plan, Data, Base) ->
opencl -> create_vab(gen_vab_2(Plan, Data, Base), Base)
end.
-create_vab({Vs, SNs0, Attrs0, MatInfo}, #base{type=Type}) ->
+create_vab({Vs, SNs0, Attrs0, Edges, MatInfo}, #base{type=Type}) ->
Ns = case Vs of
<<>> -> Vs;
<<_:3/unit:32,NsP/bytes>> ->
@@ -175,7 +175,7 @@ create_vab({Vs, SNs0, Attrs0, MatInfo}, #base{type=Type}) ->
{5*4, UVBin};
_ -> none
end,
- #vab{face_vs={S,Vs},face_fn={S,Ns},
+ #vab{face_vs={S,Vs},face_fn={S,Ns}, face_es=Edges,
face_sn=SNs, face_vc=Colors, face_uv=UVs,
mat_map=MatInfo}.
@@ -492,28 +492,21 @@ subdiv_1(N,
subdiv_1(_C, ResultBuffs, OutBuffs, _, _, Wait) ->
#cc_cache{mem=ResultBuffs, old=OutBuffs, wait=Wait}.
-gen_vab_2(#cc_cache{mem=Mem,old=Old,wait=Wait}, B=#base{n=NoFs,type=Type}) ->
+gen_vab_2(#cc_cache{mem=Mem,old=Old,wait=Wait}, B=#base{n=NoFs,level=N,type=Type}) ->
#cls{cl=CL, vab=Vab} = cl_setup(),
%% Create #vab{}
- #cl_mem{v=Vs, f=Fs, as=As} = Mem,
+ #cl_mem{v=Vs, f=Fs, e=Es, e_no=NoEs, as=As} = Mem,
WVab = wings_cl:cast(create_vab_all,[Vs,Fs,Vab,NoFs], NoFs, Wait,CL),
- Attrs = case attrs(Type) of
- {plain,_} -> <<>>;
- {_, Sz} ->
- AData = wings_cl:read(As,NoFs*4*Sz,Wait,CL),
- {ok, A0} = cl:wait(AData),
- A0;
- _ ->
- <<>>
- end,
+ Attrs = gen_attrs(attrs(Type), As, NoFs, Wait, CL),
+ Edges = gen_edges([Es, Vs, As, N, NoEs], Wait, CL),
WData = wings_cl:read(Vab,NoFs*4*6*4,[WVab],CL),
{ok, VabBin} = cl:wait(WData),
Smooth = gen_smooth_normals(Vab, NoFs, Mem, Old, [WVab], CL),
[cl:release_event(Ev) || Ev <- [WVab,WData|Wait]],
cl_release(Mem, true),
cl_release(Old, false),
- {VabBin, Smooth, Attrs, B#base.mmap}.
+ {VabBin, Smooth, Attrs, Edges, B#base.mmap}.
gen_vab_2({_Type, MatFs},
#cc_cache{mem=Mem, wait=Wait0, old=Old},
@@ -548,9 +541,9 @@ gen_vab_2({_Type, MatFs},
[cl:release_event(Ev) || Ev <- [WVab,W1|Wait]],
cl_release(Mem, true),
cl_release(Old, false),
- {VabBin, <<>>, Attrs, MatI};
+ {VabBin, <<>>, Attrs, none, MatI};
false ->
- {<<>>, <<>>, <<>>, []}
+ {<<>>, <<>>, <<>>, none, []}
end.
mat_index([{Mat,Fs}|MFs], Fun, Acc0 = [Start|_], MI) ->
@@ -561,6 +554,27 @@ mat_index([{Mat,Fs}|MFs], Fun, Acc0 = [Start|_], MI) ->
mat_index([], _, [Total|Bin], MatInfo) ->
{Total, Bin, MatInfo}.
+gen_attrs({plain,_}, _As, _Sz, _Wait, _CL) -> <<>>;
+gen_attrs({_,Sz}, As, NoFs, Wait, CL) ->
+ AData = wings_cl:read(As,NoFs*4*Sz,Wait,CL),
+ {ok, A0} = cl:wait(AData),
+ A0.
+
+gen_edges(Args, Wait, CL) ->
+ Type = wings_pref:get_value(proxy_shaded_edge_style),
+ gen_edges(Type, Args, Wait, CL).
+gen_edges(all, _Args, _Wait, _CL) -> none;
+gen_edges(cage, _Args, _Wait, _CL) -> none;
+gen_edges(some, [Es,Vs,As,N,TotNoEs], Wait, CL) ->
+ Ediv = trunc(math:pow(4,N)),
+ EMul = trunc(math:pow(2,N)),
+ NoEs = EMul * (TotNoEs div Ediv),
+ Args = [Es,Vs,As,N,NoEs],
+ EWait0 = wings_cl:cast(gen_some_edges, Args, NoEs, Wait, CL),
+ EWait1 = wings_cl:read(As, NoEs*2*3*4, [EWait0], CL),
+ {ok, EsBin} = cl:wait(EWait1),
+ {0, EsBin}.
+
gen_smooth_normals(Vab, NoFs,
#cl_mem{f=Fs,e=Es,e_no=NoEs,v=VsNs,v_no=NoVs,as=Out1},
#cl_mem{v=Vs,as=Out2}, Wait, CL) ->
View
@@ -152,6 +152,26 @@ update_edges(D, Pd) ->
update_edges_1(D, Pd, wings_pref:get_value(proxy_shaded_edge_style)).
update_edges_1(_, _, cage) -> none;
+update_edges_1(_, #sp{vab=#vab{face_vs=BinVs,face_fn=Ns,mat_map=MatMap}}, all) ->
+ wings_draw_setup:enableVertexPointer(BinVs),
+ wings_draw_setup:enableNormalPointer(Ns),
+ Dl = gl:genLists(1),
+ gl:newList(Dl, ?GL_COMPILE),
+ [{_Mat,_Type,Start,MCount}|_] = MatMap,
+ Count = Start+MCount,
+ gl:drawArrays(?GL_QUADS, 0, Count),
+ gl:endList(),
+ wings_draw_setup:disableVertexPointer(BinVs),
+ wings_draw_setup:disableNormalPointer(Ns),
+ Dl;
+update_edges_1(#dlo{}, #sp{type={wings_cc,_}, vab=#vab{face_es={0,Bin}}}, some) ->
+ Dl = gl:genLists(1),
+ gl:newList(Dl, ?GL_COMPILE),
+ gl:enableClientState(?GL_VERTEX_ARRAY),
+ wings_draw:drawVertices(?GL_LINES, Bin),
+ gl:disableClientState(?GL_VERTEX_ARRAY),
+ gl:endList(),
+ Dl;
update_edges_1(#dlo{src_we=#we{vp=OldVtab}}, #sp{we=#we{vp=Vtab,es=Etab}=We}, some) ->
Dl = gl:genLists(1),
gl:newList(Dl, ?GL_COMPILE),
@@ -174,18 +194,6 @@ update_edges_1(#dlo{src_we=#we{vp=OldVtab}}, #sp{we=#we{vp=Vtab,es=Etab}=We}, so
wings_draw:drawVertices(?GL_LINES, Bin),
gl:disableClientState(?GL_VERTEX_ARRAY),
gl:endList(),
- Dl;
-update_edges_1(_, #sp{vab=#vab{face_vs=BinVs,face_fn=Ns,mat_map=MatMap}}, all) ->
- wings_draw_setup:enableVertexPointer(BinVs),
- wings_draw_setup:enableNormalPointer(Ns),
- Dl = gl:genLists(1),
- gl:newList(Dl, ?GL_COMPILE),
- [{_Mat,_Type,Start,MCount}|_] = MatMap,
- Count = Start+MCount,
- gl:drawArrays(?GL_QUADS, 0, Count),
- gl:endList(),
- wings_draw_setup:disableVertexPointer(BinVs),
- wings_draw_setup:disableNormalPointer(Ns),
Dl.
smooth(D=#dlo{proxy=false},_) -> D;

0 comments on commit 223d862

Please sign in to comment.