[Bf-blender-cvs] [ee7e4a7d95c] soc-2018-npr: Fixed snake line taper error induced by combined batch.
Nick Wu
noreply at git.blender.org
Thu Jun 7 08:59:02 CEST 2018
Commit: ee7e4a7d95c679cc58a0246f7c77c9b75c0221a5
Author: Nick Wu
Date: Thu Jun 7 14:45:47 2018 +0800
Branches: soc-2018-npr
https://developer.blender.org/rBee7e4a7d95c679cc58a0246f7c77c9b75c0221a5
Fixed snake line taper error induced by combined batch.
===================================================================
M source/blender/draw/engines/lanpr/lanpr_snake.c
M source/blender/draw/engines/lanpr/shaders/lanpr_line_connection.geometry
M source/blender/draw/engines/lanpr/shaders/lanpr_line_connection.vertex
===================================================================
diff --git a/source/blender/draw/engines/lanpr/lanpr_snake.c b/source/blender/draw/engines/lanpr/lanpr_snake.c
index 1e55545b552..f479a83f9d9 100644
--- a/source/blender/draw/engines/lanpr/lanpr_snake.c
+++ b/source/blender/draw/engines/lanpr/lanpr_snake.c
@@ -241,7 +241,7 @@ Gwn_Batch *lanpr_get_snake_batch(LANPR_PrivateData* pd){
//Index_adjacent = MEM_callocN(sizeof(unsigned int) * e_count, "Index_adjacent buffer pre alloc");
Verts = MEM_callocN(sizeof(float) * v_count * 2, "Verts buffer pre alloc");
- Lengths = MEM_callocN(sizeof(float)* v_count, "Length buffer pre alloc");
+ Lengths = MEM_callocN(sizeof(float)* v_count * 2, "Length buffer pre alloc");
Gwn_IndexBufBuilder elb;
GWN_indexbuf_init_ex(&elb, GWN_PRIM_LINES_ADJ, e_count, v_count, true);
@@ -261,17 +261,26 @@ Gwn_Batch *lanpr_get_snake_batch(LANPR_PrivateData* pd){
i = 0;
float xf,yf;
+ TotalLength=0;
for (lsp = (LANPR_LineStripPoint *)(ls->points.first); lsp; lsp = (LANPR_LineStripPoint *)(lsp->Item.next)) {
lanpr_texture_to_ndc(lsp->P[0],lsp->P[1],pd->width, pd->height, &xf,&yf);
Verts[vert_offset*2 + i * 2 + 0] = xf;
Verts[vert_offset*2 + i * 2 + 1] = yf;
if (plsp = (LANPR_LineStripPoint *)(lsp->Item.prev)) {
TotalLength += tMatDist2v(plsp->P, lsp->P);
- Lengths[vert_offset + i] = TotalLength;
+ Lengths[(vert_offset + i) * 2] = TotalLength;
}
i++;
}
+
ls->total_length = TotalLength;
+ i = 0;
+ for (lsp = (LANPR_LineStripPoint *)(ls->points.first); lsp; lsp = (LANPR_LineStripPoint *)(lsp->Item.next)) {
+ if (plsp = (LANPR_LineStripPoint *)(lsp->Item.prev)) {
+ Lengths[(vert_offset + i) * 2 + 1] = ls->total_length - Lengths[(vert_offset + i) * 2];
+ }
+ i++;
+ }
vert_offset+=(ls->point_count);
}
@@ -280,7 +289,7 @@ Gwn_Batch *lanpr_get_snake_batch(LANPR_PrivateData* pd){
static struct { uint pos, uvs; } attr_id;
if (format.attrib_ct == 0) {
attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
- attr_id.uvs = GWN_vertformat_attr_add(&format, "uvs", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+ attr_id.uvs = GWN_vertformat_attr_add(&format, "uvs", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
}
Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
@@ -288,7 +297,7 @@ Gwn_Batch *lanpr_get_snake_batch(LANPR_PrivateData* pd){
for (int i = 0; i < v_count; ++i) {
GWN_vertbuf_attr_set(vbo, attr_id.pos, i, &Verts[i*2]);
- GWN_vertbuf_attr_set(vbo, attr_id.uvs, i, &Lengths[i]);
+ GWN_vertbuf_attr_set(vbo, attr_id.uvs, i, &Lengths[i*2]);
}
MEM_freeN(Verts);
@@ -429,7 +438,7 @@ void lanpr_snake_draw_scene(LANPR_TextureList* txl, LANPR_FramebufferList * fbl,
psl->snake_pass = DRW_pass_create("Snake Visualization Pass", DRW_STATE_WRITE_COLOR);
pd->snake_shgrp = DRW_shgroup_create(OneTime.snake_connection_shader, psl->snake_pass);
DRW_shgroup_uniform_float(pd->snake_shgrp, "LineWidth", &lanpr->line_thickness, 1);
- DRW_shgroup_uniform_float(pd->snake_shgrp, "TotalLength", &ls->total_length, 1);
+ //DRW_shgroup_uniform_float(pd->snake_shgrp, "TotalLength", &ls->total_length, 1);
DRW_shgroup_uniform_float(pd->snake_shgrp, "TaperLDist", tld, 1);
DRW_shgroup_uniform_float(pd->snake_shgrp, "TaperLStrength", tls, 1);
DRW_shgroup_uniform_float(pd->snake_shgrp, "TaperRDist", lanpr->use_same_taper?tld:trd, 1);
diff --git a/source/blender/draw/engines/lanpr/shaders/lanpr_line_connection.geometry b/source/blender/draw/engines/lanpr/shaders/lanpr_line_connection.geometry
index cdc10c7c14e..d58d6aee819 100644
--- a/source/blender/draw/engines/lanpr/shaders/lanpr_line_connection.geometry
+++ b/source/blender/draw/engines/lanpr/shaders/lanpr_line_connection.geometry
@@ -1,10 +1,9 @@
layout (lines_adjacency) in;
layout (triangle_strip, max_vertices = 6) out;
-in float gOffset[];
+in vec2 gOffset[];
uniform float LineWidth;
-uniform float TotalLength;
uniform float TaperLDist;
uniform float TaperRDist;
uniform float TaperLStrength;
@@ -20,8 +19,8 @@ vec4 MakeLeftTaperLinear(vec4 L, vec4 a, float offset){
}
vec4 MakeRightTaperLinear(vec4 R, vec4 c, float offset){
- if((TotalLength-offset) >= TaperRDist) return c;
- c = mix(mix(c,R,TaperRStrength),c,(TotalLength-offset)/TaperRDist);
+ if(offset >= TaperRDist) return c;
+ c = mix(mix(c,R,TaperRStrength),c,offset/TaperRDist);
return c;
}
@@ -34,8 +33,10 @@ void main() {
R = gl_in[2].gl_Position,
RR = gl_in[3].gl_Position;
- float OffsetL = gOffset[1];
- float OffsetR = gOffset[2];
+ float OffsetL = gOffset[1].x;
+ float OffsetR = gOffset[2].x;
+ float OffsetL2 = gOffset[1].y;
+ float OffsetR2 = gOffset[2].y;
if(L==R || L==LL || R == RR || LL==RR || L==RR || R==LL) return;
@@ -51,32 +52,9 @@ void main() {
c = R - LineWidth * Normal*0.001;
d = R + LineWidth * Normal*0.001;
- //gl_Position = a;
- //EmitVertex();
- //gl_Position = b ;
- //EmitVertex();
- //gl_Position = c;
- //EmitVertex();
- //EndPrimitive();
- //
- //gl_Position = c;
- //EmitVertex();
- //gl_Position = d;
- //EmitVertex();
- //gl_Position = b;
- //EmitVertex();
- //EndPrimitive();
- //
- //
- //return;
-
float lim = LineWidth*0.002;
-
- if(LL == L){
- a = L - LineWidth * Normal*0.001;
- b = L + LineWidth * Normal*0.001;
- }else{
+ {
vec4 Tangent = normalize( normalize(L-LL)+normalize(R-L));
vec4 Minter = normalize(vec4(-Tangent.y,Tangent.x,0,0));
float length = LineWidth/(dot(Minter,Normal))*0.001;
@@ -85,10 +63,7 @@ void main() {
if(distance(a,b)>2*lim){ a = L - lim*Minter; b=L+lim*Minter;}
}
- if (R == RR){
- c = R - LineWidth * Normal*0.001;
- d = R + LineWidth * Normal*0.001;
- }else{
+ {
vec4 Tangent = normalize( normalize(RR-R)+normalize(R-L));
vec4 Minter = normalize(vec4(-Tangent.y,Tangent.x,0,0));
float length = LineWidth/(dot(Minter,Normal))*0.001;
@@ -97,17 +72,15 @@ void main() {
if(distance(c,d)>2*lim){ c = R - lim*Minter; d=R+lim*Minter;}
}
-
-
a = MakeLeftTaperLinear(L,a,OffsetL);
b = MakeLeftTaperLinear(L,b,OffsetL);
c = MakeLeftTaperLinear(R,c,OffsetR);
d = MakeLeftTaperLinear(R,d,OffsetR);
- a = MakeRightTaperLinear(L,a,OffsetL);
- b = MakeRightTaperLinear(L,b,OffsetL);
- c = MakeRightTaperLinear(R,c,OffsetR);
- d = MakeRightTaperLinear(R,d,OffsetR);
+ a = MakeRightTaperLinear(L,a,OffsetL2);
+ b = MakeRightTaperLinear(L,b,OffsetL2);
+ c = MakeRightTaperLinear(R,c,OffsetR2);
+ d = MakeRightTaperLinear(R,d,OffsetR2);
gl_Position = a;
EmitVertex();
diff --git a/source/blender/draw/engines/lanpr/shaders/lanpr_line_connection.vertex b/source/blender/draw/engines/lanpr/shaders/lanpr_line_connection.vertex
index 65575dc6496..3a1888561de 100644
--- a/source/blender/draw/engines/lanpr/shaders/lanpr_line_connection.vertex
+++ b/source/blender/draw/engines/lanpr/shaders/lanpr_line_connection.vertex
@@ -1,7 +1,7 @@
in vec2 pos;
-in float uvs;
+in vec2 uvs;
-out float gOffset;
+out vec2 gOffset;
void main(){
gl_Position = vec4(pos, 0.0, 1.0);
More information about the Bf-blender-cvs
mailing list