[Bf-blender-cvs] [6bcc28b] alembic: Support for shading "normals" in strand rendering.

Lukas Tönne noreply at git.blender.org
Tue Mar 31 12:23:56 CEST 2015


Commit: 6bcc28b8ab51bf44e8a4e14ebe1c4b91ace3ffd8
Author: Lukas Tönne
Date:   Tue Mar 31 12:21:49 2015 +0200
Branches: alembic
https://developer.blender.org/rB6bcc28b8ab51bf44e8a4e14ebe1c4b91ace3ffd8

Support for shading "normals" in strand rendering.

Note that the fixed-function OpenGL pipeline does not support true
strand normals. The shading model used copies the method implemented for
particles, using the edge directions as normals. This is totally
unphysical but at least gives some indication of direction. Viewport
refactor and programmable shaders are needed to make this work nicer.

===================================================================

M	source/blender/blenkernel/BKE_strands.h
M	source/blender/blenkernel/intern/strands.c
M	source/blender/editors/space_view3d/drawstrands.c
M	source/blender/pointcache/alembic/abc_particles.cpp

===================================================================

diff --git a/source/blender/blenkernel/BKE_strands.h b/source/blender/blenkernel/BKE_strands.h
index 513407a..ec361b2 100644
--- a/source/blender/blenkernel/BKE_strands.h
+++ b/source/blender/blenkernel/BKE_strands.h
@@ -25,11 +25,17 @@ typedef struct StrandsVertex {
 	float co[3];
 	float time;
 	float weight;
+	
+	/* utility data */
+	float nor[3]; /* normals (edge directions) */
 } StrandsVertex;
 
 typedef struct StrandsMotionState {
 	float co[3];
 	float vel[3];
+	
+	/* utility data */
+	float nor[3]; /* normals (edge directions) */
 } StrandsMotionState;
 
 typedef struct StrandsCurve {
@@ -50,6 +56,8 @@ void BKE_strands_free(struct Strands *strands);
 
 void BKE_strands_add_motion_state(struct Strands *strands);
 
+void BKE_strands_ensure_normals(struct Strands *strands);
+
 /* ------------------------------------------------------------------------- */
 
 typedef struct StrandIterator {
diff --git a/source/blender/blenkernel/intern/strands.c b/source/blender/blenkernel/intern/strands.c
index 51e9ee2..21244ec 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -18,6 +18,8 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_math.h"
+
 #include "BKE_strands.h"
 
 Strands *BKE_strands_new(int curves, int verts)
@@ -30,6 +32,9 @@ Strands *BKE_strands_new(int curves, int verts)
 	s->totverts = verts;
 	s->verts = MEM_mallocN(sizeof(StrandsVertex) * verts, "strand vertices");
 	
+	/* must be added explicitly */
+	s->state = NULL;
+	
 	return s;
 }
 
@@ -50,3 +55,36 @@ void BKE_strands_add_motion_state(Strands *strands)
 		strands->state = MEM_mallocN(sizeof(StrandsMotionState) * strands->totverts, "strand motion states");
 	}
 }
+
+static void calc_normals(Strands *strands, bool use_motion_state)
+{
+	StrandIterator it_strand;
+	for (BKE_strand_iter_init(&it_strand, strands); BKE_strand_iter_valid(&it_strand); BKE_strand_iter_next(&it_strand)) {
+		StrandVertexIterator it_vert;
+		BKE_strand_vertex_iter_init(&it_vert, &it_strand);
+		
+		if (BKE_strand_vertex_iter_valid(&it_vert)) {
+			const float *co_prev = use_motion_state ? it_vert.state->co : it_vert.vertex->co;
+			
+			BKE_strand_vertex_iter_next(&it_vert);
+			
+			for (; BKE_strand_vertex_iter_valid(&it_vert); BKE_strand_vertex_iter_next(&it_vert)) {
+				const float *co = use_motion_state ? it_vert.state->co : it_vert.vertex->co;
+				float *nor = use_motion_state ? it_vert.state->nor : it_vert.vertex->nor;
+				
+				sub_v3_v3v3(nor, co, co_prev);
+				normalize_v3(nor);
+			}
+		}
+	}
+}
+
+void BKE_strands_ensure_normals(Strands *strands)
+{
+	const bool use_motion_state = (strands->state);
+	
+	calc_normals(strands, false);
+	
+	if (use_motion_state)
+		calc_normals(strands, true);
+}
diff --git a/source/blender/editors/space_view3d/drawstrands.c b/source/blender/editors/space_view3d/drawstrands.c
index ccc5d67..5627d0d 100644
--- a/source/blender/editors/space_view3d/drawstrands.c
+++ b/source/blender/editors/space_view3d/drawstrands.c
@@ -59,7 +59,7 @@ static void draw_strand_lines(Strands *strands, short dflag)
 	glEnableClientState(GL_VERTEX_ARRAY);
 	
 	/* setup gl flags */
-//	glEnableClientState(GL_NORMAL_ARRAY);
+	glEnableClientState(GL_NORMAL_ARRAY);
 	
 	if ((dflag & DRAW_CONSTCOLOR) == 0) {
 //		if (part->draw_col == PART_DRAW_COL_MAT)
@@ -67,7 +67,7 @@ static void draw_strand_lines(Strands *strands, short dflag)
 	}
 	
 	glColor3f(1,1,1);
-//	glEnable(GL_LIGHTING);
+	glEnable(GL_LIGHTING);
 //	glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
 //	glEnable(GL_COLOR_MATERIAL);
 	
@@ -76,7 +76,7 @@ static void draw_strand_lines(Strands *strands, short dflag)
 			continue;
 		
 		glVertexPointer(3, GL_FLOAT, sizeof(StrandsVertex), it_strand.verts->co);
-//		glNormalPointer(GL_FLOAT, sizeof(StrandsVertex), it_strand.verts->nor);
+		glNormalPointer(GL_FLOAT, sizeof(StrandsVertex), it_strand.verts->nor);
 		if ((dflag & DRAW_CONSTCOLOR) == 0) {
 //			if (part->draw_col == PART_DRAW_COL_MAT) {
 //				glColorPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->col);
@@ -89,6 +89,7 @@ static void draw_strand_lines(Strands *strands, short dflag)
 	/* restore & clean up */
 //	if (part->draw_col == PART_DRAW_COL_MAT)
 //		glDisableClientState(GL_COLOR_ARRAY);
+	glDisable(GL_LIGHTING);
 	glDisable(GL_COLOR_MATERIAL);
 	
 	glLineWidth(1.0f);
diff --git a/source/blender/pointcache/alembic/abc_particles.cpp b/source/blender/pointcache/alembic/abc_particles.cpp
index 01c24bc..65e8a0a 100644
--- a/source/blender/pointcache/alembic/abc_particles.cpp
+++ b/source/blender/pointcache/alembic/abc_particles.cpp
@@ -439,6 +439,8 @@ PTCReadSampleResult AbcStrandsReader::read_sample(float frame)
 		}
 	}
 	
+	BKE_strands_ensure_normals(m_strands);
+	
 	return PTC_READ_SAMPLE_EXACT;
 }




More information about the Bf-blender-cvs mailing list