Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_view3d/drawvolume.c')
-rw-r--r--source/blender/editors/space_view3d/drawvolume.c108
1 files changed, 92 insertions, 16 deletions
diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c
index ef3627e2b12..3c80441b9e6 100644
--- a/source/blender/editors/space_view3d/drawvolume.c
+++ b/source/blender/editors/space_view3d/drawvolume.c
@@ -119,6 +119,51 @@
#include "view3d_intern.h" // own include
+
+#ifdef _WIN32
+#include <time.h>
+#include <stdio.h>
+#include <conio.h>
+#include <windows.h>
+
+static LARGE_INTEGER liFrequency;
+static LARGE_INTEGER liStartTime;
+static LARGE_INTEGER liCurrentTime;
+
+static void tstart ( void )
+{
+ QueryPerformanceFrequency ( &liFrequency );
+ QueryPerformanceCounter ( &liStartTime );
+}
+static void tend ( void )
+{
+ QueryPerformanceCounter ( &liCurrentTime );
+}
+static double tval()
+{
+ return ((double)( (liCurrentTime.QuadPart - liStartTime.QuadPart)* (double)1000.0/(double)liFrequency.QuadPart ));
+}
+#else
+#include <sys/time.h>
+static struct timeval _tstart, _tend;
+static struct timezone tz;
+static void tstart ( void )
+{
+ gettimeofday ( &_tstart, &tz );
+}
+static void tend ( void )
+{
+ gettimeofday ( &_tend,&tz );
+}
+static double tval()
+{
+ double t1, t2;
+ t1 = ( double ) _tstart.tv_sec*1000 + ( double ) _tstart.tv_usec/ ( 1000 );
+ t2 = ( double ) _tend.tv_sec*1000 + ( double ) _tend.tv_usec/ ( 1000 );
+ return t2-t1;
+}
+#endif
+
struct GPUTexture;
int intersect_edges(float *points, float a, float b, float c, float d, float edges[12][2][3])
@@ -172,8 +217,8 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture
RegionView3D *rv3d= ar->regiondata;
float viewnormal[3];
- int i, j, n;
- float d, d0, dd;
+ int i, j, n, good_index;
+ float d, d0, dd, ds;
float *points = NULL;
int numpoints = 0;
float cor[3] = {1.,1.,1.};
@@ -227,6 +272,8 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture
float size[3];
+ tstart();
+
VECSUB(size, max, min);
// maxx, maxy, maxz
@@ -279,6 +326,7 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture
VECCOPY(edges[11][0], cv[5]); // minx, maxy, minz
// printf("size x: %f, y: %f, z: %f\n", size[0], size[1], size[2]);
+ // printf("min[2]: %f, max[2]: %f\n", min[2], max[2]);
edges[0][1][2] = size[2];
edges[1][1][2] = size[2];
@@ -306,6 +354,13 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ /*
+ printf("Viewinv:\n");
+ printf("%f, %f, %f\n", rv3d->viewinv[0][0], rv3d->viewinv[0][1], rv3d->viewinv[0][2]);
+ printf("%f, %f, %f\n", rv3d->viewinv[1][0], rv3d->viewinv[1][1], rv3d->viewinv[1][2]);
+ printf("%f, %f, %f\n", rv3d->viewinv[2][0], rv3d->viewinv[2][1], rv3d->viewinv[2][2]);
+ */
+
// get view vector
VECCOPY(viewnormal, rv3d->viewinv[2]);
Normalize(viewnormal);
@@ -314,9 +369,9 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture
for (i=0; i<8; i++) {
float x,y,z;
- x = cv[i][0] + viewnormal[0];
- y = cv[i][1] + viewnormal[1];
- z = cv[i][2] + viewnormal[2];
+ x = cv[i][0] - viewnormal[0];
+ y = cv[i][1] - viewnormal[1];
+ z = cv[i][2] - viewnormal[2];
if ((x>=min[0])&&(x<=max[0])
&&(y>=min[1])&&(y<=max[1])
@@ -326,6 +381,7 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture
}
// printf("i: %d\n", i);
+ // printf("point %f, %f, %f\n", cv[i][0], cv[i][1], cv[i][2]);
if (GL_TRUE == glewIsSupported("GL_ARB_fragment_program"))
{
@@ -349,7 +405,7 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture
else
printf("No volume shadow\n");
- if (!GLEW_ARB_texture_non_power_of_two) {
+ if (!GPU_non_power_of_two_support()) {
cor[0] = (float)res[0]/(float)larger_pow2(res[0]);
cor[1] = (float)res[1]/(float)larger_pow2(res[1]);
cor[2] = (float)res[2]/(float)larger_pow2(res[2]);
@@ -359,19 +415,35 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture
// (a,b,c), the plane normal, are given by viewdir
// d is the parameter along the view direction. the first d is given by
// inserting previously found vertex into the plane equation
- d0 = -(viewnormal[0]*cv[i][0] + viewnormal[1]*cv[i][1] + viewnormal[2]*cv[i][2]);
- dd = 2.0*d0/64.0f;
+ d0 = (viewnormal[0]*cv[i][0] + viewnormal[1]*cv[i][1] + viewnormal[2]*cv[i][2]);
+ ds = (ABS(viewnormal[0])*size[0] + ABS(viewnormal[1])*size[1] + ABS(viewnormal[2])*size[2]);
+ dd = 0.05; // ds/512.0f;
n = 0;
+ good_index = i;
- // printf("d0: %f, dd: %f\n", d0, dd);
+ // printf("d0: %f, dd: %f, ds: %f\n\n", d0, dd, ds);
points = MEM_callocN(sizeof(float)*12*3, "smoke_points_preview");
- for (d = d0; d > -d0; d -= dd) {
+ while(1) {
float p0[3];
+ float tmp_point[3], tmp_point2[3];
+
+ if(dd*(float)n > ds)
+ break;
+
+ VECCOPY(tmp_point, viewnormal);
+ VecMulf(tmp_point, -dd*((ds/dd)-(float)n));
+ VECADD(tmp_point2, cv[good_index], tmp_point);
+ d = INPR(tmp_point2, viewnormal);
+
+ // printf("my d: %f\n", d);
+
// intersect_edges returns the intersection points of all cube edges with
// the given plane that lie within the cube
- numpoints = intersect_edges(points, viewnormal[0], viewnormal[1], viewnormal[2], d, edges);
+ numpoints = intersect_edges(points, viewnormal[0], viewnormal[1], viewnormal[2], -d, edges);
+
+ // printf("points: %d\n", numpoints);
if (numpoints > 2) {
VECCOPY(p0, points);
@@ -381,19 +453,20 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture
{
for(j = i + 1; j < numpoints; j++)
{
- if(convex(p0, viewnormal, &points[j * 3], &points[i * 3]))
+ if(!convex(p0, viewnormal, &points[j * 3], &points[i * 3]))
{
float tmp2[3];
- VECCOPY(tmp2, &points[i * 3]);
- VECCOPY(&points[i * 3], &points[j * 3]);
- VECCOPY(&points[j * 3], tmp2);
+ VECCOPY(tmp2, &points[j * 3]);
+ VECCOPY(&points[j * 3], &points[i * 3]);
+ VECCOPY(&points[i * 3], tmp2);
}
}
}
+ // printf("numpoints: %d\n", numpoints);
glBegin(GL_POLYGON);
+ glColor3f(1.0, 1.0, 1.0);
for (i = 0; i < numpoints; i++) {
- glColor3f(1.0, 1.0, 1.0);
glTexCoord3d((points[i * 3 + 0] - min[0] )*cor[0]/size[0], (points[i * 3 + 1] - min[1])*cor[1]/size[1], (points[i * 3 + 2] - min[2])*cor[2]/size[2]);
glVertex3f(points[i * 3 + 0], points[i * 3 + 1], points[i * 3 + 2]);
}
@@ -402,6 +475,9 @@ void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture
n++;
}
+ tend();
+ printf ( "Draw Time: %f\n",( float ) tval() );
+
if(tex_shadow)
GPU_texture_unbind(tex_shadow);
GPU_texture_unbind(tex);